feat: log local MCP requests to stderr by method

The stdio server writes each request's method, and the tool or resource it
names, to stderr, which clients such as Claude Desktop copy into their logs.
Arguments and results are never logged.
This commit is contained in:
Sameh Khamis committed 2026-10-02 15:21:36 -07:00
1 parent 47ef168815
commit 5775eb9053
2 files changed
+39 -3

No files matched your search

+17
View File
@@ -87,3 +87,20 @@ test('command-line arguments are strict', () => {
});
assert.throws(() => parseArgs(['--port', '1']), /Unknown argument/);
});
test('the stdio log names methods, tools and resources but never arguments', async () => {
const { describeRequest } = await import('../../server/mcp/stdio.js');
assert.equal(describeRequest({ method: 'tools/list' }), 'tools/list');
assert.equal(
describeRequest({
method: 'tools/call',
params: { name: 'get_weather', arguments: { location: { place: 'x' } } },
}),
'tools/call get_weather',
);
assert.equal(
describeRequest({ method: 'resources/read', params: { uri: 'ui://a/b' } }),
'resources/read ui://a/b',
);
assert.equal(describeRequest({ result: {} }), null);
});