Skip to content

Answer pre-initialization requests in strict server mode - #315

Open
jaeminbird wants to merge 1 commit into
modelcontextprotocol:mainfrom
jaeminbird:fix/strict-pre-init-response
Open

jaeminbird wants to merge 1 commit into
modelcontextprotocol:mainfrom
jaeminbird:fix/strict-pre-init-response

Conversation

@jaeminbird

Copy link
Copy Markdown

Motivation and Context

In strict mode, a request sent before initialize throws out of handleRequest(), and the receive loop's try? swallows the error, so the client waits forever for a response. A notification sent before initialize instead gets an error reply under a random id, though notifications never get responses. Requests now get an invalidRequest (-32600) response with their own id, as the Configuration.strict doc describes, and early notifications are logged and dropped.

How Has This Been Tested?

Two new ServerTests send a tools/list request and a notification before initialize; both fail on main and pass with the fix. Full swift test passes on Linux (Swift 6.1).

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

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

In strict mode, a request sent before initialize threw out of handleRequest,
and the receive loop's detached task swallowed the error with try?, so the
client never got a response. A notification sent before initialize threw out of
handleMessage instead, and the loop then replied to it with an error under a
random id.

Return an invalidRequest response with the request's id, and drop early
notifications with a warning.
@jaeminbird
jaeminbird requested a review from a team as a code owner October 29, 2026 06:24
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.

1 participant