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

public class McpServerTool extends McpServerComponentBase<io.modelcontextprotocol.server.McpServerFeatures.SyncToolSpecification>
MCP server component for handling tool-related operations.

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:
  • Constructor Details

    • McpServerTool

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

    • from

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

      This method processes a method annotated with McpTool and creates a McpServerFeatures.SyncToolSpecification that 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.

      Parameters:
      method - the method annotated with McpTool to create a specification from
      Returns:
      a synchronous tool specification for the MCP server
      See Also:
      • McpTool
      • McpSchema.Tool
      • McpSchema.JsonSchema
    • register

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

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