Repository navigation
Give agents MCP and extension tools through a tool twin - #120
Merged
Merged
Conversation
mavam
force-pushed
the
topic/tool-twin
branch
from
November 2, 2026 13:12
6217a64 to
e6db69f
Compare
mavam
marked this pull request as ready for review
November 2, 2026 13:12
A headless Pi session in the same process loads Pi's own MCP extension and the packages listed in piAgents.twinExtensions. Every agent selects one extension of proxies for its tools; tools MCP declares only to codemode stay deferred, with their namespaces in codemode and a prompt section listing them. Agents now remove the agent tools they lack instead of naming the ones they have, so the twin's tools reach them as servers connect.
mavam
force-pushed
the
topic/tool-twin
branch
from
November 2, 2026 13:21
e6db69f to
9d4b25c
Compare
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.
🔍 Problem
Agents can't use MCP servers or tools from other extensions, such as Webfox's web search. Pi runs those tools only inside its own sessions, it has no durable version of them, and we can't change Pi.
🛠️ Solution
createAgentSession,DefaultResourceLoader,createMcpExtension). It loads only Pi's MCP extension and the packages listed inpiAgents.twinExtensions, and shares Pi'smcp.jsonand sign-ins.deferred. Their namespaces feed agents' codemode, and a prompt section lists them, as Pi'smcp_serverssection does.tool_callhooks first, so MCP waits until the server is ready.readOnlyHintoridempotentHint.mcp.jsonand nothing is shared.{ remove }tool filter instead of naming their tools, so twin tools that appear later reach them. Naming a twin tool in an allowlist changes nothing.💬 Review
web_searchfrom one script.npm:webfox. An agent found the Cloudflare docs server through the namespace section and answered from it; another called an MCP tool andweb_searchfrom one script. Opening the twin took about 0.5 s, plus about 2 s until the servers were ready.structuredContent: pi-durable strictly validates structured output against a declared schema, and Pi doesn't./mcpchanges reach agents after a restart.src/host/twin*.tsand its call in the harness.