Aider MCP Server

repository·main·Indexed 43 days ago

https://github.com/disler/aider-mcp-server

An experimental Model Context Protocol (MCP) server version 0.1.0 that allows AI agents, such as Claude Code, to offload complex coding tasks to Aider. It provides tools like `aider_ai_code` for applying changes to files via natural language prompts and `list_models` for searching supported AI models. The server integrates with various LLMs including Gemini, OpenAI, and Anthropic, and requires a valid Git repository as the working directory.

Tokens
4.9K
Snippets
20
Records
23
Agent score
51%

What's inside Aider MCP Server

  1. Add Aider MCP Server to Claude Code

    main

    You can add this server directly to Claude Code using the claude mcp add command. Replace <path to the aider mcp server project> with the absolute path to the cloned repository and <path to your project> with the absolute path to the project you want to work on.

    Using Gemini 2.5 Pro (Experimental)

    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>"

    Using Gemini 2.5 Pro (Preview)

    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>"

    Using Quasar Alpha (OpenRouter)

    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>"

    Using Llama 4 Maverick (Fireworks AI)

    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>"
  2. Install and Setup Aider MCP Server

    main

    To set up the Aider MCP Server locally, follow these steps:

    1. Clone the repository:

      git clone https://github.com/disler/aider-mcp-server.git
    2. Install dependencies using uv:

      uv sync
    3. Configure environment variables: Copy the sample environment file:

      cp .env.sample .env

      Open .env and add your API keys (e.g., GEMINI_API_KEY, OPENAI_API_KEY, ANTHROPIC_API_KEY).

    4. Configure MCP Client: Create a .mcp.json file in your project root. You must update --directory to the absolute path of the aider-mcp-server project and --current-working-dir to the absolute path of your target project.

    {
      "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>"
          }
        }
      }
    }
  3. How the aider_ai_code tool works

    main

    The aider_ai_code tool wraps the code_with_aider functionality.

    Workflow:

    1. The client sends a request with ai_coding_prompt and relative_editable_files.
    2. The server resolves the model (using the request-provided model or the default editor_model).
    3. The server executes the Aider command within the validated Git repository directory.
    4. The tool returns a JSON object containing:
      • success (boolean): Whether the operation completed successfully.
      • diff (string): The code changes (diff) produced by Aider.

    Note: If the tool fails to parse the result from Aider, it returns an error object: {"error": "Failed to process AI coding result"}.

  4. List available Aider models with list_models

    main

    The list_models function allows you to search for available LLM models supported by Aider using a substring match.

    Signature: list_models(substring: str) -> List[str]

    This function wraps aider.models.fuzzy_match_models(substr: str).

    # Example usage concept
    models = list_models("openai")
    # Returns a list containing models like ['gpt-4o', ...]
  5. Tool: list_models

    main

    The list_models tool returns a list of AI models supported by Aider that match a provided substring.

    Parameters:

    • substring (string, required): The text to search for within model names.

    Returns:

    • A list of model name strings (e.g., ["gemini/gemini-1.5-flash", "gemini/gemini-1.5-pro"]).
    {
      "name": "list_models",
      "parameters": {
        "substring": "gemini"
      }
    }
  6. Start the Aider MCP Server with serve()

    main

    The serve function is the primary entry point for running the MCP server.

    Signature: serve(editor_model: str = DEFAULT_EDITOR_MODEL, current_working_dir: str = ".", architect_model: str = None) -> None

    Parameters:

    • editor_model: The model used for editing. Defaults to DEFAULT_EDITOR_MODEL (gemini/gemini-2.5-pro-exp-03-25).
    • current_working_dir: The directory from which the server operates. Defaults to ".".
    • architect_model: The model used for architectural planning. If not provided, architect mode is not used.
    from aider_mcp_server.server import serve
    
    # Start the server with custom models
    serve(editor_model="gemini/gemini-2.5-pro-exp-03-25", architect_model="gemini/gemini-2.5-pro-exp-03-25")
  7. Use code_with_aider to perform AI coding tasks

    main

    The code_with_aider function performs a single-shot execution using Aider based on the programmable Aider documentation. It is designed to run in 'no commit' mode to ensure no changes are automatically committed to the codebase.

    Signature: code_with_aider(ai_coding_prompt: str, relative_editable_files: List[str], relative_readonly_files: List[str] = []) -> str

    Returns:

    • 'success'
    • 'failure'
    # Example usage concept
    result = code_with_aider(
        ai_coding_prompt="Implement a new feature",
        relative_editable_files=["src/main.py"],
        relative_readonly_files=["docs/api.md"]
    )
  8. Tool: aider_ai_code

    main

    The aider_ai_code tool allows you to offload AI coding tasks to Aider. It takes a natural language prompt and applies changes to specified files.

    Parameters:

    • ai_coding_prompt (string, required): The instruction for the task.
    • relative_editable_files (list of strings, required): Paths (relative to current_working_dir) that Aider can modify. Files are created if they don't exist.
    • relative_readonly_files (list of strings, optional): Paths (relative to current_working_dir) Aider can read for context but cannot modify. Defaults to [].
    • model (string, optional): The primary model for code generation. Defaults to "gemini/gemini-2.5-pro-exp-03-25".
    • editor_model (string, optional): The model used for editing/refining code (architect mode). Defaults to None.

    Returns:

    • A dictionary: {"success": boolean, "diff": string} where diff is the applied changes.
    {
      "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"
      }
    }
  9. Run tests for Aider MCP Server

    main

    The project uses pytest for testing. Note that AI coding tests require a valid Gemini API key set in your .env file.

    Run all tests:

    uv run pytest

    Run specific tests:

    • List models tests:
      uv run pytest src/aider_mcp_server/tests/atoms/tools/test_aider_list_models.py
    • AI coding tests:
      uv run pytest src/aider_mcp_server/tests/atoms/tools/test_aider_ai_code.py
  10. Validate a directory as a Git repository

    main

    The server uses the is_git_repository function to ensure that the provided current_working_dir is a valid Git work tree. It does this by executing git -C <directory> rev-parse --is-inside-work-tree.

    If the directory does not exist or is not a Git repository, the server will return an error or raise a ValueError during startup.

    # Signature for internal/utility use
    tuple[bool, Union[str, None]] = is_git_repository(directory: str)