Class McpServerTool
- All Implemented Interfaces:
McpServerComponent<io.modelcontextprotocol.server.McpServerFeatures.SyncToolSpecification>
This class extends McpServerComponentBase and implements the functionality for
creating and registering tool components with an MCP server. It processes methods annotated with
McpTool and creates appropriate tool specifications that can be used to execute
operations for LLM interactions.
The class handles:
- Creation of tool specifications from annotated methods
- Registration of all tool components with the server
- Invocation of tool methods with proper argument conversion
- JSON schema generation for input parameters and output types
- Support for both text and structured content responses
- Localization of tool attributes using resource bundles
- Author:
- codeboyzhou
- See Also:
-
McpToolMcpToolParamMcpJsonSchemaDefinitionMcpJsonSchemaPropertyMcpSchema.ToolMcpSchema.JsonSchemaMcpStructuredContent
-
Field Summary
Fields inherited from class com.github.thought2code.mcp.annotated.server.component.McpServerComponentBase
mcpSyncServer -
Constructor Summary
ConstructorsConstructorDescriptionMcpServerTool(io.modelcontextprotocol.server.McpSyncServer mcpSyncServer) Constructs a newMcpServerToolwith the specified MCP server. -
Method Summary
Methods inherited from class com.github.thought2code.mcp.annotated.server.component.McpServerComponentBase
localizeAttribute
-
Constructor Details
-
McpServerTool
public McpServerTool(io.modelcontextprotocol.server.McpSyncServer mcpSyncServer) Constructs a newMcpServerToolwith the specified MCP server.- Parameters:
mcpSyncServer- the MCP synchronous server to use for tool registration
-
-
Method Details
-
from
Creates a synchronous tool specification from the specified method.This method processes a method annotated with
McpTooland creates aMcpServerFeatures.SyncToolSpecificationthat can be registered with the MCP server. The method extracts tool information from annotations and method signature, generates JSON schemas for input parameters and output types, and creates a tool specification with appropriate metadata. -
register
public void register()Registers all tool components with the MCP server.This method scans for all methods annotated with
McpTooland registers them as tool components with the MCP server. It uses reflection to discover annotated methods and creates tool specifications for each method.
-