Skip to content

Add mcp support - #148

Merged
Akash-nath29 merged 5 commits into
devfrom
feature
Aug 4, 2026
Merged

Akash-nath29 merged 5 commits into
devfrom
feature

Conversation

@Akash-nath29

Copy link
Copy Markdown
Owner

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

  • Added support for custom MCP servers via the new 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 over httpx and asyncio without external SDK dependencies. [1] [2] [3]
  • Integrated OAuth 2.1 for MCP servers, including RFC-compliant discovery, registration, PKCE, and resource indicators. The browser-based login flow is isolated to explicit commands, and silent token refresh is supported. Credentials are stored securely in the OS keyring or a fallback file. [1] [2] [3]
  • Updated the bug report template to collect MCP server details when relevant.

Documentation and Contribution Guidelines

  • Expanded documentation in README.md, CONTRIBUTING.md, and .github/copilot-instructions.md to describe MCP architecture, design invariants, and testing strategies. [1] [2] [3]
  • Added a PyPI badge to README.md.
  • Clarified and expanded the CLAUDE.md workflow and introduced a spec system for substantial tasks, emphasizing specs over inline code comments.

Bug Fixes and Usability Improvements

  • Fixed OAuth token Authorization header normalization, schema $ref flattening for tool payloads, and improved handling of table cell markup in terminal output.
  • Improved CLI robustness on Windows consoles with limited encoding, better error reporting for provider exceptions, and sandbox subprocess cleanup on Windows.

Testing Enhancements

  • Provided clear instructions and infrastructure for offline and deterministic testing of MCP features, including the use of FakeConnection, injected OAuth browser flows, and credential storage isolation. [1] [2]

Other Notable Changes

  • Changed LLM write verification temperature default and clarified design invariants. [1] [2]

Copilot AI lite review requested due to automatic review settings August 4, 2026 03:43
@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!

@Akash-nath29
Akash-nath29 merged commit dd501c7 into dev Aug 4, 2026
3 checks passed

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

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.mcp package (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 + instance Tool.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.

Comment thread src/coderrr/mcp/oauth.py


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)
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