Skip to content

Commit 6f98a05

Browse files
committed
fix(mcp): keep resource-only servers available after unknown methods
1 parent a54e28e commit 6f98a05

2 files changed

Lines changed: 69 additions & 5 deletions

File tree

‎src/agents/agent-bundle-mcp-runtime.test.ts‎

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,15 +1728,35 @@ process.on("SIGINT", shutdown);`,
17281728
}
17291729
});
17301730

1731-
it("keeps resource-only MCP servers available for utility tools", async () => {
1731+
it.each([
1732+
{
1733+
name: "resource-only servers reporting method not found",
1734+
capabilities: { resources: { listChanged: true } },
1735+
listToolsMethodNotFound: true,
1736+
listToolsJsonRpcErrorMessage: undefined,
1737+
},
1738+
{
1739+
name: "resource-only servers reporting unknown method",
1740+
capabilities: { resources: { listChanged: true } },
1741+
listToolsMethodNotFound: false,
1742+
listToolsJsonRpcErrorMessage: "Unknown method",
1743+
},
1744+
{
1745+
name: "prompt-only servers reporting unknown method",
1746+
capabilities: { prompts: { listChanged: true } },
1747+
listToolsMethodNotFound: false,
1748+
listToolsJsonRpcErrorMessage: "Unknown method",
1749+
},
1750+
])("keeps $name available for utility tools", async (testCase) => {
17321751
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "bundle-mcp-resource-only-"));
17331752
const serverPath = path.join(tempDir, "resource-only.mjs");
17341753
const logPath = path.join(tempDir, "server.log");
17351754
await writeListToolsMcpServer({
17361755
filePath: serverPath,
17371756
logPath,
1738-
capabilities: { resources: { listChanged: true } },
1739-
listToolsMethodNotFound: true,
1757+
capabilities: testCase.capabilities,
1758+
listToolsMethodNotFound: testCase.listToolsMethodNotFound,
1759+
listToolsJsonRpcErrorMessage: testCase.listToolsJsonRpcErrorMessage,
17401760
});
17411761

17421762
const runtime = await getOrCreateSessionMcpRuntime({
@@ -1762,15 +1782,59 @@ process.on("SIGINT", shutdown);`,
17621782
expect(catalog.servers.notes).toMatchObject({
17631783
serverName: "notes",
17641784
toolCount: 0,
1765-
resources: { listChanged: true },
1785+
...testCase.capabilities,
17661786
});
1787+
expect(catalog.diagnostics ?? []).toEqual([]);
17671788
await waitForFileText(logPath, "recv initialize", LIST_TOOLS_SERVER_LOG_TIMEOUT_MS);
17681789
} finally {
17691790
await runtime.dispose();
17701791
await fs.rm(tempDir, { recursive: true, force: true });
17711792
}
17721793
});
17731794

1795+
it("does not suppress unknown tools/list methods from tools-capable MCP servers", async () => {
1796+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "bundle-mcp-tools-unknown-method-"));
1797+
const serverPath = path.join(tempDir, "tools-unknown-method.mjs");
1798+
const logPath = path.join(tempDir, "server.log");
1799+
await writeListToolsMcpServer({
1800+
filePath: serverPath,
1801+
logPath,
1802+
capabilities: { tools: {}, resources: { listChanged: true } },
1803+
listToolsJsonRpcErrorMessage: "Unknown method",
1804+
});
1805+
1806+
const runtime = await getOrCreateSessionMcpRuntime({
1807+
sessionId: "session-tools-unknown-method",
1808+
sessionKey: "agent:test:session-tools-unknown-method",
1809+
workspaceDir: "/workspace",
1810+
cfg: {
1811+
mcp: {
1812+
servers: {
1813+
notes: {
1814+
command: process.execPath,
1815+
args: [serverPath],
1816+
},
1817+
},
1818+
},
1819+
},
1820+
});
1821+
1822+
try {
1823+
const catalog = await runtime.getCatalog();
1824+
1825+
expect(catalog.servers).toEqual({});
1826+
expect(catalog.tools).toEqual([]);
1827+
expect(catalog.diagnostics?.[0]).toMatchObject({
1828+
serverName: "notes",
1829+
message: expect.stringContaining("Unknown method"),
1830+
});
1831+
await waitForFileText(logPath, "recv tools/list", LIST_TOOLS_SERVER_LOG_TIMEOUT_MS);
1832+
} finally {
1833+
await runtime.dispose();
1834+
await fs.rm(tempDir, { recursive: true, force: true });
1835+
}
1836+
});
1837+
17741838
it("does not pause MCP servers for normal tool error results", async () => {
17751839
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "bundle-mcp-error-backoff-"));
17761840
const serverPath = path.join(tempDir, "error-backoff.mjs");

‎src/agents/agent-bundle-mcp-runtime.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function isMcpMethodNotFoundError(error: unknown): boolean {
183183
return true;
184184
}
185185
const message = String(error);
186-
return message.includes("-32601") || /method not found/i.test(message);
186+
return message.includes("-32601") || /\b(?:method not found|unknown method)\b/i.test(message);
187187
}
188188

189189
async function listAllToolsBestEffort(params: {

0 commit comments

Comments
 (0)