From 7d9859beb846f62495a2bb939ace16bb1d4fecf5 Mon Sep 17 00:00:00 2001 From: Phoenix1454 Date: Sun, 5 Jul 2026 16:50:57 +0100 Subject: [PATCH] fix(mcp): document /mcp-rest/tools/call request body in OpenAPI schema MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The endpoint uses a raw Request object to read its JSON body, so FastAPI could not infer the body schema. The generated OpenAPI spec showed no parameters, causing LLMs that consume the spec to generate tool calls with empty bodies (HTTP 500). Fix: add openapi_extra to the @router.post decorator with an explicit requestBody schema (server_id, name, arguments) and a concrete example. No behavioral changes — the body is still read via request.json(). Fixes #32121 --- .../mcp_server/rest_endpoints.py | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/_experimental/mcp_server/rest_endpoints.py b/litellm/proxy/_experimental/mcp_server/rest_endpoints.py index ce0698cb7ac..ba44ef8152d 100644 --- a/litellm/proxy/_experimental/mcp_server/rest_endpoints.py +++ b/litellm/proxy/_experimental/mcp_server/rest_endpoints.py @@ -735,7 +735,44 @@ if MCP_AVAILABLE: "message": f"An unexpected error occurred: {str(e)}", } - @router.post("/tools/call", dependencies=[Depends(user_api_key_auth)]) + @router.post( + "/tools/call", + dependencies=[Depends(user_api_key_auth)], + openapi_extra={ + "requestBody": { + "required": True, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": ["name"], + "properties": { + "server_id": { + "type": "string", + "description": "ID of the MCP server that owns the tool. Required unless calling a virtual tool (mcp_tool_search or mcp_tool_call).", + }, + "name": { + "type": "string", + "description": "Name of the MCP tool to invoke.", + }, + "arguments": { + "type": "object", + "description": "Key-value arguments forwarded to the tool.", + "additionalProperties": True, + "default": {}, + }, + }, + }, + "example": { + "server_id": "17a4490465f74d3696caf12b30220166", + "name": "places_api-getPlaces", + "arguments": {"query": "coffee shops in London"}, + }, + } + }, + } + }, + ) async def call_tool_rest_api( request: Request, user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),