Skip to content

Detect backend OpenAPI version when creating an MCP Server from an existing API#1392

Closed
Shamly-Shanawaz wants to merge 1 commit into
wso2:mainfrom
Shamly-Shanawaz:fix/mcp-from-existing-api-v2-npe
Closed

Detect backend OpenAPI version when creating an MCP Server from an existing API#1392
Shamly-Shanawaz wants to merge 1 commit into
wso2:mainfrom
Shamly-Shanawaz:fix/mcp-from-existing-api-v2-npe

Conversation

@Shamly-Shanawaz

Copy link
Copy Markdown

Description

Purpose

When creating an MCP Server from an existing API, the Publisher did not send an openAPIVersion, so the backend defaulted to v3. 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 (via getAPISwagger) and send the matching openAPIVersion (v2 for Swagger 2.0, otherwise v3) on POST /mcp-servers/generate-from-api. If detection fails, it falls back to v3 (previous behavior).

Related Issue : wso2/api-manager#5127

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

MCP server OpenAPI detection

Layer / File(s) Summary
Detect and submit OpenAPI version
portals/publisher/.../MCPServer.js
createMCPServerUsingExistingAPI fetches the referenced backend API Swagger definition, detects v2 or v3, logs detection errors, and passes openAPIVersion to createMCPServerFromAPI.

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
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: detecting the backend OpenAPI version during MCP Server creation.
Description check ✅ Passed The description matches the implemented change and explains the v2/v3 detection and fallback behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 value

Make the Swagger version check more robust against malformed numeric values.

If a backend specification defines swagger: 2.0 as a numeric type instead of a string, JSON.parse will evaluate it as the number 2. 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 numeric 2.

♻️ 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

📥 Commits

Reviewing files that changed from the base of the PR and between 61590f1 and 44535c4.

📒 Files selected for processing (1)
  • portals/publisher/src/main/webapp/source/src/app/data/MCPServer.js

Comment thread portals/publisher/src/main/webapp/source/src/app/data/MCPServer.js
@Shamly-Shanawaz

Copy link
Copy Markdown
Author

Closing this PR in favour of an alternative fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant