Streamable HTTP to stdio proxy client for MCP servers with OAuth support
Project description
mcp-streamablehttp-client
A client-side bridge that enables stdio-based MCP clients (like Claude Desktop) to connect to streamable HTTP-based MCP servers with OAuth authentication. This tool handles the complete OAuth flow and provides comprehensive testing and debugging capabilities.
Overview
This client bridges the gap between:
- Stdio-based MCP clients: Applications expecting stdio transport (Claude Desktop, IDEs)
- HTTP-based MCP servers: Servers using streamable HTTP transport with OAuth protection
Key Features
- ๐ Automatic OAuth Authentication: Complete OAuth device flow with token refresh
- ๐ Bidirectional Bridge: Seamless stdio โ streamable HTTP translation
- ๐งช Raw Protocol Mode: Send raw JSON-RPC requests for testing
- ๐ Discovery Commands: List tools, resources, and prompts
- ๐ฏ Tool Execution: Execute MCP tools directly from CLI
- ๐ RFC 7592 Support: Full client registration management
- ๐ Smart Token Management: Automatic refresh and credential storage
- ๐จ Multiple Argument Formats: JSON, key=value, and smart parsing
Installation
# Via pixi (recommended)
pixi add mcp-streamablehttp-client
# Or from source
cd mcp-streamablehttp-client
pixi install -e .
Quick Start
1. Initial Setup
Create a .env file:
# Required: MCP server endpoint
MCP_SERVER_URL=https://mcp-fetch.example.com/mcp
# OAuth tokens (auto-populated after first auth)
MCP_CLIENT_ACCESS_TOKEN=
MCP_CLIENT_REFRESH_TOKEN=
MCP_CLIENT_ID=
MCP_CLIENT_SECRET=
2. First Run - Authentication
# Run the client - it will guide you through OAuth
mcp-streamablehttp-client
# The tool will:
# 1. Discover OAuth endpoints
# 2. Register as a client (if needed)
# 3. Display device authorization URL
# 4. Save credentials to .env
3. Subsequent Usage
After authentication, the client runs automatically:
# Interactive stdio mode (for Claude Desktop)
mcp-streamablehttp-client
# Or use with specific commands
mcp-streamablehttp-client --list-tools
mcp-streamablehttp-client --command "fetch https://example.com"
Command Line Interface
Basic Options
mcp-streamablehttp-client [OPTIONS]
Options:
--env-file PATH Path to .env file
--log-level LEVEL Logging level (DEBUG, INFO, WARNING, ERROR)
--server-url URL Override MCP server URL
--reset-auth Clear credentials and re-authenticate
--test-auth Test authentication and exit
-t, --token Check/refresh OAuth tokens
--help Show help and exit
Tool Execution
Execute MCP tools directly:
# Simple format
mcp-streamablehttp-client -c "echo Hello World"
# With parameters
mcp-streamablehttp-client -c "fetch https://httpbin.org/json"
# Key=value format
mcp-streamablehttp-client -c "search query='machine learning' limit=10"
# JSON format
mcp-streamablehttp-client -c 'mytool {"param": "value", "count": 42}'
Discovery Commands
List server capabilities:
# List all available tools with schemas
mcp-streamablehttp-client --list-tools
# List all resources
mcp-streamablehttp-client --list-resources
# List all prompts with arguments
mcp-streamablehttp-client --list-prompts
Raw Protocol Mode
Send raw JSON-RPC requests for testing:
# List tools using raw protocol
mcp-streamablehttp-client --raw '{"method": "tools/list", "params": {}}'
# Call a tool directly
mcp-streamablehttp-client --raw '{
"method": "tools/call",
"params": {
"name": "echo",
"arguments": {"message": "Hello"}
}
}'
# Test initialization
mcp-streamablehttp-client --raw '{
"method": "initialize",
"params": {
"protocolVersion": "2025-06-18",
"capabilities": {},
"clientInfo": {"name": "test", "version": "1.0"}
}
}'
Client Management (RFC 7592)
Manage your OAuth client registration:
# View current registration
mcp-streamablehttp-client --get-client-info
# Update client metadata
mcp-streamablehttp-client --update-client "client_name=Production Client"
# Update multiple fields
mcp-streamablehttp-client --update-client "client_name=My App,scope=read write"
# Update redirect URIs (semicolon-separated)
mcp-streamablehttp-client --update-client "redirect_uris=https://app1.com/cb;https://app2.com/cb"
# Delete registration (PERMANENT!)
mcp-streamablehttp-client --delete-client
Claude Desktop Integration
Add to your Claude Desktop configuration:
{
"mcpServers": {
"remote-fetch": {
"command": "mcp-streamablehttp-client",
"args": ["--env-file", "/path/to/.env"]
},
"another-server": {
"command": "mcp-streamablehttp-client",
"env": {
"MCP_SERVER_URL": "https://another.example.com/mcp",
"MCP_CLIENT_ACCESS_TOKEN": "existing_token"
}
}
}
}
Architecture
Core Components
-
cli.py - Command-line interface and argument parsing
- Main entry point with all CLI options
- Smart argument parsing for tool execution
- Protocol testing capabilities
-
proxy.py - Stdio โ HTTP bridge
- Handles MCP protocol translation
- Session management with
Mcp-Session-Id - Automatic initialization handling
- SSE and JSON response parsing
-
oauth.py - OAuth authentication
- Device flow implementation
- Token refresh logic
- Dynamic client registration (RFC 7591)
- Client management (RFC 7592)
-
config.py - Configuration management
- Pydantic settings validation
- Environment variable handling
- Credential persistence
Request Flow
Claude Desktop โ stdio โ Client Proxy โ HTTP โ OAuth Gateway โ MCP Server
โ โ
โโโโโโโโโโโโ stdio โโโโโโโโโโ HTTP Response โโโโโโโโโโโโโโโโโโโ
Token Management
Automatic Token Handling
The client automatically manages tokens:
- Checks expiration before each request
- Refreshes tokens when needed
- Updates .env with new tokens
- Falls back to re-authentication if refresh fails
Manual Token Management
# Check token status and refresh if needed
mcp-streamablehttp-client --token
# Force re-authentication
mcp-streamablehttp-client --reset-auth
# Test authentication without running
mcp-streamablehttp-client --test-auth
Environment Variables
| Variable | Description | Default |
|---|---|---|
MCP_SERVER_URL |
MCP server endpoint | Required |
MCP_CLIENT_ACCESS_TOKEN |
OAuth access token | Auto-generated |
MCP_CLIENT_REFRESH_TOKEN |
OAuth refresh token | Auto-generated |
MCP_CLIENT_ID |
OAuth client ID | Auto-generated |
MCP_CLIENT_SECRET |
OAuth client secret | Auto-generated |
MCP_CLIENT_REGISTRATION_TOKEN |
RFC 7592 management token | Auto-generated |
MCP_CLIENT_REGISTRATION_URI |
Client management URI | Auto-generated |
OAUTH_* |
Override OAuth endpoints | Auto-discovered |
SESSION_TIMEOUT |
Session timeout (seconds) | 300 |
REQUEST_TIMEOUT |
Request timeout (seconds) | 30 |
LOG_LEVEL |
Logging level | INFO |
VERIFY_SSL |
Verify SSL certificates | true |
Testing and Debugging
Protocol Compliance Testing
Use raw mode to test MCP protocol compliance:
# Test server capabilities
mcp-streamablehttp-client --raw '{"method": "capabilities/list", "params": {}}'
# Test error handling
mcp-streamablehttp-client --raw '{"method": "invalid/method", "params": {}}'
Integration Testing
The client is extensively tested with various MCP servers:
test_mcp_everything_client_full.py- Raw protocol teststest_mcp_everything_comprehensive.py- Tool execution teststest_mcp_everything_client_simple.py- Basic connectivity
Debugging Tips
- Enable debug logging:
--log-level DEBUG - Check token status:
--token - Test authentication:
--test-auth - Use raw mode:
--rawfor protocol-level debugging - Check server discovery: Look for OAuth metadata endpoint
Common Issues
Authentication Failures
- Check token status:
mcp-streamablehttp-client --token - Verify server URL is correct
- Try resetting auth:
--reset-auth - Check OAuth endpoint discovery
- Verify network connectivity
Session Issues
- Session IDs are extracted from response headers, not body
- Don't include session ID in initialization requests
- Sessions timeout after inactivity
Response Parsing
- Supports both JSON and SSE (text/event-stream) formats
- Multiple JSON objects may be present in output
- Parser looks for last valid JSON-RPC response
Development
# Clone repository
git clone https://github.com/atrawog/mcp-oauth-gateway
cd mcp-oauth-gateway/mcp-streamablehttp-client
# Install in development mode
pixi install -e .
# Run tests
pixi run pytest tests/ -v
# Test with local server
MCP_SERVER_URL=http://localhost:3000/mcp pixi run mcp-streamablehttp-client --list-tools
License
Apache License 2.0 - see LICENSE file for details.
Author
Andreas Trawoeger
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_streamablehttp_client-0.1.0.tar.gz.
File metadata
- Download URL: mcp_streamablehttp_client-0.1.0.tar.gz
- Upload date:
- Size: 25.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f5392052fb9f10e8287890e59df3e4546d9abcc0a26f1c9463d9378f63f67a0
|
|
| MD5 |
cadec64fd9265c617b17c59db052a946
|
|
| BLAKE2b-256 |
c4a9a0e94aa969e6e55e29bba895c5ba22d2b881bb46793818584013689ada00
|
File details
Details for the file mcp_streamablehttp_client-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mcp_streamablehttp_client-0.1.0-py3-none-any.whl
- Upload date:
- Size: 25.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9a457bb3a695df3613cb7904613d952e50ad6e976493a71d93a8754c2152744
|
|
| MD5 |
3182de739d337c2428abaa455ae40080
|
|
| BLAKE2b-256 |
10f9f6ab220a662a92d609e97a829fcfb4db9908de52237736ff6dd5dee3c055
|