[FEATURE] Dynamic MCP server loading/unloading without restart
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
问题描述
背景:
当前 Claude Code 在启动时会加载所有配置的 MCP 服务器,即使某些服务器在当前会话中不会被使用。这导致:
- Token 消耗过大:每个 MCP 服务器的工具列表都会被包含在系统提示中,10+ 个 MCP 服务器可能消耗 5,000-8,000 tokens
- 启动时间延长:所有 MCP 服务器都需要在启动时完成握手和工具发现
- 资源浪费:不常用的 MCP 服务器持续占用内存和连接
需求:
希望能够:
- 在运行时动态加载/卸载 MCP 服务器
- 按需启动 MCP 服务器(首次使用时才启动)
- 通过命令或 API 控制 MCP 服务器的生命周期
Proposed Solution
建议的解决方案
### 方案 A:运行时命令(推荐)
添加 /mcp 内置命令来管理 MCP 服务器:
/mcp list # 列出所有已加载的 MCP
/mcp load # 动态加载指定 MCP
/mcp unload # 卸载指定 MCP
/mcp reload # 重新加载 MCP(重启服务)
/mcp status # 显示 MCP 状态和连接信息
### 方案 B:懒加载模式
在 config.json 中添加 lazyLoad 选项:
```json
{
"mcpServers": {
"playwright": {
"command": "npx -y @executeautomation/playwright-mcp-server",
"lazyLoad": true // 首次使用时才启动
}
}
}
方案 C:会话级 MCP 配置
支持通过命令行参数指定会话特定的 MCP:
claude --mcp-session web # 仅加载 web 开发相关的 MCP
claude --mcp-session minimal # 仅加载核心 MCP
Alternative Solutions
_No response_
Priority
Medium - Would be very helpful
Feature Category
MCP server integration
Use Case Example
_No response_
Additional Context
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗