refac: mcp-proxy

This commit is contained in:
Timothy Jaeryang Baek 2025-03-30 00:28:49 -07:00
parent a0fc78963e
commit cc1a795cc1
2 changed files with 20 additions and 6 deletions

View File

@ -44,7 +44,7 @@ Reference implementations provided in this repository demonstrate common use-cas
(More examples and reference implementations will be actively developed and continually updated.)
## 🔌 WIP: Bridge to MCP (Optional)
## 🔌 Bridge to MCP (Optional)
For your convenience, we also provide a simple, secure MCP-to-OpenAPI proxy server. This enables tool providers who initially implemented MCP servers to expose them effortlessly as standard OpenAPI-compatible APIs, ensuring existing MCP servers and resources remain accessible without additional hassle.
@ -53,7 +53,7 @@ For your convenience, we also provide a simple, secure MCP-to-OpenAPI proxy serv
```bash
cd servers/mcp-proxy
pip install -r requirements.txt
python main.py -- uvx mcp-server-time
python main.py --host 0.0.0.0 --port 8000 -- uvx mcp-server-time --local-timezone=America/New_York
```
This can simplify your migration or integration path, avoiding headaches typically associated with MCP's transport and security complexities.

View File

@ -60,10 +60,24 @@ async def create_dynamic_endpoints(app: FastAPI, session: ClientSession):
def make_endpoint_func(endpoint_name: str, FormModel):
async def endpoint_func(form_data: FormModel):
args = form_data.model_dump()
print("Calling tool with arguments:", args)
print("Tool name:", endpoint_name)
result = await session.call_tool(endpoint_name, arguments=args)
return result
print(f"Calling {endpoint_name} with arguments:", args)
tool_call_result = await session.call_tool(
endpoint_name, arguments=args
)
response = []
for content in tool_call_result.content:
text = content.text
if isinstance(text, str):
try:
text = json.loads(text)
except json.JSONDecodeError:
pass
response.append(text)
return response
return endpoint_func