Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(pi): register the MCP tools with reference-free schemas

AkitaOnRails3709ca9f3967
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d3639798..f0601561 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Fixed
+- Fixed every Pi turn failing with a 400 on Moonshot/Kimi models: the
+ generated Pi extension registered the MCP tools with schemas containing
+ `$ref`, which Moonshot rejects. Its bridge now requests the `?flavor=moonshot`
+ schemas, with every reference inlined, which any provider accepts. Re-run
+ `ai-memory install-hooks --agent pi --apply` to regenerate the extension.
+ (#1157)
+
## [2.6.1] - 2026-10-08
### Fixed
diff --git a/crates/ai-memory-cli/src/commands/install_hooks.rs b/crates/ai-memory-cli/src/commands/install_hooks.rs
index 240280cc..ed236460 100644
--- a/crates/ai-memory-cli/src/commands/install_hooks.rs
+++ b/crates/ai-memory-cli/src/commands/install_hooks.rs
@@ -5274,7 +5274,10 @@ fn build_pi_extension(
fn pi_mcp_bridge_source() -> &'static str {
r#"
// ---- MCP bridge ------------------------------------------------------------
-const MCP_SERVER = deriveMcpServer(SERVER);
+// Pi forwards tool schemas to whichever provider it runs on, and Moonshot
+// rejects any `$ref` (#1157). The moonshot dialect inlines every reference,
+// which every provider accepts; it changes nothing but `tools/list`.
+const MCP_SERVER = `${deriveMcpServer(SERVER)}?flavor=moonshot`;
const MCP_REQUEST_TIMEOUT_MS = 10000;
let mcpRequestId = 0;
@@ -11378,7 +11381,9 @@ model = "gpt-5"
assert!(extension.contains("postHook(\"session-end\""));
assert!(extension.contains("fetchHandoff"));
assert!(extension.contains("customType: \"ai-memory-handoff\""));
- assert!(extension.contains("const MCP_SERVER = deriveMcpServer(SERVER);"));
+ assert!(
+ extension.contains("const MCP_SERVER = `${deriveMcpServer(SERVER)}?flavor=moonshot`;")
+ );
assert!(
extension.contains("return trimmed.endsWith(\"/mcp\") ? trimmed : `${trimmed}/mcp`;")
);
diff --git a/docs/mcp-install.md b/docs/mcp-install.md
index dbf8d5f4..41dce262 100644
--- a/docs/mcp-install.md
+++ b/docs/mcp-install.md
@@ -1338,7 +1338,7 @@ validation is identical in every dialect — only the advertised schema changes.
| Marker | Config key | What it changes | Who needs it |
| --- | --- | --- | --- |
-| `?flavor=moonshot` | `strip_root_combinators` | Drops root-level `anyOf`/`oneOf`/`allOf`, plus inlines every `#/$defs/*` reference and drops the emptied `$defs` table | Kimi Code (Moonshot); appended by `install-mcp` |
+| `?flavor=moonshot` | `strip_root_combinators` | Drops root-level `anyOf`/`oneOf`/`allOf`, plus inlines every `#/$defs/*` reference and drops the emptied `$defs` table | Kimi Code (Moonshot); appended by `install-mcp`. The generated Pi extension's MCP bridge always asks for it, since Pi may run on Moonshot |
| `?flavor=bedrock` | `strip_root_combinators` | Drops root-level `anyOf`/`oneOf`/`allOf` | Kiro CLI (Bedrock); appended by `install-mcp` |
| `?flavor=gemini` (alias `vertex`) | `gemini_safe_schemas` | Drops root-level `anyOf`/`oneOf`/`allOf`, plus nullable unions collapsed to a single `type` + `nullable: true` | Clients that forward schemas verbatim to Gemini/Vertex, e.g. OpenCode on a Vertex model |