-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(client): return empty lists when server lacks capability #1386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(client): return empty lists when server lacks capability #1386
Conversation
🦋 Changeset detectedLatest commit: 32900bd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
Per the MCP spec, "Both parties SHOULD respect capability negotiation."
Previously, calling listPrompts/listResources/listTools on a server that
didn't advertise those capabilities would still send the request, causing
servers to log warnings and creating unnecessary traffic.
Now the Client respects capability negotiation by default:
- listPrompts() returns { prompts: [] } if server lacks prompts capability
- listResources() returns { resources: [] } if server lacks resources capability
- listResourceTemplates() returns { resourceTemplates: [] } if server lacks resources capability
- listTools() returns { tools: [] } if server lacks tools capability
Each logs a debug message when this occurs for visibility.
The existing enforceStrictCapabilities option is preserved - when set to
true, these methods will still throw errors as before.
Co-Authored-By: Claude Opus 4.5 <[email protected]>
87ed7c6 to
8fcec13
Compare
Co-Authored-By: Claude Opus 4.5 <[email protected]>
These tests were setting up servers with tools capability in the constructor
but then returning empty capabilities in the InitializeRequestSchema handler.
Now that the client respects capability negotiation, listTools() was returning
empty lists since no tools capability was advertised.
Fixed by returning { tools: {} } in the InitializeRequestSchema handlers.
Co-Authored-By: Claude Opus 4.5 <[email protected]>
felixweinberger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use console.warn instead of console.debug? With debug, developers would need to explicitly enable debug logging to see these messages, which could hide the fact that they're calling methods for unadvertised capabilities.
The client package doesn't have precedent for either, but core uses console.warn for similar "heads up" situations (tool name validation, deprecation warnings).
I would personally prefer But I don't mind changing it to |
Motivation and Context
Going through logs of an MCP server not advertising prompts during capabilities negotiation, I noticed
listPromptsrequests from a client causing a lot of noise. I was about to create an issue with the client, but on second thought, I think the SDK shouldn't require clients to check capabilities manually before calling list methods. I can't think when it would ever be a good idea to send the request to a server that doesn't advertise the capability, so the SDK should make it easy to call the methods without causing server noise and just get an empty list anyway.Per the MCP spec, "Both parties SHOULD respect capability negotiation." Previously, calling listPrompts/listResources/listTools on a server that didn't advertise those capabilities would still send the request, causing servers to log warnings and creating unnecessary traffic.
Now the Client respects capability negotiation by default:
Each logs a debug message when this occurs for visibility. Let me know if you want this removed - I was unsure whether to add it.
The existing enforceStrictCapabilities option is preserved - when set to true, these methods will still throw errors as before.
Also fixed three subtle test bugs with incorrect capability declaration.
How Has This Been Tested?
Added tests.
Breaking Changes
None
Types of changes
Checklist