diff --git a/README.md b/README.md index f5c88a9..2aad51c 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/servers/mcp-proxy/main.py b/servers/mcp-proxy/main.py index 4a27489..da9740c 100644 --- a/servers/mcp-proxy/main.py +++ b/servers/mcp-proxy/main.py @@ -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