AMCP
](https://badge.fury.io/py/amcp-agent)   
一个乐高风格的编码代理CLI,内置工具(grep、读取文件、bash执行)和MCP服务器集成,用于扩展功能(网络搜索等)。
十、: https://x.com/zhangjintao9020/status/1995170132973466018?s=20
特性
- 内置工具:read_file、grep、bash、think、todo、apply_patch、write_file
- MCP集成:连接到任何MCP服务器以扩展功能
- 对话历史:跨运行的持续会话
- 灵活的配置:基于YAML的代理规范
- 工具调用:自动工具选择和执行
- ACP支持:IDE集成的完整代理客户端协议支持(Zed等)
- AGENTS.md支持:从自动加载项目特定规则
AGENTS.md文件 - 智能上下文压缩:具有动态阈值的智能上下文管理
- 多代理系统:具有内置代理类型(编码器、资源管理器、规划器)的主/子代理架构
- 事件总线:用于代理通信和可扩展性的发布/订阅系统
- 挂钩系统:用于工具验证、日志记录和自定义行为的可扩展挂钩
安装
使用uvx快速运行(无需安装)
# Initialize config first (API keys, model settings)
uvx amcp-agent init
# Run the agent
uvx amcp-agent
# Run as ACP server (for IDE integration)
uvx amcp-agent acp serve来自PyPI
# Install from PyPI
pip install amcp-agent
# Or with uv (requires virtual environment or --system flag)
uv pip install amcp-agent # in a virtual environment
uv pip install --system amcp-agent # global install without venv
# With Anthropic Claude support
pip install amcp-agent[anthropic]来源(开发)
# Clone the repository
git clone https://github.com/tao12345666333/amcp.git
cd amcp
# using uv (recommended)
uv venv && source .venv/bin/activate
uv pip install -e .
# or with pip
python -m venv .venv && source .venv/bin/activate
pip install -e .用法
# Initialize config
amcp init
# Agent with tool calling (default command)
amcp # interactive mode with conversation history
amcp --once "create a hello.py file with a hello function" # single message
amcp --list # list available agent specifications
amcp --agent path/to/agent.yaml # use custom agent spec
amcp --session my-session # use specific session ID
amcp --clear # clear conversation history
# MCP server management
amcp mcp tools --server exa
amcp mcp call --server exa --tool web_search_exa --args '{"query":"rust async"}'
# Run as ACP agent (for IDE integration)
amcp acp serveACP(代理客户端协议)支持
AMCP完全支持 代理客户端协议 用于与Zed等IDE集成。
特性
- 会话管理:创建、加载和列出会话
- 会话模式:切换
ask,architect,以及code模式
- ask:更改前请求许可 - architect:未实施的设计和规划 - code:实施的完整工具访问权限
- Slash命令:
/clear,/plan,/search,/help - 代理计划:复杂任务的可视化执行计划
- 权限请求:用户对敏感操作的批准
- 客户能力:使用客户端的文件系统和终端(如果可用)
以ACP代理身份运行
# Start the ACP agent server (stdio transport)
amcp acp serveZed集成
添加到Zed设置(~/.config/zed/settings.json):
{
"agent": {
"profiles": {
"amcp": {
"name": "AMCP",
"provider": {
"type": "acp",
"command": "amcp",
"args": ["acp", "serve"]
}
}
},
"default_profile": "amcp"
}
}内置工具
- read_file:使用两种模式读取文本文件:
- *切片模式* (默认):读取特定行范围 - *缩进模式*:智能读取锚线周围的代码块,自动捕获周围的上下文(函数、类)
- 全局正则表达式打印:使用ripgrep在文件中搜索模式
- bash:执行bash命令进行文件操作和系统任务
- 思考:内部推理和规划
- 待办:管理待办事项列表,以跟踪复杂操作期间的任务
- 应用程序_补丁:将基于差异的补丁应用于文件(建议编辑,请参阅 docs/apply-patch.md)
- write_file:将内容写入文件(用于创建新的小文件)
- 任务:生成用于并行任务执行的子代理
配置
CLI从以下位置加载MCP服务器 ~/.config/amcp/config.toml. 生成启动器配置:
amcp init示例(与OpenAI兼容的API):
[servers.exa]
url = "https://mcp.exa.ai/mcp"
[servers.custom]
command = "npx"
args = ["-y", "@some/mcp-server"]
env.API_KEY = "your-key"
[chat]
api_type = "openai" # "openai" (default) or "anthropic"
base_url = "https://api.openai.com/v1"
model = "gpt-4o"
api_key = "your-api-key"
mcp_tools_enabled = true
write_tool_enabled = true # Enable/disable built-in write_file tool示例(OpenAI响应API):
[chat]
api_type = "openai_responses"
model = "gpt-4o"
api_key = "your-api-key"示例(人物克劳德):
[chat]
api_type = "anthropic"
model = "claude-sonnet-4-20250514"
api_key = "your-anthropic-api-key" # or set ANTHROPIC_API_KEY env var要使用Anthropic,请安装: pip install amcp-agent[anthropic]
挂钩系统
AMCP提供了一个灵活的钩子系统来扩展和定制代理行为。挂钩可以:
- 执行前验证和修改工具输入
- 执行后处理工具输出
- 阻止危险作业
- 记录和审计代理活动
快速示例
创建 .amcp/hooks.toml 在您的项目中:
[hooks.PreToolUse]
[[hooks.PreToolUse.handlers]]
matcher = "write_file|apply_patch"
type = "python"
script = "./scripts/validate-writes.py"
timeout = 30
[[hooks.PostToolUse.handlers]]
matcher = "*"
type = "command"
command = "echo 'Tool executed' >> /tmp/tool_log.txt"看 docs/hooks.md 获取完整文档。
发展
设置开发环境
# Clone the repository
git clone https://github.com/tao12345666333/amcp.git
cd AMCP
# Install with development dependencies
pip install -e ".[dev]"
# Install pre-commit hooks
pre-commit install运行测试
# Run all tests
make test
# Run with coverage
make test-cov
# Run specific test
pytest tests/test_tools.py -v代码质量
# Lint code
make lint
# Format code
make format
# Type check
make type-check看 贡献.md 详细的开发指南。
备注
rg(ripgrep)必须安装在grep工具的PATH上。- MCP服务器必须单独安装并可运行(stdio传输)。
许可证
阿帕奇-2.0
