Skip to content

feat(mcp): integrated Model Context Protocol (MCP) server on port 2501 - #123

Merged
hapheus merged 4 commits into
mainfrom
feat/mcp-server
Nov 10, 2026
Merged

hapheus merged 4 commits into
mainfrom
feat/mcp-server

Conversation

@hapheus

@hapheus hapheus commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Summary

Implements an integrated, zero-dependency Model Context Protocol (MCP) server on port 2501 with dual-transport support (HTTP/SSE and Stdio) and native torproxy_fetch for autonomous AI agents (Claude Desktop, Cursor, Antigravity, LLM pipelines).

Closes #122


Key Features & Deliverables

  1. Zero-Dependency Core:

    • Pure Python standard library implementation (http.server, json, threading, queue, urllib).
    • Keeps the minimal Alpine container digest completely intact without third-party frameworks.
  2. Dual-Transport Support:

    • HTTP/SSE Transport (Port 2501): Runs in the API server daemon thread, handling SSE streams (GET /sse) and JSON-RPC dispatch (POST /messages?sessionId=...). Configurable via TORPROXY_MCP_PORT and TORPROXY_MCP_ENABLED.
    • Stdio Transport (torproxy mcp): Spawns via CLI / docker exec -i torproxy torproxy mcp for Claude Desktop or local agents without exposing host ports.
  3. Orchestration Tools & Resources:

    • torproxy_fetch: Execute HTTP/HTTPS or .onion requests strictly routed through Tor with zero host setup.
    • torproxy_status: Real-time Tor bootstrap, egress IP, and GeoIP metadata.
    • torproxy_get_ip: Verified egress IP.
    • torproxy_reconnect: Trigger new identity (SIGNAL NEWNYM) with optional country/strict enforcement.
    • torproxy_connect / torproxy_disconnect: Network toggle.
    • torproxy_health / torproxy_diagnostics: Automated operational health checks.
    • Resources: torproxy://status (live JSON) and torproxy://metrics (Prometheus metrics).
  4. 100% Backward Compatibility:

    • Default ports 8118, 8080, 9050 and REST endpoints remain completely untouched.
    • MCP server is enabled by default on collision-free port 2501 and can be turned off via TORPROXY_MCP_ENABLED=false.
  5. Comprehensive Documentation & Examples:


Verification & Quality Gates

Gate Result
Hermetic Unit Tests 390 passed in 22.3s (100% pass)
Test Coverage 88.24% (Required: ≥85%)
Hexagonal Architecture Clean run (test_architecture.py, zero AST violations)
Ruff Linter & Formatter Clean run (ruff check & ruff format --check, 0 errors)
Type Checking Clean run (mypy, strict, 0 errors in 27 source files)
ShellCheck & Syntax Clean run (shellcheck & bash -n)

- Implement zero-dependency Model Context Protocol (MCP) server using Python standard library
- Provide dual transport: HTTP/SSE on port 2501 and Stdio via 'torproxy mcp'
- Expose tools: torproxy_fetch, torproxy_status, torproxy_get_ip, torproxy_reconnect, torproxy_connect, torproxy_disconnect, torproxy_health, torproxy_diagnostics
- Expose resources: torproxy://status and torproxy://metrics
- Full test suite with 390 passing unit tests and >88% coverage
- Add client examples and complete documentation in docs/mcp.md and README.md

Closes #122

@MustermenschAlex MustermenschAlex left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Clean architecture and strict adherence to the zero-dependency contract. Excellent test coverage (88.24%) across protocol, stdio, and SSE transports, with clean AST validation. The addition of torproxy_fetch cleanly empowers agents without introducing external dependencies. Approved.

@kuenstlichedummheit-sys kuenstlichedummheit-sys left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Solid async queue and daemon thread handling in the SSE server. Nice touch catching BrokenPipeError / ConnectionResetError on socket disconnects so the server stays completely quiet. Looks bulletproof to me, ship it.

majorungustl
majorungustl previously approved these changes Nov 10, 2026

@majorungustl majorungustl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Loving torproxy_fetch – that saves people tons of hacking around with curl in container networks. Stdio mode works like a charm for Claude Desktop too without messing with port forwards. Looks ready to roll.

Comment thread src/torproxy/mcp/sse.py Fixed
…nary and container tests

- Add MCP stdio and SSE port 2501 checks to tests/integration/verify_container.sh
- Add live canary verification step testing torproxy_fetch against check.torproject.org
- Ensure runner host IP leak detection and IsTor confirmation in live canary

@MustermenschAlex MustermenschAlex left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Canary live verification for torproxy_fetch and container smoke test integration verified. Excellent addition. Approved.

@kuenstlichedummheit-sys kuenstlichedummheit-sys left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Canary checks for torproxy_fetch look great. Leak-free and clean. Approved.

majorungustl
majorungustl previously approved these changes Nov 10, 2026

@majorungustl majorungustl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verified the canary test update with check.torproject.org. Good to merge once CI finishes. Approved.

@MustermenschAlex MustermenschAlex left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CodeQL empty-except comment addressed cleanly. Approved.

@kuenstlichedummheit-sys kuenstlichedummheit-sys left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CodeQL finding fixed. Looks clean. Approved.

majorungustl
majorungustl previously approved these changes Nov 10, 2026

@majorungustl majorungustl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Addressed the CodeQL bot comment, all good. Approved.

- Bump package version to 2.6.0 in pyproject.toml and Dockerfile
- Update uv.lock
- Document v2.6.0 in docs/releases.md and CHANGELOG.md

@MustermenschAlex MustermenschAlex left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Release bump to 2.6.0 and release notes verified. Approved.

@kuenstlichedummheit-sys kuenstlichedummheit-sys left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Bump to 2.6.0 is good to go. Approved.

@majorungustl majorungustl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

v2.6.0 release looks solid. Approved.

@hapheus
hapheus merged commit 2c904c5 into main Nov 10, 2026
12 checks passed
@hapheus
hapheus deleted the feat/mcp-server branch November 10, 2026 08:40
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.

feat(mcp): integrated Model Context Protocol (MCP) server on port 2501

5 participants