Skip to main content

Setting Up the CodePeel MCP Server with Claude Code

Configure the CodePeel MCP server in Claude Code: tokens and OAuth, the review_code and fix_code tools, prompts, rate limits, and troubleshooting for stdio MCP setups.

CodePeel Team

CodePeel delivers code review intelligence directly to AI coding agents via a local Model Context Protocol (MCP) server, published on npm as @codepeelai/codepeel. Once registered, your agent gains ten specialized tools and three workflow prompts: review staged diffs, generate surgical patches, query architectural context, and inspect historical pull request findings.

Key Takeaways

  • Native Stdio Protocol: Runs as a child process via npx, executing over standard I/O without opening external network ports.
  • Comprehensive Tool Surface: Exposes 4 real-time review tools alongside 6 zero-credit historical review query functions.
  • Dual Auth Architecture: Supports static cpk_ API tokens for CI automation and interactive PKCE OAuth with local loopback redirects.
  • Pre-Packaged Prompts: Ships with built-in MCP prompts for instant staged reviews, security audits, and automated fix generation.

Model Context Protocol (MCP) is an open standard created by Anthropic that allows AI coding assistants to interact securely with local development environments, developer tools, and external services.

This walkthrough covers setup with Claude Code: registration commands, authentication, tool capabilities, and error handling.

Prerequisites

  • Node.js version 18 or higher (invoked automatically via npx).
  • An active CodePeel account with an API token or web login.
  • A local git checkout containing diffs for review.

Generate an API token in the dashboard under Settings → MCP Tokens. Tokens begin with the cpk_ prefix. Treat them with the same security as private SSH keys: never commit them to source control. For credential security guidance, read How CodePeel's OWASP Security Scanning Works.

Registering the server with Claude Code

Registration requires a single command in your terminal:

macOS and Linux (bash, zsh)

claude mcp add codepeel --env CODEPEEL_TOKEN=cpk_your_token_here -- npx -y @codepeelai/codepeel

Windows (PowerShell)

claude mcp add codepeel --env CODEPEEL_TOKEN=cpk_your_token_here "--" npx -y @codepeelai/codepeel

This registers an stdio server named codepeel that invokes npx -y @codepeelai/codepeel with your token injected into the runtime environment. Under the hood, Claude Code stores this entry in its JSON configuration:

{
  "mcpServers": {
    "codepeel": {
      "command": "npx",
      "args": ["-y", "@codepeelai/codepeel"],
      "env": {
        "CODEPEEL_TOKEN": "cpk_your_token_here"
      }
    }
  }
}

Configuration scope is flexible: user scope makes CodePeel available globally across all local projects, while project scope keeps settings within a single repository. After running the command, restart Claude Code and type /mcp to confirm the server connection.

The identical mcpServers configuration applies across other stdio-compatible MCP environments, including Cursor, Windsurf, Cline, and Claude Desktop. For editor-specific guides, see AI Code Review for Claude Code.

Authentication options: API token vs OAuth

The server provides two distinct authentication flows:

1. Static API token (Recommended for automated environments)

Define CODEPEEL_TOKEN inside the server's env object. Every tool request attaches this bearer token to the CodePeel API. If the token expires or becomes invalid, tools fail immediately with a clear error prompt rather than silently hanging.

2. Browser-based OAuth with PKCE

When started without an environment token, the server initiates an interactive OAuth 2.0 PKCE exchange on first tool invocation:

  1. The server discovers authorization metadata and generates a PKCE code verifier and S256 challenge.
  2. It launches an ephemeral HTTP server on a random loopback port (127.0.0.1:<PORT>) and opens your default browser.
  3. Upon approval, GitHub redirects to the loopback callback. The server exchanges the code for an access token and displays a success confirmation.
  4. The token persists securely in local user storage until expiration.

Because the callback binds strictly to loopback interface on 127.0.0.1, no external firewall ports or reverse proxies are needed.

The review tool surface

The four core review tools are declared via official MCP JSON schemas:

Tool IdentifierRequired InputsPrimary Capability
review_codediffScans a unified diff for bugs, OWASP flaws, and regressions.
fix_codefile, issueSynthesizes a concrete, ready-to-apply code patch.
ask_codepeelquestionAnswers architectural questions using diff context.
check_credits(None)Reports remaining review balance without spending credits.

A standard agent workflow follows an automated loop: Claude Code drafts a change, executes git diff --cached, forwards the diff to review_code, and reads the structured output. For each finding, the agent inspects the suggested patch, modifies the file, and re-reviews before committing.

Historical review inspection tools

The server also exposes six zero-credit analytics tools: list_workspaces, list_team_members, search_reviews, get_review, search_findings, and get_review_analytics. These tools allow coding agents to query historical PR findings across repositories without consuming review credits. Consult the MCP server documentation for full JSON schemas.

Tool requests draw from your unified monthly allowance. Use check_credits anytime without consuming balance. For plan thresholds, review our usage and limits guide.

Built-in MCP workflow prompts

The server registers three built-in MCP prompts that can be invoked directly inside Claude Code:

  • review-staged-changes: Packages the current staged diff and triggers a full review.
  • security-audit: Executes a dedicated security scan focused on OWASP Top 10 and CWE vulnerabilities.
  • explain-and-fix: Explains root causes of flagged issues and outputs automated replacements.

In Claude Code, typing /review-staged-changes invokes the structured workflow immediately without manual prompt engineering.

Error handling and status codes

Backend error responses translate into actionable agent guidance:

  • 401 Unauthorized: Invalid or missing token. The output instructs the user to regenerate their cpk_ token.
  • 429 Rate Limited: Request limit exceeded. The response includes retry headers so the agent can back off gracefully.
  • 402 Payment Required: Review allowance exhausted (30/month on Free, 500/month on Pro). The output links directly to billing.
  • 503 Service Unavailable: Temporary upstream capacity spike; agents retry automatically after a brief delay.

To test how effectively Claude Code catches vulnerabilities using CodePeel tools, review our benchmarking framework in How to Benchmark an AI Code Reviewer.

Related documentation and articles