fix(pi): emit parameters and execute in the generated pi adapter - #1678
Open
musichen wants to merge 3 commits into
Open
fix(pi): emit parameters and execute in the generated pi adapter#1678musichen wants to merge 3 commits into
musichen wants to merge 3 commits into
Conversation
The generated Pi extension registered each MCP tool as { name, run }, but
Pi's ToolDefinition requires label, description, parameters, and execute.
Tools registered that way carried no parameter schema, so strict providers
such as xAI/Grok reject the request with a 422 'missing field parameters',
and the tools were uncallable because Pi invokes execute, never run.
Emit the full tool shape from the registry: label/description via new
accessors, the input_schema embedded directly as a JSON object literal, and
execute instead of run.
Signed-off-by: Alex Musichen <alex.musichen@gmail.com>
|
Thanks for opening this — it has been seen, and it is queued. This note is automated, but it is not a brush-off: it exists so you know where your PR stands instead of having to guess from silence. Current review status: working through a backlog. What that means for this PR, concretely:
Things that will genuinely speed it up whenever review does happen:
If this fixes a bug, a reproduction we can run is worth more than a description of the symptom. Thanks for contributing, and sorry in advance for the wait. |
The generated execute forwarded the raw MCP JSON directly, but pi's
ToolDefinition.execute must return { content: [{ type: 'text', text }],
details } — a result without a content array crashes the TUI's
getTextOutput on result.content.filter(...).
Request raw JSON from the CLI ('--json') so the bridge parses the MCP
result instead of the human-readable text, then wrap it: pass the content
array through, throw on transport errors, and stringify anything else.
Adds coverage asserting the corrected execute shape and the --json flag.
Signed-off-by: Alex Musichen <alex.musichen@gmail.com>
clang-format wants no spaces inside a braced initializer. Signed-off-by: Alex Musichen <alex.musichen@gmail.com>
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
The generated Pi extension (
~/.pi/agent/extensions/cbmem.ts) registers each MCP tool as:Pi's
ToolDefinitionrequireslabel,description,parameters, andexecute. Therun-only shape is accepted by Pi's loader but produces tools that fail in two ways:parametersschema - strict providers such as xAI/Grok reject the request with422 missing field parameters(OpenAI and other providers tolerate the omission, so it only surfaces on some providers).execute- the tool is uncallable, because Pi invokesexecute, neverrun.Once
executewas wired up, a third problem surfaced:executeforwarded the raw MCP JSON (which has nocontentarray) instead of Pi's required result shape, crashing the TUI'sgetTextOutputonresult.content.filter(...).Fix
The adapter now emits the full tool shape from the registry:
Specifically:
cbm_mcp_tool_titleandcbm_mcp_tool_descriptionaccessors so the adapter reads metadata from the same registry that backstools/list, instead of drifting.input_schemais embedded directly as a JSON object literal (compact JSON is valid JavaScript), avoiding aJSON.parseindirection.callnow passes--jsonso the CLI emits the raw MCP result instead of human-readable text thatJSON.parsecannot parse.executereturns Pi's required{ content, details }shape: it passes the MCPcontentarray through, throws on transport errors, and stringifies anything else.Tests
client_adapter_pi_emits_parameters_and_executeassertingexecute/parametersare present, the legacyrun:shape is gone, the schema is embedded, and--jsonis requested.cbmem.tsloads and returns a valid result shape for success, error, null, and plain-object results.agent_clientssuite: 32/32 passing.