Class SyncModernMcpResourceMethodCallback

java.lang.Object
org.springframework.ai.mcp.annotation.method.resource.AbstractMcpResourceMethodCallback
org.springframework.ai.mcp.annotation.method.resource.SyncModernMcpResourceMethodCallback
All Implemented Interfaces:
io.modelcontextprotocol.modern.server.feature.McpSyncResource.Handler

public final class SyncModernMcpResourceMethodCallback extends AbstractMcpResourceMethodCallback implements io.modelcontextprotocol.modern.server.feature.McpSyncResource.Handler
Serves a resources/read of a 2026-07-28 ("modern") MCP server by invoking a method annotated with @McpResource.

Beyond the parameters the stateless callback supports, a method may declare McpModernSyncRequestContext, the SDK McpRequestContext, McpSyncNotifier or the modern McpSchema.ReadResourceRequest (which carries the MRTR fields). A method that declares the notifier is served as a streaming response so that progress notifications can be pushed before the result; the context alone leaves the response a plain result.

The method may return a modern McpSchema.ReadResourceOutcome (a ReadResourceResult, possibly with cache hints, or an InputRequiredResult) or any of the legacy return types, which are converted. A converted legacy result carries the ttlMs() and cacheScope() hints configured on the callback (from @McpResource); a modern result is passed through untouched and its own hints win.

Since:
2.1.0
Author:
Christian Tzolov
  • Method Details

    • isModernInfrastructureParameter

      public static boolean isModernInfrastructureParameter(Class<?> parameterType)
      Whether a parameter of this type is injected by the modern callback rather than bound from the request URI.
    • isStreaming

      public boolean isStreaming()
    • ttlMs

      public long ttlMs()
      The ttlMs cache hint applied to converted legacy results.
    • cacheScope

      public io.modelcontextprotocol.modern.McpSchema.CacheScope cacheScope()
      The cacheScope cache hint applied to converted legacy results.
    • read

      public io.modelcontextprotocol.modern.server.McpSyncResponse<io.modelcontextprotocol.modern.McpSchema.ReadResourceOutcome> read(io.modelcontextprotocol.modern.server.McpRequestContext context, io.modelcontextprotocol.modern.McpSchema.ReadResourceRequest request)
      Specified by:
      read in interface io.modelcontextprotocol.modern.server.feature.McpSyncResource.Handler
    • validateMethod

      protected void validateMethod(Method method)
      Description copied from class: AbstractMcpResourceMethodCallback
      Validates that the method signature is compatible with the resource callback.

      This method checks that the return type is valid and that the parameters match the expected pattern based on whether URI variables are present.

      Overrides:
      validateMethod in class AbstractMcpResourceMethodCallback
      Parameters:
      method - The method to validate
    • validateReturnType

      protected void validateReturnType(Method method)
      Description copied from class: AbstractMcpResourceMethodCallback
      Validates that the method return type is compatible with the resource callback. This method should be implemented by subclasses to handle specific return type validation.
      Specified by:
      validateReturnType in class AbstractMcpResourceMethodCallback
      Parameters:
      method - The method to validate
    • assignExchangeType

      protected Object assignExchangeType(Class<?> paramType, Object exchange)
      Specified by:
      assignExchangeType in class AbstractMcpResourceMethodCallback
    • isExchangeOrContextType

      protected boolean isExchangeOrContextType(Class<?> paramType)
      Description copied from class: AbstractMcpResourceMethodCallback
      Checks if a parameter type is compatible with the exchange type. This method should be implemented by subclasses to handle specific exchange type checking.
      Specified by:
      isExchangeOrContextType in class AbstractMcpResourceMethodCallback
      Parameters:
      paramType - The parameter type to check
      Returns:
      true if the parameter type is compatible with the exchange type, false otherwise
    • builder