fix(pi-claude-cli): source MCP tool list from session Context, not pi.getAllTools
The previous fix regenerated the MCP config per call but still pulled the tool set from pi.getAllTools(), which depends on the runtime binding being scoped to the right AgentSession. Engine-spawned triage/executor sessions register custom tools (fn_review_spec, fn_review_step) and pi-ai already passes those to the provider via Context.tools — that's the authoritative per-session list and bypasses any binding ambiguity. Falls back to pi.getAllTools() when the caller doesn't populate Context.tools. Also logs the tool names on refresh so missing tools are diagnosable from stderr. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -67,6 +67,31 @@ export function getCustomToolDefs(pi: PiInstance): McpToolDef[] {
|
||||
}));
|
||||
}
|
||||
|
||||
/** Minimal pi-ai Tool shape (the subset we need from `Context.tools`). */
|
||||
interface PiAiToolLike {
|
||||
name: string;
|
||||
description: string;
|
||||
parameters: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the pi-ai `Context.tools` array (the authoritative per-session tool
|
||||
* list pi-coding-agent passes to streamSimple) into MCP tool defs, filtering
|
||||
* out the 6 built-ins that pi handles natively.
|
||||
*/
|
||||
export function toolsFromContext(
|
||||
contextTools: ReadonlyArray<PiAiToolLike> | undefined,
|
||||
): McpToolDef[] {
|
||||
if (!Array.isArray(contextTools)) return [];
|
||||
return contextTools
|
||||
.filter((tool) => !BUILT_IN_TOOL_NAMES.has(tool.name))
|
||||
.map((tool) => ({
|
||||
name: tool.name,
|
||||
description: tool.description,
|
||||
inputSchema: tool.parameters,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write MCP config and tool schemas to temp files.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user