Repository navigation
Add mcp support - #148
Merged
Merged
Add mcp support#148
Conversation
|
🚀 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
This PR adds first-class support for user-configured MCP servers (HTTP + stdio), including OAuth 2.1 login, per-tool approvals, and runtime bridging of MCP-advertised tools into Coderrr’s tool registry, along with supporting schema normalization, CLI/REPL commands, tests, and documentation updates.
Changes:
- Introduces a new
coderrr.mcppackage (client, OAuth, credentials, naming, bridge, manager, setup) and wires it into the agent loop, tool gating, and prompt assembly. - Extends the tool system to support runtime-discovered tool instances (new
Tool.validate_input()hook + instanceTool.spec()), and adds per-tool approval flow for EXTERNAL tools. - Adds comprehensive offline tests for MCP + OAuth flows and updates docs/security guidance, release metadata, and templates accordingly.
Reviewed changes
Copilot reviewed 38 out of 39 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
tests/test_tools.py |
Updates schema tests to use instance spec() now that tool specs are instance-based. |
tests/test_mcp.py |
Adds extensive MCP unit/integration-style tests using FakeConnection (no SDK/network). |
tests/test_mcp_oauth.py |
Adds end-to-end OAuth tests (discovery/PKCE/loopback redirect/tokens/refresh/credentials). |
tests/test_console.py |
Adds regression test ensuring table cells aren’t interpreted as Rich markup. |
src/coderrr/ui/repl.py |
Adds /mcp REPL commands (list/add/remove/login/logout) and related UX. |
src/coderrr/ui/console.py |
Escapes table cell content to prevent Rich markup parsing in cells. |
src/coderrr/tools/registry.py |
Supports registering runtime tools, EXTERNAL approval prompting, and validate_input() hook. |
src/coderrr/tools/base.py |
Adds ToolContext.mcp and converts Tool.spec() to an instance method with validate_input(). |
src/coderrr/prompts/system.py |
Adds an MCP prompt section and clarifies MCP output is untrusted data. |
src/coderrr/policy/gate.py |
Adds EXTERNAL per-tool gating (preapproved/denied) independent of server annotations. |
src/coderrr/mcp/types.py |
Introduces provider-agnostic MCP dataclasses and connection protocols. |
src/coderrr/mcp/setup.py |
Shared server setup/probing/login helpers for CLI and REPL. |
src/coderrr/mcp/oauth.py |
Implements OAuth 2.1 flows (discovery/registration/PKCE/loopback redirect/token exchange/refresh). |
src/coderrr/mcp/naming.py |
Adds deterministic qualified tool naming (mcp__<server>__<tool>) with sanitization/truncation. |
src/coderrr/mcp/manager.py |
Manages server connections per request, bridges tools, and stores approvals. |
src/coderrr/mcp/credentials.py |
Adds credential storage (keyring or 0600 JSON file) and token refresh source. |
src/coderrr/mcp/client.py |
Implements MCP JSON-RPC client over Streamable HTTP and stdio (no SDK dependency). |
src/coderrr/mcp/catalog.py |
Adds (currently empty) built-in server shorthand resolution scaffolding. |
src/coderrr/mcp/bridge.py |
Bridges MCP tool defs to Coderrr Tool instances, including result rendering + schema flattening. |
src/coderrr/mcp/__init__.py |
Exposes MCP public API surface from the new package. |
src/coderrr/llm/types.py |
Adds ToolClass.EXTERNAL and documents its policy meaning. |
src/coderrr/llm/schema.py |
Adds $ref flattening for provider tool schemas (especially MCP-provided JSON Schema). |
src/coderrr/llm/google.py |
Ensures tool schemas are flattened before sanitization for Gemini payloads. |
src/coderrr/config.py |
Adds MCP config models, ${VAR} expansion for headers/env, and config save pruning logic. |
src/coderrr/cli.py |
Adds coderrr mcp subcommands (add/list/test/login/logout/remove/enable/reset) + doctor reporting. |
src/coderrr/agent/session.py |
Wires MCP connection lifecycle into session runs and teardown; persists approvals via config save. |
src/coderrr/agent/modes.py |
Exposes EXTERNAL tools in both planning and execution modes. |
src/coderrr/agent/loop.py |
Adds MCP context block into the system prompt assembly. |
src/coderrr/__init__.py |
Bumps version to 2.0.0. |
SECURITY.md |
Documents MCP-specific security boundaries, approvals, stdio risks, and credential handling. |
README.md |
Adds MCP usage docs (REPL + CLI), OAuth flows, approvals, and configuration examples. |
pyproject.toml |
Bumps version to 2.0.0 and excludes CLAUDE.md from sdist. |
docs/V2-MIGRATION.md |
Notes MCP servers as a new v2 capability. |
CONTRIBUTING.md |
Documents MCP package layering and testing guidance. |
CLAUDE.md |
Expands contributor workflow guidance (plan/spec/approval) and comment conventions. |
CHANGELOG.md |
Adds unreleased section documenting MCP features and related fixes/changes. |
.gitignore |
Adds uv.lock and normalizes .claude/ ignore entry. |
.github/ISSUE_TEMPLATE/bug_report.md |
Adds MCP-specific bug report fields. |
.github/copilot-instructions.md |
Documents MCP invariants and MCP testing constraints for contributors/agents. |
|
|
||
|
|
||
| def _write_response(writer: asyncio.StreamWriter, status: str, title: str, detail: str) -> None: | ||
| body = _PAGE.format(title=title, detail=detail).encode("utf-8") |
Comment on lines
+163
to
+167
| descriptor = os.open(self.path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600) | ||
| try: | ||
| os.write(descriptor, data) | ||
| finally: | ||
| os.close(descriptor) |
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.
This pull request introduces custom MCP server support, OAuth 2.1 integration, and several related infrastructure and documentation improvements, along with important bug fixes and test guidance. The MCP client is implemented without external SDK dependencies, providing a robust, testable, and secure integration for external tool providers. Documentation and contribution guidelines have been updated to reflect these changes, and several usability and reliability fixes have been made.
Major Features: MCP Servers and OAuth Integration
mcp/package, enabling both HTTP and stdio connections, per-tool approval, and server management commands (e.g.,coderrr mcp add,list,remove,enable,reset). The client is implemented overhttpxandasynciowithout external SDK dependencies. [1] [2] [3]Documentation and Contribution Guidelines
README.md,CONTRIBUTING.md, and.github/copilot-instructions.mdto describe MCP architecture, design invariants, and testing strategies. [1] [2] [3]README.md.Bug Fixes and Usability Improvements
Authorizationheader normalization, schema$refflattening for tool payloads, and improved handling of table cell markup in terminal output.Testing Enhancements
FakeConnection, injected OAuth browser flows, and credential storage isolation. [1] [2]Other Notable Changes