From 7c75fa9212c50f3818c65128c34849768cab1268 Mon Sep 17 00:00:00 2001 From: zgaetano Date: Tue, 31 Mar 2026 15:33:38 -0400 Subject: [PATCH] Add gateway-proxy/gateway_proxy_patch.py --- gateway-proxy/gateway_proxy_patch.py | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 gateway-proxy/gateway_proxy_patch.py diff --git a/gateway-proxy/gateway_proxy_patch.py b/gateway-proxy/gateway_proxy_patch.py new file mode 100644 index 0000000..ab5a75f --- /dev/null +++ b/gateway-proxy/gateway_proxy_patch.py @@ -0,0 +1,45 @@ +""" +PATCH: Add OpenAI-compatible routes to gateway_proxy.py + +This file contains the modifications needed to add OpenAI API support +to the MCP gateway. Apply these changes to gateway_proxy.py: + +1. Add import at the top of the file (after other imports): + from .openai_routes_fixed import convert_mcp_tool_to_openai, list_models, tools, chat_completions + +2. Add these routes to the routes list (before the closing bracket): + + # OpenAI-compatible API endpoints + Route("/v1/models", list_models, methods=["GET"]), + Route("/v1/tools", lambda r: tools(r, TOOL_DEFINITIONS), methods=["GET"]), + Route("/v1/chat/completions", lambda r: chat_completions(r, TOOL_DEFINITIONS), methods=["POST"]), + +3. The lambda functions are necessary to pass TOOL_DEFINITIONS to the handlers. + +IMPLEMENTATION STEPS: +===================== + +1. Make a backup of gateway_proxy.py: + cp gateway_proxy.py gateway_proxy.backup + +2. Add the import statement after line 27 (after from .openai_routes import...): + + from .openai_routes_fixed import convert_mcp_tool_to_openai, list_models, tools, chat_completions + +3. Find the routes list (around line 795) and add before the final closing bracket: + + # OpenAI-compatible API endpoints (for Open-UI and other OpenAI clients) + Route("/v1/models", list_models, methods=["GET"]), + Route("/v1/tools", lambda r: tools(r, TOOL_DEFINITIONS), methods=["GET"]), + Route("/v1/chat/completions", lambda r: chat_completions(r, TOOL_DEFINITIONS), methods=["POST"]), + +4. Restart the gateway container: + docker-compose restart gateway-proxy + +5. Test tool discovery from OpenUI: + GET http://mcp.wilddragon.net:8000/v1/tools + + Should return JSON with "data" array containing tool definitions in OpenAI format. +""" + +print(__doc__)