Class McpSchemaConverter
java.lang.Object
org.springframework.ai.mcp.modern.McpSchemaConverter
Converts between the legacy (
io.modelcontextprotocol.spec.McpSchema) and the
modern (io.modelcontextprotocol.modern.McpSchema) schema types.
Both type hierarchies serialize to the same JSON shapes, so the conversion is a
mapper-based round trip. Modern-only fields such as resultType, ttlMs
and cacheScope take their default values. This is what allows annotated methods
and ToolCallbacks written against the legacy types to be served by a 2026-07-28
server without changes.
- Since:
- 2.1.0
- Author:
- Christian Tzolov
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TConverts any JSON-compatible value to the given target type using the default MCP JSON mapper.static io.modelcontextprotocol.spec.McpSchema.CallToolRequesttoLegacy(io.modelcontextprotocol.modern.McpSchema.CallToolRequest request) Builds the legacy request a handler expects from a moderntools/callrequest.static io.modelcontextprotocol.spec.McpSchema.CompleteRequesttoLegacy(io.modelcontextprotocol.modern.McpSchema.CompleteRequest request) static io.modelcontextprotocol.spec.McpSchema.GetPromptRequesttoLegacy(io.modelcontextprotocol.modern.McpSchema.GetPromptRequest request) static io.modelcontextprotocol.spec.McpSchema.ReadResourceRequesttoLegacy(io.modelcontextprotocol.modern.McpSchema.ReadResourceRequest request) static io.modelcontextprotocol.modern.McpExceptiontoModern(io.modelcontextprotocol.spec.McpError error) Converts a legacy protocol error into its modern counterpart so that it is answered with the same JSON-RPC error code and data.static io.modelcontextprotocol.modern.McpSchema.CallToolResulttoModern(io.modelcontextprotocol.spec.McpSchema.CallToolResult result) static io.modelcontextprotocol.modern.McpSchema.CompleteReferencetoModern(io.modelcontextprotocol.spec.McpSchema.CompleteReference reference) static io.modelcontextprotocol.modern.McpSchema.CompleteResulttoModern(io.modelcontextprotocol.spec.McpSchema.CompleteResult result) static io.modelcontextprotocol.modern.McpSchema.GetPromptResulttoModern(io.modelcontextprotocol.spec.McpSchema.GetPromptResult result) static io.modelcontextprotocol.modern.McpSchema.PrompttoModern(io.modelcontextprotocol.spec.McpSchema.Prompt prompt) static io.modelcontextprotocol.modern.McpSchema.ReadResourceResulttoModern(io.modelcontextprotocol.spec.McpSchema.ReadResourceResult result) static io.modelcontextprotocol.modern.McpSchema.ResourcetoModern(io.modelcontextprotocol.spec.McpSchema.Resource resource) static io.modelcontextprotocol.modern.McpSchema.ResourceTemplatetoModern(io.modelcontextprotocol.spec.McpSchema.ResourceTemplate resourceTemplate) static io.modelcontextprotocol.modern.McpSchema.TooltoModern(io.modelcontextprotocol.spec.McpSchema.Tool tool)
-
Method Details
-
convert
Converts any JSON-compatible value to the given target type using the default MCP JSON mapper.- Type Parameters:
T- the target type- Parameters:
source- the value to converttargetType- the type to convert to- Returns:
- the converted value
-
toModern
public static io.modelcontextprotocol.modern.McpSchema.CallToolResult toModern(io.modelcontextprotocol.spec.McpSchema.CallToolResult result) -
toModern
public static io.modelcontextprotocol.modern.McpSchema.ReadResourceResult toModern(io.modelcontextprotocol.spec.McpSchema.ReadResourceResult result) -
toModern
public static io.modelcontextprotocol.modern.McpSchema.GetPromptResult toModern(io.modelcontextprotocol.spec.McpSchema.GetPromptResult result) -
toModern
public static io.modelcontextprotocol.modern.McpSchema.CompleteResult toModern(io.modelcontextprotocol.spec.McpSchema.CompleteResult result) -
toModern
public static io.modelcontextprotocol.modern.McpSchema.Tool toModern(io.modelcontextprotocol.spec.McpSchema.Tool tool) -
toModern
public static io.modelcontextprotocol.modern.McpSchema.Resource toModern(io.modelcontextprotocol.spec.McpSchema.Resource resource) -
toModern
public static io.modelcontextprotocol.modern.McpSchema.ResourceTemplate toModern(io.modelcontextprotocol.spec.McpSchema.ResourceTemplate resourceTemplate) -
toModern
public static io.modelcontextprotocol.modern.McpSchema.Prompt toModern(io.modelcontextprotocol.spec.McpSchema.Prompt prompt) -
toModern
public static io.modelcontextprotocol.modern.McpSchema.CompleteReference toModern(io.modelcontextprotocol.spec.McpSchema.CompleteReference reference) -
toModern
public static io.modelcontextprotocol.modern.McpException toModern(io.modelcontextprotocol.spec.McpError error) Converts a legacy protocol error into its modern counterpart so that it is answered with the same JSON-RPC error code and data.- Parameters:
error- the legacy error- Returns:
- the modern exception
-
toLegacy
public static io.modelcontextprotocol.spec.McpSchema.CallToolRequest toLegacy(io.modelcontextprotocol.modern.McpSchema.CallToolRequest request) Builds the legacy request a handler expects from a moderntools/callrequest. The MRTR fields (inputResponses,requestState) have no legacy counterpart and are dropped; handlers that need them take the modern request. -
toLegacy
public static io.modelcontextprotocol.spec.McpSchema.ReadResourceRequest toLegacy(io.modelcontextprotocol.modern.McpSchema.ReadResourceRequest request) -
toLegacy
public static io.modelcontextprotocol.spec.McpSchema.GetPromptRequest toLegacy(io.modelcontextprotocol.modern.McpSchema.GetPromptRequest request) -
toLegacy
public static io.modelcontextprotocol.spec.McpSchema.CompleteRequest toLegacy(io.modelcontextprotocol.modern.McpSchema.CompleteRequest request)
-