feat: MCP client support — expose external MCP server tools to agents - #393
Open
kokhlo wants to merge 6 commits into
Open
feat: MCP client support — expose external MCP server tools to agents#393kokhlo wants to merge 6 commits into
kokhlo wants to merge 6 commits into
Conversation
…g the agent chain
A dropped MCP session (server restart, idle timeout) previously poisoned every later tool call for the lifetime of the engine: CallTool kept failing with 'session not found' until the executor exhausted retries and aborted the whole agent chain. Dial a fresh session once and retry the call; concurrent callers race safely on the failed-session pointer.
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.
Motivation
Closes #296.
PentAGI agents currently reach external security tooling only through the built-in terminal/browser/file tools. Many tools teams already use (Burp Suite Pro, Nuclei, Shodan, custom internal scanners) increasingly ship Model Context Protocol servers. This PR makes PentAGI an MCP client: tools advertised by external MCP servers are discovered at startup and offered to agents as first-class tools, next to the built-in ones.
What is added
backend/pkg/mcp— a small MCP client on top of the officialmodelcontextprotocol/go-sdk:stdio(local command managed as a PentAGI child process, with optional extra env),http(streamable HTTP) andsse(legacy servers);mcp_<server>_<tool>(sanitized to[a-z0-9_], capped at 64 chars — the strictest provider function-name limit), so they can never collide with or shadow built-in tool names;IsErrorresults) are surfaced as Go errors so the existing tool-call fixing flow can react.backend/pkg/config— new settings following the existing env conventions (seebackend/docs/config.mdfor the full reference):MCP_SERVERS— JSON array of server definitions (name,transport,url/command+args+env, optionalcontexts);MCP_ALLOWED_TOOLS/MCP_DENIED_TOOLS— comma-separated selectors (*,<server>,<server>/*,<server>/<tool>), deny always wins;MCP_TOOL_TIMEOUT— per-call deadline in seconds (default 120,0= no deadline).backend/pkg/tools— integration with the agent tool registry:contextsrestricts visibility to specific agents (primary_agent,assistant,coder,installer,searcher,pentester);mcp_*tool names map toEnvironmentToolTypefor observability; the shared client is closed on graceful shutdown.README.md(Advanced Setup → External Tools (MCP)), full reference inbackend/docs/config.md,.env.exampleblock, and thedocker-compose.ymlenv mapping.Design notes / open questions
MCP_BURP_TRANSPORT=http,MCP_BURP_URL=...). I went with one JSON variable (MCP_SERVERS) because the number of servers is open-ended and a JSON array scales without inventing a new env naming scheme; happy to switch if maintainers prefer the per-server form.modelcontextprotocol/go-sdk(pinned tov1.3.1, the newest version that does not force agolang-jwt/jwt/v5upgrade on the rest of the tree) instead ofmark3labs/mcp-go. It supports all three transports plus in-memory transports used by the tests.Testing
go build ./...,go vet ./...clean; fullgo test ./...shows no new failures (the three pre-existingcmd/installerfailures reproduce onmainuntouched).