Skip to content

Refine Zod schema types for record keys, enhance client connection er…#1698

Open
sid293 wants to merge 1 commit intomodelcontextprotocol:v1.xfrom
sid293:fix/close-transport-on-connect-failure
Open

Refine Zod schema types for record keys, enhance client connection er…#1698
sid293 wants to merge 1 commit intomodelcontextprotocol:v1.xfrom
sid293:fix/close-transport-on-connect-failure

Conversation

@sid293
Copy link

@sid293 sid293 commented Mar 18, 2026

Fixed connection resource leaks when Client.connect() fails during transportation or initialization. Also addressed several Zod v4 compatibility issues and test timeouts.

Motivation and Context

  • Connection Leak: Previously, if super.connect(transport) failed (e.g., process failed to spawn), the Client would bypass its cleanup logic, leaving danging transport resources.
  • Zod v4 Compatibility: Certain schemas like z.record(z.unknown()) caused crashes in Zod v4. Additionally, using the Zod v4 Mini engine to parse V4 Classic schemas led to internal TypeErrors.
  • Test Stability: The integration tests were occasionally timing out on slower environments due to the cold-start time of tsx.

How Has This Been Tested?

  • Added a new unit test in test/client/index.test.ts specifically verifying that transport.close() is called if connect() fails.
  • Fixed Zod v4 syntax in protocol.test.ts and taskLifecycle.test.ts.
  • Verified that all tests pass successfully locally using pnpm test.

Breaking Changes

None

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

…ror handling with proper cleanup, and improve Zod compatibility utilities.
@sid293 sid293 requested a review from a team as a code owner March 18, 2026 08:40
@changeset-bot
Copy link

changeset-bot bot commented Mar 18, 2026

⚠️ No Changeset found

Latest commit: 9ebed93

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.

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

pkg-pr-new bot commented Mar 18, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@modelcontextprotocol/sdk@1698

commit: 9ebed93

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