Repository navigation
Add mcp support - #149
Merged
Merged
Add mcp support#149
Conversation
Add mcp support
|
🚀 Thanks for opening a Pull Request! A maintainer will review this soon. Meanwhile: Your contribution helps make this project better! |
There was a problem hiding this comment.
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.mcppackage (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
headeris annotated aslist[str]but defaults toNoneviatyper.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
envis annotated aslist[str]but defaults toNoneviatyper.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.labelis printed viaConsole.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 usemarkup=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 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 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 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}[/]") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.