Skip to content

feat(mcp): read-only investigation prompts (prompts/list + prompts/get) - #85

Merged
lance0 merged 2 commits into
masterfrom
feat/mcp-prompts
Jun 25, 2026
Merged

lance0 merged 2 commits into
masterfrom
feat/mcp-prompts

Conversation

@lance0

@lance0 lance0 commented Jun 25, 2026

Copy link
Copy Markdown
Owner

What

nbox serve advertises a small catalog of curated read-only investigation prompts via the MCP prompts capability. An agent discovers them with prompts/list and expands one with prompts/get; each returns a single user-role message with a structured plan naming the exact nbox tools to call, tailored to the supplied arguments.

This is the agent-wedge differentiator (ROADMAP "MCP prompts catalog"): discoverability + curated expertise, with zero live dependency — a prompt is a plan, not data (no NetBox round-trip; the agent runs the plan against the tools). It sidesteps the perm-gated gap entirely.

The four prompts

All grounded in real nbox tool capabilities (incl. the nbox_history tool shipped in #84):

Prompt Args Investigates
ip_utilization_audit site?, status? Prefixes ≥85% (near-full) and <10% (stale), with per-prefix recommendations.
cable_path_trace device, interface An interface's A-side ↔ Z-side cable path, through patch panels.
find_stale_prefixes site? Reclaimable prefixes (no/few assigned IPs), cross-checked against recent change history.
object_change_review kind, ref An object's audit-log changes, grouped by request, with risk flags (deletes, ownership/scope moves).

prompts/get returns a user-role message, e.g. cable_path_trace with device=edge01, interface=xe-0/0/1 returns a plan referencing nbox_get_interface "edge01/xe-0/0/1".

Implementation

Mirrors the manual list_resources path — the #[tool_handler] macro only emits tool methods, so hand-written list_prompts/get_prompt sit alongside it without conflict:

  • src/mcp/prompts.rs (new): prompts() static catalog + render_prompt(request) — pure functions, the underlying logic. 8 unit tests pin the catalog, arg substitution, tool references, unknown-name error (lists available prompts), and optional-arg defaults.
  • src/mcp/mod.rs: .enable_prompts() capability; list_prompts/get_prompt delegate to prompts.rs (1-line each, mirroring list_resources); get_info instructions mention prompts.
  • No new tools — tools stay at 11; prompts are a separate capability.

Verification

  • Gate: fmt, clippy --all-targets --all-features -- -D warnings, test --all-features (1125 pass, +8 unit), test --no-default-features (1030 pass) — all green.
  • Wire-level: the stdio serve handshake test now also asserts capabilities.prompts is advertised, prompts/list returns the 4 names, and prompts/get substitutes args + references nbox_get_interface. The HTTP serve test asserts capabilities.prompts.
  • Live over stdio against the 4.6.2 box: prompts/list → ['ip_utilization_audit', 'cable_path_trace', 'find_stale_prefixes', 'object_change_review']; prompts/get → user message with edge01/xe-0/0/1 substituted, referencing nbox_get_interface.

Docs

  • docs/MCP.md gains a Prompts section (table + behavior).
  • AGENTS.md MCP section adds the catalog + fixes the stale "MCP prompts are later" line.
  • ROADMAP.md prompts item ☐ → ☑.
  • CHANGELOG.md [Unreleased] → ### Added.

Files

8 files, +550/−9. New: src/mcp/prompts.rs (+358 incl. tests).

This is a new capability — the second this session after nbox history (#84). It widens the MCP surface in a way the Python competitor doesn't offer: curated, discoverable investigation plans baked into the read-only server.

lance0 added 2 commits June 24, 2026 21:33
nbox serve advertises a small catalog of curated read-only investigation
prompts via the MCP prompts capability. An agent discovers them with
prompts/list and expands one with prompts/get; each returns a single
user-role message with a structured investigation plan naming the exact
nbox tools to call (incl. nbox_history), tailored to the supplied
arguments.

The four prompts (grounded in real nbox tool capabilities):
- ip_utilization_audit (site?, status?) — flag near-full (>=85%) and stale
  (<10%) prefixes with recommendations.
- cable_path_trace (device, interface) — A-side <-> Z-side cable path.
- find_stale_prefixes (site?) — reclaimable prefixes, cross-checked against
  recent change history.
- object_change_review (kind, ref) — audit-log changes grouped by request,
  with risk flags (deletes, ownership/scope moves).

Zero live dependency: a prompt is a plan, not data — no NetBox round-trip;
the agent runs the plan against the tools. This is the agent-wedge
differentiator (ROADMAP "MCP prompts catalog"): discoverability + curated
expertise, sidestepping the perm-gated gap entirely.

Implementation mirrors the manual list_resources path (the #[tool_handler]
macro only emits tool methods, so hand-written prompt methods sit alongside
without conflict):
- src/mcp/prompts.rs: prompts() static catalog + render_prompt(request) —
  pure functions, the underlying logic (8 unit tests pin the catalog, arg
  substitution, tool references, unknown-name error, optional-arg defaults).
- src/mcp/mod.rs: enable_prompts() capability; list_prompts/get_prompt
  delegate to prompts.rs (1-line each, mirroring list_resources); get_info
  instructions mention prompts.
- No new tools (tools stay at 11) — prompts are a separate capability.

Tests: 8 prompts unit tests + the stdio serve handshake test now also asserts
capabilities.prompts is advertised, prompts/list returns the 4 names, and
prompts/get substitutes args + references nbox_get_interface. The HTTP
serve test asserts capabilities.prompts.

Verified: gate green (1125 all-features / 1030 no-default, clippy -D
warnings, fmt). Live over stdio against the 4.6.2 box: prompts/list returns
the 4 prompts; prompts/get returns a user message with args substituted
(edge01/xe-0/0/1) referencing nbox_get_interface.

Docs: docs/MCP.md gains a Prompts section (table + behavior); AGENTS.md
MCP section adds the catalog + fixes the stale "MCP prompts are later"
line; ROADMAP item -> done; CHANGELOG [Unreleased] Added.
The prompt plans named response fields and call args that don't match what
the tools actually return, undercutting the "executable plan" promise:

- `cable_path_trace` told the agent to call `nbox_get_interface` with
  `kind`/`ref` (those are `nbox_get`'s args; the dedicated tool takes
  `device`/`interface`) and to read a `cable_path` field that doesn't exist.
  The interface view exposes `trace` (structured A↔Z hops) and `cable` (the
  attached-cable label); `diagram` is render-only (`#[serde(skip)]`). Fixed
  the call args and pointed the plan at `trace`.
- `ip_utilization_audit` / `find_stale_prefixes` leaned on a `utilization`
  field as the sole signal. NetBox 4.5+ no longer returns `utilization` from
  the prefix REST API (verified live against 4.6.2), and the single-object
  view doesn't recompute it — so the headline thresholds yielded nothing on
  current servers. Reworked both to use the assigned `ip_addresses` count and
  `child_prefixes` as the primary signal, with `utilization` as a best-effort
  cross-check when present.
- Replaced the CLI-ism "`--partial`-style tolerance" with the real MCP signal
  (the `errors` array `nbox_search` returns on partial failure).

Add `plan_field_references_exist_in_tool_output`: pins each prefix/interface
plan's cited fields to the real serialized fields of the view the tool returns
(`PrefixView`, `InterfaceView`) and asserts the cable plan names no non-field
(`cable_path`, `diagram`). Catches this class of drift if a view field is
renamed.

Also reflow the plan format strings so source wrapping only breaks at `\n`
boundaries — the previous bare `\` continuations ate the inter-word space and
glued words together ("structuredhops", "expansioncandidates") in the rendered
plan text.
@lance0
lance0 merged commit c0dfd7a into master Jun 25, 2026
4 checks passed
@lance0
lance0 deleted the feat/mcp-prompts branch June 25, 2026 13:14
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