Argo CD MCP Server

repository·main·Indexed 19 days ago

https://github.com/argoproj-labs/mcp-for-argocd

An implementation of the Model Context Protocol (MCP) that enables AI assistants (such as Cursor, VS Code, and Claude Desktop) to manage and inspect Argo CD clusters, projects, applications, and workloads using natural language. It supports stdio and HTTP stream transport modes, provides a comprehensive set of tools for resource management, and includes features like read-only mode, stateless mode, and a token registry for multi-instance support.

Tokens
20.4K
Snippets
49
Records
91
Agent score
65%

What's inside argocd-mcp

  1. Overview of Argo CD MCP Server

    main

    The Argo CD MCP Server is an implementation of the Model Context Protocol (MCP) that enables AI assistants to interact with Argo CD via natural language. It provides a bridge between AI clients (like VS Code, Cursor, or Claude Desktop) and the Argo CD API, allowing assistants to manage clusters, projects, applications, and resources.

    Key features include:

    • Transport Protocols: Supports stdio and HTTP stream transport modes.
    • Full API Integration: Provides comprehensive access to Argo CD resources and operations.
    • AI-Ready Tools: Pre-configured tools designed specifically for natural language interaction.
  2. Understand the Argo CD MCP security model and token resolution

    main

    The server uses two types of tokens to prevent credential exfiltration: Default tokens and Registry tokens.

    Token Types

    TypeSourceScope
    Default tokenARGOCD_API_TOKEN env var or x-argocd-api-token headerThe default base URL only
    Registry tokenEntry in ARGOCD_TOKEN_REGISTRY_PATH JSON fileThe specific base URL it is keyed to

    Resolution Logic

    1. Targeting the Default Base URL: The server uses the Default token. If no default token is provided, it checks the registry for a token matching the default base URL.
    2. Targeting a Different Base URL: The server only uses a Registry token for that specific host. It will never send the Default token to a different host, even if argocdBaseUrl is provided in the tool call.
    3. Failure: If no token can be resolved for the requested URL, the call returns a "Missing required ArgoCD API token" error and no request is made.

    Crucial Rule: The default token is strictly bound to the default base URL. To interact with any other instance, you must register its token in the registry.

  3. Interact with the Argo CD MCP HTTP server

    main

    The HTTP server listens on POST /mcp (default port 3000) and GET /healthz.

    To interact with the server via HTTP, you must follow a session-based workflow:

    1. Initialize a session: Call POST /mcp with the initialize method. Capture the mcp-session-id from the response headers.
    2. Call a tool: Call POST /mcp using the captured mcp-session-id header and provide the argocdBaseUrl in the tool arguments.

    Alternatively, run in stateless mode using node dist/index.js http --stateless to make every request self-contained without managing session IDs.

    # 1. Initialize a session — note the mcp-session-id response header
    curl -sD - http://localhost:3000/mcp \
      -H 'Content-Type: application/json' \
      -H 'Accept: application/json, text/event-stream' \
      -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"curl","version":"1.0"}}}'
    
    # 2. Call a tool, reusing that session id
    curl -s http://localhost:3000/mcp \
      -H 'Content-Type: application/json' \
      -H 'Accept: application/json, text/event-stream' \
      -H 'mcp-session-id: <session-id-from-step-1>' \
      -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"list_applications","arguments":{"argocdBaseUrl":"https://argo-a.example.com"}}}'
  4. Run the Argo CD MCP Server locally via HTTP

    main

    The project includes a Makefile to run the server over the HTTP transport. You can run it in production-style (build then run) or in development mode (run from source with tsx watch).

    • make run: Builds and runs the HTTP server.
    • make dev: Runs from source with hot reloading.

    You can override the port using the PORT variable.

    make run PORT=4000
    make run    # build, then run the HTTP server (production-style)
    make dev    # run from source with hot reloading (tsx watch)
    make run PORT=4000
  5. Set up the Argo CD MCP Server for development

    main

    To develop on the Argo CD MCP Server, clone the repository, install dependencies using pnpm, and start the development server with hot reloading. Once running, the server can be used by MCP clients like Visual Studio Code.

    # Clone and enter the repository
    git clone https://github.com/argoproj-labs/mcp-for-argocd.git
    cd mcp-for-argocd
    
    # Install dependencies
    pnpm install
    
    # Start development server with hot reloading
    pnpm run dev
    git clone https://github.com/argoproj-labs/mcp-for-argocd.git
    cd mcp-for-argocd
    pnpm install
    pnpm run dev
  6. Install and configure Argo CD MCP for Cursor

    main

    To use the Argo CD MCP server with Cursor, create a .cursor/mcp.json file in your project directory. This configuration uses npx to run the latest version of the server via the stdio transport. You must provide your Argo CD instance URL and API token as environment variables.

    Prerequisites:

    • Node.js (v18 or higher recommended)
    • Argo CD instance with API access
    • Argo CD API token

    After configuration, start a conversation in Cursor's Agent mode to begin using the tools.

    {
      "mcpServers": {
        "argocd-mcp": {
          "command": "npx",
          "args": [
            "argocd-mcp@latest",
            "stdio"
          ],
          "env": {
            "ARGOCD_BASE_URL": "<argocd_url>",
            "ARGOCD_API_TOKEN": "<argocd_token>"
          }
        }
      }
    }
  7. Run Argo CD MCP in Stateless mode

    main

    By default, the HTTP transport uses session IDs and in-memory maps. This causes issues in distributed environments (like Kubernetes with HPA) where requests might be routed to different replicas without sticky sessions.

    To run in Stateless mode, use the --stateless flag. In this mode:

    • No Mcp-Session-Id is required or returned.
    • Any replica can handle any request.
    • Requirement: ArgoCD credentials (Base URL and API Token) must be supplied on every request via environment variables or x-argocd-base-url / x-argocd-api-token headers.
    • Session-level SSE (GET /mcp and DELETE /mcp) is not supported.

    Usage via CLI:

    node dist/index.js http --stateless

    Usage via Docker:

    docker run -e ARGOCD_BASE_URL=<argocd_url> -e ARGOCD_API_TOKEN=<argocd_token> \
      argoprojlabs/mcp-for-argocd http --stateless
  8. Install and configure Argo CD MCP for Claude Desktop

    main

    To use the Argo CD MCP server with Claude Desktop, create a claude_desktop_config.json configuration file. This configuration uses npx to run the server via the stdio transport. You must provide your Argo CD instance URL and API token as environment variables.

    After creating the file, ensure Claude Desktop is configured to use this configuration file in its settings.

    {
      "mcpServers": {
        "argocd-mcp": {
          "command": "npx",
          "args": [
            "argocd-mcp@latest",
            "stdio"
          ],
          "env": {
            "ARGOCD_BASE_URL": "<argocd_url>",
            "ARGOCD_API_TOKEN": "<argocd_token>"
          }
        }
      }
    }
  9. Update ArgoCD TypeScript types from Swagger

    main

    If you need to update the TypeScript type definitions to match a newer Argo CD API version:

    1. Download the swagger.json file from the ArgoCD release page.
    2. Place swagger.json in the root of the argocd-mcp project.
    3. Run the type generation command:
      pnpm run generate-types
      This overwrites src/types/argocd.d.ts.
    4. Manually update src/types/argocd-types.ts to export the required types from the newly generated file.
    pnpm run generate-types
  10. Install and configure Argo CD MCP for VS Code

    main

    To use the Argo CD MCP server with VS Code, create a .vscode/mcp.json file in your project directory. This configuration uses npx to run the server via the stdio transport. You must provide your Argo CD instance URL and API token as environment variables.

    After configuration, start a conversation with an AI assistant in VS Code that supports MCP.

    {
      "servers": {
        "argocd-mcp-stdio": {
          "type": "stdio",
          "command": "npx",
          "args": [
            "argocd-mcp@latest",
            "stdio"
          ],
          "env": {
            "ARGOCD_BASE_URL": "<argocd_url>",
            "ARGOCD_API_TOKEN": "<argocd_token>"
          }
        }
      }
    }
  11. Understand Application Status (V1alpha1ApplicationStatus)

    main

    The V1alpha1ApplicationStatus interface provides real-time observability into an Argo CD application. It includes:

    • Health: health (current health state) and conditions (list of observed conditions, often errors or warnings).
    • Sync State: sync (observed live vs desired state) and history (previous sync revisions).
    • Resources: resources (list of managed Kubernetes resources and their individual status).
    • Metadata: observedAt and reconciledAt timestamps, and controllerNamespace.
    • Summary: summary containing externalURLs and images used by the application.
  12. Filter SCM Provider Repositories

    main

    Use V1alpha1SCMProviderGeneratorFilter to restrict which repositories are discovered by the generator. Multiple filters are combined using a logical AND.

    Available filters:

    • branchMatch: Regex for branch names.
    • labelMatch: Regex for repository labels.
    • repositoryMatch: Regex for repository names.
    • pathsExist: Array of paths that must exist in the repo.
    • pathsDoNotExist: Array of paths that must not exist in the repo.