diff --git a/plugin/.mcp.json b/plugin/.mcp.json index f7c3760336..4a74a3bb03 100644 --- a/plugin/.mcp.json +++ b/plugin/.mcp.json @@ -5,7 +5,8 @@ "args": ["-y", "@agentmemory/mcp"], "env": { "AGENTMEMORY_URL": "${AGENTMEMORY_URL}", - "AGENTMEMORY_SECRET": "${AGENTMEMORY_SECRET}" + "AGENTMEMORY_SECRET": "${AGENTMEMORY_SECRET}", + "AGENTMEMORY_TOOLS": "all" } } } diff --git a/src/mcp/standalone.ts b/src/mcp/standalone.ts index f4683747f0..2731bb7cee 100644 --- a/src/mcp/standalone.ts +++ b/src/mcp/standalone.ts @@ -418,6 +418,17 @@ export async function handleToolsList(): Promise<{ tools: unknown[] }> { ); } if (remote && Array.isArray(remote.tools)) { + if ( + process.env["AGENTMEMORY_TOOLS"] === "all" && + remote.tools.length < getAllTools().length + ) { + if (debug) { + process.stderr.write( + `[@agentmemory/mcp] tools/list: remote returned ${remote.tools.length} tools; AGENTMEMORY_TOOLS=all so returning ${getAllTools().length} bundled tool definitions\n`, + ); + } + return { tools: getAllTools() }; + } if (debug) { process.stderr.write( `[@agentmemory/mcp] tools/list: returning ${remote.tools.length} tools from server\n`, diff --git a/test/codex-plugin.test.ts b/test/codex-plugin.test.ts index 63aa1803fa..03a52e79bf 100644 --- a/test/codex-plugin.test.ts +++ b/test/codex-plugin.test.ts @@ -84,6 +84,7 @@ describe("Codex plugin manifest (developers.openai.com/codex/plugins)", () => { expect(mcp.mcpServers.agentmemory?.env).toMatchObject({ AGENTMEMORY_URL: "${AGENTMEMORY_URL}", AGENTMEMORY_SECRET: "${AGENTMEMORY_SECRET}", + AGENTMEMORY_TOOLS: "all", }); }); diff --git a/test/mcp-standalone-proxy.test.ts b/test/mcp-standalone-proxy.test.ts index dc08a024ee..1edda8e24d 100644 --- a/test/mcp-standalone-proxy.test.ts +++ b/test/mcp-standalone-proxy.test.ts @@ -2,6 +2,7 @@ import { describe, expect, it, beforeEach, afterEach, vi } from "vitest"; import { handleToolCall } from "../src/mcp/standalone.js"; import { resetHandleForTests } from "../src/mcp/rest-proxy.js"; import { InMemoryKV } from "../src/mcp/in-memory-kv.js"; +import { getAllTools } from "../src/mcp/tools-registry.js"; type FetchMock = ReturnType; @@ -28,6 +29,7 @@ describe("@agentmemory/mcp standalone — server proxy (issue #159)", () => { resetHandleForTests(); globalThis.fetch = originalFetch; delete process.env["AGENTMEMORY_URL"]; + delete process.env["AGENTMEMORY_TOOLS"]; }); it("proxies memory_sessions to GET /agentmemory/sessions when server is up", async () => { @@ -265,6 +267,27 @@ describe("@agentmemory/mcp standalone — server proxy (issue #159)", () => { }); }); + it("keeps all bundled tools visible when shim requests all but server lists core only (#400)", async () => { + process.env["AGENTMEMORY_TOOLS"] = "all"; + const { handleToolsList } = await import("../src/mcp/standalone.js"); + const coreOnly = getAllTools().slice(0, 8); + installFetch((url) => { + if (url.endsWith("/agentmemory/livez")) return new Response("ok", { status: 200 }); + if (url.endsWith("/agentmemory/mcp/tools")) { + return new Response(JSON.stringify({ tools: coreOnly }), { + status: 200, + headers: { "content-type": "application/json" }, + }); + } + return new Response("not found", { status: 404 }); + }); + + const listed = await handleToolsList(); + const tools = listed.tools as Array<{ name: string }>; + expect(tools).toHaveLength(getAllTools().length); + expect(tools.map((t) => t.name)).toContain("memory_lesson_save"); + }); + it("rejects non-essential tools when no server is reachable (#234)", async () => { installFetch(() => { throw new Error("ECONNREFUSED");