Skip to content

Commit 7451c78

Browse files
committed
fix(server): echo requested URI in not-found data
1 parent bbe2f97 commit 7451c78

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

.changeset/sep-2164-resource-not-found-invalid-params.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
Resource not found now returns `-32602` (Invalid params) per SEP-2164; `-32002` (`ProtocolErrorCode.ResourceNotFound`) is deprecated. The error includes the requested URI in `data.uri` so clients can still distinguish not-found from other invalid-params errors. Clients SHOULD
88
continue to accept legacy `-32002` from older servers.
99

10+
This supersedes the earlier 2.0.0-alpha.1 / #1389 resource error-code change that moved unknown resource reads to `-32002`.
11+
1012
`NodeStreamableHTTPServerTransport` now forwards server-configured supported protocol versions to the underlying web-standard transport, so custom version lists passed to `McpServer` are also honored by HTTP header validation.

packages/server/src/server/mcp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ export class McpServer {
428428

429429
// SEP-2164: nonexistent resources MUST return -32602 (Invalid params); the
430430
// requested URI is included in `data` so clients can distinguish not-found.
431-
throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Resource ${uri} not found`, { uri: uri.toString() });
431+
throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Resource ${uri} not found`, { uri: request.params.uri });
432432
});
433433

434434
this._resourceHandlersInitialized = true;

test/integration/test/server/mcp.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2741,6 +2741,43 @@ describe('Zod v4', () => {
27412741
});
27422742
});
27432743

2744+
test('should echo the exact requested URI for nonexistent resources', async () => {
2745+
const mcpServer = new McpServer({
2746+
name: 'test server',
2747+
version: '1.0'
2748+
});
2749+
const client = new Client({
2750+
name: 'test client',
2751+
version: '1.0'
2752+
});
2753+
const requestedUri = 'HTTP://example.com:80/docs/../missing file.txt';
2754+
mcpServer.registerResource('test', 'test://resource', {}, async () => ({
2755+
contents: [
2756+
{
2757+
uri: 'test://resource',
2758+
text: 'Test content'
2759+
}
2760+
]
2761+
}));
2762+
2763+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
2764+
2765+
await Promise.all([client.connect(clientTransport), mcpServer.server.connect(serverTransport)]);
2766+
2767+
await expect(
2768+
client.request({
2769+
method: 'resources/read',
2770+
params: {
2771+
uri: requestedUri
2772+
}
2773+
})
2774+
).rejects.toMatchObject({
2775+
code: ProtocolErrorCode.InvalidParams,
2776+
message: expect.stringContaining('not found'),
2777+
data: { uri: requestedUri }
2778+
});
2779+
});
2780+
27442781
/***
27452782
* Test: ProtocolError for Disabled Resource
27462783
*/

0 commit comments

Comments
 (0)