Detect backend OpenAPI version when creating an MCP Server from an existing API#1392
Detect backend OpenAPI version when creating an MCP Server from an existing API#1392Shamly-Shanawaz wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughChangesMCP server OpenAPI detection
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant createMCPServerUsingExistingAPI
participant getAPISwagger
participant createMCPServerFromAPI
createMCPServerUsingExistingAPI->>getAPISwagger: Fetch backend API Swagger
getAPISwagger-->>createMCPServerUsingExistingAPI: Return Swagger definition
createMCPServerUsingExistingAPI->>createMCPServerFromAPI: Submit openAPIVersion metadata
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
portals/publisher/src/main/webapp/source/src/app/data/MCPServer.js (1)
195-198: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueMake the Swagger version check more robust against malformed numeric values.
If a backend specification defines
swagger: 2.0as a numeric type instead of a string,JSON.parsewill evaluate it as the number2.String(2)is"2", which does not start with"2."and would incorrectly fall back to'v3'.Consider relaxing the check to
.startsWith('2')to safely handle both properly stringified"2.0"and numeric2.♻️ Proposed refactor
- if (definition && definition.swagger - && String(definition.swagger).startsWith('2.')) { + if (definition && definition.swagger + && String(definition.swagger).startsWith('2')) {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@portals/publisher/src/main/webapp/source/src/app/data/MCPServer.js` around lines 195 - 198, Update the Swagger version detection in the definition check to recognize both string values such as “2.0” and numeric values such as 2 after String conversion; use a prefix check for “2” instead of requiring “2.”, while preserving the existing openAPIVersion assignments.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@portals/publisher/src/main/webapp/source/src/app/data/MCPServer.js`:
- Around line 188-191: Update MCPServer._requestMetaData to return the result of
Resource._requestMetaData, forwarding its data argument when provided, so
callers such as getAPISwagger receive the parent request metadata and headers.
---
Nitpick comments:
In `@portals/publisher/src/main/webapp/source/src/app/data/MCPServer.js`:
- Around line 195-198: Update the Swagger version detection in the definition
check to recognize both string values such as “2.0” and numeric values such as 2
after String conversion; use a prefix check for “2” instead of requiring “2.”,
while preserving the existing openAPIVersion assignments.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8217d9b2-3634-48b5-8443-42300d409248
📒 Files selected for processing (1)
portals/publisher/src/main/webapp/source/src/app/data/MCPServer.js
|
Closing this PR in favour of an alternative fix |



Description
Purpose
When creating an MCP Server from an existing API, the Publisher did not send an
openAPIVersion, so the backend defaulted tov3. For an existing API whose definition is Swagger 2.0 (v2), that mismatch caused the create call to fail.Change
In
MCPServer.createMCPServerUsingExistingAPI, detect the referenced backend API's OpenAPI version (viagetAPISwagger) and send the matchingopenAPIVersion(v2for Swagger 2.0, otherwisev3) onPOST /mcp-servers/generate-from-api. If detection fails, it falls back tov3(previous behavior).Related Issue : wso2/api-manager#5127