Skip to content

Commit 333ca17

Browse files
committed
feat: refactor ObjectMapper configuration to use McpServerObjectMapperFactory
Signed-off-by: liugddx <[email protected]>
1 parent 327cd93 commit 333ca17

File tree

3 files changed

+2
-32
lines changed

3 files changed

+2
-32
lines changed

auto-configurations/mcp/spring-ai-autoconfigure-mcp-server-common/src/main/java/org/springframework/ai/mcp/server/common/autoconfigure/McpServerAutoConfiguration.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@
2121
import java.util.function.BiConsumer;
2222
import java.util.function.BiFunction;
2323

24-
import com.fasterxml.jackson.annotation.JsonInclude;
25-
import com.fasterxml.jackson.databind.DeserializationFeature;
2624
import com.fasterxml.jackson.databind.ObjectMapper;
27-
import com.fasterxml.jackson.databind.SerializationFeature;
28-
import com.fasterxml.jackson.databind.json.JsonMapper;
2925
import io.modelcontextprotocol.json.jackson.JacksonMcpJsonMapper;
3026
import io.modelcontextprotocol.server.McpAsyncServer;
3127
import io.modelcontextprotocol.server.McpAsyncServerExchange;
@@ -54,7 +50,6 @@
5450

5551
import org.springframework.ai.mcp.server.common.autoconfigure.properties.McpServerChangeNotificationProperties;
5652
import org.springframework.ai.mcp.server.common.autoconfigure.properties.McpServerProperties;
57-
import org.springframework.ai.util.JacksonUtils;
5853
import org.springframework.beans.factory.ObjectProvider;
5954
import org.springframework.boot.autoconfigure.AutoConfiguration;
6055
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -114,18 +109,7 @@ public class McpServerAutoConfiguration {
114109
@Bean(name = "mcpServerObjectMapper")
115110
@ConditionalOnMissingBean(name = "mcpServerObjectMapper")
116111
public ObjectMapper mcpServerObjectMapper() {
117-
return JsonMapper.builder()
118-
// Deserialization configuration
119-
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
120-
.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)
121-
// Serialization configuration
122-
.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
123-
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
124-
.serializationInclusion(JsonInclude.Include.NON_NULL)
125-
// Register standard modules (Jdk8, JavaTime, ParameterNames, Kotlin if
126-
// available)
127-
.addModules(JacksonUtils.instantiateAvailableModules())
128-
.build();
112+
return McpServerObjectMapperFactory.createObjectMapper();
129113
}
130114

131115
@Bean

auto-configurations/mcp/spring-ai-autoconfigure-mcp-server-common/src/main/java/org/springframework/ai/mcp/server/common/autoconfigure/McpServerObjectMapperFactory.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,8 @@
4545
* <li><b>Jackson Modules:</b> Registers standard modules for Java 8, JSR-310, parameter
4646
* names, and Kotlin (if available)</li>
4747
* </ul>
48-
* <p>
49-
* This factory was introduced to fix Issue #4451 where @McpTool annotated methods failed
50-
* to load with STDIO protocol due to JSON serialization errors caused by using an
51-
* unconfigured ObjectMapper instance.
5248
*
5349
* @author Spring AI Team
54-
* @see <a href="https://github.com/spring-projects/spring-ai/issues/4451">Issue #4451</a>
5550
*/
5651
public final class McpServerObjectMapperFactory {
5752

auto-configurations/mcp/spring-ai-autoconfigure-mcp-server-common/src/test/java/org/springframework/ai/mcp/server/common/autoconfigure/McpToolWithStdioIT.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@
4141

4242
/**
4343
* Integration tests for @McpTool annotations with STDIO transport.
44-
* <p>
45-
* This test verifies the fix for Issue #4451 where @McpTool annotated methods failed to
46-
* load when using STDIO protocol due to JSON serialization issues with unconfigured
47-
* ObjectMapper.
48-
*
49-
* @see <a href="https://github.com/spring-projects/spring-ai/issues/4451">Issue #4451</a>
5044
*/
5145
public class McpToolWithStdioIT {
5246

@@ -92,10 +86,7 @@ void stdioTransportShouldUseConfiguredObjectMapper() {
9286

9387
/**
9488
* Verifies that @McpTool annotated methods are successfully registered with STDIO
95-
* transport.
96-
* <p>
97-
* This is the core test for Issue #4451 - it ensures that tool specifications
98-
* generated from @McpTool annotations can be properly serialized to JSON without
89+
* transport and that tool specifications can be properly serialized to JSON without
9990
* errors.
10091
*/
10192
@Test

0 commit comments

Comments
 (0)