Files
mcp-proxy/src/mcp_proxy/sse_client.py
andersenthomas98 1de8394767 feat: support 'headers' argument for SSE server connection (#23)
I have replaced the `--api-access-token` argument with the more generic
`--headers` argument for SSE. This will allow for other auth mechanisms
such as api keys as well. Intended usage:

```sh
# API key
mcp-proxy http://example.io/sse --headers x-api-key my-super-secret-api-key

# Bearer token
mcp-proxy http://example.io/sse --headers Authorization 'Bearer my-super-secret-bearer-token'

# Multiple headers
mcp-proxy http://example.io/sse --headers Authorization 'Bearer my-super-secret-bearer-token' --headers x-api-key my-super-secret-api-key
```
2025-02-07 20:49:27 +01:00

28 lines
867 B
Python

"""Create a local server that proxies requests to a remote server over SSE."""
from typing import Any
from mcp.client.session import ClientSession
from mcp.client.sse import sse_client
from mcp.server.stdio import stdio_server
from .proxy_server import create_proxy_server
async def run_sse_client(url: str, headers: dict[str, Any] | None = None) -> None:
"""Run the SSE client.
Args:
url: The URL to connect to.
headers: Headers for connecting to MCP server.
"""
async with sse_client(url=url, headers=headers) as streams, ClientSession(*streams) as session:
app = await create_proxy_server(session)
async with stdio_server() as (read_stream, write_stream):
await app.run(
read_stream,
write_stream,
app.create_initialization_options(),
)