spring-projects / spring-projects/spring-ai

MCP Server Response Result Consistency Optimization

Open
#5,240 1 comment 0 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 10h
Merged PRs (30d)
5

Description

Issue: MCP Server Tool Result Serialization Uses Wrong ObjectMapper

Expected Behavior

MCP server tool results should use the Spring-configured ObjectMapper for serialization.

Current Behavior

MCP server tool result serialization uses the static OBJECT_MAPPER from org.springaicommunity.mcp.method.tool.utils.JsonParser instead of the configured mcpServerObjectMapper. This causes tool responses to contain null fields instead of excluding them as configured.

Context

I am using Spring AI MCP Server with SSE transport. I have configured a custom ObjectMapper bean with NON_NULL inclusion, but tool results still contain null fields.

The issue appears to be in the serialization path when converting tool method return values to CallToolResult content. The JsonParser utility class uses its own static ObjectMapper that doesn't respect my Spring configuration.

I need clean JSON responses without null fields for client consumption. Current workarounds involve manual null filtering in each tool method, which is not maintainable.

The requested fix is to either make the tool result serialization use the configured mcpServerObjectMapper, or ensure org.springaicommunity.mcp.method.tool.utils.JsonParser OBJECT_MAPPER configuration matches the server configuration.

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 with org.springaicommunity.mcp.method.tool.utils.JsonParser and trace the serialization path that converts tool return values into CallToolResult content. Compare its static OBJECT_MAPPER with the configured mcpServerObjectMapper; done means tool results honor the server's NON_NULL configuration without requiring manual filtering in each tool method.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.