Skip to content

feat: add create_proxy() factory function#29

Merged
0xeb merged 8 commits intomainfrom
feature/create-proxy-parity
Jan 30, 2026
Merged

feat: add create_proxy() factory function#29
0xeb merged 8 commits intomainfrom
feature/create-proxy-parity

Conversation

@0xeb
Copy link
Owner

@0xeb 0xeb commented Jan 30, 2026

Summary

  • Add create_proxy() template factory function matching Python fastmcp's API
  • Add unified fastmcpp.hpp header for convenient single-include usage
  • Add unit tests and documentation

Changes

1. create_proxy() factory function

Implements the create_proxy() factory function to match Python fastmcp's convenience API:

// From URL - auto-detects transport (HTTP/WS)
auto proxy = create_proxy("http://localhost:8000/mcp");

// From existing client
auto proxy = create_proxy(std::move(client), "my_proxy", "1.0.0");

Features:

  • Auto-detects transport type from URL scheme (http/https → HttpTransport, ws/wss → WebSocketTransport)
  • Supports creating proxy from existing Client instance
  • Local tools take precedence over remote (override behavior)

2. Unified header

Adds fastmcpp.hpp main header for single-include convenience:

#include <fastmcpp.hpp>  // All common types available

3. Tests & Documentation

  • 3 new unit tests for create_proxy() in tests/proxy/basic.cpp
  • Proxy section added to README.md
  • Compile test for unified header

Test Results

  • All 76 unit tests passing ✅
  • E2E interop test (Python backend → C++ proxy → Python client): 8/9 passing

Test plan

  • ctest --test-dir build -C Release passes (76/76)
  • Manual verification of create_proxy() with URLs and Clients
  • E2E interop testing with Python fastmcp

0xeb added 8 commits January 29, 2026 20:49
Add create_proxy() factory function for creating proxy servers.
Matches Python's fastmcp.server.create_proxy() API.

- Supports std::string URL (auto-detects HTTP/HTTPS/WS/WSS)
- Supports client::Client instances (creates fresh sessions)
- Session strategy: Always fresh sessions per request (for safety)
- Note: unique_ptr<ITransport> not supported (use Client instead)

Refers to Python fastmcp commit 3163e61e which replaced
FastMCP.as_proxy() with create_proxy().

Completes parity task from kb/sync/review_result.md
Phase 1, Task 1.

Fixes: Feature gap - create_proxy() factory function

Changes:
- include/fastmcpp/proxy.hpp: Add create_proxy() template declaration
- src/proxy.cpp: Implement URL and Client specializations
- Add unit tests for create_proxy() factory function:
  - test_create_proxy_from_client: Create proxy from Client instance
  - test_create_proxy_url_detection: Verify URL scheme auto-detection
  - test_create_proxy_with_local_tools: Verify local+remote tool mixing
- Add Proxy server section to README with usage examples
- Documents URL auto-detection (http/https -> HTTP, ws/wss -> WebSocket)
- Documents local override precedence

Completes Phase 1 Task 2 and Phase 2 Task 3 from review_result.md
Add main header that includes all commonly used components:
- Core types, exceptions, content, settings
- Client and transports
- Server and context
- Tools, resources, prompts managers
- MCP handler
- Proxy with create_proxy() factory
- High-level FastMCP app

Add compile test to verify header works correctly.

Completes Phase 2 Task 4 from review_result.md
- proxy.cpp: Use string value directly instead of dump() for string
  results to avoid double JSON serialization
- handler.cpp: Unwrap single-element content arrays for prompts/get
  to match MCP protocol expectations
The template-only API required rvalue std::string, breaking common
usage patterns like create_proxy("http://localhost:8080/mcp").

Now provides non-template overloads:
- create_proxy(const std::string& url, ...)  - lvalue strings
- create_proxy(const char* url, ...)         - string literals
- create_proxy(client::Client&& client, ...) - rvalue clients

All documented examples now work as expected.
Replace raw JSON-RPC construction with clean high-level methods:
- client.initialize() for MCP session setup
- client.list_tools() for tool discovery
- client.call_tool() for invoking tools
- result.text() helper for extracting text results

Examples now show the recommended API usage pattern.
@0xeb 0xeb merged commit 2285a92 into main Jan 30, 2026
4 of 7 checks passed
@0xeb 0xeb deleted the feature/create-proxy-parity branch January 30, 2026 20:12
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.

1 participant