fix(draft_ENG-14445): Fixed the package analytics endpoint generation by mcp, included v2 in it - #417
Open
agupta-cruiser wants to merge 1 commit into
Open
fix(draft_ENG-14445): Fixed the package analytics endpoint generation by mcp, included v2 in it#417agupta-cruiser wants to merge 1 commit into
agupta-cruiser wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes MCP tool URL construction so dynamically generated tools for Cloudsmith API v2 include the required /v2 prefix (derived from the OpenAPI spec’s servers[].url for v2 or basePath for v1), preventing authenticated v2 calls from incorrectly hitting unversioned endpoints and returning 404s.
Changes:
- Added
DynamicMCPServer._spec_base_url()to compute a version-aware base URL from the loaded spec while preserving the configured API host. - Updated tool generation to accept and use a per-spec
base_urlinstead of always usingself.api_base_url. - Added unit tests validating base URL derivation and that a v2 tool is generated under the
/v2/...path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| cloudsmith_cli/core/mcp/server.py | Builds a version-aware base URL from spec metadata and uses it when generating MCP tools so v2 endpoints resolve correctly. |
| cloudsmith_cli/cli/tests/commands/test_mcp.py | Adds coverage to ensure v2 uses servers[].url path prefix, v1 falls back to basePath, and generated tool URLs include /v2. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The Cloudsmith MCP server was returning 404 for every v2 backed tool, even when authentication was valid and the workspace slug was correct. This first surfaced with a customer using analytics_logs_package_list, but it affected all v2 endpoints.
The root cause is in how the server builds request URLs. It generates tools dynamically from Cloudsmith's OpenAPI specs and builds each request URL by joining the API host with the path taken from the spec. The version prefix (/v1 or /v2) is not part of the path keys though. It is declared separately: the v2 spec puts it in the servers section (https://api.cloudsmith.io/v2/) and the v1 spec puts it in basePath. The server was ignoring that, so a v2 tool was sent to https://api.cloudsmith.io/analytics/logs/package/{workspace}/ instead of https://api.cloudsmith.io/v2/analytics/logs/package/{workspace}/, which 404s.
v1 tools were never affected because the v1 API also answers at the un-versioned root, so dropping the prefix was harmless for v1. The v2 API only answers under /v2/, so every v2 tool failed. This is a client side URL construction bug, not a permissions or plan issue.
This PR adds a helper that reads the version prefix from the right place for whichever spec is being loaded (the servers URL for v2, or basePath for v1) and prepends it to the configured host. Tool generation now uses that version aware base URL. The fix keeps the configured API host and only borrows the version path from the spec, so a custom API host still works, and v1 behaviour is unchanged.
Type of Change
Bug fix
Additional Notes
Added some tests also.