Skip to content

Add get_upgrade_guidance MCP tool - #299

Open
singhrohit90 wants to merge 2 commits into
blackducksoftware:masterfrom
singhrohit90:feature/get-upgrade-guidance-tool
Open

Add get_upgrade_guidance MCP tool#299
singhrohit90 wants to merge 2 commits into
blackducksoftware:masterfrom
singhrohit90:feature/get-upgrade-guidance-tool

Conversation

@singhrohit90

Copy link
Copy Markdown

Summary

The MCP server (blackduck/mcp_server.py) exposes list_project_components and get_project_vulnerabilities, but nothing wires up BlackDuck's upgrade-guidance endpoints — so an agent using this MCP server can find a vulnerable component but has no way to ask "what should I upgrade to?" without dropping out of MCP and hitting the REST API directly.

What this adds

  • A new get_upgrade_guidance(component_id, component_version_id) tool. It tries .../transitive-upgrade-guidance first, then falls back to .../upgrade-guidance — the transitive variant needs an originId that isn't always available from list_project_components's output, so the fallback keeps the tool useful even without it.
  • componentId / componentVersionId fields added to list_project_components's output (extracted from the existing component/componentVersion href fields), so a caller can chain straight from list_project_components into get_upgrade_guidance without any extra lookups.

Testing

  • Live-verified against a real BlackDuck 2025.7.1 instance on an actual vulnerable component (ag-grid-community 24.0.0) — transitive-upgrade-guidance 404'd (no originId), correctly fell back, and returned real short/long-term upgrade recommendations with vulnerability-risk counts (e.g. long-term target with 0 critical/high/medium/low).
  • Also verified on Apache Commons BeanUtils (1.8.0/1.9.1/1.9.3) — all three resolved to the same safe target version (1.11.0, zero known vulnerabilities), consistent with what the BlackDuck UI itself would recommend.
  • Added test/test_mcp_server_upgrade_guidance.py: unit tests (mocked Client, no network) covering the fallback behavior, the both-endpoints-unavailable case, and the id-extraction addition to list_project_components.
  • Ran the full existing suite (pytest test/) — all 45 tests pass, no regressions.

Note: the new test file guards its fastmcp import with pytest.importorskip since fastmcp isn't in requirements.lock.txt (it's the optional mcp extra) — so it skips cleanly rather than failing CI in environments without it installed.

Possible follow-ups (didn't want to scope-creep this PR)

  • Origin-aware lookup so transitive-upgrade-guidance can actually succeed when an originId is available (e.g. threading it through from a BOM listing that includes origins).
  • list_project_components could optionally return originId alongside componentId/componentVersionId to support the above.

Happy to adjust scope, naming, or approach — this is one of my first contributions to a project I don't maintain, so please push back on anything that doesn't fit your conventions.

Related: #298 (independent bug fix in the same file, opened separately so it can be reviewed/merged on its own).

rohising added 2 commits August 29, 2026 16:58
Wires up the upgrade-guidance endpoint that Black Duck exposes but the
existing MCP tools never call. Tries transitive-upgrade-guidance first,
falls back to upgrade-guidance since the transitive variant requires an
originId not always available from list_project_components. Also adds
componentId/componentVersionId to list_project_components output so
results can be chained straight into this tool.

Verified live against a real 2025.7.1 instance.
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