-
Notifications
You must be signed in to change notification settings - Fork 1.5k
No automatic completion support unless needed - Revisited #1024
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
No automatic completion support unless needed - Revisited #1024
Conversation
- add `isCompletable` function, a runtime type guard to detect `Completable`-wrapped Zod types
* In mcp.test.ts
- Added tests
- "should not advertise support for completion when a resource template without a complete callback is defined"
- "should not advertise support for completion when a prompt without a completable argument is defined"
* In mcp.ts
- in `handlePromptCompletion` method,
- fix warning "Invalid 'instanceof' check: 'field' has type that is not related to 'Completable<any>'" by using the new `isCompletable` function from `completable.ts`
- in `setResourceRequestHandlers` method
- remove unconditional call to `setCompletionRequestHandler` - supporting resources does not automatically mean that resource template completion is supported
- in `setPromptRequestHandlers` method
- remove unconditional call to `setCompletionRequestHandler` - supporting prompts does not automatically mean that prompt argument completion is supported
- in `_createRegisteredResourceTemplate` method
- check if the resource template being registered has a complete callback,
- if so, call `setCompletionRequestHandler`
- in _`createRegisteredPrompt` method
- check if any argument of the prompt has a `Completable` schema
- if so, call `setCompletionRequestHandler`
commit: |
|
@evalstate hard to believe, but it looks like once again there are conflicts to resolve in this PR that leave me wanting to redo the PR from scratch. |
|
Yet again, this one has languished with no 👀 from @modelcontextprotocol/typescript-sdk maintainers for long enough that resolving the conflicts is more difficult than redoing the entire PR from scratch. This will be the third time creating this PR, hopefully that's the charm. |


Description
isCompletablefunction, a runtime type guard to detectCompletable-wrapped Zod typeshandlePromptCompletionmethod,isCompletablefunction fromcompletable.tssetResourceRequestHandlersmethodsetCompletionRequestHandler- supporting resources does not automatically mean that resource template completion is supportedsetPromptRequestHandlersmethodsetCompletionRequestHandler- supporting prompts does not automatically mean that prompt argument completion is supported_createRegisteredResourceTemplatemethodsetCompletionRequestHandlercreateRegisteredPromptmethodCompletableschemasetCompletionRequestHandlerMotivation and Context
@evalstate discovered that when registering a prompt or resource template, it was automatically setting a completion request handler and advertising the
completionscapability. However in order to support completions, at least one argument of a prompt must have aCompletableschema or one argument of a resource template must have acompleteCallback.In his case, he was not supporting
completionson his prompts and resources, and was concerned that clients would send unnecessary completion requests because of this automatic advertisement of completions.This PR checks each registered prompt and resource template, and only does automatic advertisement and listening for completion requests if completable argument is found.
How Has This Been Tested?
Breaking Changes
Nope. Existing behavior for auto-advertisement of completions will still allow completable arguments to be completed. If no completable prompt or resource template arguments exist, then the previous behavior of allowing completion requests was a bug and will now be defeated.
Types of changes
Checklist
Additional context
Redo of #974. It had been approved but never merged, and when I tried to resolve conflicts, the
mcp.tsfile had changed too much to do it with confidence. So, I made the changes again against what's currently onmain.