Skip to content

Add config to control MCP path appending to backend endpoint URL#14223

Open
nisan-abeywickrama wants to merge 2 commits into
wso2:masterfrom
nisan-abeywickrama:master
Open

Add config to control MCP path appending to backend endpoint URL#14223
nisan-abeywickrama wants to merge 2 commits into
wso2:masterfrom
nisan-abeywickrama:master

Conversation

@nisan-abeywickrama

Copy link
Copy Markdown
Contributor

Purpose

When the MCP path append feature flag is enabled, /mcp was unconditionally appended to MCP server backend endpoint URLs, causing 404 errors for MCP servers that don't expose a /mcp path segment. This change updates the Velocity templates to conditionally strip the URL postfix for MCP APIs based on the mcpPathAppended metadata flag.

Related issue: wso2/api-manager#5046

Approach

  • velocity_template.xml (all four distribution profiles: all-in-one-apim, api-control-plane, gateway, traffic-manager) — added a Velocity conditional block that removes the REST_URL_POSTFIX axis2 property for MCP APIs when $mcpPathAppended is not true. This ensures that when MCP path appending is disabled (the default), the gateway forwards requests to the backend URL as-is without appending /mcp.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6c58156e-f858-40dc-9be0-d09054262bbc

📥 Commits

Reviewing files that changed from the base of the PR and between d76a859 and 111a76d.

📒 Files selected for processing (5)
  • all-in-one-apim/modules/distribution/resources/api_templates/velocity_template.xml
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/mcp/MCPServerTestCase.java
  • api-control-plane/modules/distribution/resources/api_templates/velocity_template.xml
  • gateway/modules/distribution/resources/api_templates/velocity_template.xml
  • traffic-manager/modules/distribution/resources/api_templates/velocity_template.xml
🚧 Files skipped from review as they are similar to previous changes (5)
  • api-control-plane/modules/distribution/resources/api_templates/velocity_template.xml
  • traffic-manager/modules/distribution/resources/api_templates/velocity_template.xml
  • all-in-one-apim/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/am/integration/tests/mcp/MCPServerTestCase.java
  • gateway/modules/distribution/resources/api_templates/velocity_template.xml
  • all-in-one-apim/modules/distribution/resources/api_templates/velocity_template.xml

📝 Walkthrough

Walkthrough

Across four distribution module velocity templates (all-in-one-apim, api-control-plane, gateway, traffic-manager), a conditional guard is added to remove the Axis2 REST_URL_POSTFIX property only when $mcpPathAppended != true, placed before the McpMediator block. The <!--$endpoint_security--> comment placeholder is also adjusted in each template. Integration test URLs in MCPServerTestCase are updated to include the /mcp path.

Changes

MCP Path Handling and Test Updates

Layer / File(s) Summary
Velocity templates: conditional REST_URL_POSTFIX removal
all-in-one-apim/.../velocity_template.xml, api-control-plane/.../velocity_template.xml, gateway/.../velocity_template.xml, traffic-manager/.../velocity_template.xml
Each template's MCP inSequence now wraps the REST_URL_POSTFIX axis2 property removal in a #if($mcpPathAppended != true) guard, executed before the McpMediator block.
Velocity templates: endpoint_security comment adjustment
all-in-one-apim/.../velocity_template.xml, api-control-plane/.../velocity_template.xml, gateway/.../velocity_template.xml, traffic-manager/.../velocity_template.xml
The <!--$endpoint_security--> placeholder comment is adjusted or reinserted near the end of each template with no functional logic change.
Integration tests: /mcp path in URLs
all-in-one-apim/.../mcp/MCPServerTestCase.java
The proxy request URL (line 713) and buildDefaultEndpointConfig endpoint URL (line 1261) are updated to append /mcp to the host+port.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding configuration to control MCP path appending behavior to backend endpoint URLs, which is the core purpose of this PR.
Description check ✅ Passed The description is well-related to the changeset, explaining the problem (404 errors when /mcp path is not exposed), the solution (conditional stripping of URL postfix), and the approach (Velocity template modifications across four distribution profiles).
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 8, 2026
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 9.30%. Comparing base (a7a0665) to head (5a5c778).
⚠️ Report is 10 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master   #14223      +/-   ##
============================================
- Coverage     11.25%    9.30%   -1.95%     
+ Complexity      827      763      -64     
============================================
  Files           361      361              
  Lines         17719    17719              
  Branches       1897     1897              
============================================
- Hits           1994     1649     -345     
- Misses        15691    16043     +352     
+ Partials         34       27       -7     
Flag Coverage Δ
integration_tests 9.30% <ø> (-1.95%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 8, 2026
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