Skip to content

Conversation

@cliffhall
Copy link
Member

Description

  • 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 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

Motivation and Context

@evalstate discovered that when registering a prompt or resource template, it was automatically setting a completion request handler and advertising the completions capability. However in order to support completions, at least one argument of a prompt must have a Completable schema or one argument of a resource template must have a completeCallback.

In his case, he was not supporting completions on 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?

  • Existing tests that auto advertisement is triggered by prompts and resource templates with completable arguments still pass:
    • "should advertise support for completion when a resource template with a complete callback is defined"
    • "should advertise support for completion when a prompt with a completable argument is defined"
  • New tests that auto advertisement is not triggered by prompts and resource templates with no completable arguments also pass:
    • "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"

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Redo of #1024 which was a redo of #974. Both languished so long that when I tried to resolve conflicts, the files had changed too much to do it with confidence. So, once again I have made the changes against what's currently on main.

  - 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 `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`
@cliffhall cliffhall requested a review from a team as a code owner December 4, 2025 21:14
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 4, 2025

Open in StackBlitz

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/sdk@1237

commit: a57d59d

@cliffhall cliffhall changed the title * In mcp.test.ts No automatic completion support unless needed - Revisited yet again Dec 4, 2025
Copy link
Contributor

@KKonstantinov KKonstantinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for this!

@KKonstantinov KKonstantinov merged commit a57303c into modelcontextprotocol:main Dec 5, 2025
6 checks passed
@cliffhall cliffhall deleted the third-attempt-to-fix-auto-completions branch December 5, 2025 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants