Skip to content

fix(server): reject requests before initialization#2122

Open
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/reject-preinit-requests
Open

fix(server): reject requests before initialization#2122
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/reject-preinit-requests

Conversation

@he-yufeng
Copy link
Copy Markdown

Summary

  • reject non-HTTP server requests before the MCP initialize -> initialized lifecycle completes
  • keep initialize and ping available before initialization
  • leave Streamable HTTP behavior unchanged because that transport already gates initialization itself

Refs modelcontextprotocol/servers#4195.

Validation

  • pnpm --filter @modelcontextprotocol/server exec vitest run test/server/server.test.ts -t "rejects requests before the initialized notification"
  • pnpm --filter @modelcontextprotocol/server test
  • pnpm --filter @modelcontextprotocol/server typecheck
  • pnpm --filter @modelcontextprotocol/server lint
  • git diff --check
  • pre-push hook: workspace typecheck, build, lint

@he-yufeng he-yufeng requested a review from a team as a code owner May 19, 2026 03:21
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 19, 2026

⚠️ No Changeset found

Latest commit: 554a24b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 19, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@2122

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@2122

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@2122

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@2122

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@2122

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@2122

commit: 554a24b

@he-yufeng he-yufeng force-pushed the fix/reject-preinit-requests branch from 3668618 to 554a24b Compare May 19, 2026 03:41
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