关于 Aider MCP Server - Experimental
Aider MCP Server 是一个实验性的 MCP 服务,允许 Claude Code 将编码任务委派给 Aider 执行。适合希望降低成本、控制编码模型并让 Claude Code 审阅修改的开发者。
主要功能
- 01提供 aider_ai_code 工具执行编码任务
- 02返回修改是否成功及 diff
- 03提供 list_models 工具按子串查询模型
- 04支持指定可编辑与只读文件
适用场景
- 01将重构任务交给 Aider 完成后由 Claude Code 审阅
- 02按子串查找可用模型
- 03在指定文件范围内自动修改代码
MCP 相关
该项目是 MCP 服务,向 Claude Code 等 MCP 客户端暴露 aider_ai_code 与 list_models 两个工具。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
Aider MCP 服务 - 实验性
用于将 AI 编码任务交由 Aider 处理的模型上下文协议服务,提升开发效率和灵活性。
概述
此服务允许 Claude Code 将 AI 编码任务交由 Aider(最佳开源 AI 编码助手)处理。通过将特定编码任务委派给 Aider,我们可以降低成本、掌控所用的编码模型,并以更侧重编排的方式使用 Claude Code 来审查和修改代码。
设置
- 克隆仓库:
git clone https://github.com/disler/aider-mcp-server.git
- 安装依赖项:
uv sync
- 创建环境文件:
cp .env.sample .env
- 在
.env文件中配置 API 密钥(或使用 mcpServers 的 "env" 部分),以设置 Aider 中所用模型需要的 API 密钥:
GEMINI_API_KEY=your_gemini_api_key_here
OPENAI_API_KEY=your_openai_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here
...see .env.sample for more
- 将
.mcp.json复制到项目根目录并填写,然后更新--directory,使其指向此项目的根目录;再更新--current-working-dir,使其指向你的项目根目录。
{
"mcpServers": {
"aider-mcp-server": {
"type": "stdio",
"command": "uv",
"args": [
"--directory",
"<path to this project>",
"run",
"aider-mcp-server",
"--editor-model",
"gpt-4o",
"--current-working-dir",
"<path to your project>"
],
"env": {
"GEMINI_API_KEY": "<your gemini api key>",
"OPENAI_API_KEY": "<your openai api key>",
"ANTHROPIC_API_KEY": "<your anthropic api key>",
...see .env.sample for more
}
}
}
}
测试
测试使用 gemini-2.5-pro-exp-03-25 运行
运行所有测试:
uv run pytest
运行指定测试:
# Test listing models
uv run pytest src/aider_mcp_server/tests/atoms/tools/test_aider_list_models.py
# Test AI coding
uv run pytest src/aider_mcp_server/tests/atoms/tools/test_aider_ai_code.py
注意:AI 编码测试需要有效的 Gemini 模型 API 密钥。运行测试前,请确保已在 .env 文件中设置该密钥。
将此 MCP 服务添加到 Claude Code
使用 gemini-2.5-pro-exp-03-25 添加
claude mcp add aider-mcp-server -s local \
-- \
uv --directory "<path to the aider mcp server project>" \
run aider-mcp-server \
--editor-model "gemini/gemini-2.5-pro-exp-03-25" \
--current-working-dir "<path to your project>"
使用 gemini-2.5-pro-preview-03-25 添加
claude mcp add aider-mcp-server -s local \
-- \
uv --directory "<path to the aider mcp server project>" \
run aider-mcp-server \
--editor-model "gemini/gemini-2.5-pro-preview-03-25" \
--current-working-dir "<path to your project>"
使用 quasar-alpha 添加
claude mcp add aider-mcp-server -s local \
-- \
uv --directory "<path to the aider mcp server project>" \
run aider-mcp-server \
--editor-model "openrouter/openrouter/quasar-alpha" \
--current-working-dir "<path to your project>"
使用 llama4-maverick-instruct-basic 添加
claude mcp add aider-mcp-server -s local \
-- \
uv --directory "<path to the aider mcp server project>" \
run aider-mcp-server \
--editor-model "fireworks_ai/accounts/fireworks/models/llama4-maverick-instruct-basic" \
--current-working-dir "<path to your project>"
用法
此 MCP 服务提供以下功能:
-
将 AI 编码任务交由 Aider 处理:
- 接收提示词和文件路径
- 使用 Aider 实现所请求的更改
- 返回成功或失败
-
列出可用模型:
- 提供与子字符串匹配的模型列表
- 可用于查找受支持的模型
可用工具
此 MCP 服务提供以下工具:
1. aider_ai_code
此工具可运行 Aider,根据提供的提示词和指定文件执行 AI 编码任务。
参数:
ai_coding_prompt(字符串,必填):AI 编码任务的自然语言指令。relative_editable_files(字符串列表,必填):文件路径列表(相对于current_working_dir),Aider 可以修改这些文件。如果文件不存在,则会创建该文件。relative_readonly_files(字符串列表,可选):文件路径列表(相对于current_working_dir),Aider 可以读取这些文件以获取上下文,但无法修改。默认为空列表[]。model(字符串,可选):Aider 用于生成代码的主要 AI 模型。默认为"gemini/gemini-2.5-pro-exp-03-25"。你可以使用list_models工具查找其他可用模型。editor_model(字符串,可选):Aider 用于编辑或优化代码的 AI 模型,尤其是在使用 architect 模式时。如果未提供,则可能根据 Aider 的内部逻辑使用主要的model。默认为None。
使用示例(在 MCP 请求中):
Claude Code 提示词:
Use the Aider AI Code tool to: Refactor the calculate_sum function in calculator.py to handle potential TypeError exceptions.
结果:
{
"name": "aider_ai_code",
"parameters": {
"ai_coding_prompt": "Refactor the calculate_sum function in calculator.py to handle potential TypeError exceptions.",
"relative_editable_files": ["src/calculator.py"],
"relative_readonly_files": ["docs/requirements.txt"],
"model": "openai/gpt-4o"
}
}
返回值:
- 简单的字典:{success, diff}
success:布尔值 - 操作是否成功。diff:字符串 - 对文件所做更改的差异。
2. list_models
此工具会列出 Aider 支持且与指定子字符串匹配的可用 AI 模型。
参数:
substring(字符串,必填):要在可用模型名称中搜索的子字符串。
使用示例(在 MCP 请求中):
Claude Code 提示词:
Use the Aider List Models tool to: List models that contain the substring "gemini".
结果:
{
"name": "list_models",
"parameters": {
"substring": "gemini"
}
}
返回值:
- 与所提供子字符串匹配的模型名称字符串列表。示例:
["gemini/gemini-1.5-flash", "gemini/gemini-1.5-pro", "gemini/gemini-pro"]
架构
服务器的结构如下:
- 服务器层:处理 MCP 协议通信
- Atoms 层:独立的纯函数组件
- 工具:特定功能(AI 编码、列出模型)
- Utils:常量和辅助函数
- 数据类型:使用 Pydantic 定义类型
所有组件都经过全面测试,以确保可靠性。
代码库结构
项目按以下主要目录和文件组织:
.
├── ai_docs # Documentation related to AI models and examples
│ ├── just-prompt-example-mcp-server.xml
│ └── programmable-aider-documentation.md
├── pyproject.toml # Project metadata and dependencies
├── README.md # This file
├── specs # Specification documents
│ └── init-aider-mcp-exp.md
├── src # Source code directory
│ └── aider_mcp_server # Main package for the server
│ ├── __init__.py # Package initializer
│ ├── __main__.py # Main entry point for the server executable
│ ├── atoms # Core, reusable components (pure functions)
│ │ ├── __init__.py
│ │ ├── data_types.py # Pydantic models for data structures
│ │ ├── logging.py # Custom logging setup
│ │ ├── tools # Individual tool implementations
│ │ │ ├── __init__.py
│ │ │ ├── aider_ai_code.py # Logic for the aider_ai_code tool
│ │ │ └── aider_list_models.py # Logic for the list_models tool
│ │ └── utils.py # Utility functions and constants (like default models)
│ ├── server.py # MCP server logic, tool registration, request handling
│ └── tests # Unit and integration tests
│ ├── __init__.py
│ └── atoms # Tests for the atoms layer
│ ├── __init__.py
│ ├── test_logging.py # Tests for logging
│ └── tools # Tests for the tools
│ ├── __init__.py
│ ├── test_aider_ai_code.py # Tests for AI coding tool
│ └── test_aider_list_models.py # Tests for model listing tool
src/aider_mcp_server:包含主应用程序代码。atoms:包含基础构建模块。这些模块旨在实现为纯函数或依赖项极少的简单类。tools:此处的每个文件都实现一个特定 MCP 工具(aider_ai_code、list_models)的核心逻辑。utils.py:包含共享常量,例如默认模型名称。data_types.py:定义用于请求/响应结构的 Pydantic 模型,以确保数据验证。logging.py:为控制台和文件输出设置统一的日志格式。
server.py:负责协调 MCP 服务。它初始化服务,注册atoms/tools目录中定义的工具,处理传入请求,将请求路由到相应的工具逻辑,并按照 MCP 协议发送响应。__main__.py:提供命令行接口入口点(aider-mcp-server),解析--editor-model等参数,并启动server.py中定义的服务。tests:包含与src目录结构对应的测试,确保每个组件(尤其是 atoms)都能按预期工作。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。