feat: add MCP server endpoint for dynamic tool discovery and invocation#123
feat: add MCP server endpoint for dynamic tool discovery and invocation#123syn-zhu wants to merge 1 commit intokagent-dev:mainfrom
Conversation
2b876c1 to
326a8ef
Compare
Add a Streamable HTTP MCP server endpoint to the kmcp controller, enabling agents to dynamically discover, introspect, and invoke tools on any MCPServer in the cluster at runtime. This mirrors the pattern already established by kagent-controller's A2A MCP endpoint (list_agents / invoke_agent) but for MCP server interactions. New tools exposed at :8083/mcp: - list_mcp_servers: List MCPServer CRs (name, namespace, status, port) - list_tools: Connect to a specific MCPServer and return its tool catalog - call_tool: Invoke a specific tool on a specific MCPServer Includes: - MCP handler with session caching and automatic reconnection - HTTP server wrapper implementing manager.Runnable - --mcp-bind-address flag (default :8083, set to 0 to disable) - Helm chart updates (values, deployment port, MCP service) - Comprehensive unit tests (18 test cases) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Simon Zhu <simon.zhu@mongodb.com>
326a8ef to
5446928
Compare
|
Hey there, I really love this idea, but I think we should put this in |
Lemme take a look, just need to remind myself; the kagent controller already knows about RemoteMCPServers? If so then yeah, i think that makes sense |
Adds three new MCP tools to the kagent-controller's existing MCP endpoint at :8083/mcp, enabling dynamic discovery and invocation of tools across all tool source types: - list_tool_servers: Lists all tool servers (RemoteMCPServer, Service with kagent.dev/mcp-service=true label, MCPServer CRs) - list_tools: Connects to a tool server and returns its tool catalog - call_tool: Invokes a specific tool on a specific tool server This moves the functionality originally proposed in kagent-dev/kmcp#123 into kagent per reviewer feedback, since kagent already watches all three resource types and has the existing MCP handler infrastructure. Key design decisions: - Unified ref format: Kind/namespace/name (e.g. RemoteMCPServer/default/my-server) - Session caching with evict-and-retry for stale connections - Reuses existing ConvertServiceToRemoteMCPServer and ConvertMCPServerToRemoteMCPServer from the translator package - MCPServer CRD is optional (graceful degradation if not installed) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Moved this to kagent per @EItanya's feedback — the implementation now lives in kagent-dev/kagent#1437, which adds the same three tools ( The key improvement from moving to kagent: unified discovery across all tool source types (RemoteMCPServer, Service with |
Adds three new MCP tools to the kagent-controller's existing MCP endpoint at :8083/mcp, enabling dynamic discovery and invocation of tools across all tool source types: - list_tool_servers: Lists all tool servers (RemoteMCPServer, Service with kagent.dev/mcp-service=true label, MCPServer CRs) - list_tools: Connects to a tool server and returns its tool catalog - call_tool: Invokes a specific tool on a specific tool server This moves the functionality originally proposed in kagent-dev/kmcp#123 into kagent per reviewer feedback, since kagent already watches all three resource types and has the existing MCP handler infrastructure. Key design decisions: - Unified ref format: Kind/namespace/name (e.g. RemoteMCPServer/default/my-server) - Session caching with evict-and-retry for stale connections - Reuses existing ConvertServiceToRemoteMCPServer and ConvertMCPServerToRemoteMCPServer from the translator package - MCPServer CRD is optional (graceful degradation if not installed) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds three new MCP tools to the kagent-controller's existing MCP endpoint at :8083/mcp, enabling dynamic discovery and invocation of tools across all tool source types: - list_tool_servers: Lists all tool servers (RemoteMCPServer, Service with kagent.dev/mcp-service=true label, MCPServer CRs) - list_tools: Connects to a tool server and returns its tool catalog - call_tool: Invokes a specific tool on a specific tool server This moves the functionality originally proposed in kagent-dev/kmcp#123 into kagent per reviewer feedback, since kagent already watches all three resource types and has the existing MCP handler infrastructure. Key design decisions: - Unified ref format: Kind/namespace/name (e.g. RemoteMCPServer/default/my-server) - Session caching with evict-and-retry for stale connections - Reuses existing ConvertServiceToRemoteMCPServer and ConvertMCPServerToRemoteMCPServer from the translator package - MCPServer CRD is optional (graceful degradation if not installed) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Simon Zhu <simon.zhu@mongodb.com>
Adds three new MCP tools to the kagent-controller's existing MCP endpoint at :8083/mcp, enabling dynamic discovery and invocation of tools across all tool source types: - list_tool_servers: Lists all tool servers (RemoteMCPServer, Service with kagent.dev/mcp-service=true label, MCPServer CRs) - list_tools: Connects to a tool server and returns its tool catalog - call_tool: Invokes a specific tool on a specific tool server This moves the functionality originally proposed in kagent-dev/kmcp#123 into kagent per reviewer feedback, since kagent already watches all three resource types and has the existing MCP handler infrastructure. Key design decisions: - Unified ref format: Kind/namespace/name (e.g. RemoteMCPServer/default/my-server) - Session caching with evict-and-retry for stale connections - Reuses existing ConvertServiceToRemoteMCPServer and ConvertMCPServerToRemoteMCPServer from the translator package - MCPServer CRD is optional (graceful degradation if not installed) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Simon Zhu <simon.zhu@mongodb.com>
Adds three new MCP tools to the kagent-controller's existing MCP endpoint at :8083/mcp, enabling dynamic discovery and invocation of tools across all tool source types: - list_tool_servers: Lists all tool servers (RemoteMCPServer, Service with kagent.dev/mcp-service=true label, MCPServer CRs) - list_tools: Connects to a tool server and returns its tool catalog - call_tool: Invokes a specific tool on a specific tool server This moves the functionality originally proposed in kagent-dev/kmcp#123 into kagent per reviewer feedback, since kagent already watches all three resource types and has the existing MCP handler infrastructure. Key design decisions: - Unified ref format: Kind/namespace/name (e.g. RemoteMCPServer/default/my-server) - Session caching with evict-and-retry for stale connections - Reuses existing ConvertServiceToRemoteMCPServer and ConvertMCPServerToRemoteMCPServer from the translator package - MCPServer CRD is optional (graceful degradation if not installed) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Simon Zhu <simon.zhu@mongodb.com>
Summary
Adds a Streamable HTTP MCP server endpoint to the kmcp controller, enabling agents to dynamically discover, introspect, and invoke tools on any MCPServer in the cluster at runtime. This mirrors the pattern already established by kagent-controller's A2A MCP endpoint (
list_agents/invoke_agent) but for MCP server interactions.Closes #122
New tools exposed at
:8083/mcplist_mcp_serverslist_toolscall_toolChanges
pkg/mcp/handler.go— MCP handler implementing the three tools with session caching and automatic reconnection on stale sessionspkg/mcp/server.go— HTTP server wrapper implementingmanager.Runnablefor controller-runtime lifecycle integrationpkg/app/app.go—--mcp-bind-addressflag (default:8083, set to0to disable) and MCP server wiringgo.mod— Addedgithub.com/modelcontextprotocol/go-sdkv1.2.0 (same version as kagent)mcp-service.yaml(ClusterIP)Tests
pkg/mcp/handler_test.go— 16 unit tests covering:list_mcp_servers: empty cluster, multi-namespace listing, namespace filtering, mixed ready/not-ready, default portlist_toolsvalidation: invalid ref format, server not foundcall_toolvalidation: missing tool name, invalid ref, server not foundgetMCPServerhelper: valid lookup, invalid format, non-existentmcpServerURLderivation: stdio/http transport, custom path, default portpkg/mcp/server_test.go— 2 tests covering server start/shutdown lifecycle and constructionTest plan
go build ./...— compiles cleanlygo vet ./...— no issuesgo test ./pkg/mcp/...— all 18 tests passhelm template test helm/kmcp/— renders correctly with MCP port, args, and servicelist_mcp_servers/list_tools/call_toolwork🤖 Generated with Claude Code