Class McpProxyTool

java.lang.Object
com.tnsai.server.tools.McpProxyTool

public final class McpProxyTool extends Object
Factory + dispatcher for MCP proxy tools.

An MCP proxy tool forwards LLM tool calls to an MCP server reachable through the CLI WebSocket: when the LLM calls the tool, this dispatcher emits an WsProtocol.ServerEvent.McpCall event and parks a CompletableFuture keyed by toolCallId. The CLI executes the call against the real MCP server and replies with an WsProtocol.ClientEvent.McpResult, which WsHandler routes back here via completeCall(String, String, String).

toDynamicToolMethod(java.lang.String, java.lang.String, java.util.Map<java.lang.String, java.lang.Object>, java.lang.String, java.lang.String, com.tnsai.server.ws.WsConnectionManager) produces a DynamicToolMethod suitable for passing to AgentBuilder.dynamicTool(DynamicToolMethod).

Pre-0.7.0 this class implemented the legacy Tool interface. The function- shape POJO migration (RFC #188) finished in v0.7.0 by removing Tool entirely; MCP proxies join the runtime through the same ToolMethod abstraction as every other tool, with a callback rather than a reflected method.

Since:
0.7.0 (rewritten — was implements Tool in 0.6.0 and earlier)
  • Method Details

    • toDynamicToolMethod

      public static com.tnsai.tools.method.DynamicToolMethod toDynamicToolMethod(String name, String description, Map<String,Object> inputSchema, String serverName, String sessionId, WsConnectionManager connectionManager)
      Build a DynamicToolMethod fronting an MCP-server tool.
      Parameters:
      name - MCP tool name (e.g. "read_file")
      description - human-readable description
      inputSchema - JSON Schema describing expected parameters (used as the tool's DynamicToolMethod.parametersSchema())
      serverName - MCP server name (e.g. "filesystem")
      sessionId - owning WebSocket session
      connectionManager - for broadcasting events to the CLI
      Returns:
      a registry-ready dynamic tool
    • completeCall

      public static void completeCall(String toolCallId, String result, String error)
      Completes a pending MCP tool call with the result from the CLI.
      Parameters:
      toolCallId - unique call identifier
      result - the tool result (may be null on error)
      error - error message (null on success)
    • cancelAll

      public static void cancelAll()
      Cancels all pending MCP calls. Called during shutdown or session cleanup.
    • getPendingCount

      public static int getPendingCount()
      Returns the number of pending MCP calls (for monitoring/testing).