Skip to main content
Glama
blackduck-mcp

blackduck-mcp

README.md
# blackduck-mcp

> MCP server for Black Duck Software Composition Analysis — lets AI assistants (Claude, Cursor, VS Code) query component vulnerabilities and find safe upgrade paths.

![CI](https://github.com/maheshkumargangula/blackduck-mcp/actions/workflows/ci.yml/badge.svg)
![Node.js](https://img.shields.io/badge/node-%3E%3D18-brightgreen)
![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
![MCP](https://img.shields.io/badge/MCP-compatible-blue)

---

## Quick Start

```bash
git clone https://github.com/maheshkumargangula/blackduck-mcp.git
cd blackduck-mcp
npm install && npm run build
```

Then wire it into your MCP client (see [Integration](#integration) below).

---

## Architecture

```
MCP Client (Claude / Cursor / VS Code)
         |
         | MCP Protocol (stdio)
         v
  ┌─────────────────────────────────┐
  │        blackduck-mcp            │
  │                                 │
  │  src/index.ts  ←  tool registry │
  │        │                        │
  │        ├── search_component     │
  │        ├── list_component_vers. │
  │        ├── get_version_vulns    │
  │        ├── get_upgrade_guidance │
  │        └── analyze_component ──────── (orchestrator)
  │               │                 │
  │        src/client.ts            │
  │  (auth + retry + API mapping)   │
  └─────────────┬───────────────────┘
                │
                │ HTTPS REST
                v
  ┌─────────────────────────────────┐
  │   Black Duck Server             │
  │   POST /api/tokens/authenticate │
  │   GET  /api/search/kb-components│
  │   GET  .../versions             │
  │   GET  .../vulnerabilities      │
  │   GET  .../upgrade-guidance     │
  └─────────────────────────────────┘
```

`analyze_component` is the high-level orchestrator. It calls the other four API methods in sequence: **search → version lookup → vulnerability check → upgrade guidance**.

---

## Prerequisites

- **Node.js 18+** (ESM + `URL` global required)
- **A running Black Duck instance** (on-prem or SaaS) with API access
- **A Black Duck API token** — generate one from the Black Duck UI:
  1. Log in to Black Duck
  2. Click your username (top right) → **My Profile**
  3. Navigate to **User → API Tokens**
  4. Click **Generate New Token**, copy the value

---

## Configuration

Copy `.env.example` to `.env` and fill in your values, or pass them inline at runtime.

| Variable | Required | Description |
|---|---|---|
| `BLACKDUCK_BASE_URL` | Yes | Your Black Duck instance URL, e.g. `https://blackduck.company.com` |
| `BLACKDUCK_API_TOKEN` | Yes | API token from Black Duck UI → User → API Tokens |

---

## Integration

### Claude Code (CLI)

Add to `~/.claude/claude.json`:

```json
{
  "mcpServers": {
    "blackduck": {
      "command": "node",
      "args": ["/absolute/path/to/blackduck-mcp/dist/index.js"],
      "env": {
        "BLACKDUCK_BASE_URL": "https://your-blackduck.company.com",
        "BLACKDUCK_API_TOKEN": "your-token-here"
      }
    }
  }
}
```

Or use the CLI shortcut:

```bash
claude mcp add blackduck node /absolute/path/to/blackduck-mcp/dist/index.js \
  -e BLACKDUCK_BASE_URL=https://your-host \
  -e BLACKDUCK_API_TOKEN=your-token
```

Verify it was registered:

```bash
claude mcp list
```

---

### Claude Desktop

Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):

```json
{
  "mcpServers": {
    "blackduck": {
      "command": "node",
      "args": ["/absolute/path/to/blackduck-mcp/dist/index.js"],
      "env": {
        "BLACKDUCK_BASE_URL": "https://your-blackduck.company.com",
        "BLACKDUCK_API_TOKEN": "your-token-here"
      }
    }
  }
}
```

---

### VS Code / Cursor

Add to `.vscode/mcp.json` (workspace) or your user settings:

```json
{
  "servers": {
    "blackduck": {
      "type": "stdio",
      "command": "node",
      "args": ["/absolute/path/to/blackduck-mcp/dist/index.js"],
      "env": {
        "BLACKDUCK_BASE_URL": "https://your-blackduck.company.com",
        "BLACKDUCK_API_TOKEN": "your-token-here"
      }
    }
  }
}
```

---

## Manual Testing with MCP Inspector

Test the server directly in a browser UI before wiring it into an AI client:

```bash
BLACKDUCK_BASE_URL=https://your-host BLACKDUCK_API_TOKEN=your-token \
  npx @modelcontextprotocol/inspector node dist/index.js
```

This opens a browser UI where you can call each tool individually and inspect the raw JSON responses.

---

## Available Tools

### `search_component`

Search for a component by name in the Black Duck Global KnowledgeBase.

| Parameter | Type | Required | Description |
|---|---|---|---|
| `name` | string | Yes | Component name, e.g. `"log4j"` |

**Output:** List of matching components sorted by exact name match, then by release count. Each entry includes the `href` needed by other tools.

**Example prompt:**
> "Find the log4j component in Black Duck"

---

### `list_component_versions`

List versions of a component, optionally filtered by version string.

| Parameter | Type | Required | Description |
|---|---|---|---|
| `componentHref` | string | Yes | `href` from a `search_component` result |
| `versionFilter` | string | No | Version name to filter on, e.g. `"1.2.17"` |

**Output:** List of versions with release dates, vulnerability counts (⚠️ / ✓), and hrefs.

**Example prompt:**
> "List all versions of log4j and show which ones have vulnerabilities"

---

### `get_version_vulnerabilities`

Get all known CVEs and BDSAs for a specific component version.

| Parameter | Type | Required | Description |
|---|---|---|---|
| `componentVersionHref` | string | Yes | `href` from a `list_component_versions` result |

**Output:** Vulnerabilities grouped by severity (CRITICAL / HIGH / MEDIUM / LOW / UNKNOWN), each with CVSS score, CWE ID, source, and description.

**Example prompt:**
> "What CVEs does log4j 1.2.17 have?"

---

### `get_upgrade_guidance`

Get Black Duck's recommended safe upgrade versions for a component version.

| Parameter | Type | Required | Description |
|---|---|---|---|
| `componentVersionHref` | string | Yes | `href` of the vulnerable version |

**Output:** Short-term (patch) and long-term (major) upgrade recommendations, each with version string and href.

**Example prompt:**
> "What does Black Duck recommend upgrading log4j 1.2.17 to?"

---

### `analyze_component` *(orchestrator)*

High-level end-to-end analysis: given a component name and version, performs a full vulnerability assessment and identifies the safest upgrade path.

| Parameter | Type | Required | Description |
|---|---|---|---|
| `componentName` | string | Yes | Component name, e.g. `"log4j"` |
| `currentVersion` | string | Yes | Version to check, e.g. `"1.2.17"` |

**Internal sequence:**
```
1. search_component(componentName)
2. list_component_versions(href, filter=currentVersion)
3. get_version_vulnerabilities(versionHref)
4. get_upgrade_guidance(versionHref)
   → if no guidance: scans up to 20 recent versions for a clean one
```

**Output:** Markdown report including:
- Component identity in the KnowledgeBase
- Version confirmation
- All vulnerabilities grouped by severity (top 5 per group shown)
- Short-term and long-term upgrade recommendations
- Summary with recommended upgrade version

**Example prompt:**
> "Our project uses log4j 1.2.17. Is it safe to use? What should we upgrade to?"

---

## Example Workflow

```
User: "Our project uses log4j 1.2.17. Is it safe?"

Claude uses analyze_component(componentName="log4j", currentVersion="1.2.17"):
  → Finds log4j in the KnowledgeBase
  → Confirms version 1.2.17 exists
  → Finds CVE-2019-17571 and others (CRITICAL/HIGH severity)
  → Recommends upgrading to 2.17.1 (from Black Duck guidance)
  → Returns full markdown report with all findings
```

---

## Authentication

1. On first API call: `POST /api/tokens/authenticate` with `Authorization: token {API_TOKEN}`
2. Bearer token cached in memory for the process lifetime
3. On HTTP 401: re-authenticates once automatically, then retries the original request
4. If the second attempt also fails, the error is propagated to the AI client

The token is **not** persisted to disk. Each server restart requires fresh authentication, which happens automatically on the first tool call.

> **Note:** The `[BD] GET ...` lines you may see on stderr are intentional debug logs from `client.ts`. They are not part of MCP protocol output and do not affect functionality.

---

## Troubleshooting

| Symptom | Likely Cause | Fix |
|---|---|---|
| `BLACKDUCK_BASE_URL is not set` | Env vars not passed to the process | Check the `env` block in your MCP client config |
| `401 Unauthorized` | Expired or invalid API token | Regenerate token in Black Duck UI → User → API Tokens |
| `ECONNREFUSED` / connection timeout | Wrong base URL or firewall blocking | Verify the URL is reachable: `curl https://your-host/api/tokens/authenticate` |
| Tool returns "not found" for a known package | Component name mismatch | Use `search_component` first to find the exact name |
| `Cannot find module 'dist/index.js'` | `dist/` not built | Run `npm run build` |
| Stderr output visible in client | Normal — server logs to stderr intentionally | Logs are separate from MCP protocol; not a bug |

---

## Contributing

1. Fork the repository
2. Create a feature branch: `git checkout -b feat/my-feature`
3. Make changes and run `npm run build` to confirm no TypeScript errors
4. Submit a pull request with a clear description

The codebase uses strict TypeScript (`"strict": true` in `tsconfig.json`). All new tools should follow the pattern in `src/tools/searchComponent.ts`: export a zod schema object and a handler function, then register both in `src/index.ts`.

---

## License

MIT — see [LICENSE](./LICENSE)

TDQS

A3.5/5.0

Scored across 5 tools

Disambiguation4/5

The four granular tools target distinct steps (search, list versions, get vulnerabilities, get upgrade guidance) and are easy to tell apart. analyze_component overlaps by design with the granular chain, but its description clearly frames it as a high-level aggregate, so misselection risk is low though not zero.

Naming Consistency5/5

All five tools follow a consistent snake_case verb_noun pattern (search_component, list_component_versions, get_version_vulnerabilities, get_upgrade_guidance, analyze_component). Verb choices (search/list/get/analyze) accurately signal the operation type.

Tool Count5/5

Five tools is well-scoped for a vulnerability-and-upgrade lookup workflow. Each tool maps to a clear step in the pipeline, with the composite tool as a convenience entry point rather than filler.

Completeness4/5

The search → versions → vulnerabilities → upgrade path is fully covered end-to-end, including a composite shortcut. However, Black Duck's domain also includes license/security risk metadata and project/BOM scanning, which are absent, leaving minor gaps an agent cannot work around.

Maintenance

ActivityInactive
ResponsivenessNo recent community issues