mcpField
A
agent-link

agent-link

本地服务
github.com/mikusnuzAI 与智能体111 周前更新

关于 agent-link

agent-link 是供使用 AI 编码 Agent 命令行工具的团队进行双向协作的 MCP 服务。它启动 CLI 子进程,支持并行任务和后续回复,会话保存在内存中。

主要功能

  1. 01将支持的 Agent CLI 作为子进程启动
  2. 02并行运行多个 Agent
  3. 03往返交换追问与回复
  4. 04列出可用 CLI 和活动会话
  5. 05取消正在运行的 Agent 进程

适用场景

  1. 01为受阻的编码任务征求第二意见
  2. 02让另一个 Agent 审查代码变更
  3. 03在 Agent 间拆分研究与实现工作

MCP 相关

MCP 服务提供启动 Agent CLI、回复、列出和停止进程的工具。兼容 MCP 的客户端可借此协调 Claude Code、Codex、Gemini 和 Aider 等 Agent。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"mikusnuz-agent-link": {
"command": "npx",
"args": [
"-y",
"agent-link-mcp"
]
}
}
}
启动命令npx -y agent-link-mcp

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
npmagent-link-mcp0.5.3

工具

6

收录的工具列表 · 更新于 1 周前

参数类型必填说明
cwdstring否Agent 进程的工作目录
taskstring是发送给 Agent 的任务描述
agentstring是Agent 名称(例如 "claude"、"codex"、"gemini"、"aider")
modelstring否要使用的模型(例如 "o3"、"gpt-5.4"、"claude-sonnet-4"、"gemini-2.5-pro")。通过 --model 标志传递给 Agent CLI。
retryboolean否失败时自动重试(默认值:false)。
contextobject否可选的任务上下文
context.diffany否将 git diff 作为上下文。true = 所有更改,"staged" = 仅暂存的更改,"unstaged" = 仅未暂存的更改。
context.errorstring否要作为上下文包含的错误消息
context.filesarray否要作为上下文包含的绝对文件路径
context.intentstring否任务背后的高层意图或目标
escalateboolean否重试时自动提高思考层级(默认值:false)。需要设置 retry: true。
thinkingstring否思考/推理深度级别(例如 "low"、"medium"、"high"、"max")。控制 Agent 推理的深度。
timeoutMsinteger否超时时间(毫秒,默认值:3600000)

详细介绍

agent-link-mcp

npm version License: MIT

English | 한국어

用于双向 AI Agent 协作的 MCP 服务。启动并与任意 AI 编码 Agent CLI 通信——Claude Code、Codex、Gemini、Aider 等。

适用场景

0.5.2 版修复了 Claude JSON 响应解析问题,可在回复之间保留原始任务、上下文和工作目录,并将取消操作连接到运行中的进程。reply 会使用记录的对话启动新的 CLI 调用,而不会恢复提供方侧的会话。同一会话的并发回复会被拒绝。kill_agent 会等待进程终止;必要时会在五秒后升级终止操作。服务关闭时也会取消活动的子进程。会话保存在内存中,服务重启后不会保留。

  • 遇到难解的 bug?——你的 Agent 已经尝试两次但仍未成功。让它向另一个 Agent 寻求新的思路。
  • 需要第二种意见?——请另一个 AI 模型进行代码审查或提供架构建议。
  • 发挥不同模型的优势——用 Claude 规划,用 Codex 执行,用 Gemini 调研。
  • 并行工作——同时启动多个 Agent,处理互不相关的子任务。
  • 结对调试——让一个 Agent 向另一个 Agent 解释问题,并获取解决方案。

使用场景

遇到难题时寻求帮助

你的主 Agent 总是在同一个问题上失败?向另一个 Agent 求助:

# Claude Code is stuck on a TypeScript error it can't resolve.
# It spawns Codex for a second opinion:

spawn_agent("codex", "This TypeScript error keeps appearing. How do I fix it?", {
  error: "Type 'string' is not assignable to type 'number'",
  files: ["src/utils.ts"]
})
跨 Agent 代码审查

让另一个模型审查你的 Agent 所做的代码修改:

spawn_agent("claude", "Review these changes for bugs and edge cases", {
  files: ["src/api.ts", "src/handler.ts"],
  intent: "Code review before merge"
})
多 Agent 流水线

构建由多个 Agent 处理不同阶段的流水线:

# Agent 1: Research
spawn_agent("gemini", "Find the best approach for WebSocket reconnection")

# Agent 2: Implementation (using Agent 1's advice)
spawn_agent("codex", "Implement WebSocket reconnection with exponential backoff", {
  files: ["src/ws-client.ts"]
})

# Agent 3: Review
spawn_agent("claude", "Review this implementation for production readiness", {
  files: ["src/ws-client.ts"]
})
双向协作

Agent 也可以反过来提问。宿主会作答,工作随后继续:

Host: spawn_agent("codex", "Add caching to the API layer")
Codex: [QUESTION] Should I use Redis or in-memory cache?
Host: reply("codex-a1b2c3", "Use Redis, we have it in our docker-compose")
Codex: [RESULT] Added Redis caching with 5-minute TTL...

原因

AI 编码 Agent 有时会陷入困境。它们不必一直等你,可以向另一个 Agent 求助。agent-link-mcp 让任何兼容 MCP 的 Agent 都能启动其他 Agent CLI 作为协作者、互相提问并获取结果——整个过程都通过标准 MCP 工具完成。

  • 只需在一端安装——只有宿主 Agent 需要安装此 MCP 服务。启动的 Agent 只是 CLI 子进程。
  • 双向交互——宿主可以向启动的 Agent 提问,启动的 Agent 也可以反过来提问。
  • 支持任意 Agent——适用于任何能够接收提示词并返回文本的 CLI。内置 Claude、Codex、Gemini 和 Aider 配置。
  • 多 Agent——同时启动多个 Agent,进行并行协作。

前置条件

需要 Node.js 20 或更高版本,包括 MCP 宿主的 npx 环境。Agent CLI 可能还有各自的额外要求。

agent-link-mcp 会将其他 AI Agent 作为 CLI 子进程启动。你需要安装并完成身份验证,才能使用希望协作的 Agent CLI:

Agent安装身份验证
Claude Codenpm install -g @anthropic-ai/claude-codeclaude login
Codexnpm install -g @openai/codexcodex login
Gemini CLInpm install -g @google/gemini-cli运行 gemini 并按照登录提示操作
Aiderpip install aider-chat设置 OPENAI_API_KEY 或 ANTHROPIC_API_KEY

只需安装你计划使用的 Agent。agent-link-mcp 会自动检测已安装的 CLI。

安装

# Claude Code
claude mcp add agent-link npx agent-link-mcp

# Codex
codex mcp add agent-link npx agent-link-mcp

# Any MCP client
npx agent-link-mcp

**注意:**只需在你正在使用的 Agent 中安装此 MCP 服务。其他 Agent 会作为子进程启动,无需安装 agent-link-mcp。

工具

spawn_agent

生成一个 Agent 并向其发送任务。

{
  "agent": "codex",
  "task": "Refactor this function for better performance",
  "context": {
    "files": ["src/utils.ts"],
    "error": "TypeError: Cannot read property 'x' of undefined",
    "intent": "Performance improvement"
  },
  "model": "o3",
  "timeoutMs": 7200000
}
参数类型默认值描述
agentstring必填Agent 名称("claude"、"codex"、"gemini"、"aider")
taskstring必填任务描述
contextobject—可选的 { files, error, intent, diff }。diff: true 会包含 git diff 输出。diff: "staged" 仅包含暂存内容。
cwdstringcwdAgent 进程的工作目录
modelstring—要使用的模型(例如 "o3"、"gpt-5.4"、"claude-sonnet-4"、"gemini-2.5-pro")。通过 --model 标志传入。
thinkingstring—思考/推理深度;支持的值取决于所选的 CLI 和模型。Claude:--effort,Codex:-c model_reasoning_effort,Aider:--reasoning-effort。
retrybooleanfalse失败时自动重试(最多 3 次)。
escalatebooleanfalse重试时自动提高思考级别。需要设置 retry: true。
timeoutMsnumber3600000超时时间,单位为 ms。默认值:1 小时。

返回以下其中一种:

  • { status: "done", agentId: "codex-a1b2c3", result: "..." } — 任务已完成
  • { status: "waiting_for_reply", agentId: "codex-a1b2c3", question: "..." } — Agent 需要澄清
  • { error: "...", agentId: "codex-a1b2c3" } — 发生错误
spawn_agents

并行运行多个 Agent。一次性返回所有结果。

{
  "agents": [
    { "agent": "codex", "task": "Review for bugs", "context": { "diff": true } },
    { "agent": "claude", "task": "Review for security", "context": { "diff": true } }
  ],
  "cwd": "/path/to/project"
}

返回 { summary: { total, succeeded, failed, waiting }, results: [...] }。

reply

回答已生成的 Agent 提出的问题,并继续对话。

{
  "agentId": "codex-a1b2c3",
  "message": "Yes, you can remove the side effects"
}
kill_agent

中止正在运行的 Agent 会话。

{
  "agentId": "codex-a1b2c3"
}
list_agents

列出可用的 Agent CLI。

{
  "agents": [
    { "name": "claude", "command": "claude", "source": "auto", "available": true },
    { "name": "codex", "command": "codex", "source": "auto", "available": true },
    { "name": "gemini", "command": "gemini", "source": "auto", "available": false }
  ]
}
get_status

获取活跃的 Agent 会话。

{
  "sessions": [
    { "agentId": "codex-a1b2c3", "agent": "codex", "status": "waiting_for_reply", "startedAt": "..." }
  ]
}

工作原理

You (using Claude Code)
  ↓
"Ask Codex to help with this refactoring"
  ↓
Claude Code → spawn_agent("codex", task, context)
  ↓
agent-link-mcp server → spawns `codex` CLI as subprocess
  ↓
Codex processes the task...
  ↓
Codex: "[QUESTION] Should I remove the side effects?"
  ↓
agent-link-mcp → parses response → returns to Claude Code
  ↓
Claude Code → reply("codex-a1b2c3", "Yes, remove them")
  ↓
agent-link-mcp → re-invokes Codex with accumulated context
  ↓
Codex: "[RESULT] Refactoring complete. Here's what I changed..."
  ↓
Claude Code receives the result and continues working

配置

使用 outputFormat: "json" 的自定义配置文件必须输出单个结果对象,其中包含字符串类型的 result 字段(Claude 打印模式格式)。is_error: true 或错误的 subtype 会被视为失败;元数据不会包含在对话中。

自动检测

agent-link-mcp 会自动检测已安装的 Agent CLI:

AgentCLI 命令
Claude Codeclaude
Codexcodex
Geminigemini
Aideraider
自定义 Agent

通过 ~/.agent-link/config.json 配置文件添加自定义 Agent:

{
  "agents": {
    "codex": {
      "command": "/usr/local/bin/codex",
      "args": ["--full-auto"],
      "promptFlag": null,
      "outputFormat": "text"
    },
    "my-local-llm": {
      "command": "ollama",
      "args": ["run", "codellama"],
      "promptFlag": null,
      "outputFormat": "text"
    }
  }
}

使用 AGENT_LINK_CONFIG 环境变量覆盖配置文件路径。

模型选择

可以通过 model 参数指定生成的 Agent 应使用的模型:

# Use a specific model for Codex
spawn_agent("codex", "Debug this issue", { model: "o3" })

# Use a specific model for Claude
spawn_agent("claude", "Review this code", { model: "claude-sonnet-4" })

模型名称会通过 Agent CLI 的 --model 标志传入。如果省略,Agent 将使用其默认模型。

思考/推理深度

通过 thinking 参数控制 Agent 的推理深度:

# High reasoning for complex debugging
spawn_agent("codex", "Debug this race condition", { thinking: "high" })

# Max effort for Claude
spawn_agent("claude", "Architect a new auth system", { thinking: "max" })
Agent标志取值
Claude--effortlow、medium、high、max
Codex-c model_reasoning_effort取决于模型,例如 low、medium、high、xhigh
Aider--reasoning-effortlow、medium、high

如果省略,Agent 将使用其默认推理级别。

超时

默认超时时间为 1 小时(3,600,000ms)。可以针对每次调用进行覆盖:

# 2 hour timeout for complex tasks
spawn_agent("codex", "Refactor the entire auth system", { timeoutMs: 7200000 })

对话协议

生成的 Agent 会收到格式化回复的说明:

  • [QUESTION] ... — 需要主 Agent 澄清
  • [RESULT] ... — 任务已完成

如果 Agent 不遵循此格式,则将整个输出视为结果。

开发

在本地运行 npm ci、npm run build 和 npm test。测试使用离线 Node.js 测试样例,不会调用模型提供商。CI 为手动触发(workflow_dispatch),且需要可用的自托管运行器;推送和拉取请求不会启动 GitHub 托管的作业。

许可证

MIT

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。