Repository navigation
perf(core): load MCP client lazily - #42468
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Keep the MCP SDK out of startup evaluation when a location has no enabled MCP servers. Configured enabled servers still connect eagerly during location service construction; disabled servers and installations without MCP defer the SDK until connect or OAuth authorization is actually used.
How
packages/core/src/mcp/index.tskeepsMCPClientas a type-only import.packages/core/test/mcp-import-boundary.test.tsbundles the production entry and asserts that both runtime edges remain dynamic.Impact
The flat workerd artifact remains one download, so its benefit is deferred evaluation rather than transfer size. In 20-process local measurements after importing
mcp/index.ts, first client import averaged 77.31 ms; OAuth followed by client averaged 58.92 ms because the modules share SDK dependencies. That cost moves to the first enabled connect and is absent for no-MCP/disabled startup.Scope
This does not make configured enabled servers connect on demand and does not change the MCP service API, config, protocol, server routes, connection policy, failure mapping, reconnect behavior, or shutdown behavior.
Testing
bun run testinpackages/core: 1,771 passed, 16 skippedbun typecheckinpackages/corebun run test test/workerd.test.tsinpackages/serverbun typecheckinpackages/serverbun run probe:workerdinpackages/serverbun turbo typecheck --concurrency=3, 35 tasks passedbun run lint packages/core/src/mcp/index.ts packages/core/test/mcp-import-boundary.test.ts: no errors; six pre-existing warnings inmcp/index.ts