java.lang.Object
com.github.thought2code.mcp.annotated.server.component.McpServerComponentBase<io.modelcontextprotocol.server.McpServerFeatures.SyncResourceSpecification>
com.github.thought2code.mcp.annotated.server.component.McpServerResource
All Implemented Interfaces:
McpServerComponent<io.modelcontextprotocol.server.McpServerFeatures.SyncResourceSpecification>

public class McpServerResource extends McpServerComponentBase<io.modelcontextprotocol.server.McpServerFeatures.SyncResourceSpecification>
MCP server component for handling resource-related operations.

This class extends McpServerComponentBase and implements the functionality for creating and registering resource components with an MCP server. It processes methods annotated with McpResource and creates appropriate resource specifications that can be used to expose data to LLM interactions.

The class handles:

  • Creation of resource specifications from annotated methods
  • Registration of all resource components with the server
  • Invocation of resource methods to retrieve data
  • Localization of resource attributes using resource bundles
Author:
codeboyzhou
See Also:
  • McpResource
  • McpSchema.Resource
  • McpSchema.ResourceContents
  • Constructor Details

    • McpServerResource

      public McpServerResource(io.modelcontextprotocol.server.McpSyncServer mcpSyncServer)
      Constructs a new McpServerResource with the specified MCP server.
      Parameters:
      mcpSyncServer - the MCP synchronous server to use for resource registration
  • Method Details

    • from

      public io.modelcontextprotocol.server.McpServerFeatures.SyncResourceSpecification from(Method method)
      Creates a synchronous resource specification from the specified method.

      This method processes a method annotated with McpResource and creates a McpServerFeatures.SyncResourceSpecification that can be registered with the MCP server. The method extracts resource information from annotations and method signature, and builds a resource specification with appropriate metadata.

      Parameters:
      method - the method annotated with McpResource to create a specification from
      Returns:
      a synchronous resource specification for the MCP server
      See Also:
    • register

      public void register()
      Registers all resource components with the MCP server.

      This method scans for all methods annotated with McpResource and registers them as resource components with the MCP server. It uses reflection to discover annotated methods and creates resource specifications for each method.