mcp_proxy_shim
mcp_proxy_shim
¶
stdio-to-socket MCP proxy shim.
A lightweight bridge that forwards MCP JSON-RPC messages between a CLI instrument's stdin/stdout and the conductor's shared MCP pool Unix socket.
The proxy is spawned as a subprocess by MCP-native CLI instruments (e.g. claude-code via --mcp-config). It reads JSON-RPC from stdin, forwards to the pool's Unix socket, reads responses from the socket, and writes them to stdout.
Usage::
python -m marianne.daemon.mcp_proxy_shim /tmp/mzt/mcp/github.sock
Or invoked automatically via MCP config JSON::
{"mcpServers": {"github": {
"command": "python3",
"args": ["-m", "marianne.daemon.mcp_proxy_shim",
"/tmp/mzt/mcp/github.sock"]
}}}
Design constraints: - Minimal dependencies (stdlib only — no Pydantic, no Marianne imports) - Async I/O throughout for non-blocking forwarding - Graceful error handling (log to stderr, exit non-zero on failure) - Bidirectional: stdin -> socket AND socket -> stdout run concurrently
Functions:¶
forward_stdin_to_socket
async
¶
Forward data from stdin to the Unix socket.
Reads chunks from stdin and writes them to the socket connection. Closes the socket write side when stdin is exhausted (EOF).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reader
|
StreamReader
|
asyncio StreamReader wrapping stdin. |
required |
writer
|
StreamWriter
|
asyncio StreamWriter connected to the Unix socket. |
required |
Source code in src/marianne/daemon/mcp_proxy_shim.py
forward_socket_to_stdout
async
¶
Forward data from the Unix socket to stdout.
Reads chunks from the socket connection and writes them to stdout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reader
|
StreamReader
|
asyncio StreamReader connected to the Unix socket. |
required |
stdout_writer
|
StreamWriter
|
asyncio StreamWriter wrapping stdout. |
required |
Source code in src/marianne/daemon/mcp_proxy_shim.py
run_proxy
async
¶
Run the stdio-to-socket proxy.
Connects to the Unix socket at socket_path, then concurrently
forwards stdin->socket and socket->stdout until either side closes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
socket_path
|
str
|
Path to the Unix domain socket. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Exit code: 0 on success, 1 on connection failure. |
Source code in src/marianne/daemon/mcp_proxy_shim.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
main
¶
Entry point for the proxy shim.