Skip to content

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
masterfrom
fix_mcp_analytics_v2_endpoint
Open

fix(draft_ENG-14445): Fixed the package analytics endpoint generation by mcp, included v2 in it#417
agupta-cruiser wants to merge 1 commit into
masterfrom
fix_mcp_analytics_v2_endpoint

Conversation

@agupta-cruiser

Copy link
Copy Markdown

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.

Copilot AI lite review requested due to automatic review settings September 8, 2026 21:49
@agupta-cruiser
agupta-cruiser requested a review from a team as a code owner September 8, 2026 21:49

Copilot AI 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.

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_url instead of always using self.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.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants