其他MCP
一个MCP(模型上下文协议)服务器,为LangChain.js支持的子代理工具提供会话管理。它允许Claude Code(或任何MCP客户端)将任务委托给另一个LLM,同时保持对话上下文。
特性
- 多提供商支持:OpenAI兼容API(Qwen、DeepSeek、本地模型)和Anthropic兼容API
- 模型注册表:配置多个模型并在运行时在它们之间切换
- 会话管理:创建持久对话,以维护多条消息的上下文
- 会话日志记录:所有对话都会自动保存为markdown文件
sessions/目录 - 内置工具:代理可以读取文件、列出目录、使用grep进行搜索等
- 简单集成:通过与Claude Code合作
claude mcp add
安装
cd /path/to/other-mcp
npm install
npm run build配置
环境变量
| 变量 | 描述 | 默认值 |
|---|---|---|
SUBAGENT_PROVIDER | openai 或 anthropic | openai |
SUBAGENT_BASE_URL | API基本URL | 提供程序默认值 |
SUBAGENT_API_KEY | API密钥(必需) | - |
SUBAGENT_MODEL | 默认型号ID | gpt-4o-mini / claude-sonnet-4-20250514 |
SUBAGENT_MODELS | JSON模型注册表 | {} |
使用.env文件
创建 .env 项目根目录中的文件:
# Provider: 'openai' or 'anthropic'
SUBAGENT_PROVIDER=openai
# API endpoint (for OpenAI-compatible APIs)
SUBAGENT_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
# Your API key
SUBAGENT_API_KEY=sk-your-api-key-here
# Default model
SUBAGENT_MODEL=qwen-max
# Model registry (JSON format)
# Simple format: model name -> model ID
SUBAGENT_MODELS={"qwen-max":"qwen-max","qwen-turbo":"qwen-turbo","qwen-plus":"qwen-plus"}模型注册表格式
这 SUBAGENT_MODELS 环境变量支持两种格式:
简单格式 -只需将名称映射到模型ID(使用默认提供程序设置):
{
"qwen": "qwen-max",
"gpt4o": "gpt-4o-mini",
"turbo": "qwen-turbo"
}完整配置格式 -覆盖每个模型的提供者/baseUrl:
{
"qwen": {
"provider": "openai",
"modelId": "qwen-max",
"baseUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1",
"apiKey": "sk-qwen-key"
},
"claude": {
"provider": "anthropic",
"modelId": "claude-3-5-haiku-latest",
"baseUrl": "https://api.anthropic.com"
},
"local": {
"provider": "openai",
"modelId": "llama3",
"baseUrl": "http://localhost:11434/v1",
"apiKey": "ollama"
}
}添加到克劳德代码
基本设置(单一型号)
claude mcp add -s user subagent \
-e "SUBAGENT_PROVIDER=openai" \
-e "SUBAGENT_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1" \
-e "SUBAGENT_API_KEY=your-api-key" \
-e "SUBAGENT_MODEL=qwen-max" \
-- node /path/to/other-mcp/dist/index.js多模型设置
claude mcp add -s user subagent \
-e "SUBAGENT_PROVIDER=openai" \
-e "SUBAGENT_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1" \
-e "SUBAGENT_API_KEY=your-api-key" \
-e "SUBAGENT_MODEL=qwen-max" \
-e 'SUBAGENT_MODELS={"qwen-max":"qwen-max","qwen-turbo":"qwen-turbo","qwen-plus":"qwen-plus"}' \
-- node /path/to/other-mcp/dist/index.js多提供商设置
对于使用多个提供商(例如,Qwen和当地Ollama):
claude mcp add -s user subagent \
-e "SUBAGENT_PROVIDER=openai" \
-e "SUBAGENT_API_KEY=your-qwen-key" \
-e 'SUBAGENT_MODELS={"qwen":{"provider":"openai","modelId":"qwen-max","baseUrl":"https://dashscope.aliyuncs.com/compatible-mode/v1"},"local":{"provider":"openai","modelId":"llama3","baseUrl":"http://localhost:11434/v1","apiKey":"ollama"}}' \
-- node /path/to/other-mcp/dist/index.jsMCP工具
run_agent
使用给定的提示符运行LangChain代理(无状态,单圈)。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
prompt | string | Yes | 代理的任务/提示 |
system_prompt | string | 否 | 代理的系统提示 |
max_iterations | number | No | 最大工具迭代次数(默认值:10) |
model | string | 否 | 来自SUBAGENT_MODELS的模型名称 |
例子:
mcp__other__run_agent(prompt="Summarize the key points of quantum computing")
mcp__other__run_agent(prompt="Translate to Chinese", model="qwen-turbo")list_models
列出SUBAGENT_models中配置的所有可用型号。
输出示例:
## Available Models
| Name | Provider | Model ID | Base URL |
|------|----------|----------|----------|
| _default | openai | qwen-max | https://dashscope.aliyuncs.com/compati... |
| qwen-max | openai | qwen-max | (default) |
| qwen-turbo | openai | qwen-turbo | (default) |
| qwen-plus | openai | qwen-plus | (default) |
Use the `model` parameter in `run_agent` to select a model by name.创建会话
创建一个新的对话会话,以维护多条消息的上下文。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 否 | 来自SUBAGENT_MODELS的模型名称 |
system_prompt | string | 否 | 会话的系统提示 |
例子:
mcp__other__create_session(model="gpt-5.1", system_prompt="You are a helpful assistant")
# Returns: session_idsend_message
向现有会话发送消息并获得响应。对话历史被保留。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
session_id | string | 是 | 要向其发送消息的会话ID |
message | string | 是 | 要发送的消息 |
例子:
mcp__other__send_message(session_id="abc-123", message="Hello, how are you?")
mcp__other__send_message(session_id="abc-123", message="What did I just say?")
# The agent remembers the previous messagelist_sessions
列出所有活动的对话会话。
输出示例:
## Active Sessions
| Session ID | Model | Messages | Last Active |
|------------|-------|----------|-------------|
| `d7fbfd49...` | gpt-5.1 | 7 | 2025-12-10T07:59:32.956Z |
Total: 1 session(s)get_session历史记录
获取特定会话的对话历史记录。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
session_id | string | 是 | 要获取历史记录的会话ID |
删除会话
删除对话会话。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
session_id | string | 是 | 要删除的会话ID |
代理工具(内置)
代理可以访问以下只读工具来探索文件系统:
read_file
读取文件的内容。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
file_path | string | 是 | 要读取的文件的路径 |
max_lines | number | 否 | 要读取的最大行数 |
list_directory
列出目录的内容,包括文件大小和修改时间。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
directory_path | string | 是 | 要列出的目录的路径 |
show_hidden | boolean | 否 | 是否显示隐藏文件(默认值:false) |
全局正则表达式打印
使用正则表达式在文件中搜索模式。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
pattern | string | Yes | 要搜索的正则表达式模式 |
path | string | 是 | 要搜索的文件或目录路径 |
ignore_case | boolean | 否 | 是否忽略大小写(默认值:false) |
max_results | number | 否 | 每个文件的最大结果数 |
通配符
查找与glob模式匹配的文件。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
pattern | string | Yes | 要匹配的glob模式(例如,“\*.ts”) |
path | string | 是 | 要搜索的目录 |
file_info
获取有关文件或目录的详细信息。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
file_path | string | 是 | 文件或目录的路径 |
提供商示例
Qwen(阿里云)
SUBAGENT_PROVIDER=openai
SUBAGENT_BASE_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
SUBAGENT_API_KEY=sk-your-qwen-key
SUBAGENT_MODEL=qwen-max深度求索
SUBAGENT_PROVIDER=openai
SUBAGENT_BASE_URL=https://api.deepseek.com/v1
SUBAGENT_API_KEY=sk-your-deepseek-key
SUBAGENT_MODEL=deepseek-chat开放人工智能
SUBAGENT_PROVIDER=openai
# SUBAGENT_BASE_URL not needed for official OpenAI
SUBAGENT_API_KEY=sk-your-openai-key
SUBAGENT_MODEL=gpt-4o-miniAnthropic
SUBAGENT_PROVIDER=anthropic
# SUBAGENT_BASE_URL not needed for official Anthropic
SUBAGENT_API_KEY=sk-ant-your-key
SUBAGENT_MODEL=claude-3-5-haiku-latestOllama(当地)
SUBAGENT_PROVIDER=openai
SUBAGENT_BASE_URL=http://localhost:11434/v1
SUBAGENT_API_KEY=ollama
SUBAGENT_MODEL=llama3发展
# Build
npm run build
# Test tools/list
echo '{"jsonrpc":"2.0","method":"tools/list","id":1}' | node dist/index.js
# Test list_models with config
export SUBAGENT_API_KEY=test
export SUBAGENT_MODELS='{"model1":"gpt-4o","model2":"qwen-max"}'
echo '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"list_models","arguments":{}},"id":2}' | node dist/index.js许可证
麻省理工学院
