mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
fix(mcp): document /mcp-rest/tools/call request body in OpenAPI schema
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
This commit is contained in:
parent
2e076b110f
commit
7d9859beb8
1 changed files with 38 additions and 1 deletions
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue