Skip to content

fix: isolate default completion results - #759

Open
yorzi wants to merge 1 commit into
modelcontextprotocol:mainfrom
yorzi:fix/isolated-default-completion-results
Open

yorzi wants to merge 1 commit into
modelcontextprotocol:mainfrom
yorzi:fix/isolated-default-completion-results

Conversation

@yorzi

@yorzi yorzi commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Motivation and Context

The default completion/complete result was the DEFAULT_COMPLETION_RESULT constant itself, whose nested completion Hash and values Array are not frozen, so every server in the process handed out the same objects.

The built-in handler now returns nil, and normalize_completion_result builds the empty result for nil and for any other result without a completion Hash, the same way it builds a result from a handler's values. Each response gets new objects. Nothing reads DEFAULT_COMPLETION_RESULT any more, so it is removed.

Fixes #752

How Has This Been Tested?

  • test/mcp/server_test.rb: the tests for the default result and for a handler that returns nil now send the request twice and check that the responses do not share the completion Hash or the values Array. The expected responses are unchanged.
  • Both tests fail on main.
  • With this change the script in the issue prints empty values for both requests (its last line, which prints the constant, now raises NameError).

bundle exec rake passes on Ruby 4.0.10 (RuboCop, 2857 runs with 0 failures, and the conformance baseline). yard --no-output passes.

  • Automated unit / integration tests
  • Tested manually
  • Tested in a real application

Breaking Changes

The responses have the same value; only their identity changes. MCP::Server::DEFAULT_COMPLETION_RESULT is removed. It was not documented, but it was a public constant in 0.11.0 through 0.13.0, so code that refers to it directly must define its own value.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Test update (non-breaking change which adds or updates tests)
  • Refactoring (non-breaking change which makes things better)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • CI/build script update (update CI workflow or build scripts)

Checklist

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

Comment thread lib/mcp/server.rb
Methods::NOTIFICATIONS_PROGRESS => ->(_) {},
Methods::NOTIFICATIONS_ROOTS_LIST_CHANGED => ->(_) {},
Methods::COMPLETION_COMPLETE => ->(_) { DEFAULT_COMPLETION_RESULT },
Methods::COMPLETION_COMPLETE => ->(_) {},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nothing reads DEFAULT_COMPLETION_RESULT after this change. Could it be removed in this pull request as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks. Removed it in 6dd455e, and noted the removal of the public constant under Breaking Changes in the description.

Normalize missing and malformed handler results through the regular
empty-completion path, which builds a new completion Hash and values
Array for each call. Remove the `DEFAULT_COMPLETION_RESULT` constant,
which nothing reads any more.

Fixes modelcontextprotocol#752.
@yorzi
yorzi force-pushed the fix/isolated-default-completion-results branch from 7aee334 to 6dd455e Compare December 5, 2026 01:57

This branch has not been deployed

No deployments
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.

Default completion/complete results share one mutable Hash and Array across all servers

2 participants