Skip to content

Commit c54e5cf

Browse files
committed
simplify and clean for release
1 parent 27e2fc4 commit c54e5cf

File tree

5 files changed

+104
-587
lines changed

5 files changed

+104
-587
lines changed

README.md

Lines changed: 70 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,91 @@
11
# Open MCP Proxy
22

3-
An open source proxy for MCP servers.
3+
A simple and lightweight open-source bidirectional proxy for MCP servers.
44

5-
## Usage
5+
It exposes several callbacks that you can use to implement your own logic and do your own actions during the MCP protocol lifecycle.
6+
7+
It supports both SSE and STDIO protocols so it can be used to enable MCP Client supporting only stdio (like the Claude Desktop App) to also support SSE.
68

7-
Replace the mcp server command with `uvx omproxy@latest` followed by the command.
9+
It leverages as much as possible the official mcp-python-sdk to remains simple, lightweight and future-proof.
810

9-
For example:
11+
it declines in 2 versions to support both SSE and STDIO protocols:
1012

11-
replace:
13+
**SSE Proxy**
1214

13-
```json
14-
{
15-
"mcpServers":{
16-
"server1":{
17-
"command":"uv"
18-
"args": ["run", "src/example_server.py"]
19-
}
20-
}
21-
}
15+
```mermaid
16+
graph LR
17+
STDIN -->|stdio| Proxy[Open MCP Proxy]
18+
Proxy -->|SSE| Server[Remote MCP Server]
2219
```
2320

24-
with:
25-
26-
```json
27-
{
28-
"mcpServers":{
29-
"server1":{
30-
"command": "uvx",
31-
"args": [
32-
"--python",
33-
"3.12",
34-
"omproxy@latest",
35-
"--name",
36-
"example_server",
37-
"uv",
38-
"run",
39-
"src/example_server.py"
40-
]
41-
}
42-
}
43-
}
21+
```mermaid
22+
graph RL
23+
Server[Remote MCP Server] -->|SSE| Proxy[Open MCP Proxy]
24+
Proxy -->|stdio| STDOUT
25+
```
26+
27+
**STDIO Proxy**
28+
29+
```mermaid
30+
graph LR
31+
STDIN -->|stdio| Proxy[Open MCP Proxy]
32+
Proxy -->|stdio| Server[Local MCP Server]
4433
```
4534

46-
## Telemetry Data Collection and Handling
35+
```mermaid
36+
graph RL
37+
Server[Local MCP Server] -->|stdio| Proxy[Open MCP Proxy]
38+
Proxy -->|stdio| STDOUT
39+
```
40+
41+
Note that in both cases the proxy listen to STDIN and write to STDOUT to work seemlessly with stdio MCP Clients.
42+
43+
## Usage
4744

48-
We collect anonymous telemetry data of MCP server running through the proxy.
45+
### Hook into the MCP protocol lifecycle
4946

50-
The information collected help us:
47+
The recommended approach to hook into the MCP protocol lifecycle is to subclass one of the Proxy class that we expose and override the callback methods you need.
5148

52-
* display lively health status of MCP servers on our website: https://iod.ai
53-
* troubleshoot MCP servers, take them out and report issues to corresponding MCP server owner repository.
54-
* aggregate usage metric to display information such as the most used MCP servers, or the most used tool for a given MCP server.
49+
At the moment, we expose 4 callback methods:
5550

56-
We collect the minimal amount of data to support the use cases above. In practice it means that we collect:
57-
* 1 anonymous event everytime the proxy is started
58-
* 1 anonymous event everytime a 'call_tool' is made containing the name of the tool and the arguments passed to the tool.
59-
* 1 anonymous event everytime a 'resource' is accessed containing the uri accessed but not the content of the resource.
51+
| Method | Description | Parameters |
52+
|--------|-------------|------------|
53+
| `_on_mcp_client_message` | Can be used to handle messages from the MCP client | `message: JSONRPCMessage` |
54+
| `_on_mcp_server_message` | Can be used to handle messages from the MCP server | `message: JSONRPCMessage \| Exception` |
55+
| `_on_start` | Can be used to handle the start of the proxy | None |
56+
| `_on_close` | Can be used to handle the close of the proxy | None |
6057

61-
Note: for tool use and resource we do store access or log the response in any way.
58+
For example if you need a proxy over the stdio protocol:
6259

63-
All the data collected is anonymous we use OpenTelemetry the open source standard for collecting telemetry data through logfire (the observability framework by the pydantic team).
60+
```python
61+
from omproxy.proxy import StdioProxy
6462

65-
Your anonymous data is stored by logfire for a period of 30 days as per logfire retention policy.
63+
class MyStdioProxy(StdioProxy):
64+
def _on_start(self):
65+
print("Starting proxy", file=sys.stderr)
6666

67+
def _on_mcp_client_message(self, message: JSONRPCMessage):
68+
print(message, file=sys.stderr)
6769

70+
def _on_mcp_server_message(self, message: JSONRPCMessage | Exception):
71+
print(message, file=sys.stderr)
72+
73+
def _on_close(self):
74+
print("Closing proxy", file=sys.stderr)
75+
76+
if __name__ == "__main__":
77+
proxy = MyStdioProxy()
78+
proxy.run(StdioServerParameters(command="uv", args=["run", "src/example_server.py"]))
79+
```
80+
81+
**tip**: dont write to stdout in your callbacks or anywhere really as it will mess with the stdio MCP communication.
82+
83+
### MCP Client supporting only STDIO to your SSE MCP Server
84+
85+
We provide a simple CLI to start the proxy if you have an SSE MCP server running and you want to make it available to an MCP Client supporting only stdio you can simply do:
86+
87+
```bash
88+
uvx omproxy@latest sse --url https://yourssemcpserver.io
89+
```
6890

91+
see `uvx omproxy@latest sse --help` for more information including setting headers for authorization for example.

src/echo.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""
2+
FastMCP dummy Echo Server for testing purposes.
3+
"""
4+
5+
from mcp.server.fastmcp import FastMCP
6+
7+
# Create server
8+
mcp = FastMCP("Echo Server")
9+
10+
11+
@mcp.tool()
12+
def echo_tool(text: str) -> str:
13+
"""Echo the input text"""
14+
return text
15+
16+
17+
@mcp.resource("echo://static")
18+
def echo_resource() -> str:
19+
return "Echo!"
20+
21+
22+
@mcp.resource("echo://{text}")
23+
def echo_template(text: str) -> str:
24+
"""Echo the input text"""
25+
return f"Echo: {text}"
26+
27+
28+
@mcp.prompt("echo")
29+
def echo_prompt(text: str) -> str:
30+
return text
31+
32+
33+
if __name__ == "__main__":
34+
mcp.run()

src/omproxy/highlevel_proxy.py

Lines changed: 0 additions & 175 deletions
This file was deleted.

0 commit comments

Comments
 (0)