add-mcp

repository·main·Indexed 42 days ago

https://github.com/neon-solutions/add-mcp

A CLI tool and programmatic library (v2.4.0) designed to quickly add Model Context Protocol (MCP) servers to coding agents such as Cursor, Claude Code, and VS Code. It supports installing servers via remote URLs, npm packages, or local scripts, with features for managing installation scopes (Project vs. Global), configuring HTTP/SSE transports, and discovering servers through a registry.

Tokens
32.5K
Snippets
109
Records
143
Agent score
52%

What's inside add-mcp

  1. Core capabilities of add-mcp

    main

    add-mcp provides the following management capabilities for MCP servers:

    • Install remote or local servers: Supports installation via URL (streamable HTTP or SSE), npm packages, or arbitrary commands.
    • Find servers: Search the add-mcp registry directly from the terminal using add-mcp find and install matches interactively.
    • Manage installs: Use list, remove, and sync commands to manage server configurations across all your agents.
    • Programmatic use: Use the add-mcp npm package SDK to integrate MCP server installation into your own CLI or tools.
  2. Implement a custom MCP registry API

    main

    To use a custom registry with the add-mcp CLI, your server must implement a registry-compatible API. The CLI performs a GET request to your configured url using the following query parameters:

    • search: The user's search keyword (lowercased)
    • version: latest
    • limit: 100
    • source: cli

    The endpoint must return a JSON object containing a servers array with the following schema:

    {
      "servers": [
        {
          "server": {
            "name": "example-server",
            "description": "An example MCP server",
            "version": "1.0.0",
            "remotes": [
              {
                "type": "streamable-http",
                "url": "https://mcp.example.com/mcp"
              }
            ]
          }
        }
      ]
    }

    Once implemented, add your registry to ~/.config/add-mcp/config.json:

    {
      "url": "https://my-registry.example.com/api/v1/servers",
      "label": "My custom registry"
    }
  3. How add-mcp handles agent configuration

    main

    Different coding agents use different configuration files, formats, and schemas. For example:

    • Cursor: .cursor/mcp.json
    • Codex: .codex/config.toml (TOML)
    • Goose: YAML
    • Claude Code: Uses both project and global configurations.

    add-mcp maintains a single canonical server definition and maps it into each client's native schema. If a client does not support specific fields (like certain timeouts or OAuth scopes), add-mcp will drop those unsupported fields and issue a warning rather than writing a broken configuration file.

  4. How the add-mcp secure publishing pipeline works

    main

    The add-mcp project uses a high-security publishing pipeline that prohibits publishing from local machines. Instead, it relies on npm Trusted Publishing (OIDC) and staged publishing to ensure that every version is cryptographically signed and manually approved.

    The workflow follows these stages:

    1. GitHub Release: A maintainer creates a GitHub Release with a v* tag.
    2. CI Execution: GitHub Actions runs release.yml, which builds the project and executes npm stage publish --provenance. This creates a short-lived OIDC token for authentication.
    3. Staging: The package enters an npm staging area but is not yet live on the registry.
    4. Manual Review: The maintainer inspects the staged tarball using the npm stage CLI.
    5. WebAuthn Approval: The maintainer approves the release using a phishing-resistant WebAuthn/passkey. Only then does the package go live with a Sigstore provenance attestation.
    flowchart LR
        devCommit[Commit on main] --> ghRelease["Maintainer publishes GitHub Release vX.Y.Z"]
        ghRelease --> tagProt["Tag-protection rule allows tag"]
        tagProt --> ciRun["release.yml runs on GitHub-hosted runner"]
        ciRun --> oidc["GitHub mints OIDC token (id-token: write)"]
        oidc --> npmStage["npm stage publish --provenance"]
        npmStage --> staging["Package sits in npm staging area"]
        staging --> review["Maintainer: npm stage view add-mcp"]
        review --> approve["npm stage approve add-mcp (WebAuthn)"]
        approve --> live["Live on registry.npmjs.org with provenance"]
  5. How smart detection works in add-mcp

    main

    The CLI automatically detects which coding agents are available based on your current environment and the flags you provide:

    • Project mode (default): The CLI looks for project-level configuration files (such as .cursor/, .vscode/, or .mcp.json) and preselects the agents associated with those files.
    • Global mode (-g): The CLI detects all globally-installed agents (including Claude Desktop, Codex, and Zed) and preselects them.
    • No agents detected:
      • In interactive mode, the CLI defaults to your last selection.
      • When using the --yes flag, the CLI installs to all project-capable agents (in project mode) or all global-capable agents (in global mode).
  6. Understand installation scope and smart detection

    main

    add-mcp uses two scopes for installation:

    1. Project (default): Installs to local config files (e.g., .cursor/mcp.json) to be committed and shared with a team.
    2. Global (-g): Installs to global config files (e.g., ~/.cursor/mcp.json) available across all projects.

    Smart Detection Behavior:

    • In Project Mode: The CLI detects project-level config files in your current directory. It selects detected agents by default and shows them alongside all other supported agents.
    • In Global Mode (-g): The CLI detects all globally-installed agents (like Claude Desktop or Zed). It selects detected agents by default.
    • No Agents Detected: In interactive mode, it defaults to the last selection. Using --yes will install to all project-capable agents (in project mode) or all global-capable agents (in global mode).
  7. Configure add-mcp installation scope

    main

    You can choose between Project scope (default) or Global scope for your MCP server installations.

    ScopeFlagWritten toUse case
    Project(default).cursor/mcp.json, etc.Committed with your project, shared with team
    Global-g~/.cursor/mcp.json etc.Available across all projects

    When all selected agents support both scopes, add-mcp will ask you to choose in interactive mode. Use -g to force global installation.

  8. Auto-approve MCP tool calls for supported agents

    main

    You can preconfigure agents to automatically approve MCP tool calls using the --auto-approve flag. This is useful for servers that already have internal security gating.

    • All Tools: Using --auto-approve without additional flags approves all tools for supported agents.
    • Specific Tools: Use --approve-tool <tool_name> (repeatable) to approve only specific tools. This is the most reliable method for Claude Code due to known issues with all-tool rules.

    Agent-Specific Implementation

    • Codex: Writes approval modes into config.toml (either per-tool or a default_tools_approval_mode).
    • Claude Code: Writes permission allow rules to a settings file (.claude/settings.local.json for projects or ~/.claude/settings.json for global).
    # Auto-approve all tools for Codex and Claude Code
    npx add-mcp "executor mcp" --name executor -a codex -a claude-code --auto-approve
    
    # Auto-approve only the 'execute' tool for Codex
    npx add-mcp "executor mcp" --name executor -a codex --auto-approve --approve-tool execute
  9. Configure and manage MCP registries

    main

    The CLI stores registry configurations in ~/.config/add-mcp/config.json (respecting XDG_CONFIG_HOME). The first time you run find or search, the default add-mcp registry is saved automatically.

    Built-in Registries

    • add-mcp registry: https://add-mcp.com/registry/api/v1/servers (sourced from integrations.sh)
    • Official Anthropic registry: https://registry.modelcontextprotocol.io/v0.1/servers

    Adding a Custom Registry

    To add a custom registry, append an entry to the findRegistries array in your config file. The registry must implement a GET endpoint that accepts search, version, and limit query parameters and returns a JSON object containing a servers array with the appropriate schema.

    {
      "version": 1,
      "findRegistries": [
        {
          "url": "https://my-registry.example.com/api/v1/servers",
          "label": "My custom registry"
        }
      ]
    }
  10. How transport selection works during installation

    main

    The CLI automatically infers the transport method from registry metadata.

    • Preference Order: The CLI prefers HTTP remotes. It only falls back to SSE (Server-Sent Events) if HTTP is unavailable for the current installation context.
    • Interactive Mode: If a server offers both a remote and a stdio package option, you will be prompted to choose. Remote is the default choice.
    • Non-interactive Mode: When using the -y flag, the CLI automatically selects the remote option.

    Handling Variables and Headers: If a remote server requires URL variables or header inputs:

    • Required values must be provided manually.
    • Optional values can be skipped by pressing Enter.
    • When using -y, the CLI will insert placeholders (e.g., <your-header-value-here>) for required inputs.