Aider MCP Server

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Supports reading environment variables from .env files in various locations to configure the Aider MCP server.

  • Provides tools for checking git repository status, creating files and committing them to git, and working within git repositories.

  • Enables extraction of code blocks from markdown text, preserving language information from code block markers.

Aider MCP 服务器

模型上下文协议 (MCP) 服务器允许 Claude 和其他 MCP 客户端连接到Aider以实现高效的文件编辑功能。

概述

该 MCP 服务器弥补了 Claude 等 AI 助手与 Aider 强大文件编辑功能之间的差距。它通过模型上下文协议 (MCP) 提供标准化接口,使 Claude 能够:

  • 使用 Aider 的功能编辑现有文件
  • 创建具有内容的新文件
  • 从 markdown 文本中提取代码块
  • 获取 git 状态信息
  • 检查 Aider 安装状态
  • 访问并使用 Aider 的配置系统

先决条件

  • Python 3.8 或更高版本
  • 安装了 Aider ( pip install aider-chat )
  • OpenAI 或 Anthropic 的 API 密钥(取决于您希望 Aider 使用哪种模型)
  • 用于文件编辑的 Git 存储库

安装

您可以通过多种方式安装 Aider MCP 服务器:

使用紫外线(推荐)

如果您已安装uv

# Install uv if you don't have it curl -fsSL https://astral.sh/uv/install.sh | bash # Run directly with uvx (no installation required) uvx aider-mcp

使用 PIP

# Install the package pip install aider-mcp # Run the server aider-mcp

用法

Aider MCP 服务器默认通过 stdio 以 MCP 协议模式运行,旨在与 Claude Desktop 和 Cursor IDE 等 MCP 客户端直接集成。

# Run directly with uvx (recommended) uvx aider-mcp # With repository path specified uvx aider-mcp --repo-path=/path/to/your/repo # With custom Aider executable path uvx aider-mcp --aider-path=/path/to/aider # With environment variables REPO_PATH=/path/to/your/repo uvx aider-mcp

命令行选项

您可以使用以下环境变量或命令行参数自定义服务器:

  • --aider-path :Aider 可执行文件的路径(默认值:“aider”,自动搜索 PATH)
  • --repo-path :git 存储库的路径(默认值:当前目录)
  • --config-file :自定义 Aider 配置文件的路径
  • --env-file :自定义 .env 文件的路径
  • --verbose-v :启用详细输出

客户端配置

克劳德桌面

将其添加到您的 Claude Desktop 配置文件中:

{ "mcpServers": { "aider-mcp": { "command": "uvx", "args": [ "aider-mcp", "--repo-path", "/path/to/your/repo" ] } } }

游标 IDE

要与 Cursor IDE 集成:

  1. 打开游标设置
  2. 导航至Features > MCP Servers
  3. 点击Add new MCP server
  4. 输入此配置:
    name: aider-mcp type: command command: uvx aider-mcp --repo-path=/path/to/your/repo
  5. 配置完成后,请确保您在 Composer 中处于代理模式以使用 MCP 工具

Aider 配置支持

该 MCP 服务器支持 Aider 的配置系统,允许您:

  1. 使用来自.aider.conf.yml文件的配置:
    • 您的主目录
    • git 仓库根目录
    • 当前目录
    • 使用--config-file指定的自定义路径
  2. 使用.env文件中的环境变量:
    • 您的主目录
    • git 仓库根目录
    • 当前目录
    • 使用--env-file指定的自定义路径
  3. 通过 MCP 工具编辑文件时传递自定义 Aider 选项。

克劳德的示例提示

一旦连接到 Claude,您可以使用如下提示:

  • “编辑我的 app.py 文件以向主函数添加错误处理”
  • “创建一个名为 utils.py 的新文件,其中包含用于日期格式化的辅助函数”
  • “显示存储库的当前 git 状态”
  • “从此解释中提取 Python 代码并将其保存到文件中”

可用工具

MCP 服务器提供以下基于目录的工具:

  • edit_files :在指定目录中进行有针对性的代码更改
    • 需要目录路径和详细说明
    • 自动接受所有建议的更改(使用--yes-always
    • 需要时可以指定其他 Aider 选项
  • create_files :在指定目录中创建具有内容的新文件
    • 您可以提供多个文件来同时创建
    • 可选择将新文件提交到 git
  • git_status :获取指定目录存储库的 git 状态
    • 快速检查已修改、已添加、已删除和未跟踪的文件
  • extract_code :从 markdown 或文本中提取代码块
    • 可以选择将提取的代码块保存到指定目录中的文件中
    • 保留代码块标记中的语言信息
  • aider_status :检查Aider安装和环境状态
    • 验证 Aider 是否已正确安装并可访问
    • 可以检查特定目录的配置
    • API 密钥和环境变量的报告
  • aider_config :获取详细的 Aider 配置信息
    • 显示正在使用的配置文件
    • 显示各层配置的设置
    • 报告可用的环境变量

环境变量

服务器使用可以直接设置或通过.env文件设置的环境变量:

  • AIDER_PATH :Aider 可执行文件的路径
  • REPO_PATH :git 存储库的路径
  • AIDER_CONFIG_FILE :自定义 Aider 配置文件的路径
  • AIDER_ENV_FILE :自定义 .env 文件的路径
  • AIDER_MCP_VERBOSE :启用详细日志记录
  • OPENAI_API_KEY :您的 OpenAI API 密钥(如果将 GPT-4 与 Aider 一起使用)
  • ANTHROPIC_API_KEY :您的 Anthropic API 密钥(如果将 Claude 与 Aider 一起使用)

调试

您可以使用 MCP 检查器来调试服务器:

# Test with MCP inspector npx @modelcontextprotocol/inspector uvx aider-mcp # Test with specific repository path npx @modelcontextprotocol/inspector uvx aider-mcp --repo-path=/path/to/your/repo # If running from Python package npx @modelcontextprotocol/inspector python -m aider_mcp

检查器提供了一个交互式用户界面来:

  1. 查看可用工具及其方案
  2. 调用带有测试参数的工具
  3. 查看回复并调试问题

发展

对于本地开发:

git clone https://github.com/yourusername/aider-mcp-server.git cd aider-mcp-server pip install -e .

执照

取消许可

-
security - not tested
A
license - permissive license
-
quality - not tested

模型上下文协议服务器将 Claude 和其他 MCP 客户端连接到 Aider,使 AI 助手能够高效地编辑文件、创建新文件以及通过自然语言与 git 存储库交互。

  1. Overview
    1. Prerequisites
      1. Installation
        1. Using UV (Recommended)
        2. Using PIP
      2. Usage
        1. Command Line Options
      3. Client Configuration
        1. Claude Desktop
        2. Cursor IDE
      4. Aider Configuration Support
        1. Example Prompts for Claude
          1. Available Tools
            1. Environment Variables
              1. Debugging
                1. Development
                  1. License
                    ID: 8fd63v5mwh