Skip to content

Add mcp support - #149

Merged
Akash-nath29 merged 3 commits into
mainfrom
dev
Aug 4, 2026
Merged

Akash-nath29 merged 3 commits into
mainfrom
dev

Conversation

@Akash-nath29

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI lite review requested due to automatic review settings August 4, 2026 03:44
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

🚀 Thanks for opening a Pull Request!

A maintainer will review this soon.

Meanwhile:
✔ Ensure tests are passing
✔ Link related issues
✔ Code follows the project guidelines

Your contribution helps make this project better!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class support for user-configured MCP servers to Coderrr (including OAuth-based HTTP servers and local stdio servers), bridging server-advertised tools into the existing tool registry with per-tool approval and prompt-hardening against untrusted external outputs.

Changes:

  • Introduces a new coderrr.mcp package (client, OAuth, credentials, tool bridge, manager, naming, setup) and wires it into session startup and system prompt assembly.
  • Extends the tool gating/policy model with ToolClass.EXTERNAL, per-tool approval/remembering, and schema normalization ($ref flattening) for provider compatibility.
  • Adds CLI + REPL UX for adding/listing/testing/logging into MCP servers, plus extensive tests and documentation/security updates.

Reviewed changes

Copilot reviewed 36 out of 36 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/test_tools.py Updates schema tests to call Tool.spec() as an instance method.
tests/test_mcp.py New comprehensive tests for MCP naming, bridge behavior, manager, policy, and REPL flow integration.
tests/test_mcp_oauth.py New end-to-end OAuth tests (discovery, registration, PKCE, loopback redirect, token refresh/storage).
tests/test_console.py Adds regression test ensuring bracketed table cell content isn’t parsed as Rich markup.
src/coderrr/ui/repl.py Adds /mcp REPL commands (add/remove/login/logout) and live config updates.
src/coderrr/ui/console.py Escapes table cell contents to avoid Rich markup parsing of bracketed data.
src/coderrr/tools/registry.py Adds runtime tool registration, EXTERNAL approval prompt flow, and input validation hook.
src/coderrr/tools/base.py Adds MCP manager to ToolContext; makes spec() instance-based; introduces validate_input().
src/coderrr/prompts/system.py Extends system prompt guidance to treat MCP output as untrusted data; adds MCP prompt block.
src/coderrr/policy/gate.py Adds EXTERNAL tool gating (per-tool allow/deny/preapproval) and integrates into policy evaluation.
src/coderrr/mcp/types.py New MCP vocabulary dataclasses + protocols (tool defs, results, connection interfaces, errors).
src/coderrr/mcp/setup.py New shared “parse user input → server config / probe / login” helpers for CLI + REPL.
src/coderrr/mcp/oauth.py New OAuth 2.1 implementation for MCP servers (discovery, dynamic registration, PKCE, loopback).
src/coderrr/mcp/naming.py New tool-name qualification/sanitization (mcp__<server>__<tool>) with collision handling.
src/coderrr/mcp/manager.py New manager to connect servers sequentially, bridge tools, track status, and store approvals.
src/coderrr/mcp/credentials.py New credential storage (keyring or 0600 file) and refresh-aware token source.
src/coderrr/mcp/client.py New MCP JSON-RPC client over Streamable HTTP (SSE) and stdio, with auth retry semantics.
src/coderrr/mcp/catalog.py Adds placeholder “built-in server shorthand” resolution (currently empty).
src/coderrr/mcp/bridge.py Bridges MCP tool definitions into Coderrr Tool instances; result rendering + truncation.
src/coderrr/mcp/init.py Exposes MCP public surface area for importers.
src/coderrr/llm/types.py Adds ToolClass.EXTERNAL and documents intended semantics.
src/coderrr/llm/schema.py New $ref flattener for JSON Schemas from MCP servers/providers.
src/coderrr/llm/google.py Flattens refs before sanitizing schema for Gemini tool payloads.
src/coderrr/config.py Adds MCP config schema (servers, env var interpolation, pruning on save).
src/coderrr/cli.py Adds coderrr mcp command group (add/list/test/login/logout/remove/enable/reset) + doctor output.
src/coderrr/agent/session.py Connects MCP servers per request, registers bridged tools, and cleans up EXTERNAL tools on teardown.
src/coderrr/agent/modes.py Exposes EXTERNAL tools in both planning and execution modes.
src/coderrr/agent/loop.py Includes MCP context block in assembled system prompt.
SECURITY.md Documents MCP security boundaries, approval model, output trust model, and credential storage.
README.md Adds user-facing MCP documentation, examples, and config shape.
docs/V2-MIGRATION.md Notes MCP servers as a new capability vs v1.
CONTRIBUTING.md Documents MCP layering/testing expectations and invariants.
CLAUDE.md Updates repository workflow/spec guidelines text.
CHANGELOG.md Adds unreleased entry documenting MCP/OAuth/features and related fixes/changes.
.github/ISSUE_TEMPLATE/bug_report.md Adds MCP-specific bug report fields.
.github/copilot-instructions.md Updates contributor instructions with MCP architecture/invariants/testing notes.
Suppressed comments (4)

src/coderrr/cli.py:378

  • header is annotated as list[str] but defaults to None via typer.Option(None, ...), which is a type mismatch under mypy/pyright. Mark it optional to reflect that the option can be omitted.
    header: list[str] = typer.Option(
        None,
        "--header",
        "-H",
        help="HTTP header as KEY=VALUE. Quote '${VAR}' to read a token from the environment.",
    ),

src/coderrr/cli.py:381

  • env is annotated as list[str] but defaults to None via typer.Option(None, ...), which is a type mismatch and will fail strict type checking. Mark it optional.
    env: list[str] = typer.Option(
        None, "--env", "-e", help="Environment variable for a stdio server, as KEY=VALUE."
    ),

src/coderrr/cli.py:581

  • server.label is printed via Console.info() (Rich markup enabled). If the label includes bracketed text (e.g. IPv6 URLs), Rich may parse it as markup and drop it. Escape [ so the label is reliably shown.
    ui.info(f"Connecting to {name} ({server.label})...")

src/coderrr/cli.py:474

  • This prints a URL inside Rich markup; bracketed content (e.g. IPv6 literals) will be parsed as markup and may be dropped. Escape [ (or use markup=False) so the fallback URL is always readable.
    def show(url: str) -> None:
        if browser:
            ui.info("Opening your browser to authorize...")
            webbrowser.open(url)
            ui.print(f"  [dim]If it did not open: {url}[/]")
        else:

Comment thread src/coderrr/cli.py
Comment on lines +366 to +369
target: list[str] = typer.Argument(
None,
help="A URL, or -- followed by a command to run. Omit for a built-in server.",
),
Comment thread src/coderrr/cli.py
Comment on lines +438 to +441
config.mcp.servers[name] = server
path = save_config(config)
ui.success(f"Added MCP server {name!r} → {server.label}")
ui.info(f"Saved to {path}")
Comment thread src/coderrr/ui/repl.py
Comment on lines +385 to +388
def show(url: str) -> None:
self.ui.info("Opening your browser to authorize...")
webbrowser.open(url)
self.ui.print(f" [dim]If it did not open: {url}[/]")
@Akash-nath29
Akash-nath29 merged commit 933dd35 into main Aug 4, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants