Intelligent lazy-loading for Claude Code MCP tools. Let the agent decide what tools to load based on usage patterns and context needs.
Lazy MCP is a Claude Code plugin that enables agent-driven tool loading with intelligent context optimization. Instead of loading all available MCP servers upfront (consuming precious context window space), Lazy MCP uses a registry-based approach to inform Claude about available tools and loads them on-demand based on your actual needs.
What It Does:
- Agent-Driven Loading: Claude intelligently requests tools based on conversation analysis
- Registry-Informed: Maintains a registry of tool capabilities, keywords, and usage patterns
- Lazy Loading: Tools are loaded only when needed, then purged when usage ceases
- Context Optimization: Automatically manages context window to prevent limitations
- Profile Support: Save and switch between different tool configurations
Traditional MCP integration loads all configured servers at session start, quickly consuming your context window with tools you may never use in a particular conversation. This leads to:
- Frequent context limit errors
- Wasted tokens on unused tool definitions
- Poor agent performance due to context clutter
Lazy MCP uses a registry + lazy loading approach:
- Registry: Maintains metadata about all available tools (capabilities, keywords, usage patterns)
- Agent Analysis: Claude analyzes your request and identifies potentially useful tools
- On-Demand Loading: Only requested tools are loaded into context
- Intelligent Purging: Tools are removed when usage patterns indicate they're no longer needed
- Persistent Learning: Usage patterns improve tool selection over time
# Install the plugin package
npm install -g @lazy-mcp/plugin
# The plugin will be automatically detected by Claude Code
# Commands will be available as /lazy:* in your sessions# Global installation
npm install -g @lazy-mcp/cli
# Or use with npx (no installation)
npx @lazy-mcp/cliOnce installed, use these commands in any Claude Code session:
/lazy:status # Show current loaded tools and context usage
/lazy:help # Show all available commands
/lazy:version # Show version information- Start Session: Lazy MCP analyzes available tools and creates a registry
- Work Naturally: Ask Claude to help with your tasks
- Automatic Loading: Claude identifies needed tools from registry and loads them
- Context Monitoring: Tools are automatically purged when no longer needed
- Save Profiles: Capture successful configurations for reuse
- π§ Agent-Driven: Claude decides what tools to load based on conversation analysis
- π Registry System: Maintains comprehensive tool metadata and usage patterns
- β‘ Lazy Loading: Load tools on-demand, purge when finished
- π― Context Optimization: Intelligent management of context window space
- πΎ Profile Support: Save and switch between tool configurations
- π Seamless Integration: Works within Claude Code plugin system
When tools are disabled/blocked:
- PreToolUse hook prevents execution
- Clear user feedback with enable instructions
- No token waste on blocked tool calls
Claude Code Session
β
SessionStart Hook β Load registry, analyze available tools
β
User Request β Claude analyzes needs
β
Agent Decision β Request specific tools
β
Lazy Loading β Load only requested tools
β
Tool Usage β Monitor usage patterns
β
Intelligent Purge β Remove unused tools
{
"tool-name": {
"capabilities": ["search", "documentation"],
"keywords": ["docs", "api", "reference"],
"usagePattern": "documentation-lookup",
"avgTokens": 2500,
"contextPriority": "medium"
}
}# Clone the repository
git clone https://github.com/machjesusmoto/lazy-mcp.git
cd lazy-mcp
# Install dependencies
npm install
# Build all packages
npm run build
# Run tests
npm testlazy-mcp/
βββ plugin/ # Claude Code plugin
βββ cli/ # Standalone CLI tool
βββ shared/ # Shared core library
βββ docs/ # Documentation
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
MIT License - see LICENSE file for details.
- Built for Claude Code by Anthropic
- Inspired by the need for smarter context management
- Thanks to the Claude Code plugin system for making this possible