Skip to content

Commit 781cab8

Browse files
authored
Merge pull request #341 from OWASP/array-response-fix
array response fix required due to fastmcp update
2 parents e2a0fbe + fdf0f8c commit 781cab8

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

services/chatbot/src/mcpserver/server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import httpx
77
from fastmcp import FastMCP
88

9+
from .tool_helpers import fix_array_responses_in_spec
910
from .config import Config
1011

1112
# Configure logging
@@ -77,6 +78,7 @@ def get_http_client():
7778
# Load your OpenAPI spec
7879
with open(Config.OPENAPI_SPEC, "r") as f:
7980
openapi_spec = json.load(f)
81+
openapi_spec = fix_array_responses_in_spec(openapi_spec)
8082

8183
# Create the MCP server
8284
mcp = FastMCP.from_openapi(

services/chatbot/src/mcpserver/tool_helpers.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,18 @@ async def get_any_api_key():
1212
if doc and "openai_api_key" in doc:
1313
return doc["openai_api_key"]
1414
return None
15+
16+
def fix_array_responses_in_spec(spec):
17+
for path_item in spec.get("paths", {}).values():
18+
for method, operation in path_item.items():
19+
if method not in ["get", "post", "put", "patch", "delete"]:
20+
continue
21+
22+
for response in operation.get("responses", {}).values():
23+
for media in response.get("content", {}).values():
24+
schema = media.get("schema", {})
25+
26+
if schema.get("type") == "array":
27+
del media["schema"]
28+
29+
return spec

0 commit comments

Comments
 (0)