perf: lazy-load CLI command modules to reduce startup time#621
Open
MrRealORG wants to merge 1 commit into
Open
perf: lazy-load CLI command modules to reduce startup time#621MrRealORG wants to merge 1 commit into
MrRealORG wants to merge 1 commit into
Conversation
…o#520) All 22 CLI command modules (run, serve, web, agent, providers, etc.) were eagerly imported at the top of src/index.ts. Each command pulls in heavy transitive dependencies (tool registry, provider system, app-runtime, SDK, MCP client, etc.) even when the command is not being executed. This change introduces a helper that creates a lightweight command module stub containing only the command name and description. The full module is dynamically imported only when yargs matches and executes that specific command. This means running or no longer loads the entire tool/provider/agent stack. Additionally, ClaudeImport is now dynamically imported inside the middleware callback instead of at the top level, since it only runs once per install. Addresses: XiaomiMiMo#520
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.
Summary
Closes #520
All 22 CLI command modules (, , , , ,
Usage: mcp [OPTIONS] COMMAND [ARGS]...
MCP development tools
╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ version Show the MCP version. │
│ dev Run an MCP server with the MCP Inspector. │
│ run Run an MCP server. │
│ install Install an MCP server in the Claude desktop app. │
╰──────────────────────────────────────────────────────────────────────────────╯, etc.) were eagerly imported at the top of . Each command pulls in heavy transitive dependencies (tool registry with 12+ tools, provider system, app-runtime with ~50 service layers, SDK, MCP client, etc.) — even when the user is only running , , or the default TUI command.
Changes
New:
A helper that creates a lightweight yargs stub containing only:
The full command module is dynamically imported only when yargs matches and executes that specific command. The helper is compatible with yargs 18's synchronous path (all accessed properties return synchronously).
Modified:
Impact