Class McpServerResource
- All Implemented Interfaces:
McpServerComponent<io.modelcontextprotocol.server.McpServerFeatures.SyncResourceSpecification>
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:
-
McpResourceMcpSchema.ResourceMcpSchema.ResourceContents
-
Field Summary
Fields inherited from class com.github.thought2code.mcp.annotated.server.component.McpServerComponentBase
mcpSyncServer -
Constructor Summary
ConstructorsConstructorDescriptionMcpServerResource(io.modelcontextprotocol.server.McpSyncServer mcpSyncServer) Constructs a newMcpServerResourcewith the specified MCP server. -
Method Summary
Methods inherited from class com.github.thought2code.mcp.annotated.server.component.McpServerComponentBase
localizeAttribute
-
Constructor Details
-
McpServerResource
public McpServerResource(io.modelcontextprotocol.server.McpSyncServer mcpSyncServer) Constructs a newMcpServerResourcewith 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
McpResourceand creates aMcpServerFeatures.SyncResourceSpecificationthat 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 withMcpResourceto create a specification from- Returns:
- a synchronous resource specification for the MCP server
- See Also:
-
McpResourceMcpSchema.ResourceMcpSchema.Annotations
-
register
public void register()Registers all resource components with the MCP server.This method scans for all methods annotated with
McpResourceand registers them as resource components with the MCP server. It uses reflection to discover annotated methods and creates resource specifications for each method.
-