Repository navigation
feat(mcp): read-only investigation prompts (prompts/list + prompts/get) - #85
Merged
Merged
Conversation
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.
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.
What
nbox serveadvertises a small catalog of curated read-only investigation prompts via the MCPpromptscapability. An agent discovers them withprompts/listand expands one withprompts/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_historytool shipped in #84):ip_utilization_auditsite?,status?cable_path_tracedevice,interfacefind_stale_prefixessite?object_change_reviewkind,refprompts/getreturns a user-role message, e.g.cable_path_tracewithdevice=edge01, interface=xe-0/0/1returns a plan referencingnbox_get_interface "edge01/xe-0/0/1".Implementation
Mirrors the manual
list_resourcespath — the#[tool_handler]macro only emits tool methods, so hand-writtenlist_prompts/get_promptsit 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_promptdelegate toprompts.rs(1-line each, mirroringlist_resources);get_infoinstructions mention prompts.Verification
fmt,clippy --all-targets --all-features -- -D warnings,test --all-features(1125 pass, +8 unit),test --no-default-features(1030 pass) — all green.capabilities.promptsis advertised,prompts/listreturns the 4 names, andprompts/getsubstitutes args + referencesnbox_get_interface. The HTTP serve test assertscapabilities.prompts.prompts/list→['ip_utilization_audit', 'cable_path_trace', 'find_stale_prefixes', 'object_change_review'];prompts/get→ user message withedge01/xe-0/0/1substituted, referencingnbox_get_interface.Docs
docs/MCP.mdgains a Prompts section (table + behavior).AGENTS.mdMCP section adds the catalog + fixes the stale "MCP prompts are later" line.ROADMAP.mdprompts 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.