From 89e4ee2e7945fa4d0ebc145e40e7a01edfab17c3 Mon Sep 17 00:00:00 2001 From: maatheusgois-dd Date: Wed, 3 Jun 2026 14:20:11 -0300 Subject: [PATCH] Fix agent-debug-log MCP resource auto-read error. Move the parameterized agent-debug-log URI from resources/list to resources/templates/list so clients no longer prefetch a bare URI that requires ?path= and throw -32000. Co-authored-by: Cursor --- src/mcp/server.test.ts | 35 +++++++++++++++++++++++++++++++++-- src/mcp/server.ts | 10 ++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/mcp/server.test.ts b/src/mcp/server.test.ts index 85a3c81..6a56c64 100644 --- a/src/mcp/server.test.ts +++ b/src/mcp/server.test.ts @@ -109,11 +109,42 @@ describe('MCP server protocol', () => { ]); const resp = lines.map((l) => JSON.parse(l)).find((r) => r.id === 2); - expect(resp.result.resources).toHaveLength(3); + expect(resp.result.resources).toHaveLength(2); const uris = resp.result.resources.map((r: { uri: string }) => r.uri); expect(uris).toContain('xcodebazel://last-command'); expect(uris).toContain('xcodebazel://session-status'); - expect(uris).toContain('xcodebazel://agent-debug-log'); + expect(uris).not.toContain('xcodebazel://agent-debug-log'); + }); + + it('lists agent-debug-log as a resource template (requires path param)', async () => { + const lines = await sendMcpRequest([ + { jsonrpc: '2.0', id: 1, method: 'initialize', params: { protocolVersion: '2024-11-05' } }, + { jsonrpc: '2.0', id: 2, method: 'resources/templates/list' }, + ]); + + const resp = lines.map((l) => JSON.parse(l)).find((r) => r.id === 2); + expect(resp.result.resourceTemplates).toHaveLength(1); + expect(resp.result.resourceTemplates[0].uriTemplate).toBe( + 'xcodebazel://agent-debug-log?path={path}', + ); + }); + + it('reads agent-debug-log resource when path query is provided', async () => { + const lines = await sendMcpRequest([ + { jsonrpc: '2.0', id: 1, method: 'initialize', params: { protocolVersion: '2024-11-05' } }, + { + jsonrpc: '2.0', + id: 2, + method: 'resources/read', + params: { uri: 'xcodebazel://agent-debug-log?path=%2Ftmp%2Fmissing-agent-debug.log' }, + }, + ]); + + const resp = lines.map((l) => JSON.parse(l)).find((r) => r.id === 2); + expect(resp.error).toBeUndefined(); + const parsed = JSON.parse(resp.result.contents[0].text); + expect(parsed.exists).toBe(false); + expect(parsed.logPath).toBe('/tmp/missing-agent-debug.log'); }); it('reads last-command resource (no command yet)', async () => { diff --git a/src/mcp/server.ts b/src/mcp/server.ts index 2e46405..09bf16b 100644 --- a/src/mcp/server.ts +++ b/src/mcp/server.ts @@ -89,10 +89,16 @@ async function handleMessage(message: JsonRpcMessage): Promise { description: 'Current session state: active workflows, defaults, uptime.', mimeType: 'application/json', }, + ], + }); + } + if (method === 'resources/templates/list') { + return sendResult(id, { + resourceTemplates: [ { - uri: 'xcodebazel://agent-debug-log', + uriTemplate: 'xcodebazel://agent-debug-log?path={path}', name: 'Agent debug NDJSON log', - description: 'Structured agent debug log. Read with ?path= query on the URI.', + description: 'Structured agent debug log at an absolute host path. Use bazel_ios_agent_debug_log_read or pass ?path=.', mimeType: 'application/json', }, ],