feat: add MCP server endpoint for dynamic tool discovery and invocation#123
Open
syn-zhu wants to merge 1 commit intokagent-dev:mainfrom
Open
feat: add MCP server endpoint for dynamic tool discovery and invocation#123syn-zhu wants to merge 1 commit intokagent-dev:mainfrom
syn-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
Contributor
|
Hey there, I really love this idea, but I think we should put this in |
Author
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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