Class McpProxyTool
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 Toolin 0.6.0 and earlier)
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidCancels all pending MCP calls.static voidcompleteCall(String toolCallId, String result, String error) Completes a pending MCP tool call with the result from the CLI.static intReturns the number of pending MCP calls (for monitoring/testing).static com.tnsai.tools.method.DynamicToolMethodtoDynamicToolMethod(String name, String description, Map<String, Object> inputSchema, String serverName, String sessionId, WsConnectionManager connectionManager) Build aDynamicToolMethodfronting an MCP-server tool.
-
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 aDynamicToolMethodfronting an MCP-server tool.- Parameters:
name- MCP tool name (e.g."read_file")description- human-readable descriptioninputSchema- JSON Schema describing expected parameters (used as the tool'sDynamicToolMethod.parametersSchema())serverName- MCP server name (e.g."filesystem")sessionId- owning WebSocket sessionconnectionManager- for broadcasting events to the CLI- Returns:
- a registry-ready dynamic tool
-
completeCall
Completes a pending MCP tool call with the result from the CLI.- Parameters:
toolCallId- unique call identifierresult- 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).
-