Bridge API#

The stdio bridge adapts local MCP stdio clients to a Litestar MCP Streamable HTTP endpoint. Most users should run it through Litestar's app-bound CLI: litestar --app my_app:app mcp bridge. The functions below are available for tests and embedded launchers.

run_stdio_streamable_http_bridge#

async litestar_mcp.mcp.bridge.run_stdio_streamable_http_bridge(endpoint, *, transport=None, client_info=None, headers=None, token_provider=None, header_name='Authorization', token_prefix='Bearer ', timeout=30.0, sse_read_timeout=300.0, stdin=None, stdout=None, stderr=None, max_message_size=16777216)[source]#

Bridge local stdio JSON-RPC to a Litestar Streamable HTTP MCP endpoint.

Parameters:
  • endpoint (str) -- Full MCP Streamable HTTP endpoint URL.

  • transport (Optional[AsyncBaseTransport]) -- Optional httpx2 transport. Pass ASGIStreamingTransport to serve an in-process ASGI app instead of a remote endpoint.

  • client_info (Optional[Mapping[str, str]]) -- Default io.modelcontextprotocol/clientInfo injected into requests that do not carry one.

  • headers (Optional[Mapping[str, str]]) -- Static HTTP headers sent to the endpoint.

  • token_provider (Union[Callable[[], str], Callable[[], Awaitable[str]], None]) -- Optional callable that returns a fresh token per request.

  • header_name (str) -- Header used for token auth.

  • token_prefix (str) -- Prefix prepended to token values.

  • timeout (float) -- HTTP connect, write, and pool timeout in seconds.

  • sse_read_timeout (float | None) -- Read timeout for streaming SSE responses. None or 0 disables quiet-period timeouts for server streams.

  • stdin (Optional[ByteReceiveStream]) -- Optional byte receive stream for tests or embedding.

  • stdout (Optional[ByteSendStream]) -- Optional byte send stream for tests or embedding.

  • stderr (Optional[Any]) -- Optional diagnostic text stream. Defaults to sys.stderr.

  • max_message_size (int) -- Maximum bytes allowed for one newline-delimited JSON-RPC message, applied both to stdin lines and to server-sent events read from the endpoint. Set to -1 to disable the limit.

Return type:

int

Returns:

Process-style exit code. 0 means clean EOF/shutdown; non-zero means a transport or pump error was surfaced to the local stdio client.

DEFAULT_MAX_STDIN_MESSAGE_SIZE#

litestar_mcp.mcp.bridge.DEFAULT_MAX_STDIN_MESSAGE_SIZE = 16777216#

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int('0b100', base=0) 4

run_bridge#

litestar_mcp.mcp.bridge.run_bridge(endpoint, *, headers=None, token_provider=None, header_name='Authorization', token_prefix='Bearer ', timeout=30.0, sse_read_timeout=300.0, stdout=None, stderr=None, max_message_size=16777216)[source]#

Synchronously run the stdio bridge for CLI integrations.

Return type:

int

BridgeConnectionError#

class litestar_mcp.mcp.bridge.BridgeConnectionError[source]#

Bases: LitestarMCPError

Raised when the stdio bridge cannot connect to its target endpoint.

__init__(endpoint)[source]#

BridgeMessageTooLargeError#

class litestar_mcp.mcp.bridge.BridgeMessageTooLargeError[source]#

Bases: LitestarMCPError, ValueError

Raised when a stdio JSON-RPC frame exceeds the bridge line limit.

__init__(max_bytes)[source]#