Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions src/mcp/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
10 changes: 8 additions & 2 deletions src/mcp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,16 @@ async function handleMessage(message: JsonRpcMessage): Promise<void> {
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=<absolute-log-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=<absolute-log-path>.',
mimeType: 'application/json',
},
],
Expand Down
Loading