spring-projects / spring-projects/spring-ai

Unable to specify custom Jackson object mapper when using @McpTool

Open
#4,479 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

Bug description
When using the @McpTool annotation, it is currently not possible via the Spring AI public API to use any Jackson configuration other than McpJsonMapper.createDefault(). This behavior is hardcoded in SyncMcpToolProvider (and other subclasses of AbstractMcpToolProvider). While AbstractMcpToolProvider does provide a method setJsonMapper, these providers are not spring beans and cannot be configured as such. To the best of my knowledge I cannot get a reference to a tool provider during the autoconfiguration process to call that setter.

Environment
Spring AI 1.1.0-M2
OpenJDK 21

Steps to reproduce
Configure a non-standard jackson object mapper for spring MVC:

@Configuration
public class JsonConfig {

    @Bean
    public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
         // configure properties here...
    }

}

Expected behavior
Spring AI should use the same jackson object mapper as spring MVC. Creating multiple instances of ObjectMapper is possible, but discouraged by the jackson team.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading SyncMcpToolProvider and AbstractMcpToolProvider, then trace the @McpTool autoconfiguration path to determine where the provider receives its JSON mapper. Done means a configured Spring MVC ObjectMapper can be used through the public API instead of always using McpJsonMapper.createDefault().

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.