mcp-http-agent-md 是一个轻量级的 MCP(Model Context Protocol)HTTP 服务器,专为 AGENTS.md 和结构化任务设计。它具备版本化历史记录(日志/回滚)和临时便签功能,并通过可流式传输的 HTTP 端点对外提供服务。便签还可用于生成上下文隔离的子代理,以解决特定任务。此外,该服务器还提供了认证中间件,用于用户隔离和公共服务,用户还能在服务器内共享和协作项目。
本项目由 Codex (OpenAI) 共同创作。
$HOME/.config/mcp-http-agent-md 并以默认用户启动)curl -fsSL https://raw.githubusercontent.com/benhaotang/mcp-http-agent-md/main/install/install.sh | bash
$HOME/.config/mcp-http-agent-md/data)curl -fsSL https://raw.githubusercontent.com/benhaotang/mcp-http-agent-md/main/install/install-docker.sh | bash
首先,克隆仓库:git clone https://github.com/benhaotang/mcp-http-agent-md.git
你可以在终端通过 export XXX=xxx 设置 .env.example 中定义的所有环境变量。
如果你更喜欢通过 .env 文件设置:cp .env.example .env
HOST=localhost,PORT=3000,BASE_PATH=/mcp。.env 文件或环境变量中设置。了解更多支持的 提供商和模型。USE_EXTERNAL_AI=true
AI_API_TYPE=google # google | openai | groq | compat | mcp
AI_API_KEY=... # 启用时必需
AI_MODEL="gemini-2.5-pro" # 可选;默认值取决于提供商
AI_TIMEOUT=120 # 可选
⚠️ 重要提示
对于 Docker,出于安全考虑,目前仅支持通过
-e XXX=xxx添加环境变量。如果你想使用.env文件,请从.dockerignore中移除它并本地构建镜像。详见 Docker。
pnpm installpnpm devpnpm startnpm installnpx nodemon --watch index.js --ext js,mjs,cjs index.jsnpm run startdocker pull ghcr.io/benhaotang/mcp-http-agent-md:latest
docker run -it --restart always \
-p 3000:3000 \
-e MAIN_API_KEY=change-me \
-e HOST=0.0.0.0 \
-v $(pwd)/data:/app/data \
--name mcp-http-agent-md \
ghcr.io/benhaotang/mcp-http-agent-md:latest
-e AI_API_KEY=xxx -e USE_EXTERNAL_AI=true。docker build -t mcp-http-agent-md .本项目为从事长期项目的 AI 代理实现了一个分层上下文管理系统:
graph LR
subgraph "Full Project Knowledge"
PK["📚 Entire Project
• All code files
• All documentation
• Web resources
• Tool outputs
MASSIVE CONTEXT"]
end
subgraph "Compressed Knowledge"
A["📄 AGENTS.md
(Essential Knowledge)"]
P["📋 progress.md
(Task Board)"]
end
subgraph "Main Agent"
MA["🧠 Orchestrator
LOW CONTEXT
• Reads compressed knowledge
• Spawns scratchpads
• Updates project state"]
end
subgraph "Scratchpad"
CM["Common Memory
(Shared Context)"]
subgraph "Task Pool"
T1["Task 1"]
T2["Task 2"]
T3["Task ..."]
end
subgraph "Subagents"
SA1["🤖 Agent 1
HIGH CONTEXT"]
SA2["🤖 Agent 2
HIGH CONTEXT"]
end
end
%% Knowledge compression flow
PK --> |compresses to| A
PK --> |compresses to| P
%% Main agent reads compressed knowledge
A --> MA
P --> MA
%% Main agent creates scratchpad with smaller tasks
MA --> |break into tasks| T1
MA --> |break into tasks| T2
MA --> |break into tasks| T3
MA --> |maintains| CM
%% Main agent can read/write directly
MA <--> |read/write| CM
MA <--> |read/write| T1
MA <--> |read/write| T2
MA <--> |read/write| T3
%% Tasks spawn subagents
T1 --> |spawns| SA1
T2 --> |spawns| SA2
%% Subagents get context and work on specific tasks
SA1 --> |full access| PK
SA2 --> |full access| PK
CM --> |shared context| SA1
CM --> |shared context| SA2
%% Subagents report back to their tasks
SA1 --> |results/comments| T1
SA2 --> |results/comments| T2
%% Main agent updates compressed knowledge
MA --> |updates| A
MA --> |updates| P
style PK fill:#ffecb3
style A fill:#e1f5fe
style P fill:#e8f5e8
style MA fill:#ffebee
style CM fill:#f3e5f5
style SA1 fill:#fff3e0
style SA2 fill:#fff3e0
主要优势:
$HOME/.config/mcp-http-agent-md 并以默认用户启动)curl -fsSL https://raw.githubusercontent.com/benhaotang/mcp-http-agent-md/main/install/install.sh | bash
$HOME/.config/mcp-http-agent-md/data)curl -fsSL https://raw.githubusercontent.com/benhaotang/mcp-http-agent-md/main/install/install-docker.sh | bash
首先,克隆仓库:git clone https://github.com/benhaotang/mcp-http-agent-md.git
你可以在终端通过 export XXX=xxx 设置 .env.example 中定义的所有环境变量。
如果你更喜欢通过 .env 文件设置:cp .env.example .env
HOST=localhost,PORT=3000,BASE_PATH=/mcp。.env 文件或环境变量中设置。了解更多支持的 提供商和模型。USE_EXTERNAL_AI=true
AI_API_TYPE=google # google | openai | groq | compat | mcp
AI_API_KEY=... # 启用时必需
AI_MODEL="gemini-2.5-pro" # 可选;默认值取决于提供商
AI_TIMEOUT=120 # 可选
⚠️ 重要提示
对于 Docker,出于安全考虑,目前仅支持通过
-e XXX=xxx添加环境变量。如果你想使用.env文件,请从.dockerignore中移除它并本地构建镜像。详见 Docker。
pnpm installpnpm devpnpm startnpm installnpx nodemon --watch index.js --ext js,mjs,cjs index.jsnpm run startdocker pull ghcr.io/benhaotang/mcp-http-agent-md:latest
docker run -it --restart always \
-p 3000:3000 \
-e MAIN_API_KEY=change-me \
-e HOST=0.0.0.0 \
-v $(pwd)/data:/app/data \
--name mcp-http-agent-md \
ghcr.io/benhaotang/mcp-http-agent-md:latest
-e AI_API_KEY=xxx -e USE_EXTERNAL_AI=true。docker build -t mcp-http-agent-md .管理 API:http://localhost:3000/auth(Bearer MAIN_API_KEY),首先生成一个 USER_API_KEY,详见 认证和管理
{
"mcpServers": {
"mcp-agent-md": {
"command": "npx",
"args": ["-y","mcp-remote","http://localhost:3000/mcp?apiKey=USER_API_KEY`"]
}
}
}
{
"mcpServers": {
"mcp-agent-md": {
"url": "https:///mcp?apiKey=USER_API_KEY" ,
}
}
}
curl -X POST 'http://localhost:3000/mcp?apiKey=USER_API_KEY' \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":"1","method":"tools/list"}'
一个可选的轻量级管理控制台(Next.js App Router)已打包并在 /ui 提供服务:
在运行 pnpm dev 时会自动包含(热重载)。服务器启动后访问 /ui。
先构建 UI,然后以生产模式启动服务器:
pnpm build:ui
NODE_ENV=production pnpm start
# 示例代码调用 list_projects 工具
# 示例代码调用 init_project 工具
# 示例代码调用 delete_project 工具
# 示例代码调用 rename_project 工具
# 示例代码调用 read_agent 工具
# 示例代码调用 write_agent 工具
# 示例代码调用 read_progress 工具
# 示例代码调用 progress_add 工具
# 示例代码调用 progress_set_new_state 工具
# 示例代码调用 generate_task_ids 工具
# 示例代码调用 get_agents_md_best_practices_and_examples 工具
# 示例代码调用 list_project_logs 工具
# 示例代码调用 revert_project 工具
# 示例代码调用 scratchpad_initialize 工具
# 示例代码调用 review_scratchpad 工具
# 示例代码调用 scratchpad_update_task 工具
# 示例代码调用 scratchpad_append_common_memory 工具
# 示例代码调用 scratchpad_subagent 工具
# 示例代码调用 scratchpad_subagent_status 工具
?apiKey=... 或 Authorization: Bearer ... 提供用户 apiKey。Authorization: Bearer MAIN_API_KEY。curl -X POST http://localhost:3000/auth/users \
-H "Authorization: Bearer $MAIN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name":"alice"}'
基础路径:/auth(Bearer MAIN_API_KEY)
/auth/users:创建用户 → { id, apiKey, name? }/auth/users:列出用户(?reveal=true 显示完整密钥)/auth/users/:id:获取用户信息/auth/users/:id/regenerate:旋转 API 密钥/auth/users/:id:删除用户通过 REST API 与其他用户共享项目。基础路径:/project(Bearer 令牌认证)
curl -X POST http://localhost:3000/project/share \
-H "Authorization: Bearer $USER_API_KEY/$MAIN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"project_id":"","target_user_id":"","permission":"ro"}'
/project/list:列出项目(管理员:所有项目;用户:拥有的 + 共享的)/project/share:共享项目 { project_id, target_user_id, permission, revoke? }。权限:ro(只读)或 rw(读写)。设置 revoke: true 以移除访问权限。/project/status?project_id=...:获取项目共享状态POST /mcp(可流式传输的 HTTP,无状态 JSON-RPC)curl -X POST 'http://localhost:3000/mcp?apiKey=USER_API_KEY' \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":"1","method":"tools/list"}'
一个可选的轻量级管理控制台(Next.js App Router)已打包并在 /ui 提供服务:
在运行 pnpm dev 时会自动包含(热重载)。服务器启动后访问 /ui。
先构建 UI,然后以生产模式启动服务器:
pnpm build:ui
NODE_ENV=production pnpm start
{ name, agent?, progress? }。立即创建初始备份(提交)并返回 hash。{ name }。(仅限所有者){ oldName, newName, comment? }(仅限所有者)。返回更新后的 hash。AGENTS.md { name }。AGENTS.md { name, content, comment? }。也支持补丁/差异;响应包括更新后的 hash。{ name, only? }。返回 JSON { tasks: [...], markdown: "..." },其中 markdown 是一个嵌套的、人性化的大纲。only 按 pending | in_progress | completed | archived 过滤(接受同义词)。默认情况下,存档任务被排除;只有当 only 包含 archived 时才会包含。{ name, item, comment? }。添加任务时创建一个提交;返回 hash。task_id(8 个字符)或匹配 task_info 子字符串更新任务 { name, match, state?, task_info?, parent_id?, extra_note?, comment? }。发生更改时创建一个提交;返回 hash。
completed 或 archived 状态时,不允许对该任务或其后代进行编辑,除非将任务本身解锁为 pending 或 in_progress(并且只有当它的任何祖先都没有锁定时)。解锁父任务会传播到其后代。{ count? }(默认 5 个)。返回 { ids: ["abcd1234", ...] }。example_agent_md.json 返回最佳实践和示例。默认仅返回 the_art_of_writing_agents_md(最佳实践)。使用 include='all' 包含所有示例,或将 include 设置为字符串/数组以按用例/标题过滤。{ name } → { logs: [{ hash, message, modified_by, created_at }] }。modified_by 字段显示每个提交的作者。hash { name, hash }。共享参与者只能回滚到他们最近的连续序列中的提交(以防止丢弃他人的工作)。将历史记录修剪到该点(无分支)。{ name, tasks }。服务器生成并返回一个随机的 scratchpad_id。tasks 最多 6 项 { task_id, status: 'open'|'complete', task_info, scratchpad?, comments? }。返回 { scratchpad_id, project_id, tasks, common_memory }。{ name, scratchpad_id, IncludeCM?, IncludeTk? } 查看便签。
true 时,在输出中包含 common_memory。task_id(不区分大小写的精确匹配)或 task_info(不区分大小写的子字符串)过滤任务。提供时,仅返回匹配的任务。IncludeCM 也没有提供 IncludeTk,则返回 tasks 和 common_memory(向后兼容的默认值)。否则,仅包含请求的字段;如果省略 IncludeTk,则不返回 tasks。task_id 更新现有便签任务 { name, scratchpad_id, updates },其中 updates 是一个 { task_id, status?, task_info?, scratchpad?, comments? } 数组。返回 { updated, notFound, scratchpad }。{ name, scratchpad_id, append },其中 append 是一个字符串或字符串数组。返回更新后的便签。USE_EXTERNAL_AI 不为 false 时显示){ name, scratchpad_id, task_id, prompt, sys_prompt?, tool? }。工具取决于提供商(AI_API_TYPE)。规范工具:grounding(搜索),crawling(网页抓取),code_execution(运行代码)。自动将 common_memory 追加到提示中。可能会提前返回 status: in_progress 和一个 run_id。{ name, run_id }。返回最终状态,或在仍在运行时最多轮询约 25 秒。(项目名称, 便签 ID) 来引用便签,以便在同一会话中重新打开现有的便签。所有任务工具都接受一个 name(项目名称)参数;服务器将其解析为内部项目 ID。你永远不需要提供 project_id。
AI_BASE_ENDPOINT 和 AI_MODEL;在 subagent_config.json 中配置 MCP 服务器。要求端点和模型组合支持函数调用# Gemini
AI_API_TYPE=google
AI_MODEL="gemini-2.5-pro"
# OpenAI
# AI_API_TYPE=openai
# AI_MODEL="gpt-5-mini"
# Groq
# AI_API_TYPE=groq
# AI_MODEL="openai/gpt-oss-120b"
# OpenAI 兼容(例如,LM Studio)
# AI_API_TYPE=compat
# AI_BASE_ENDPOINT="http://localhost:1234/v1"
# AI_MODEL="qwen/qwen3-4b-2507"
# MCP + OpenAI 兼容
# AI_API_TYPE=mcp
# AI_BASE_ENDPOINT="http://localhost:1234/v1"
# AI_MODEL="qwen/qwen3-4b-2507"
subagent_config.json 中。本仓库中包含示例。mcpServers 下定义服务器。对于远程服务器,使用 { "serverUrl": "https://.../mcp" }(HTTP)或 .../sse(SSE;旧版但支持)。对于本地标准输入输出服务器,使用 { "command": "...", "args": [ ... ] }。short_descriptions 以帮助代理选择(推荐)。详见仓库中的 subagent_config.json 示例。本项目为从事长期项目的 AI 代理实现了一个分层上下文管理系统,其架构图如下:
graph LR
subgraph "Full Project Knowledge"
PK["📚 Entire Project
• All code files
• All documentation
• Web resources
• Tool outputs
MASSIVE CONTEXT"]
end
subgraph "Compressed Knowledge"
A["📄 AGENTS.md
(Essential Knowledge)"]
P["📋 progress.md
(Task Board)"]
end
subgraph "Main Agent"
MA["🧠 Orchestrator
LOW CONTEXT
• Reads compressed knowledge
• Spawns scratchpads
• Updates project state"]
end
subgraph "Scratchpad"
CM["Common Memory
(Shared Context)"]
subgraph "Task Pool"
T1["Task 1"]
T2["Task 2"]
T3["Task ..."]
end
subgraph "Subagents"
SA1["🤖 Agent 1
HIGH CONTEXT"]
SA2["🤖 Agent 2
HIGH CONTEXT"]
end
end
%% Knowledge compression flow
PK --> |compresses to| A
PK --> |compresses to| P
%% Main agent reads compressed knowledge
A --> MA
P --> MA
%% Main agent creates scratchpad with smaller tasks
MA --> |break into tasks| T1
MA --> |break into tasks| T2
MA --> |break into tasks| T3
MA --> |maintains| CM
%% Main agent can read/write directly
MA <--> |read/write| CM
MA <--> |read/write| T1
MA <--> |read/write| T2
MA <--> |read/write| T3
%% Tasks spawn subagents
T1 --> |spawns| SA1
T2 --> |spawns| SA2
%% Subagents get context and work on specific tasks
SA1 --> |full access| PK
SA2 --> |full access| PK
CM --> |shared context| SA1
CM --> |shared context| SA2
%% Subagents report back to their tasks
SA1 --> |results/comments| T1
SA2 --> |results/comments| T2
%% Main agent updates compressed knowledge
MA --> |updates| A
MA --> |updates| P
style PK fill:#ffecb3
style A fill:#e1f5fe
style P fill:#e8f5e8
style MA fill:#ffebee
style CM fill:#f3e5f5
style SA1 fill:#fff3e0
style SA2 fill:#fff3e0
本项目采用 MIT 许可证。详见 LICENSE。