Repository navigation
perf(mcp): Load the server stack only when the stdio server starts - #1764
Merged
Merged
Conversation
runMcpServer() imported mcp-core's server and tools, the AI SDK providers, @sentry/node, and the stdio transport at module load, so --help, --version, and argument errors paid for all of them. Import them after the config and token are resolved instead, and load the auth command and device-code flow only on the paths that use them. Part of #1761 Co-Authored-By: BYK <burak.kaya@sentry.io>
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
BYK
approved these changes
Oct 31, 2026
sentry-junior Bot
added a commit
that referenced
this pull request
Oct 31, 2026
Brings in the squash-merged #1763 (Zod English locale), #1764 (lazy server stack) and #1765 (lazy syntax highlighting), which this branch had merged from their PR branches. Conflicts: - packages/mcp-server/src/index.ts: kept deleted. #1764's lazy loading is already applied to the unified entry (commands/mcp.ts -> lib/mcp.ts -> lib/mcp/server.ts). - script/bundle.ts, script/build.ts: kept the zod/v3 stub plugin. bundle.ts keeps the shared script/lib/require-alias-plugin.ts (the @sentry/mcp-server bundle uses it too) instead of main's inline copy. main's filter also lists list-command.ts, but on this branch that file no longer uses _require (the route registry replaced it), so it stays out. - formatters/highlight.ts, syntax-highlight-bundle.test.ts: identical to main apart from comments that point at the shared require-alias plugin.
This branch was previously deployed
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.
Part of #1761.
runMcpServer()in@sentry/mcp-serverimported mcp-core's server and every tool, the AI SDK providers,@sentry/node, and the v1 stdio transport at module load.--help,--version, and argument errors paid for all of that before printing one line. Those imports now load only after the config and token resolve, right before the server starts. The auth subcommand and the device-code flow load only on the paths that use them.Measured on Node 22, max RSS from
process.resourceUsage().maxRSSin a-rpreload, 3 runs each:sentry mcp --version(CLI npm bundle)sentry mcp --help(CLI npm bundle)sentry-mcp --version(standalonepackages/mcp-server/dist)sentry mcpidle: initialize + tools/listdist/index.cjsbytes (metafile)The idle server still loads the same modules, so idle RSS doesn't change.
For #1731's restack: the same issue exists in
packages/cli/src/lib/mcp.ts. There,startMcpServer()importsparseMcpInvocationfrom./mcp/server.js, which statically imports mcp-core and@sentry/node. On a local copy of that branch, returning before that import for--versiontooksentry-mcp --versionfrom 137 MB / 335 ms to 107 MB / 165 ms. MovingparseMcpInvocationinto a module without those imports, next toargs.tsandusage.ts, would carry this change over. This PR editspackages/mcp-server/src/index.ts, which #1731 deletes, so the restack can drop this file's changes.Lazy-loading the tool modules themselves (option 3 in the issue) is left out on purpose:
tools/listneeds every tool's schema at startup. Stubbing the whole AI SDK out of the #1731 bundle, an upper bound for lazy-loading it, saved only about 3.7 MB of idle RSS and about 30 ms.via BYK.
--
View Session in Sentry