@neat.is/mcp 0.9.2-dev.20260821 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +39 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/base-url.ts","../src/client.ts","../src/endpoint-check.ts","../src/resources.ts","../src/tools.ts","../src/format.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { McpServer, type ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'\nimport { z } from 'zod'\nimport {\n CheckPoliciesScopeSchema,\n DivergenceTypeSchema,\n HypotheticalActionSchema,\n type MCPToolName,\n} from '@neat.is/types'\nimport { resolveBaseUrlWithSource } from './base-url.js'\nimport { createHttpClient } from './client.js'\nimport { checkEndpointIsNeat, describeForeignEndpoint } from './endpoint-check.js'\nimport { registerResources } from './resources.js'\nimport {\n checkPolicies,\n expandNode,\n getBlastRadius,\n getDependencies,\n getDivergences,\n getGraphDiff,\n getIncidentHistory,\n getObservedDependencies,\n getRecentStaleEdges,\n getRootCause,\n neatApplyExtension,\n neatDescribeProjectInstrumentation,\n neatDryRunExtension,\n neatListUninstrumented,\n neatLookupInstrumentation,\n neatRollbackExtension,\n relate,\n semanticSearch,\n} from './tools.js'\n\nconst resolved = resolveBaseUrlWithSource()\nconst baseUrl = resolved.url\n// ADR-073 §3 — carry the operator's bearer to a secured core. Sourced from\n// NEAT_AUTH_TOKEN, the same env the daemon enforces against; empty/unset\n// keeps the header off so a loopback dev core stays reachable.\nconst authToken = process.env.NEAT_AUTH_TOKEN\nconst bearerToken = authToken && authToken.length > 0 ? authToken : undefined\nconst client = createHttpClient(baseUrl, bearerToken)\n\n// `NEAT_DEFAULT_PROJECT` is the implicit project for tool calls that don't\n// pass a `project` arg. Unset means \"use the core's `default` project\" — we\n// route those calls through the legacy unprefixed URL so an older core (one\n// that predates #83) still gets the request it expects.\nconst defaultProject = process.env.NEAT_DEFAULT_PROJECT\nconst projectFor = (input: { project?: string }): string | undefined =>\n input.project ?? defaultProject\n\nconst projectField = z\n .string()\n .optional()\n .describe(\n 'Project name when the core hosts more than one (set NEAT_PROJECTS=...). Omit to use the default project.',\n )\n\n// Server-level orientation the MCP `initialize` handshake hands the connecting\n// agent, so it knows what NEAT's data *is* before it reads a tool result. NEAT\n// is one server among however many the agent has wired up — some of them\n// (Supabase, Cloudflare, ...) may be the very platforms NEAT's connectors pull\n// from. The line to draw: NEAT's tools answer from its own fused graph, not a\n// live connection to those platforms, and every answer carries provenance so\n// the agent can weigh it. The agent's other servers, and their overlap with\n// NEAT's view, are the agent's own to reconcile — NEAT can't see its peers and\n// doesn't try to; it just says plainly what its own data is.\nconst serverInstructions = [\n 'NEAT serves a fused semantic graph of one software system — static code (EXTRACTED) and live runtime behavior (OBSERVED) in a single model — for the one project this daemon owns. Every tool answers from that graph.',\n 'A result is a graph fact, not a live call to the underlying system. Each edge and result carries a provenance — OBSERVED (seen via OTel), INFERRED (stitched, ~0.6 confidence), EXTRACTED (from source/config), STALE (was observed, gone quiet) — plus a confidence. Trust a claim by its provenance.',\n 'Some OBSERVED data is pulled by connectors from a provider that runs its own telemetry (Supabase, Railway, Firebase, Cloudflare). That is NEAT\\'s own view of the provider, keyed on the provider node (an InfraNode carries `provider`; a service/file carries `platform`). If you also have that provider\\'s own MCP server, NEAT is not it and does not replace it — NEAT tells you how the graph relates, the provider server acts on the live system.',\n 'Reach for NEAT before grepping source for architecture-level questions: dependencies, runtime traffic, recent failures, blast radius, divergence between declared and observed. If a query comes back empty, confirm the daemon is up before falling back to reading files.',\n].join('\\n\\n')\n\nconst server = new McpServer(\n {\n name: 'neat',\n version: '0.1.0',\n },\n { instructions: serverInstructions },\n)\n\n// Register every MCP tool through this wrapper, not server.tool directly.\n// The tool name is constrained to MCP_TOOL_NAMES in @neat.is/types — add the\n// name there first or this won't compile. The contracts audit also checks\n// that registrations and the manifest match both ways, so the tool surface\n// can't drift from the contract again.\nconst registerTool = <Args extends z.ZodRawShape>(\n name: MCPToolName,\n description: string,\n paramsSchema: Args,\n cb: ToolCallback<Args>,\n): ReturnType<typeof server.tool> => server.tool(name, description, paramsSchema, cb)\n\nregisterTool(\n 'get_root_cause',\n 'Trace a failing node up its dependency graph to find the underlying cause. Use this when something is breaking and you want to know which upstream component is the actual culprit.',\n {\n errorNode: z\n .string()\n .describe('Graph node id where the error surfaced, e.g. \"database:payments-db\"'),\n errorId: z\n .string()\n .optional()\n .describe('Specific error event id from incident history; if set, the result is coloured with that error message'),\n project: projectField,\n },\n async (input) => getRootCause(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'get_blast_radius',\n 'List every node that depends on the given node — what would break if this node failed or was redeployed.',\n {\n nodeId: z.string().describe('Graph node id to compute blast radius from'),\n depth: z\n .number()\n .int()\n .nonnegative()\n .max(20)\n .optional()\n .describe('Max BFS depth (default 10)'),\n project: projectField,\n },\n async (input) => getBlastRadius(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'get_dependencies',\n 'List the transitive outgoing dependencies of a node, BFS to depth N (default 3, max 10). Each result carries distance, edge type, and provenance — both static (EXTRACTED) and runtime (OBSERVED). Pass depth=1 for direct-only.',\n {\n nodeId: z.string().describe('Graph node id to inspect'),\n depth: z\n .number()\n .int()\n .min(1)\n .max(10)\n .optional()\n .describe('BFS depth (default 3, max 10). depth=1 returns direct dependencies only.'),\n project: projectField,\n },\n async (input) => getDependencies(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'get_observed_dependencies',\n 'List only the runtime (OBSERVED via OTel) outgoing dependencies of a node. Use this to compare what code SAYS the service depends on vs what production actually does.',\n {\n nodeId: z.string().describe('Graph node id to inspect'),\n project: projectField,\n },\n async (input) => getObservedDependencies(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'expand',\n 'Take one navigation step from a node and classify the neighbourhood (ADR-189). direction \"up\" walks to callers/dependents (who calls this), \"down\" walks to callees/dependencies (what this calls). Each neighbour comes back classified primary-failure / symptom-only / unrelated. Use this to navigate a failure one hop at a time instead of trusting a single verdict — a symptom-only node is a downstream victim, so walk \"up\" from it toward the real cause.',\n {\n nodeId: z.string().describe('Graph node id to step from'),\n direction: z\n .enum(['up', 'down'])\n .describe('up = callers/dependents (toward the cause), down = callees/dependencies'),\n project: projectField,\n },\n async (input) => expandNode(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'relate',\n 'Confirm whether two nodes are connected, which way, and whether the connecting path carries the failure (ADR-189). Returns the direction (a→b or b→a), the path with per-hop provenance, and carriesSignal — whether errors/latency run end to end, which turns \"a path exists\" into \"a is actually causing b\". No path within the depth bound returns \"no path within N hops\", never a false \"unrelated\".',\n {\n a: z.string().describe('First node id (the hypothesised cause)'),\n b: z.string().describe('Second node id (the hypothesised symptom)'),\n maxDepth: z\n .number()\n .int()\n .min(1)\n .max(10)\n .optional()\n .describe('Max path length to search (default 5)'),\n project: projectField,\n },\n async (input) => relate(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'get_incident_history',\n 'Return recent OTel error events recorded against a node, most recent first.',\n {\n nodeId: z.string().describe('Graph node id to query'),\n limit: z.number().int().positive().max(100).optional().describe('Max events to return (default 20)'),\n project: projectField,\n },\n async (input) => getIncidentHistory(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'semantic_search',\n 'Search nodes by natural-language query. Uses embedding vectors when an embedder is available (Ollama nomic-embed-text → in-process MiniLM → substring fallback) — phrase the query the way you would describe what you want.',\n {\n query: z.string().describe('Free-text query, e.g. \"service handling checkout payments\"'),\n project: projectField,\n },\n async (input) => semanticSearch(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'get_graph_diff',\n 'Diff a saved graph snapshot against the current live graph. Useful for change reviews and post-incidents — answers \"what changed in the architecture between then and now.\" Returns added/removed/changed nodes and edges with both snapshot timestamps.',\n {\n againstSnapshot: z\n .string()\n .describe(\n 'Path or http(s) URL of the snapshot to diff against (the \"before\" state). The current graph is the \"after\".',\n ),\n project: projectField,\n },\n async (input) => getGraphDiff(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'get_recent_stale_edges',\n 'List the most recent OBSERVED → STALE edge transitions. Use this to spot integrations that have gone quiet — a CALLS edge that just went stale typically means an upstream stopped calling, not that the link is healthy.',\n {\n limit: z\n .number()\n .int()\n .positive()\n .max(200)\n .optional()\n .describe('Max events to return (default 50)'),\n edgeType: z\n .string()\n .optional()\n .describe('Filter by edge type — e.g. \"CALLS\" or \"CONNECTS_TO\"'),\n project: projectField,\n },\n async (input) => getRecentStaleEdges(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'get_divergences',\n \"Returns places where what the code declares (EXTRACTED) doesn't match what production observed (OBSERVED). The single most NEAT-shaped query — the one that justifies the whole graph. Use when the user asks 'is anything weird?' or 'what does production do that the code doesn't?' or 'find me a bug' on an unfamiliar codebase. Returns divergences ranked by confidence × severity. Prefer this over `get_root_cause` when no specific node is failing.\",\n {\n type: z\n .array(DivergenceTypeSchema)\n .optional()\n .describe(\n 'Filter by divergence type. One or more of: missing-observed, missing-extracted, version-mismatch, host-mismatch, compat-violation. Omit for all.',\n ),\n minConfidence: z\n .number()\n .min(0)\n .max(1)\n .optional()\n .describe('Drop divergences below this confidence threshold (0.0 - 1.0).'),\n node: z\n .string()\n .optional()\n .describe('Scope to divergences involving this node id (as source or target).'),\n project: projectField,\n },\n async (input) =>\n getDivergences(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'check_policies',\n 'Inspect, dry-run, or get the soft guardrail for the project\\'s policy.json. With applicableTo, returns the policies that apply where you are working — surfaced as context so you stay inside the lines (informs, never blocks). Without hypotheticalAction or applicableTo, returns currently-recorded violations. With hypotheticalAction, returns violations that would result if the action were applied. Architectural assertions in five shapes (structural / compatibility / provenance / ownership / blast-radius).',\n {\n scope: CheckPoliciesScopeSchema.optional().describe(\n 'Narrow to a subset. Default \"all\".',\n ),\n hypotheticalAction: HypotheticalActionSchema.optional().describe(\n 'Dry-run mode: simulate the action and return resulting violations. Omit for current state.',\n ),\n applicableTo: z\n .string()\n .optional()\n .describe(\n 'Soft guardrail (ADR-108): pass the node id you are about to edit and check_policies returns the policies that govern it, as a context block — so you stay inside the lines. Advisory only; never blocks.',\n ),\n project: projectField,\n },\n async (input) =>\n checkPolicies(client, {\n ...input,\n project: projectFor(input),\n } as Parameters<typeof checkPolicies>[1]),\n)\n\n// ── /neat extend tools (ADR-081, ADR-086) ────────────────────────────────\n\nregisterTool(\n 'neat_list_uninstrumented',\n 'List libraries in the project that need instrumentation beyond the auto-instrumentations bundle. Returns first-party, third-party, and gap libraries that require an explicit instrumentation package.',\n { project: projectField },\n async (input) => neatListUninstrumented(client, { project: projectFor(input) }),\n)\n\nregisterTool(\n 'neat_lookup_instrumentation',\n 'Look up the registry entry for a specific library. Returns the canonical instrumentation package, version, and registration snippet if one exists.',\n {\n library: z.string().describe('npm package name, e.g. \"@prisma/client\"'),\n installedVersion: z.string().optional().describe('Installed version for range matching'),\n project: projectField,\n },\n async (input) => neatLookupInstrumentation(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'neat_describe_project_instrumentation',\n 'Describe the current state of OTel instrumentation in the project: which hook files exist, whether .env.neat is present, which OTel deps are installed.',\n { project: projectField },\n async (input) => neatDescribeProjectInstrumentation(client, { project: projectFor(input) }),\n)\n\nregisterTool(\n 'neat_apply_extension',\n 'Install an instrumentation package and splice its registration into the existing OTel hook file. Idempotent — calling twice with the same args is a no-op. Only modifies instrumentation files, package.json, and the lockfile (via the project package manager).',\n {\n library: z.string().describe('The library being instrumented, e.g. \"@prisma/client\"'),\n instrumentation_package: z.string().describe('The instrumentation npm package, e.g. \"@prisma/instrumentation\"'),\n version: z.string().describe('Semver range for the instrumentation package, e.g. \"^6.0.0\"'),\n registration_snippet: z.string().describe('The JS/TS snippet to splice into the instrumentations array, e.g. \"instrumentations.push(new PrismaInstrumentation())\"'),\n project: projectField,\n },\n async (input) => neatApplyExtension(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'neat_dry_run_extension',\n 'Preview what neat_apply_extension would do without making any changes. Returns the exact file diff, deps to add, and install command.',\n {\n library: z.string().describe('The library being instrumented, e.g. \"@prisma/client\"'),\n instrumentation_package: z.string().describe('The instrumentation npm package, e.g. \"@prisma/instrumentation\"'),\n version: z.string().describe('Semver range for the instrumentation package, e.g. \"^6.0.0\"'),\n registration_snippet: z.string().describe('The JS/TS snippet to splice into the instrumentations array'),\n project: projectField,\n },\n async (input) => neatDryRunExtension(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'neat_rollback_extension',\n 'Undo the last neat_apply_extension for a given library. Removes the dep from package.json and the registration from the hook file. Does not re-run the package manager — run install manually to sync the lockfile.',\n {\n library: z.string().describe('The library whose instrumentation should be rolled back'),\n project: projectField,\n },\n async (input) => neatRollbackExtension(client, { ...input, project: projectFor(input) }),\n)\n\n// Resources sit alongside tools — same data, different access pattern. Read\n// the per-node resource for raw attrs+edges JSON; subscribe to the incidents\n// resource to be notified when new errors land. The tools above are unchanged.\nconst incidentsPollMs = process.env.NEAT_RESOURCE_POLL_MS\n ? Number(process.env.NEAT_RESOURCE_POLL_MS)\n : undefined\nconst resourceRegistration = registerResources(server, client, {\n ...(incidentsPollMs !== undefined ? { incidentsPollMs } : {}),\n ...(defaultProject ? { project: defaultProject } : {}),\n})\n\n// Before the MCP handshake, confirm the resolved endpoint is actually NEAT.\n// Resolution falls back to :8080 when it can't find a project daemon, and if\n// another service holds that port the server would otherwise query it and hand\n// the agent an opaque HTML/404 on every tool call (#1069). A single /health\n// probe separates NEAT (proceed) from a confirmed-foreign service (fail fast\n// with a clear fix) from merely-unreachable (proceed — a daemon may still be\n// booting, or be gated behind auth this server lacks the token for; the per-\n// request path reports that cleanly). NEAT_SKIP_ENDPOINT_CHECK=1 opts out.\nasync function guardEndpoint(): Promise<void> {\n const skip = process.env.NEAT_SKIP_ENDPOINT_CHECK\n if (skip === '1' || skip === 'true') return\n\n const check = await checkEndpointIsNeat(baseUrl, { bearerToken })\n if (check.kind === 'foreign') {\n console.error(describeForeignEndpoint(baseUrl, resolved.source, check))\n process.exit(1)\n }\n}\n\nasync function main(): Promise<void> {\n await guardEndpoint()\n const transport = new StdioServerTransport()\n await server.connect(transport)\n}\n\nconst stopPolling = (): void => {\n resourceRegistration.stop()\n}\nprocess.on('SIGTERM', stopPolling)\nprocess.on('SIGINT', stopPolling)\n\nmain().catch((err) => {\n console.error(err)\n process.exit(1)\n})\n","// Resolve the daemon URL the MCP server talks to.\n//\n// Under the per-project daemon model (ADR-096 / docs/contracts/project-daemon.md)\n// each project runs its own daemon on its own ports and records them in\n// `<projectRoot>/neat-out/daemon.json`. The MCP server points at the daemon for\n// the project it was launched in, so resolution walks up from the cwd to the\n// nearest `neat-out/daemon.json` and uses its REST port. An explicit\n// `NEAT_CORE_URL` / `NEAT_API_URL` still wins — that's how the hosted/prod\n// substrate pins the MCP server at a fixed daemon — and the canonical loopback\n// default catches the case where neither the env nor a daemon record is present.\n//\n// `NEAT_API_URL` is honored as an accepted alias so configs written by older\n// `neat skill` versions — which emitted `NEAT_API_URL` — still reach the daemon\n// (#488). `NEAT_CORE_URL` wins when both are set.\n//\n// Lives in its own module so the resolution is testable without importing\n// index.ts, which starts the stdio transport on load.\nimport { readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\n\nconst DEFAULT_BASE_URL = 'http://localhost:8080'\n\n// The slice of `neat-out/daemon.json` the MCP server depends on. The full record\n// (pid, projectPath, otlp/web ports, …) is owned by the daemon writer; the MCP\n// server only needs the REST port and the liveness status. We read the file as\n// plain JSON rather than importing the writer's type so this stays decoupled\n// from the daemon package that owns the schema.\ninterface DaemonRecordShape {\n status?: unknown\n ports?: { rest?: unknown }\n}\n\n// Read the REST base URL out of a project's `neat-out/daemon.json`, walking up\n// from `cwd` to the filesystem root to find the nearest one. Returns undefined\n// for every failure mode — no file, unreadable, malformed JSON, a stopped\n// daemon, or a missing/invalid REST port — so the caller falls through to the\n// next precedence level rather than the MCP server failing to start.\nfunction resolveFromDaemonRecord(cwd: string): string | undefined {\n let dir = cwd\n // Walk parents until the path stops changing (the filesystem root, where\n // dirname() is a fixed point).\n for (;;) {\n const url = readDaemonRecord(join(dir, 'neat-out', 'daemon.json'))\n if (url !== undefined) return url\n\n const parent = dirname(dir)\n if (parent === dir) return undefined\n dir = parent\n }\n}\n\nfunction readDaemonRecord(path: string): string | undefined {\n let raw: string\n try {\n raw = readFileSync(path, 'utf8')\n } catch {\n // No daemon.json here (the common case while walking up). Keep looking.\n return undefined\n }\n\n let record: DaemonRecordShape\n try {\n record = JSON.parse(raw) as DaemonRecordShape\n } catch {\n // A daemon.json that exists but is garbage: a daemon caught mid-write, a\n // truncated file. Treat it as absent rather than crashing the MCP server.\n return undefined\n }\n\n if (record == null || typeof record !== 'object') return undefined\n // A daemon that has marked itself stopped no longer answers on its ports.\n if (record.status === 'stopped') return undefined\n\n const rest = record.ports?.rest\n if (typeof rest !== 'number' || !Number.isInteger(rest) || rest <= 0 || rest > 65535) {\n return undefined\n }\n\n return `http://localhost:${rest}`\n}\n\n// How `resolveBaseUrl` arrived at its URL. The startup endpoint check\n// (index.ts / endpoint-check.ts) reads this to word a precise error when the\n// resolved URL turns out to be a foreign service: the :8080 fallback landing on\n// someone else's server reads very differently from an explicit NEAT_CORE_URL\n// pointing at the wrong place, and the fix differs too.\nexport type BaseUrlSource = 'env' | 'daemon-record' | 'default'\n\nexport interface ResolvedBaseUrl {\n url: string\n source: BaseUrlSource\n}\n\n// Same precedence and the same never-throws guarantee as `resolveBaseUrl`, but\n// it also reports which precedence level won so the caller can explain itself.\nexport function resolveBaseUrlWithSource(\n env: NodeJS.ProcessEnv = process.env,\n cwd: string = process.cwd(),\n): ResolvedBaseUrl {\n const override = env.NEAT_CORE_URL ?? env.NEAT_API_URL\n if (override) return { url: override, source: 'env' }\n\n const fromRecord = resolveFromDaemonRecord(cwd)\n if (fromRecord !== undefined) return { url: fromRecord, source: 'daemon-record' }\n\n return { url: DEFAULT_BASE_URL, source: 'default' }\n}\n\nexport function resolveBaseUrl(\n env: NodeJS.ProcessEnv = process.env,\n cwd: string = process.cwd(),\n): string {\n return resolveBaseUrlWithSource(env, cwd).url\n}\n","// Thin HTTP client for the neat-core REST surface. Tools call out via this\n// instead of fetch() directly so tests can swap in a stub implementation\n// without monkey-patching globals.\n\nexport interface HttpClient {\n get<T>(path: string): Promise<T>\n // POST is optional on the interface so test stubs that only need GET don't\n // have to implement it. Production createHttpClient always provides it.\n post?<T>(path: string, body: unknown): Promise<T>\n}\n\n// A daemon that has bound its port but isn't answering yet — mid-boot, wedged\n// mid-extraction, deadlocked, or sitting behind a proxy that black-holes the\n// request — accepts the TCP connection and then never writes a response. With\n// no deadline on the fetch, undici only gives up at its 5-minute headers\n// timeout, which to an interactive agent is indistinguishable from a hang. The\n// MCP surface must stay queryable \"at all times\": a slow or wedged daemon has\n// to surface as a clean, bounded error the agent can act on, never an open-\n// ended wait. So every request carries a deadline; when it trips we translate\n// the abort into a plain-language error the tool layer formats as isError.\nconst DEFAULT_TIMEOUT_MS = 30_000\n\nfunction resolveTimeoutMs(explicit?: number): number {\n if (typeof explicit === 'number' && explicit > 0) return explicit\n const fromEnv = Number(process.env.NEAT_CORE_TIMEOUT_MS)\n if (Number.isFinite(fromEnv) && fromEnv > 0) return fromEnv\n return DEFAULT_TIMEOUT_MS\n}\n\n// AbortSignal.timeout rejects the fetch with a DOMException named\n// 'TimeoutError'; a caller-triggered abort surfaces as 'AbortError'. Match on\n// the name rather than the type so this holds across Node's DOMException /\n// Error representations.\nfunction isTimeoutAbort(err: unknown): boolean {\n const name = (err as { name?: string } | null)?.name\n return name === 'TimeoutError' || name === 'AbortError'\n}\n\nasync function fetchWithTimeout(\n url: string,\n init: RequestInit,\n timeoutMs: number,\n method: string,\n path: string,\n): Promise<Response> {\n try {\n return await fetch(url, { ...init, signal: AbortSignal.timeout(timeoutMs) })\n } catch (err) {\n if (isTimeoutAbort(err)) {\n throw new RequestTimeoutError(\n `Timed out after ${timeoutMs}ms waiting for neat-core on ${method} ${path} — ` +\n `the daemon may be starting up, busy, or wedged. Confirm it is reachable ` +\n `(curl its /health endpoint) or raise NEAT_CORE_TIMEOUT_MS.`,\n )\n }\n throw err\n }\n}\n\n// ADR-073 §3 — the MCP server is a first-party read client, so it carries the\n// operator's bearer on every call the same way the CLI does. `bearerToken`\n// comes from `NEAT_AUTH_TOKEN` (sourced once in index.ts). Empty / undefined\n// keeps the header off, so an unauthenticated loopback dev daemon still works.\n// `timeoutMs` bounds every request; it defaults to NEAT_CORE_TIMEOUT_MS or 30s\n// and is overridable for tests.\nexport function createHttpClient(\n baseUrl: string,\n bearerToken?: string,\n timeoutMs?: number,\n): HttpClient {\n const root = baseUrl.replace(/\\/$/, '')\n const deadline = resolveTimeoutMs(timeoutMs)\n const authHeader: Record<string, string> =\n bearerToken && bearerToken.length > 0\n ? { authorization: `Bearer ${bearerToken}` }\n : {}\n return {\n async get<T>(path: string): Promise<T> {\n const res = await fetchWithTimeout(\n `${root}${path}`,\n { headers: { ...authHeader } },\n deadline,\n 'GET',\n path,\n )\n if (!res.ok) {\n const body = await res.text().catch(() => '')\n throw httpErrorFor(res.status, res.statusText, 'GET', path, body)\n }\n return (await res.json()) as T\n },\n async post<T>(path: string, body: unknown): Promise<T> {\n const res = await fetchWithTimeout(\n `${root}${path}`,\n {\n method: 'POST',\n headers: { 'content-type': 'application/json', ...authHeader },\n body: JSON.stringify(body),\n },\n deadline,\n 'POST',\n path,\n )\n if (!res.ok) {\n const text = await res.text().catch(() => '')\n throw httpErrorFor(res.status, res.statusText, 'POST', path, text)\n }\n return (await res.json()) as T\n },\n }\n}\n\nexport class HttpError extends Error {\n constructor(\n public readonly status: number,\n message: string,\n ) {\n super(message)\n this.name = 'HttpError'\n }\n}\n\n// A 404 whose body is the core's `{\"error\":\"project not found\"}` — the daemon\n// this MCP server is pointed at does not host that project (#884). This is a\n// different failure from a node-not-found 404: the tool layer must NOT swallow\n// it into an empty \"no results\" answer (which reads as a confident, wrong answer\n// about a codebase the core isn't even serving). It carries the project name so\n// the message can name it.\nexport class ProjectNotFoundError extends HttpError {\n constructor(public readonly project: string, where: string) {\n super(\n 404,\n `neat-core does not serve project \"${project}\" (on ${where}). This MCP server is pointed at a daemon for a different codebase — it cannot answer about \"${project}\". Point it at that project's daemon (set NEAT_CORE_URL, or run the agent from the project directory so it discovers the local daemon), then retry.`,\n )\n this.name = 'ProjectNotFoundError'\n }\n}\n\n// Distinguish a project-not-found 404 (the core doesn't host the project) from\n// any other error, so the client throws the right type once, centrally.\nfunction httpErrorFor(\n status: number,\n statusText: string,\n method: 'GET' | 'POST',\n path: string,\n body: string,\n): HttpError {\n if (status === 404) {\n try {\n const parsed = JSON.parse(body) as { error?: unknown; project?: unknown }\n if (parsed && parsed.error === 'project not found' && typeof parsed.project === 'string') {\n return new ProjectNotFoundError(parsed.project, `${method} ${path}`)\n }\n } catch {\n // Not JSON / not the project-not-found shape — fall through to a plain HttpError.\n }\n }\n return new HttpError(status, `${status} ${statusText} on ${method} ${path}: ${body}`)\n}\n\n// Thrown when a request exceeds its deadline. Not an HttpError — there was no\n// HTTP response — so the tool layer's 404 fallback doesn't swallow it; it lands\n// in the generic branch and surfaces as a formatted isError the agent can read.\nexport class RequestTimeoutError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'RequestTimeoutError'\n }\n}\n","// Startup guard: confirm the resolved daemon URL actually speaks NEAT before the\n// MCP server commits to it.\n//\n// `resolveBaseUrl` (base-url.ts) honors NEAT_CORE_URL/NEAT_API_URL, else walks up\n// to a project's `neat-out/daemon.json`, else falls back to the canonical\n// `http://localhost:8080`. That last fallback is a foot-gun: launched outside any\n// NEAT project, on a machine where some *other* service happens to own :8080 (an\n// otel-demo frontend, a stray dev server), resolution silently lands on a foreign\n// server. Every tool call then comes back as an opaque HTML/404 the agent can't\n// read — it looks like NEAT is broken when in fact the server never reached NEAT.\n//\n// So once, at boot, we probe the resolved URL's `/health`. NEAT's `/health` is a\n// stable identity signal: every daemon answers `{ ok: true, uptimeMs: <n>, ... }`\n// JSON (docs/contracts/rest-api.md, issue #343), it is mounted ahead of any\n// project route so a real daemon never 404s it, and it is cheap.\n\nimport type { BaseUrlSource } from './base-url.js'\n\n// A short, self-contained deadline for the boot probe — independent of the\n// per-tool NEAT_CORE_TIMEOUT_MS. If a daemon is too slow to answer /health in\n// this window we treat the endpoint as merely unreachable (not foreign) and let\n// the server start; the per-request path reports a clean, bounded error later.\nconst PROBE_TIMEOUT_MS = 2500\n\nexport type EndpointCheck =\n | { kind: 'neat' }\n | { kind: 'unreachable'; detail: string }\n | { kind: 'foreign'; status: number; contentType: string }\n\nexport interface CheckOptions {\n bearerToken?: string\n timeoutMs?: number\n // Injectable for tests; defaults to the global fetch.\n fetchImpl?: typeof fetch\n}\n\n// Probe the resolved endpoint's /health once and classify it. Never throws —\n// a boot check that itself blew up would be worse than the papercut it guards.\nexport async function checkEndpointIsNeat(\n baseUrl: string,\n opts: CheckOptions = {},\n): Promise<EndpointCheck> {\n const root = baseUrl.replace(/\\/$/, '')\n const doFetch = opts.fetchImpl ?? fetch\n const headers: Record<string, string> =\n opts.bearerToken && opts.bearerToken.length > 0\n ? { authorization: `Bearer ${opts.bearerToken}` }\n : {}\n\n let res: Response\n try {\n res = await doFetch(`${root}/health`, {\n headers,\n signal: AbortSignal.timeout(opts.timeoutMs ?? PROBE_TIMEOUT_MS),\n })\n } catch (err) {\n // Connection refused, DNS failure, or our own timeout — no HTTP response at\n // all. A daemon that isn't up yet lives here; never call this \"not NEAT\".\n return { kind: 'unreachable', detail: errMessage(err) }\n }\n\n // 401/403 means *something* is enforcing auth on this port — far more likely a\n // real NEAT daemon this server holds the wrong (or no) token for than a foreign\n // service. 5xx is an ambiguous gateway/boot hiccup. Neither is a foreign\n // signal, so don't fail startup on them.\n if (res.status === 401 || res.status === 403 || res.status >= 500) {\n return { kind: 'unreachable', detail: `HTTP ${res.status}` }\n }\n\n const contentType = res.headers.get('content-type') ?? 'unknown'\n const body = await res.text().catch(() => '')\n if (isNeatHealth(body)) return { kind: 'neat' }\n return { kind: 'foreign', status: res.status, contentType }\n}\n\n// NEAT's /health — daemon-wide and per-project alike — always answers\n// `{ ok: true, uptimeMs: <number>, ... }`. That pair is the signature: present on\n// every real daemon, absent from an arbitrary foreign body (HTML, or some other\n// service's JSON).\nfunction isNeatHealth(body: string): boolean {\n let parsed: unknown\n try {\n parsed = JSON.parse(body)\n } catch {\n return false\n }\n if (parsed === null || typeof parsed !== 'object') return false\n const rec = parsed as Record<string, unknown>\n return rec.ok === true && typeof rec.uptimeMs === 'number'\n}\n\nfunction errMessage(err: unknown): string {\n return err instanceof Error ? err.message : String(err)\n}\n\n// The actionable message the server prints (and exits on) when the resolved\n// endpoint answered but is not NEAT. Worded per resolution source so the fix is\n// specific — the :8080 fallback hitting a foreign server is the common case.\nexport function describeForeignEndpoint(\n url: string,\n source: BaseUrlSource,\n check: { status: number; contentType: string },\n): string {\n const how: Record<BaseUrlSource, string> = {\n env: 'from NEAT_CORE_URL / NEAT_API_URL',\n 'daemon-record':\n 'from a neat-out/daemon.json record found while walking up from the working directory',\n default:\n 'from the default http://localhost:8080 — no NEAT_CORE_URL was set and no neat-out/daemon.json was found walking up from the working directory',\n }\n const fix: Record<BaseUrlSource, string> = {\n env: 'Check that NEAT_CORE_URL points at a running NEAT daemon.',\n 'daemon-record':\n 'The REST port recorded in that daemon.json is now answered by something else — the record is stale. Restart the project daemon, or set NEAT_CORE_URL to its address.',\n default:\n \"Another service — not NEAT — is answering on :8080. Run the MCP server from inside a NEAT project so it can discover neat-out/daemon.json, or set NEAT_CORE_URL to your daemon's address.\",\n }\n return [\n `NEAT MCP server: resolved the daemon at ${url} (${how[source]}), but it does not look like NEAT — ` +\n `a probe of ${url}/health returned HTTP ${check.status} (${check.contentType}), not NEAT's health JSON.`,\n fix[source],\n 'If this really is your NEAT daemon (for example behind a proxy that rewrites /health), set NEAT_SKIP_ENDPOINT_CHECK=1 to bypass this check.',\n ].join('\\n\\n')\n}\n","// MCP Resources — additive surface alongside the eight tools. Two resources:\n//\n// neat://node/<id> — one resource per graph node. Read returns the\n// node attributes plus its outbound edges.\n// neat://incidents/recent — most recent error events. Pollable by the SDK\n// via subscribe; we send `notifications/resources/\n// updated` when /incidents grows.\n//\n// Pure read helpers are exported so tests can exercise them without spinning up\n// an MCP transport. `registerResources()` does the SDK wiring + the poll loop.\n\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport {\n ResourceTemplate,\n} from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type {\n ListResourcesResult,\n ReadResourceResult,\n} from '@modelcontextprotocol/sdk/types.js'\nimport type { ErrorEvent, GraphEdge, GraphNode, PolicyViolation } from '@neat.is/types'\nimport { HttpError, type HttpClient } from './client.js'\n\ninterface EdgesResponse {\n inbound: GraphEdge[]\n outbound: GraphEdge[]\n}\n\ninterface SerializedGraph {\n nodes: GraphNode[]\n edges: GraphEdge[]\n}\n\nconst NODE_RESOURCE_MIME = 'application/json'\nconst INCIDENTS_URI = 'neat://incidents/recent'\nconst INCIDENTS_DEFAULT_LIMIT = 50\nconst POLICY_VIOLATIONS_URI = 'neat://policies/violations'\nconst POLICY_VIOLATIONS_DEFAULT_LIMIT = 100\n\nfunction nodeUri(id: string): string {\n // Node ids contain `:` which RFC 6570 percent-encodes; doing it explicitly\n // here keeps the URI we hand the SDK identical to what `list` produces.\n return `neat://node/${encodeURIComponent(id)}`\n}\n\n// Project-aware URL prefix for the underlying core. When unset, hit the\n// legacy unprefixed routes (which the core resolves to project=`default`).\nfunction corePrefix(project: string | undefined): string {\n return project ? `/projects/${encodeURIComponent(project)}` : ''\n}\n\nfunction nameFromAttrs(attrs: GraphNode): string {\n return (attrs as { name?: string }).name ?? attrs.id\n}\n\nexport async function listNodeResources(\n client: HttpClient,\n project?: string,\n): Promise<ListResourcesResult> {\n const graph = await client.get<SerializedGraph>(`${corePrefix(project)}/graph`)\n return {\n resources: graph.nodes.map((n) => ({\n uri: nodeUri(n.id),\n name: nameFromAttrs(n),\n description: `${n.type} — ${nameFromAttrs(n)}`,\n mimeType: NODE_RESOURCE_MIME,\n })),\n }\n}\n\nexport async function readNodeResource(\n client: HttpClient,\n id: string,\n project?: string,\n): Promise<ReadResourceResult> {\n const uri = nodeUri(id)\n const prefix = corePrefix(project)\n try {\n const [nodeBody, edges] = await Promise.all([\n client.get<{ node: GraphNode }>(`${prefix}/graph/node/${encodeURIComponent(id)}`),\n client.get<EdgesResponse>(`${prefix}/graph/edges/${encodeURIComponent(id)}`),\n ])\n const body = {\n node: nodeBody.node,\n // Outbound only — the issue spec says \"attrs + outbound edges\". Inbound\n // edges are still reachable via the other endpoint and would double the\n // payload for hub nodes (e.g. a shared database).\n outboundEdges: edges.outbound,\n }\n return {\n contents: [\n {\n uri,\n mimeType: NODE_RESOURCE_MIME,\n text: JSON.stringify(body, null, 2),\n },\n ],\n }\n } catch (err) {\n if (err instanceof HttpError && err.status === 404) {\n return {\n contents: [\n {\n uri,\n mimeType: NODE_RESOURCE_MIME,\n text: JSON.stringify({ error: 'node not found', id }),\n },\n ],\n }\n }\n throw err\n }\n}\n\nexport async function readPolicyViolationsResource(\n client: HttpClient,\n limit: number = POLICY_VIOLATIONS_DEFAULT_LIMIT,\n project?: string,\n): Promise<ReadResourceResult> {\n const body = await client.get<{ violations: PolicyViolation[] }>(\n `${corePrefix(project)}/policies/violations`,\n )\n const violations = body.violations\n // Latest first; cap at limit so an exploding violations log doesn't blow\n // up the resource read. The full file is still on disk for forensic use.\n const ordered = [...violations].reverse().slice(0, limit)\n return {\n contents: [\n {\n uri: POLICY_VIOLATIONS_URI,\n mimeType: NODE_RESOURCE_MIME,\n text: JSON.stringify(\n { count: ordered.length, total: violations.length, violations: ordered },\n null,\n 2,\n ),\n },\n ],\n }\n}\n\nexport async function readRecentIncidentsResource(\n client: HttpClient,\n limit: number = INCIDENTS_DEFAULT_LIMIT,\n project?: string,\n): Promise<ReadResourceResult> {\n const body = await client.get<{ count: number; total: number; events: ErrorEvent[] }>(\n `${corePrefix(project)}/incidents`,\n )\n const events = body.events\n // ndjson order is append-time = oldest first. Reverse so most-recent leads.\n const ordered = [...events].reverse().slice(0, limit)\n return {\n contents: [\n {\n uri: INCIDENTS_URI,\n mimeType: NODE_RESOURCE_MIME,\n text: JSON.stringify(\n { count: ordered.length, total: events.length, events: ordered },\n null,\n 2,\n ),\n },\n ],\n }\n}\n\n// Pure helper so the poll loop can be tested without timers. Returns true when\n// the visible state of /incidents has changed in a way subscribers should hear\n// about. Compares total count + the id of the newest event — either is enough\n// on its own, but the pair makes deletes (if they ever happen) survive a\n// missed update.\nexport function incidentsChanged(\n prev: { total: number; lastId?: string } | null,\n next: { total: number; lastId?: string },\n): boolean {\n if (!prev) return false // first observation seeds, doesn't notify\n if (prev.total !== next.total) return true\n if (prev.lastId !== next.lastId) return true\n return false\n}\n\nexport interface RegisterResourcesOptions {\n // Poll interval for /incidents in ms. 5s by default; 0 disables polling.\n incidentsPollMs?: number\n // Project this MCP instance reports against. Unset → core's `default`\n // project via the legacy unprefixed URLs.\n project?: string\n}\n\nexport interface ResourceRegistration {\n // Stops the poll loop. The SDK keeps the registered resources around as\n // long as the server is alive — calling stop() doesn't unregister them.\n stop: () => void\n}\n\nexport function registerResources(\n server: McpServer,\n client: HttpClient,\n options: RegisterResourcesOptions = {},\n): ResourceRegistration {\n const pollMs = options.incidentsPollMs ?? 5000\n const project = options.project\n\n // neat://node/<id> — templated. The list callback enumerates current nodes;\n // the read callback resolves a specific id.\n server.registerResource(\n 'graph-node',\n new ResourceTemplate('neat://node/{id}', {\n list: async () => listNodeResources(client, project),\n }),\n {\n description:\n 'A single graph node by id. Reading returns the node attributes plus its outbound edges as JSON.',\n mimeType: NODE_RESOURCE_MIME,\n },\n async (_uri, variables) => {\n const raw = variables.id\n const id = Array.isArray(raw) ? raw[0] : raw\n if (typeof id !== 'string' || id.length === 0) {\n throw new Error('neat://node/{id} requires an id')\n }\n const decoded = id.includes('%') ? decodeURIComponent(id) : id\n return readNodeResource(client, decoded, project)\n },\n )\n\n // neat://incidents/recent — static. Subscribers get notifications/resources/\n // updated on each tick where /incidents has changed.\n server.registerResource(\n 'incidents-recent',\n INCIDENTS_URI,\n {\n description:\n 'Most recent error events recorded by neat-core, newest first. JSON: { count, total, events[] }.',\n mimeType: NODE_RESOURCE_MIME,\n },\n async () => readRecentIncidentsResource(client, INCIDENTS_DEFAULT_LIMIT, project),\n )\n\n // neat://policies/violations — static. Same poll-and-notify pattern as\n // incidents. Subscribers get resource-updated notifications when the\n // policy-violations.ndjson grows. ADR-045.\n server.registerResource(\n 'policies-violations',\n POLICY_VIOLATIONS_URI,\n {\n description:\n 'Current policy violations from policy-violations.ndjson, newest first. JSON: { count, total, violations[] }.',\n mimeType: NODE_RESOURCE_MIME,\n },\n async () => readPolicyViolationsResource(client, POLICY_VIOLATIONS_DEFAULT_LIMIT, project),\n )\n\n let stopped = false\n let timer: NodeJS.Timeout | null = null\n let lastIncidents: { total: number; lastId?: string } | null = null\n let lastViolations: { total: number; lastId?: string } | null = null\n\n const tick = async (): Promise<void> => {\n if (stopped) return\n // Incidents poll.\n try {\n const incidents = await client.get<{ count: number; total: number; events: ErrorEvent[] }>(\n `${corePrefix(project)}/incidents`,\n )\n const events = incidents.events\n const next = {\n total: incidents.total,\n lastId: events.length > 0 ? events[events.length - 1].id : undefined,\n }\n if (incidentsChanged(lastIncidents, next)) {\n await server.server.sendResourceUpdated({ uri: INCIDENTS_URI }).catch(() => {})\n }\n lastIncidents = next\n } catch {\n // Core down — keep polling, next tick will catch up.\n }\n // Policy-violations poll. Fires the alert action's notifications/\n // resources/updated for neat://policies/violations subscribers per\n // ADR-044 §alert. Same change-detection shape as incidents.\n try {\n const polBody = await client.get<{ violations: PolicyViolation[] }>(\n `${corePrefix(project)}/policies/violations`,\n )\n const violations = polBody.violations\n const next = {\n total: violations.length,\n lastId:\n violations.length > 0 ? violations[violations.length - 1].id : undefined,\n }\n if (incidentsChanged(lastViolations, next)) {\n await server.server\n .sendResourceUpdated({ uri: POLICY_VIOLATIONS_URI })\n .catch(() => {})\n }\n lastViolations = next\n } catch {\n // Core down or no policies yet — keep polling.\n }\n }\n\n if (pollMs > 0) {\n // Seed `last` on first tick so we don't fire an \"updated\" notification\n // when the server first comes up.\n timer = setInterval(() => {\n void tick()\n }, pollMs)\n if (typeof timer.unref === 'function') timer.unref()\n }\n\n return {\n stop: (): void => {\n stopped = true\n if (timer) clearInterval(timer)\n timer = null\n },\n }\n}\n","// Tool implementations. Each one takes an HttpClient + the validated input and\n// returns an MCP CallToolResult routed through formatToolResponse for the\n// three-part shape (NL + structured + footer) per ADR-039 / contract #12.\n// Keeping these as pure functions of (client, input) means tests don't need a\n// running server — just a stub client that returns canned JSON.\n\nimport type {\n ApplicablePoliciesResponse,\n BlastRadiusAffectedNode,\n BlastRadiusResult,\n Divergence,\n DivergenceResult,\n DivergenceType,\n ErrorEvent,\n ExpandResult,\n GraphEdge,\n GraphNode,\n HypotheticalAction,\n ObservedDependenciesResult,\n PolicyViolation,\n RelateResult,\n RootCauseResult,\n TransitiveDependenciesResult,\n} from '@neat.is/types'\nimport { Provenance } from '@neat.is/types'\nimport { HttpError, ProjectNotFoundError, type HttpClient } from './client.js'\nimport {\n formatEmptyResponse,\n formatErrorResponse,\n formatToolResponse,\n type ToolResponse,\n} from './format.js'\n\nexport type { ToolResponse } from './format.js'\n\n// Project-aware path builder. When `project` is set, route through\n// /projects/<name>/...; otherwise hit the legacy root URL (which the core\n// resolves to project=`default`). Keeping the legacy path means callers\n// running an older core still talk to a known route.\nfunction projectPath(project: string | undefined, suffix: string): string {\n if (!project) return suffix\n return `/projects/${encodeURIComponent(project)}${suffix}`\n}\n\n// Most tools want \"node missing → friendly message, anything else → real error\".\nasync function withMissingNodeFallback(\n fn: () => Promise<ToolResponse>,\n notFoundMessage: string,\n): Promise<ToolResponse> {\n try {\n return await fn()\n } catch (err) {\n // A project-not-found 404 is NOT a missing node — the core doesn't serve\n // this project at all, so an empty \"no results\" would be a confident answer\n // about the wrong codebase (#884). Surface it as a real error. Checked\n // before the generic 404 since ProjectNotFoundError extends HttpError.\n if (err instanceof ProjectNotFoundError) {\n return formatErrorResponse(err.message)\n }\n if (err instanceof HttpError && err.status === 404) {\n return formatEmptyResponse(notFoundMessage)\n }\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nexport interface RootCauseInput {\n errorNode: string\n errorId?: string\n project?: string\n}\n\nexport async function getRootCause(client: HttpClient, input: RootCauseInput): Promise<ToolResponse> {\n const qs = input.errorId ? `?errorId=${encodeURIComponent(input.errorId)}` : ''\n const path = projectPath(\n input.project,\n `/graph/root-cause/${encodeURIComponent(input.errorNode)}${qs}`,\n )\n\n return withMissingNodeFallback(async () => {\n const result = await client.get<RootCauseResult>(path)\n const arrowPath = result.traversalPath.join(' ← ')\n const provenances = result.edgeProvenances.length\n ? result.edgeProvenances.join(', ')\n : '(direct, no edges traversed)'\n const summary =\n `Root cause for ${input.errorNode} is ${result.rootCauseNode}. ` +\n result.rootCauseReason +\n (result.fixRecommendation ? ` Recommended fix: ${result.fixRecommendation}.` : '')\n const blockLines = [\n `Traversal path: ${arrowPath}`,\n `Edge provenances: ${provenances}`,\n ]\n if (result.fixRecommendation) {\n blockLines.push(`Recommended fix: ${result.fixRecommendation}`)\n }\n // Navigation (ADR-189): show the ranked candidate set with per-node\n // classification so the agent can weigh alternatives, not just relay one\n // verdict. A symptom-only node is a downstream victim — not the cause.\n if (result.candidates && result.candidates.length > 0) {\n blockLines.push('', 'Candidates (ranked, most likely cause first):')\n for (const c of result.candidates) {\n blockLines.push(\n ` • ${c.node} — ${c.classification} (confidence ${c.confidence.toFixed(2)}): ${c.reason}`,\n )\n }\n }\n return formatToolResponse({\n summary,\n block: blockLines.join('\\n'),\n confidence: result.confidence,\n provenance: result.edgeProvenances.length ? result.edgeProvenances : undefined,\n })\n }, `No root cause found for ${input.errorNode}. The node may be healthy, or it may not exist in the graph.`)\n}\n\nexport interface BlastRadiusInput {\n nodeId: string\n depth?: number\n project?: string\n}\n\nexport async function getBlastRadius(\n client: HttpClient,\n input: BlastRadiusInput,\n): Promise<ToolResponse> {\n const qs = input.depth !== undefined ? `?depth=${input.depth}` : ''\n const path = projectPath(\n input.project,\n `/graph/blast-radius/${encodeURIComponent(input.nodeId)}${qs}`,\n )\n\n return withMissingNodeFallback(async () => {\n const result = await client.get<BlastRadiusResult>(path)\n if (result.totalAffected === 0) {\n return formatEmptyResponse(\n `${result.origin} has no dependents. Nothing else would break if it failed.`,\n )\n }\n const sorted = [...result.affectedNodes].sort(\n (a, b) => a.distance - b.distance || a.nodeId.localeCompare(b.nodeId),\n )\n const blockLines = sorted.map(formatBlastEntry)\n // Worst-case confidence — the path with the lowest cascaded confidence\n // is the headline number; agents should treat this as \"what's the\n // weakest reachability NEAT actually knows about?\"\n const minConfidence = sorted.reduce(\n (m, n) => Math.min(m, n.confidence),\n Number.POSITIVE_INFINITY,\n )\n const provenances = [...new Set(sorted.map((n) => n.edgeProvenance))]\n return formatToolResponse({\n summary: `Blast radius for ${result.origin}: ${result.totalAffected} dependent node${result.totalAffected === 1 ? '' : 's'} would break if it changed.`,\n block: blockLines.join('\\n'),\n confidence: Number.isFinite(minConfidence) ? minConfidence : undefined,\n provenance: provenances.length ? provenances : undefined,\n })\n }, `Node ${input.nodeId} not found in the graph.`)\n}\n\nfunction formatBlastEntry(n: BlastRadiusAffectedNode): string {\n const tag = n.edgeProvenance === Provenance.STALE ? ' [STALE — last seen too long ago]' : ''\n return ` • ${n.nodeId} (distance ${n.distance}, ${n.edgeProvenance})${tag}`\n}\n\nexport interface DependenciesInput {\n nodeId: string\n // BFS depth. Default 3; max 10. Direct-only consumers pass 1.\n depth?: number\n project?: string\n}\n\n// Transitive get_dependencies (issue #144). Calls the core endpoint\n// /graph/dependencies/:nodeId?depth=N which BFS-walks outbound. The output\n// groups results by hop so direct dependencies stand out from transitives —\n// agents asked \"what does X depend on?\" usually want the direct list with\n// transitives as context.\nexport async function getDependencies(\n client: HttpClient,\n input: DependenciesInput,\n): Promise<ToolResponse> {\n const depth = input.depth ?? 3\n const path = projectPath(\n input.project,\n `/graph/dependencies/${encodeURIComponent(input.nodeId)}?depth=${depth}`,\n )\n\n return withMissingNodeFallback(async () => {\n const result = await client.get<TransitiveDependenciesResult>(path)\n if (result.total === 0) {\n return formatEmptyResponse(\n depth === 1\n ? `${input.nodeId} has no direct dependencies in the graph.`\n : `${input.nodeId} has no dependencies (BFS to depth ${depth}).`,\n )\n }\n // Group by distance so the structured block reads as concentric rings.\n const byDistance = new Map<number, typeof result.dependencies>()\n for (const dep of result.dependencies) {\n const ring = byDistance.get(dep.distance) ?? []\n ring.push(dep)\n byDistance.set(dep.distance, ring)\n }\n const blockLines: string[] = []\n for (const distance of [...byDistance.keys()].sort((a, b) => a - b)) {\n const label = distance === 1 ? 'Direct (distance 1)' : `Distance ${distance}`\n blockLines.push(`${label}:`)\n for (const dep of byDistance.get(distance)!) {\n blockLines.push(` • ${dep.nodeId} — ${dep.edgeType} (${dep.provenance})`)\n }\n }\n const provenances = [...new Set(result.dependencies.map((d) => d.provenance))]\n const directCount = byDistance.get(1)?.length ?? 0\n const summary =\n depth === 1\n ? `${input.nodeId} has ${directCount} direct dependenc${directCount === 1 ? 'y' : 'ies'}.`\n : `${input.nodeId} has ${result.total} dependenc${result.total === 1 ? 'y' : 'ies'} reachable to depth ${depth} (${directCount} direct).`\n return formatToolResponse({\n summary,\n block: blockLines.join('\\n'),\n provenance: provenances,\n })\n }, `Node ${input.nodeId} not found in the graph.`)\n}\n\n// Render one OBSERVED dependency, file-grained. When the edge source isn't the\n// queried node — a service's owned file made the call — name that file, so the\n// answer stays file-first rather than a service rollup (file-awareness §3).\nfunction observedDepLine(nodeId: string, e: GraphEdge): string {\n const via = e.source !== nodeId ? ` (via ${e.source})` : ''\n return ` • ${e.target} — ${e.type}${via}${edgeMeta(e)}`\n}\n\nexport async function getObservedDependencies(\n client: HttpClient,\n input: DependenciesInput,\n): Promise<ToolResponse> {\n return withMissingNodeFallback(async () => {\n const result = await client.get<ObservedDependenciesResult>(\n projectPath(\n input.project,\n `/graph/observed-dependencies/${encodeURIComponent(input.nodeId)}`,\n ),\n )\n if (result.dependencies.length === 0) {\n // A pure receiver is fully observed — it just calls nothing downstream.\n // Reporting \"is OTel running?\" at it would be wrong; that note is honest\n // only when nothing has been observed at all and static deps exist.\n if (result.observed) {\n return formatToolResponse({\n summary:\n `${input.nodeId} makes no outbound runtime calls, but OTel has observed it ` +\n `receiving traffic on ${result.inboundObservedCount} inbound call ` +\n `path${result.inboundObservedCount === 1 ? '' : 's'} — it's a pure receiver.`,\n provenance: Provenance.OBSERVED,\n })\n }\n const note = result.hasExtractedOutbound\n ? ' Static (EXTRACTED) dependencies exist but no runtime traffic has been seen — is OTel running?'\n : ''\n return formatEmptyResponse(`No OBSERVED dependencies for ${input.nodeId}.${note}`)\n }\n const blockLines = result.dependencies.map((e) => observedDepLine(input.nodeId, e))\n return formatToolResponse({\n summary: `${input.nodeId} has ${result.dependencies.length} runtime dependenc${result.dependencies.length === 1 ? 'y' : 'ies'} confirmed by OTel.`,\n block: blockLines.join('\\n'),\n provenance: Provenance.OBSERVED,\n })\n }, `Node ${input.nodeId} not found in the graph.`)\n}\n\nfunction edgeMeta(e: GraphEdge): string {\n const bits: string[] = []\n if (e.signal) {\n // Prefer the runtime signal numbers — \"saw 1,247 calls, 3 errors\" reads\n // better than a derived 0.94 confidence.\n bits.push(`spans=${e.signal.spanCount}`)\n if (e.signal.errorCount > 0) bits.push(`errors=${e.signal.errorCount}`)\n if (e.signal.lastObservedAgeMs !== undefined) {\n bits.push(`age=${formatDuration(e.signal.lastObservedAgeMs)}`)\n }\n } else if (e.callCount !== undefined) {\n bits.push(`callCount=${e.callCount}`)\n }\n if (e.lastObserved) bits.push(`lastObserved=${e.lastObserved}`)\n if (e.confidence !== undefined) bits.push(`confidence=${e.confidence}`)\n return bits.length ? ` [${bits.join(', ')}]` : ''\n}\n\nfunction formatDuration(ms: number): string {\n if (ms < 1000) return `${Math.round(ms)}ms`\n const s = Math.round(ms / 1000)\n if (s < 60) return `${s}s`\n const m = Math.round(s / 60)\n if (m < 60) return `${m}m`\n const h = Math.round(m / 60)\n if (h < 48) return `${h}h`\n return `${Math.round(h / 24)}d`\n}\n\n// Expand — one bidirectional navigation step (ADR-189). The agent walks the\n// failure neighbourhood one legible hop at a time instead of relaying a verdict.\nexport interface ExpandInput {\n nodeId: string\n direction: 'up' | 'down'\n project?: string\n}\n\nexport async function expandNode(client: HttpClient, input: ExpandInput): Promise<ToolResponse> {\n const path = projectPath(\n input.project,\n `/graph/expand/${encodeURIComponent(input.nodeId)}?direction=${input.direction}`,\n )\n return withMissingNodeFallback(async () => {\n const result = await client.get<ExpandResult>(path)\n const dirWord =\n input.direction === 'up' ? 'callers/dependents (up)' : 'callees/dependencies (down)'\n const summary =\n `${result.node.id} is ${result.node.classification}. ` +\n `${result.neighbours.length} ${dirWord}.`\n const blockLines = result.neighbours.map(\n (n) => ` • ${n.node} — ${n.classification} via ${n.edgeType} (${n.provenance})`,\n )\n return formatToolResponse({\n summary,\n block: blockLines.length ? blockLines.join('\\n') : '(no runtime neighbours in this direction)',\n })\n }, `Node ${input.nodeId} not found in the graph.`)\n}\n\n// Relate — pairwise directed link-confirmation (ADR-189). Confirms a hypothesised\n// cause→symptom link and whether the connecting path carries the failure.\nexport interface RelateInput {\n a: string\n b: string\n maxDepth?: number\n project?: string\n}\n\nexport async function relate(client: HttpClient, input: RelateInput): Promise<ToolResponse> {\n const qs = input.maxDepth !== undefined ? `&maxDepth=${input.maxDepth}` : ''\n const path = projectPath(\n input.project,\n `/graph/relate?a=${encodeURIComponent(input.a)}&b=${encodeURIComponent(input.b)}${qs}`,\n )\n try {\n const result = await client.get<RelateResult>(path)\n if (!result.related) {\n return formatEmptyResponse(\n `${input.a} and ${input.b} are not related — ${result.note ?? 'no path found'}.`,\n )\n }\n const arrow =\n result.direction === 'a->b' ? `${input.a} → ${input.b}` : `${input.b} → ${input.a}`\n const carries = result.paths[0]?.carriesSignal\n ? 'and the path carries the failure end to end'\n : 'but the path carries no failure signal'\n const gap = result.grainGap ? ' (grain gap — only a coarser link is in evidence)' : ''\n const summary = `${arrow}: a path exists ${carries}${gap}.`\n const blockLines = result.paths.map(\n (p) => ` ${p.nodes.join(' → ')} [${p.edgeTypes.join(', ')}] carriesSignal=${p.carriesSignal}`,\n )\n return formatToolResponse({ summary, block: blockLines.join('\\n') })\n } catch (err) {\n if (err instanceof ProjectNotFoundError) return formatErrorResponse(err.message)\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nexport interface IncidentHistoryInput {\n nodeId: string\n limit?: number\n project?: string\n}\n\nexport async function getIncidentHistory(\n client: HttpClient,\n input: IncidentHistoryInput,\n): Promise<ToolResponse> {\n return withMissingNodeFallback(async () => {\n const body = await client.get<{ count: number; total: number; events: ErrorEvent[] }>(\n projectPath(input.project, `/incidents/${encodeURIComponent(input.nodeId)}`),\n )\n const events = body.events\n if (events.length === 0) {\n return formatEmptyResponse(`No incidents recorded against ${input.nodeId}.`)\n }\n // ndjson order is append-time = oldest first. Reverse so the most recent\n // event leads, then trim to the requested limit.\n const ordered = [...events].reverse().slice(0, input.limit ?? 20)\n const blockLines: string[] = []\n for (const ev of ordered) {\n blockLines.push(` ${ev.timestamp} — ${ev.service}: ${ev.errorMessage}`)\n blockLines.push(` trace=${ev.traceId} span=${ev.spanId}`)\n }\n return formatToolResponse({\n summary: `${input.nodeId} has ${body.total} recorded incident${body.total === 1 ? '' : 's'}; showing the ${ordered.length} most recent.`,\n block: blockLines.join('\\n'),\n // ErrorEvents are observation records, not graph edges — provenance is\n // OBSERVED by definition (the OTel span happened).\n provenance: Provenance.OBSERVED,\n })\n }, `Node ${input.nodeId} not found in the graph.`)\n}\n\nexport interface SemanticSearchInput {\n query: string\n project?: string\n}\n\ninterface SearchResponse {\n query: string\n provider?: 'ollama' | 'transformers' | 'substring'\n matches: (GraphNode & { score?: number })[]\n}\n\nexport async function semanticSearch(\n client: HttpClient,\n input: SemanticSearchInput,\n): Promise<ToolResponse> {\n try {\n const result = await client.get<SearchResponse>(\n projectPath(input.project, `/search?q=${encodeURIComponent(input.query)}`),\n )\n if (result.matches.length === 0) {\n return formatEmptyResponse(`No matches for \"${input.query}\".`)\n }\n const provider = result.provider ?? 'substring'\n const blockLines: string[] = []\n let topScore: number | undefined\n for (const n of result.matches) {\n // Embedding tiers attach a cosine score in [0,1]; substring fallback\n // doesn't, so we elide the score when it's the placeholder 1.\n const score = provider !== 'substring' && typeof n.score === 'number' ? n.score : undefined\n const scoreBit = score !== undefined ? ` [score=${score.toFixed(2)}]` : ''\n if (score !== undefined && (topScore === undefined || score > topScore)) topScore = score\n blockLines.push(\n ` • ${n.id} (${n.type}) — ${(n as { name?: string }).name ?? n.id}${scoreBit}`,\n )\n }\n return formatToolResponse({\n summary: `Found ${result.matches.length} match${result.matches.length === 1 ? '' : 'es'} for \"${input.query}\" via ${provider} provider.`,\n block: blockLines.join('\\n'),\n // Top similarity score doubles as a \"how confident is the embedder\n // about the best match\" signal. Substring provider returns no score —\n // the footer shows n/a in that case.\n confidence: topScore,\n })\n } catch (err) {\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nexport interface GraphDiffInput {\n againstSnapshot: string\n project?: string\n}\n\ninterface GraphDiffResponse {\n base: { exportedAt?: string }\n current: { exportedAt: string }\n added: { nodes: GraphNode[]; edges: GraphEdge[] }\n removed: { nodes: GraphNode[]; edges: GraphEdge[] }\n changed: {\n nodes: { id: string; before: GraphNode; after: GraphNode }[]\n edges: { id: string; before: GraphEdge; after: GraphEdge }[]\n }\n}\n\nexport async function getGraphDiff(\n client: HttpClient,\n input: GraphDiffInput,\n): Promise<ToolResponse> {\n try {\n const result = await client.get<GraphDiffResponse>(\n projectPath(\n input.project,\n `/graph/diff?against=${encodeURIComponent(input.againstSnapshot)}`,\n ),\n )\n const total =\n result.added.nodes.length +\n result.added.edges.length +\n result.removed.nodes.length +\n result.removed.edges.length +\n result.changed.nodes.length +\n result.changed.edges.length\n const baseLabel = result.base.exportedAt ?? 'unknown'\n if (total === 0) {\n return formatEmptyResponse(\n `No differences between the current graph and ${input.againstSnapshot} (base exportedAt=${baseLabel}).`,\n )\n }\n const blockLines: string[] = [\n ` base exportedAt: ${baseLabel}`,\n ` current exportedAt: ${result.current.exportedAt}`,\n '',\n ]\n if (result.added.nodes.length || result.added.edges.length) {\n blockLines.push('Added:')\n for (const n of result.added.nodes) blockLines.push(` + node ${n.id} (${n.type})`)\n for (const e of result.added.edges)\n blockLines.push(` + edge ${e.id} — ${e.source} -> ${e.target} (${e.type}, ${e.provenance})`)\n blockLines.push('')\n }\n if (result.removed.nodes.length || result.removed.edges.length) {\n blockLines.push('Removed:')\n for (const n of result.removed.nodes) blockLines.push(` - node ${n.id} (${n.type})`)\n for (const e of result.removed.edges)\n blockLines.push(` - edge ${e.id} — ${e.source} -> ${e.target} (${e.type}, ${e.provenance})`)\n blockLines.push('')\n }\n if (result.changed.nodes.length || result.changed.edges.length) {\n blockLines.push('Changed:')\n for (const c of result.changed.nodes) {\n blockLines.push(` ~ node ${c.id} — ${summariseAttrDiff(c.before, c.after)}`)\n }\n for (const c of result.changed.edges) {\n const provBit =\n c.before.provenance !== c.after.provenance\n ? `provenance ${c.before.provenance} → ${c.after.provenance}`\n : summariseAttrDiff(c.before, c.after)\n blockLines.push(` ~ edge ${c.id} — ${provBit}`)\n }\n }\n return formatToolResponse({\n summary: `Diff against ${input.againstSnapshot}: ${total} change${total === 1 ? '' : 's'} between the snapshot and the live graph.`,\n block: blockLines.join('\\n').trimEnd(),\n // Diff results don't have a per-result provenance — the diff spans\n // every edge type and provenance kind. Footer shows n/a.\n })\n } catch (err) {\n if (err instanceof HttpError && err.status === 400) {\n return formatErrorResponse(\n `Could not load snapshot ${input.againstSnapshot}: ${err.message}`,\n )\n }\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nfunction summariseAttrDiff(\n before: Record<string, unknown>,\n after: Record<string, unknown>,\n): string {\n const keys = new Set([...Object.keys(before), ...Object.keys(after)])\n const changed: string[] = []\n for (const k of keys) {\n if (JSON.stringify(before[k]) !== JSON.stringify(after[k])) changed.push(k)\n }\n return changed.length === 0\n ? 'attributes differ'\n : `fields changed: ${changed.sort().join(', ')}`\n}\n\nexport interface RecentStaleEdgesInput {\n limit?: number\n edgeType?: string\n project?: string\n}\n\ninterface StaleEventResponse {\n edgeId: string\n source: string\n target: string\n edgeType: string\n thresholdMs: number\n ageMs: number\n lastObserved: string\n transitionedAt: string\n}\n\nexport async function getRecentStaleEdges(\n client: HttpClient,\n input: RecentStaleEdgesInput,\n): Promise<ToolResponse> {\n const params = new URLSearchParams()\n if (input.limit !== undefined) params.set('limit', String(input.limit))\n if (input.edgeType) params.set('edgeType', input.edgeType)\n const qs = params.size > 0 ? `?${params.toString()}` : ''\n\n try {\n const body = await client.get<{ count: number; total: number; events: StaleEventResponse[] }>(\n projectPath(input.project, `/stale-events${qs}`),\n )\n const events = body.events\n if (events.length === 0) {\n return formatEmptyResponse(\n input.edgeType\n ? `No stale ${input.edgeType} edges recorded.`\n : 'No stale-edge transitions recorded yet.',\n )\n }\n const blockLines = events.map(\n (e) =>\n ` ${e.transitionedAt} — ${e.source} -[${e.edgeType}]-> ${e.target}` +\n ` (last seen ${e.lastObserved}, threshold ${formatDuration(e.thresholdMs)})`,\n )\n return formatToolResponse({\n summary: `${events.length} stale-edge transition${events.length === 1 ? '' : 's'} recorded${input.edgeType ? ` for ${input.edgeType}` : ''}.`,\n block: blockLines.join('\\n'),\n // STALE by definition — every event is a transition into STALE.\n provenance: Provenance.STALE,\n })\n } catch (err) {\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nexport interface CheckPoliciesInput {\n // 'all' (default) returns every current violation. 'unresolved' is reserved\n // for future resolution tracking — for the MVP it behaves the same as 'all'.\n // { policyId } narrows to violations of one named policy.\n scope?: 'all' | 'unresolved' | { policyId: string }\n // When provided, dry-run evaluation: return violations that *would* result\n // if the action were applied. Without it, return current violations.\n hypotheticalAction?: HypotheticalAction\n // Soft guardrail (ADR-108). When provided, return the policies APPLICABLE to\n // this node — the rules the agent should keep in mind while editing it,\n // surfaced as context. Informs only; never blocks. Takes precedence over the\n // violation-read and dry-run modes.\n applicableTo?: string\n project?: string\n}\n\ninterface PoliciesCheckResponse {\n allowed: boolean\n hypotheticalAction?: HypotheticalAction\n violations: PolicyViolation[]\n}\n\n// check_policies — single MCP tool covering both state-read and dry-run modes\n// per ADR-045. The contract explicitly rejects the audit's two-tool split\n// (evaluate_policy + get_policy_violations); both modes route through here.\nexport async function checkPolicies(\n client: HttpClient,\n input: CheckPoliciesInput,\n): Promise<ToolResponse> {\n try {\n // Soft guardrail mode (ADR-108). Surface the policies that govern the node\n // the agent is working at, as a labeled context block. It informs; it does\n // not block — there is no allowed/denied verdict on this path.\n if (input.applicableTo) {\n const body = await client.get<ApplicablePoliciesResponse>(\n projectPath(\n input.project,\n `/policies/applicable?node=${encodeURIComponent(input.applicableTo)}`,\n ),\n )\n return formatApplicablePolicies(body)\n }\n\n let violations: PolicyViolation[]\n let allowed = true\n let hypothetical: HypotheticalAction | undefined\n\n if (input.hypotheticalAction) {\n // Dry-run via POST /policies/check.\n const body = await postJson<PoliciesCheckResponse>(\n client,\n projectPath(input.project, '/policies/check'),\n { hypotheticalAction: input.hypotheticalAction },\n )\n violations = body.violations\n allowed = body.allowed\n hypothetical = body.hypotheticalAction\n } else {\n // State read via GET /policies/violations. Optional scope filters via\n // ?policyId=, severity isn't surfaced in the tool input today.\n const qsParams = new URLSearchParams()\n if (typeof input.scope === 'object' && 'policyId' in input.scope) {\n qsParams.set('policyId', input.scope.policyId)\n }\n const qs = qsParams.size > 0 ? `?${qsParams.toString()}` : ''\n const body = await client.get<{ violations: PolicyViolation[] }>(\n projectPath(input.project, `/policies/violations${qs}`),\n )\n violations = body.violations\n allowed = violations.every((v) => v.onViolation !== 'block')\n }\n\n if (violations.length === 0) {\n return formatEmptyResponse(\n hypothetical\n ? `No violations would result from the hypothetical action (${hypothetical.kind}).`\n : 'No policy violations recorded.',\n )\n }\n\n const blockCount = violations.filter((v) => v.onViolation === 'block').length\n const summaryParts: string[] = []\n if (hypothetical) {\n summaryParts.push(\n `Hypothetical ${hypothetical.kind} would surface ${violations.length} violation${violations.length === 1 ? '' : 's'}`,\n )\n } else {\n summaryParts.push(\n `${violations.length} policy violation${violations.length === 1 ? '' : 's'} currently recorded`,\n )\n }\n if (blockCount > 0) {\n summaryParts.push(`${blockCount} of which block`)\n }\n if (!allowed && hypothetical) {\n summaryParts.push('action denied')\n }\n const summary = summaryParts.join('; ') + '.'\n\n const blockLines = violations.map((v) => {\n const subject = v.subject.nodeId ?? v.subject.edgeId ?? v.subject.path?.[0] ?? '(global)'\n return ` • [${v.severity}/${v.onViolation}] ${v.policyName}: ${v.message} — ${subject}`\n })\n const severities = [...new Set(violations.map((v) => v.severity))]\n return formatToolResponse({\n summary,\n block: blockLines.join('\\n'),\n // Confidence: hypothetical results inherit a 0.7 cap (the engine\n // can't fully simulate every action shape in MVP); confirmed\n // violations report 1.00 since the engine ran against current state.\n confidence: hypothetical ? 0.7 : 1,\n provenance: severities.join(' '),\n })\n } catch (err) {\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\n// The soft-guardrail context block (ADR-108). This is the \"hook to the top of\n// agent memory\": the policies that govern where the agent is working, surfaced\n// so the rules ride along as it edits. It INFORMS — there is deliberately no\n// allowed/denied verdict and no blocking language here. The post-launch kernel\n// gate (ADR-093) is the only surface that refuses an action; this is not it.\nfunction formatApplicablePolicies(body: ApplicablePoliciesResponse): ToolResponse {\n const { node, applicable } = body\n if (applicable.length === 0) {\n return formatEmptyResponse(\n `No policies apply to ${node}. Nothing to keep inside the lines here — and note this is advisory: NEAT surfaces policies for awareness, it never blocks your edit.`,\n )\n }\n const summary =\n `APPLICABLE POLICIES — ${applicable.length} ${applicable.length === 1 ? 'policy applies' : 'policies apply'} where you're working (${node}). ` +\n `Keep these in mind as you edit. They inform; they do not block. Nothing here gates or stops your change.`\n const lines = applicable.map((p) => {\n const tail = p.match === 'region' ? ' [nearby]' : ''\n return ` • [${p.severity}/${p.onViolation}] ${p.policyName}${tail}: ${p.reason}`\n })\n return formatToolResponse({\n summary,\n block: lines.join('\\n'),\n // The policies themselves are declared in policy.json — EXTRACTED, fully\n // known; the confidence is in the rule's existence, not a guess.\n confidence: 1,\n provenance: 'EXTRACTED (policy.json)',\n })\n}\n\n// ──────────────────────────────────────────────────────────────────────────\n// get_divergences (ADR-060) — the thesis surface\n// ──────────────────────────────────────────────────────────────────────────\n\nexport interface DivergencesInput {\n type?: ReadonlyArray<DivergenceType>\n minConfidence?: number\n node?: string\n project?: string\n}\n\nfunction buildDivergencesPath(input: DivergencesInput): string {\n const params = new URLSearchParams()\n if (input.type && input.type.length > 0) params.set('type', input.type.join(','))\n if (input.minConfidence !== undefined) {\n params.set('minConfidence', String(input.minConfidence))\n }\n if (input.node) params.set('node', input.node)\n const qs = params.size > 0 ? `?${params.toString()}` : ''\n return projectPath(input.project, `/graph/divergences${qs}`)\n}\n\nfunction formatDivergenceLine(d: Divergence): string {\n switch (d.type) {\n case 'missing-observed':\n case 'missing-extracted':\n // Column locus (ADR-157 §4) — a column-grain drift on one `sql-table` node,\n // no edge. Edge locus — the declared/observed edge triple.\n if (d.column) {\n return ` • [${d.type}] ${d.table ?? d.source} column ${d.column} — confidence ${d.confidence.toFixed(2)}`\n }\n return ` • [${d.type}] ${d.source} → ${d.target} (${d.edgeType}) — confidence ${d.confidence.toFixed(2)}`\n case 'version-mismatch':\n return ` • [${d.type}] ${d.source} → ${d.target} — declared ${d.extractedVersion}, observed engine ${d.observedVersion} (${d.compatibility})`\n case 'host-mismatch':\n return ` • [${d.type}] ${d.source} → ${d.target} — declared host ${d.extractedHost}, observed host ${d.observedHost}`\n case 'compat-violation':\n return ` • [${d.type}] ${d.source} → ${d.target} — ${d.rule.kind}${d.rule.package ? ` (${d.rule.package})` : ''}`\n }\n}\n\nexport async function getDivergences(\n client: HttpClient,\n input: DivergencesInput,\n): Promise<ToolResponse> {\n try {\n const result = await client.get<DivergenceResult>(buildDivergencesPath(input))\n if (result.totalAffected === 0) {\n return formatEmptyResponse(\n 'No divergences found between the declared (EXTRACTED) and observed (OBSERVED) views of the graph.',\n )\n }\n // Sorted by confidence descending already; first entry is the headline.\n const headline = result.divergences[0]!\n const summary =\n `Found ${result.totalAffected} divergence${result.totalAffected === 1 ? '' : 's'} between code and production. ` +\n `Highest-confidence: ${headline.type} on ${headline.source} → ${headline.target}. ${headline.reason}`\n const blockLines: string[] = []\n for (const d of result.divergences) {\n blockLines.push(formatDivergenceLine(d))\n blockLines.push(` reason: ${d.reason}`)\n blockLines.push(` recommendation: ${d.recommendation}`)\n }\n const maxConfidence = result.divergences.reduce(\n (m, d) => Math.max(m, d.confidence),\n 0,\n )\n return formatToolResponse({\n summary,\n block: blockLines.join('\\n'),\n confidence: maxConfidence,\n // Composite provenance — divergences sit between EXTRACTED and\n // OBSERVED by construction; that's what makes them divergences.\n provenance: 'composite (EXTRACTED + OBSERVED)',\n })\n } catch (err) {\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nasync function postJson<T>(\n client: HttpClient,\n path: string,\n body: unknown,\n): Promise<T> {\n // The base HttpClient interface only exposes get(). For POST we need to\n // reach into the underlying transport. Most callers pass the client built\n // by createHttpClient which has post; types are kept minimal so test\n // stubs don't have to implement post unless the tool needs it.\n const c = client as HttpClient & { post?: <U>(p: string, b: unknown) => Promise<U> }\n if (typeof c.post !== 'function') {\n throw new Error('HttpClient does not support POST — required for check_policies dry-run')\n }\n return c.post<T>(path, body)\n}\n\n// ── /neat extend tools (ADR-081, ADR-086) ────────────────────────────────\n\nexport interface ListUninstrumentedInput {\n project?: string\n}\n\ninterface LibraryCoverageResult {\n library: string\n coverage: string\n installedVersion?: string\n instrumentation_package?: string\n package_version?: string\n registration?: string\n notes?: string\n}\n\nexport async function neatListUninstrumented(\n client: HttpClient,\n input: ListUninstrumentedInput,\n): Promise<ToolResponse> {\n try {\n const result = await client.get<{ libraries: LibraryCoverageResult[] }>(\n projectPath(input.project, '/extend/list-uninstrumented'),\n )\n const libs = result.libraries\n if (libs.length === 0) {\n return formatEmptyResponse(\n 'All detected libraries are covered by the auto-instrumentations bundle or the HTTP fallback. No extension needed.',\n )\n }\n const blockLines = libs.map((l) => {\n const pkgBit = l.instrumentation_package ? ` → ${l.instrumentation_package}@${l.package_version ?? '*'}` : ' → no registry entry'\n return ` • ${l.library} [${l.coverage}]${pkgBit}${l.notes ? ` — ${l.notes}` : ''}`\n })\n return formatToolResponse({\n summary: `${libs.length} librar${libs.length === 1 ? 'y needs' : 'ies need'} instrumentation beyond the auto-instrumentations bundle.`,\n block: blockLines.join('\\n'),\n })\n } catch (err) {\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nexport interface LookupInstrumentationInput {\n library: string\n installedVersion?: string\n project?: string\n}\n\nexport async function neatLookupInstrumentation(\n client: HttpClient,\n input: LookupInstrumentationInput,\n): Promise<ToolResponse> {\n const qs = input.installedVersion ? `?library=${encodeURIComponent(input.library)}&version=${encodeURIComponent(input.installedVersion)}` : `?library=${encodeURIComponent(input.library)}`\n try {\n const result = await client.get<LibraryCoverageResult>(\n projectPath(input.project, `/extend/lookup${qs}`),\n )\n const lines = [\n ` coverage: ${result.coverage}`,\n ...(result.instrumentation_package ? [` instrumentation_package: ${result.instrumentation_package}@${result.package_version ?? '*'}`] : []),\n ...(result.registration ? [` registration: ${result.registration}`] : []),\n ...(result.notes ? [` notes: ${result.notes}`] : []),\n ]\n return formatToolResponse({\n summary: `Registry entry for ${input.library}: coverage is ${result.coverage}.`,\n block: lines.join('\\n'),\n })\n } catch (err) {\n if (err instanceof HttpError && err.status === 404) {\n return formatEmptyResponse(`${input.library} is not in the instrumentation registry.`)\n }\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nexport interface DescribeProjectInstrumentationInput {\n project?: string\n}\n\ninterface ProjectInstrumentationState {\n hookFiles: string[]\n envNeat: boolean\n installedDeps: Record<string, string>\n}\n\nexport async function neatDescribeProjectInstrumentation(\n client: HttpClient,\n input: DescribeProjectInstrumentationInput,\n): Promise<ToolResponse> {\n try {\n const state = await client.get<ProjectInstrumentationState>(\n projectPath(input.project, '/extend/describe'),\n )\n const lines: string[] = [\n ` hook files: ${state.hookFiles.length > 0 ? state.hookFiles.join(', ') : '(none — run neat init first)'}`,\n ` .env.neat: ${state.envNeat ? 'present' : 'absent'}`,\n ]\n const depEntries = Object.entries(state.installedDeps)\n if (depEntries.length > 0) {\n lines.push(' installed OTel deps:')\n for (const [pkg, ver] of depEntries) {\n lines.push(` ${pkg}@${ver}`)\n }\n } else {\n lines.push(' installed OTel deps: (none)')\n }\n const ready = state.hookFiles.length > 0\n return formatToolResponse({\n summary: ready\n ? `Project has ${state.hookFiles.length} instrumentation hook file${state.hookFiles.length === 1 ? '' : 's'} and is ready for neat_apply_extension.`\n : 'Project has no instrumentation hook files. Run neat init before extending.',\n block: lines.join('\\n'),\n })\n } catch (err) {\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nexport interface ApplyExtensionInput {\n library: string\n instrumentation_package: string\n version: string\n registration_snippet: string\n project?: string\n}\n\ninterface ExtensionApplyResult {\n library: string\n filesTouched: string[]\n depsAdded: string[]\n installOutput: string\n alreadyApplied: boolean\n}\n\nexport async function neatApplyExtension(\n client: HttpClient,\n input: ApplyExtensionInput,\n): Promise<ToolResponse> {\n try {\n const result = await postJson<ExtensionApplyResult>(\n client,\n projectPath(input.project, '/extend/apply'),\n {\n library: input.library,\n instrumentation_package: input.instrumentation_package,\n version: input.version,\n registration_snippet: input.registration_snippet,\n },\n )\n if (result.alreadyApplied) {\n return formatEmptyResponse(\n `${input.library} instrumentation is already applied — no changes made.`,\n )\n }\n const lines = [\n ` files touched: ${result.filesTouched.join(', ') || '(none)'}`,\n ` deps added: ${result.depsAdded.join(', ') || '(none)'}`,\n ` install: ${result.installOutput}`,\n ]\n return formatToolResponse({\n summary: `Applied ${input.instrumentation_package} for ${input.library}. ${result.filesTouched.length} file${result.filesTouched.length === 1 ? '' : 's'} touched, logged to ~/.neat/extend-log.ndjson.`,\n block: lines.join('\\n'),\n })\n } catch (err) {\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nexport interface DryRunExtensionInput {\n library: string\n instrumentation_package: string\n version: string\n registration_snippet: string\n project?: string\n}\n\ninterface ExtensionDiff {\n library: string\n filesTouched: string[]\n depsToAdd: string[]\n packageJsonPatch: object\n templatePatch: string\n}\n\nexport async function neatDryRunExtension(\n client: HttpClient,\n input: DryRunExtensionInput,\n): Promise<ToolResponse> {\n try {\n const result = await postJson<ExtensionDiff>(\n client,\n projectPath(input.project, '/extend/dry-run'),\n {\n library: input.library,\n instrumentation_package: input.instrumentation_package,\n version: input.version,\n registration_snippet: input.registration_snippet,\n },\n )\n const lines = [\n ` files that would be touched: ${result.filesTouched.join(', ') || '(none)'}`,\n ` deps to add: ${result.depsToAdd.join(', ') || '(none)'}`,\n ` hook file patch: ${result.templatePatch}`,\n ]\n return formatToolResponse({\n summary: `Dry run for ${input.library}: ${result.filesTouched.length} file${result.filesTouched.length === 1 ? '' : 's'} would be touched. No changes made.`,\n block: lines.join('\\n'),\n })\n } catch (err) {\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nexport interface RollbackExtensionInput {\n library: string\n project?: string\n}\n\nexport async function neatRollbackExtension(\n client: HttpClient,\n input: RollbackExtensionInput,\n): Promise<ToolResponse> {\n try {\n const result = await postJson<{ undone: boolean; message: string }>(\n client,\n projectPath(input.project, '/extend/rollback'),\n { library: input.library },\n )\n if (!result.undone) {\n return formatEmptyResponse(\n `No prior apply found for ${input.library} — nothing to roll back.`,\n )\n }\n return formatToolResponse({\n summary: `Rolled back instrumentation for ${input.library}. ${result.message}. Run your package manager install to sync the lockfile.`,\n block: ` result: ${result.message}`,\n })\n } catch (err) {\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n","// Standardized three-part response format for every MCP tool (ADR-039,\n// issue #143). Output shape:\n//\n// {summary — NL paragraph: what was found, why it matters}\n//\n// {block — typed payload, formatted}\n//\n// confidence: 0.94 · provenance: OBSERVED\n//\n// Empty result → footer reads \"confidence: n/a · provenance: n/a\". Every tool\n// in packages/mcp/src/tools.ts routes through this helper so consumers get a\n// consistent shape — agents can pattern-match on the footer to know how much\n// to trust the answer.\n\nexport interface ToolResponse {\n [x: string]: unknown\n content: { type: 'text'; text: string }[]\n isError?: boolean\n}\n\nexport interface FormatToolResponseInput {\n // NL paragraph. One or two sentences. What was found and why it matters.\n summary: string\n // Structured block. The formatted typed payload — usually a bullet list,\n // sometimes a multi-section breakdown. May be empty when the summary\n // already conveys everything.\n block?: string\n // Per-result confidence in [0, 1]. Undefined → footer reads \"n/a\".\n confidence?: number\n // Per-result provenance. Single value, or an array if the result spans\n // mixed provenances (e.g. a path of OBSERVED + EXTRACTED edges). Undefined\n // → footer reads \"n/a\".\n provenance?: string | string[]\n // Set on transport / 5xx errors. Routes through ToolResponse.isError so\n // MCP clients can surface a non-\"normal\" return.\n isError?: boolean\n}\n\nfunction formatFooter(\n confidence: number | undefined,\n provenance: string | string[] | undefined,\n): string {\n const c = confidence === undefined ? 'n/a' : confidence.toFixed(2)\n const p =\n provenance === undefined\n ? 'n/a'\n : Array.isArray(provenance)\n ? [...new Set(provenance)].join(', ')\n : provenance\n return `confidence: ${c} · provenance: ${p}`\n}\n\nexport function formatToolResponse(input: FormatToolResponseInput): ToolResponse {\n const sections: string[] = [input.summary.trim()]\n if (input.block && input.block.trim().length > 0) {\n sections.push(input.block.trimEnd())\n }\n sections.push(formatFooter(input.confidence, input.provenance))\n const text = sections.join('\\n\\n')\n return {\n content: [{ type: 'text', text }],\n ...(input.isError ? { isError: true } : {}),\n }\n}\n\n// Convenience for the \"node not found / empty graph\" path. Keeps the\n// three-part shape (summary still landed) but sets the footer to n/a / n/a\n// since there's nothing to confidence-tag or provenance-tag.\nexport function formatEmptyResponse(summary: string): ToolResponse {\n return formatToolResponse({ summary })\n}\n\n// Convenience for transport / 5xx errors at the MCP boundary. isError set\n// so MCP clients route the response into their error path.\nexport function formatErrorResponse(message: string): ToolResponse {\n return formatToolResponse({ summary: message, isError: true })\n}\n"],"mappings":";;;;AAEA,IAAAA,cAA6C;AAC7C,mBAAqC;AACrC,iBAAkB;AAClB,IAAAC,gBAKO;;;ACOP,qBAA6B;AAC7B,uBAA8B;AAE9B,IAAM,mBAAmB;AAiBzB,SAAS,wBAAwB,KAAiC;AAChE,MAAI,MAAM;AAGV,aAAS;AACP,UAAM,MAAM,qBAAiB,uBAAK,KAAK,YAAY,aAAa,CAAC;AACjE,QAAI,QAAQ,OAAW,QAAO;AAE9B,UAAM,aAAS,0BAAQ,GAAG;AAC1B,QAAI,WAAW,IAAK,QAAO;AAC3B,UAAM;AAAA,EACR;AACF;AAEA,SAAS,iBAAiB,MAAkC;AAC1D,MAAI;AACJ,MAAI;AACF,cAAM,6BAAa,MAAM,MAAM;AAAA,EACjC,QAAQ;AAEN,WAAO;AAAA,EACT;AAEA,MAAI;AACJ,MAAI;AACF,aAAS,KAAK,MAAM,GAAG;AAAA,EACzB,QAAQ;AAGN,WAAO;AAAA,EACT;AAEA,MAAI,UAAU,QAAQ,OAAO,WAAW,SAAU,QAAO;AAEzD,MAAI,OAAO,WAAW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wB,SAAS,SAAS,QAAQ,KAAK,CAAC;AACtE,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;AAEA,eAAe,OAAsB;AACnC,QAAM,cAAc;AACpB,QAAM,YAAY,IAAI,kCAAqB;AAC3C,QAAM,OAAO,QAAQ,SAAS;AAChC;AAEA,IAAM,cAAc,MAAY;AAC9B,uBAAqB,KAAK;AAC5B;AACA,QAAQ,GAAG,WAAW,WAAW;AACjC,QAAQ,GAAG,UAAU,WAAW;AAEhC,KAAK,EAAE,MAAM,CAAC,QAAQ;AACpB,UAAQ,MAAM,GAAG;AACjB,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["import_mcp","import_types","baseUrl","bearerToken","baseUrl","client","server","client"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/base-url.ts","../src/client.ts","../src/endpoint-check.ts","../src/resources.ts","../src/tools.ts","../src/format.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport { McpServer, type ToolCallback } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'\nimport { z } from 'zod'\nimport {\n CheckPoliciesScopeSchema,\n DivergenceTypeSchema,\n HypotheticalActionSchema,\n type MCPToolName,\n} from '@neat.is/types'\nimport { resolveBaseUrlWithSource } from './base-url.js'\nimport { createHttpClient } from './client.js'\nimport { checkEndpointIsNeat, describeForeignEndpoint } from './endpoint-check.js'\nimport { registerResources } from './resources.js'\nimport {\n ask,\n checkPolicies,\n expandNode,\n getBlastRadius,\n getDependencies,\n getDivergences,\n getGraphDiff,\n getIncidentHistory,\n getObservedDependencies,\n getRecentStaleEdges,\n getRootCause,\n neatApplyExtension,\n neatDescribeProjectInstrumentation,\n neatDryRunExtension,\n neatListUninstrumented,\n neatLookupInstrumentation,\n neatRollbackExtension,\n relate,\n semanticSearch,\n} from './tools.js'\n\nconst resolved = resolveBaseUrlWithSource()\nconst baseUrl = resolved.url\n// ADR-073 §3 — carry the operator's bearer to a secured core. Sourced from\n// NEAT_AUTH_TOKEN, the same env the daemon enforces against; empty/unset\n// keeps the header off so a loopback dev core stays reachable.\nconst authToken = process.env.NEAT_AUTH_TOKEN\nconst bearerToken = authToken && authToken.length > 0 ? authToken : undefined\nconst client = createHttpClient(baseUrl, bearerToken)\n\n// `NEAT_DEFAULT_PROJECT` is the implicit project for tool calls that don't\n// pass a `project` arg. Unset means \"use the core's `default` project\" — we\n// route those calls through the legacy unprefixed URL so an older core (one\n// that predates #83) still gets the request it expects.\nconst defaultProject = process.env.NEAT_DEFAULT_PROJECT\nconst projectFor = (input: { project?: string }): string | undefined =>\n input.project ?? defaultProject\n\nconst projectField = z\n .string()\n .optional()\n .describe(\n 'Project name when the core hosts more than one (set NEAT_PROJECTS=...). Omit to use the default project.',\n )\n\n// Server-level orientation the MCP `initialize` handshake hands the connecting\n// agent, so it knows what NEAT's data *is* before it reads a tool result. NEAT\n// is one server among however many the agent has wired up — some of them\n// (Supabase, Cloudflare, ...) may be the very platforms NEAT's connectors pull\n// from. The line to draw: NEAT's tools answer from its own fused graph, not a\n// live connection to those platforms, and every answer carries provenance so\n// the agent can weigh it. The agent's other servers, and their overlap with\n// NEAT's view, are the agent's own to reconcile — NEAT can't see its peers and\n// doesn't try to; it just says plainly what its own data is.\nconst serverInstructions = [\n 'NEAT serves a fused semantic graph of one software system — static code (EXTRACTED) and live runtime behavior (OBSERVED) in a single model — for the one project this daemon owns. Every tool answers from that graph.',\n 'A result is a graph fact, not a live call to the underlying system. Each edge and result carries a provenance — OBSERVED (seen via OTel), INFERRED (stitched, ~0.6 confidence), EXTRACTED (from source/config), STALE (was observed, gone quiet) — plus a confidence. Trust a claim by its provenance.',\n 'Some OBSERVED data is pulled by connectors from a provider that runs its own telemetry (Supabase, Railway, Firebase, Cloudflare). That is NEAT\\'s own view of the provider, keyed on the provider node (an InfraNode carries `provider`; a service/file carries `platform`). If you also have that provider\\'s own MCP server, NEAT is not it and does not replace it — NEAT tells you how the graph relates, the provider server acts on the live system.',\n 'Reach for NEAT before grepping source for architecture-level questions: dependencies, runtime traffic, recent failures, blast radius, divergence between declared and observed. If a query comes back empty, confirm the daemon is up before falling back to reading files.',\n].join('\\n\\n')\n\nconst server = new McpServer(\n {\n name: 'neat',\n version: '0.1.0',\n },\n { instructions: serverInstructions },\n)\n\n// Register every MCP tool through this wrapper, not server.tool directly.\n// The tool name is constrained to MCP_TOOL_NAMES in @neat.is/types — add the\n// name there first or this won't compile. The contracts audit also checks\n// that registrations and the manifest match both ways, so the tool surface\n// can't drift from the contract again.\nconst registerTool = <Args extends z.ZodRawShape>(\n name: MCPToolName,\n description: string,\n paramsSchema: Args,\n cb: ToolCallback<Args>,\n): ReturnType<typeof server.tool> => server.tool(name, description, paramsSchema, cb)\n\nregisterTool(\n 'ask',\n 'Ask the graph a question in plain language — the front door to NEAT. Reach for this FIRST, before Read/Grep/Bash, for any question about this system\\'s behaviour, dependencies, failures, root cause, or blast radius. You do NOT need to know which tool or the exact node id: `ask` resolves the entities in your question to graph nodes and routes it to the right traversal (root cause, dependencies, observed runtime calls, incidents, divergences, blast radius), returning one compact answer with every fact provenance-tagged (EXTRACTED/OBSERVED/INFERRED/STALE) and confidence-scored. Use the structured tools (get_root_cause, get_dependencies, …) when you already have a node id and want just that one traversal.',\n {\n question: z\n .string()\n .describe('A natural-language question, e.g. \"why is checkout failing?\" or \"what breaks if I change the orders table?\"'),\n project: projectField,\n },\n async (input) => ask(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'get_root_cause',\n 'Trace a failing node up its dependency graph to find the underlying cause. Use this when something is breaking and you want to know which upstream component is the actual culprit.',\n {\n errorNode: z\n .string()\n .describe('Graph node id where the error surfaced, e.g. \"database:payments-db\"'),\n errorId: z\n .string()\n .optional()\n .describe('Specific error event id from incident history; if set, the result is coloured with that error message'),\n project: projectField,\n },\n async (input) => getRootCause(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'get_blast_radius',\n 'List every node that depends on the given node — what would break if this node failed or was redeployed.',\n {\n nodeId: z.string().describe('Graph node id to compute blast radius from'),\n depth: z\n .number()\n .int()\n .nonnegative()\n .max(20)\n .optional()\n .describe('Max BFS depth (default 10)'),\n project: projectField,\n },\n async (input) => getBlastRadius(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'get_dependencies',\n 'List the transitive outgoing dependencies of a node, BFS to depth N (default 3, max 10). Each result carries distance, edge type, and provenance — both static (EXTRACTED) and runtime (OBSERVED). Pass depth=1 for direct-only.',\n {\n nodeId: z.string().describe('Graph node id to inspect'),\n depth: z\n .number()\n .int()\n .min(1)\n .max(10)\n .optional()\n .describe('BFS depth (default 3, max 10). depth=1 returns direct dependencies only.'),\n project: projectField,\n },\n async (input) => getDependencies(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'get_observed_dependencies',\n 'List only the runtime (OBSERVED via OTel) outgoing dependencies of a node. Use this to compare what code SAYS the service depends on vs what production actually does.',\n {\n nodeId: z.string().describe('Graph node id to inspect'),\n project: projectField,\n },\n async (input) => getObservedDependencies(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'expand',\n 'Take one navigation step from a node and classify the neighbourhood (ADR-189). direction \"up\" walks to callers/dependents (who calls this), \"down\" walks to callees/dependencies (what this calls). Each neighbour comes back classified primary-failure / symptom-only / unrelated. Use this to navigate a failure one hop at a time instead of trusting a single verdict — a symptom-only node is a downstream victim, so walk \"up\" from it toward the real cause.',\n {\n nodeId: z.string().describe('Graph node id to step from'),\n direction: z\n .enum(['up', 'down'])\n .describe('up = callers/dependents (toward the cause), down = callees/dependencies'),\n project: projectField,\n },\n async (input) => expandNode(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'relate',\n 'Confirm whether two nodes are connected, which way, and whether the connecting path carries the failure (ADR-189). Returns the direction (a→b or b→a), the path with per-hop provenance, and carriesSignal — whether errors/latency run end to end, which turns \"a path exists\" into \"a is actually causing b\". No path within the depth bound returns \"no path within N hops\", never a false \"unrelated\".',\n {\n a: z.string().describe('First node id (the hypothesised cause)'),\n b: z.string().describe('Second node id (the hypothesised symptom)'),\n maxDepth: z\n .number()\n .int()\n .min(1)\n .max(10)\n .optional()\n .describe('Max path length to search (default 5)'),\n project: projectField,\n },\n async (input) => relate(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'get_incident_history',\n 'Return recent OTel error events recorded against a node, most recent first.',\n {\n nodeId: z.string().describe('Graph node id to query'),\n limit: z.number().int().positive().max(100).optional().describe('Max events to return (default 20)'),\n project: projectField,\n },\n async (input) => getIncidentHistory(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'semantic_search',\n 'Search nodes by natural-language query. Uses embedding vectors when an embedder is available (Ollama nomic-embed-text → in-process MiniLM → substring fallback) — phrase the query the way you would describe what you want.',\n {\n query: z.string().describe('Free-text query, e.g. \"service handling checkout payments\"'),\n project: projectField,\n },\n async (input) => semanticSearch(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'get_graph_diff',\n 'Diff a saved graph snapshot against the current live graph. Useful for change reviews and post-incidents — answers \"what changed in the architecture between then and now.\" Returns added/removed/changed nodes and edges with both snapshot timestamps.',\n {\n againstSnapshot: z\n .string()\n .describe(\n 'Path or http(s) URL of the snapshot to diff against (the \"before\" state). The current graph is the \"after\".',\n ),\n project: projectField,\n },\n async (input) => getGraphDiff(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'get_recent_stale_edges',\n 'List the most recent OBSERVED → STALE edge transitions. Use this to spot integrations that have gone quiet — a CALLS edge that just went stale typically means an upstream stopped calling, not that the link is healthy.',\n {\n limit: z\n .number()\n .int()\n .positive()\n .max(200)\n .optional()\n .describe('Max events to return (default 50)'),\n edgeType: z\n .string()\n .optional()\n .describe('Filter by edge type — e.g. \"CALLS\" or \"CONNECTS_TO\"'),\n project: projectField,\n },\n async (input) => getRecentStaleEdges(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'get_divergences',\n \"Returns places where what the code declares (EXTRACTED) doesn't match what production observed (OBSERVED). The single most NEAT-shaped query — the one that justifies the whole graph. Use when the user asks 'is anything weird?' or 'what does production do that the code doesn't?' or 'find me a bug' on an unfamiliar codebase. Returns divergences ranked by confidence × severity. Prefer this over `get_root_cause` when no specific node is failing.\",\n {\n type: z\n .array(DivergenceTypeSchema)\n .optional()\n .describe(\n 'Filter by divergence type. One or more of: missing-observed, missing-extracted, version-mismatch, host-mismatch, compat-violation. Omit for all.',\n ),\n minConfidence: z\n .number()\n .min(0)\n .max(1)\n .optional()\n .describe('Drop divergences below this confidence threshold (0.0 - 1.0).'),\n node: z\n .string()\n .optional()\n .describe('Scope to divergences involving this node id (as source or target).'),\n project: projectField,\n },\n async (input) =>\n getDivergences(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'check_policies',\n 'Inspect, dry-run, or get the soft guardrail for the project\\'s policy.json. With applicableTo, returns the policies that apply where you are working — surfaced as context so you stay inside the lines (informs, never blocks). Without hypotheticalAction or applicableTo, returns currently-recorded violations. With hypotheticalAction, returns violations that would result if the action were applied. Architectural assertions in five shapes (structural / compatibility / provenance / ownership / blast-radius).',\n {\n scope: CheckPoliciesScopeSchema.optional().describe(\n 'Narrow to a subset. Default \"all\".',\n ),\n hypotheticalAction: HypotheticalActionSchema.optional().describe(\n 'Dry-run mode: simulate the action and return resulting violations. Omit for current state.',\n ),\n applicableTo: z\n .string()\n .optional()\n .describe(\n 'Soft guardrail (ADR-108): pass the node id you are about to edit and check_policies returns the policies that govern it, as a context block — so you stay inside the lines. Advisory only; never blocks.',\n ),\n project: projectField,\n },\n async (input) =>\n checkPolicies(client, {\n ...input,\n project: projectFor(input),\n } as Parameters<typeof checkPolicies>[1]),\n)\n\n// ── /neat extend tools (ADR-081, ADR-086) ────────────────────────────────\n\nregisterTool(\n 'neat_list_uninstrumented',\n 'List libraries in the project that need instrumentation beyond the auto-instrumentations bundle. Returns first-party, third-party, and gap libraries that require an explicit instrumentation package.',\n { project: projectField },\n async (input) => neatListUninstrumented(client, { project: projectFor(input) }),\n)\n\nregisterTool(\n 'neat_lookup_instrumentation',\n 'Look up the registry entry for a specific library. Returns the canonical instrumentation package, version, and registration snippet if one exists.',\n {\n library: z.string().describe('npm package name, e.g. \"@prisma/client\"'),\n installedVersion: z.string().optional().describe('Installed version for range matching'),\n project: projectField,\n },\n async (input) => neatLookupInstrumentation(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'neat_describe_project_instrumentation',\n 'Describe the current state of OTel instrumentation in the project: which hook files exist, whether .env.neat is present, which OTel deps are installed.',\n { project: projectField },\n async (input) => neatDescribeProjectInstrumentation(client, { project: projectFor(input) }),\n)\n\nregisterTool(\n 'neat_apply_extension',\n 'Install an instrumentation package and splice its registration into the existing OTel hook file. Idempotent — calling twice with the same args is a no-op. Only modifies instrumentation files, package.json, and the lockfile (via the project package manager).',\n {\n library: z.string().describe('The library being instrumented, e.g. \"@prisma/client\"'),\n instrumentation_package: z.string().describe('The instrumentation npm package, e.g. \"@prisma/instrumentation\"'),\n version: z.string().describe('Semver range for the instrumentation package, e.g. \"^6.0.0\"'),\n registration_snippet: z.string().describe('The JS/TS snippet to splice into the instrumentations array, e.g. \"instrumentations.push(new PrismaInstrumentation())\"'),\n project: projectField,\n },\n async (input) => neatApplyExtension(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'neat_dry_run_extension',\n 'Preview what neat_apply_extension would do without making any changes. Returns the exact file diff, deps to add, and install command.',\n {\n library: z.string().describe('The library being instrumented, e.g. \"@prisma/client\"'),\n instrumentation_package: z.string().describe('The instrumentation npm package, e.g. \"@prisma/instrumentation\"'),\n version: z.string().describe('Semver range for the instrumentation package, e.g. \"^6.0.0\"'),\n registration_snippet: z.string().describe('The JS/TS snippet to splice into the instrumentations array'),\n project: projectField,\n },\n async (input) => neatDryRunExtension(client, { ...input, project: projectFor(input) }),\n)\n\nregisterTool(\n 'neat_rollback_extension',\n 'Undo the last neat_apply_extension for a given library. Removes the dep from package.json and the registration from the hook file. Does not re-run the package manager — run install manually to sync the lockfile.',\n {\n library: z.string().describe('The library whose instrumentation should be rolled back'),\n project: projectField,\n },\n async (input) => neatRollbackExtension(client, { ...input, project: projectFor(input) }),\n)\n\n// Resources sit alongside tools — same data, different access pattern. Read\n// the per-node resource for raw attrs+edges JSON; subscribe to the incidents\n// resource to be notified when new errors land. The tools above are unchanged.\nconst incidentsPollMs = process.env.NEAT_RESOURCE_POLL_MS\n ? Number(process.env.NEAT_RESOURCE_POLL_MS)\n : undefined\nconst resourceRegistration = registerResources(server, client, {\n ...(incidentsPollMs !== undefined ? { incidentsPollMs } : {}),\n ...(defaultProject ? { project: defaultProject } : {}),\n})\n\n// Before the MCP handshake, confirm the resolved endpoint is actually NEAT.\n// Resolution falls back to :8080 when it can't find a project daemon, and if\n// another service holds that port the server would otherwise query it and hand\n// the agent an opaque HTML/404 on every tool call (#1069). A single /health\n// probe separates NEAT (proceed) from a confirmed-foreign service (fail fast\n// with a clear fix) from merely-unreachable (proceed — a daemon may still be\n// booting, or be gated behind auth this server lacks the token for; the per-\n// request path reports that cleanly). NEAT_SKIP_ENDPOINT_CHECK=1 opts out.\nasync function guardEndpoint(): Promise<void> {\n const skip = process.env.NEAT_SKIP_ENDPOINT_CHECK\n if (skip === '1' || skip === 'true') return\n\n const check = await checkEndpointIsNeat(baseUrl, { bearerToken })\n if (check.kind === 'foreign') {\n console.error(describeForeignEndpoint(baseUrl, resolved.source, check))\n process.exit(1)\n }\n}\n\nasync function main(): Promise<void> {\n await guardEndpoint()\n const transport = new StdioServerTransport()\n await server.connect(transport)\n}\n\nconst stopPolling = (): void => {\n resourceRegistration.stop()\n}\nprocess.on('SIGTERM', stopPolling)\nprocess.on('SIGINT', stopPolling)\n\nmain().catch((err) => {\n console.error(err)\n process.exit(1)\n})\n","// Resolve the daemon URL the MCP server talks to.\n//\n// Under the per-project daemon model (ADR-096 / docs/contracts/project-daemon.md)\n// each project runs its own daemon on its own ports and records them in\n// `<projectRoot>/neat-out/daemon.json`. The MCP server points at the daemon for\n// the project it was launched in, so resolution walks up from the cwd to the\n// nearest `neat-out/daemon.json` and uses its REST port. An explicit\n// `NEAT_CORE_URL` / `NEAT_API_URL` still wins — that's how the hosted/prod\n// substrate pins the MCP server at a fixed daemon — and the canonical loopback\n// default catches the case where neither the env nor a daemon record is present.\n//\n// `NEAT_API_URL` is honored as an accepted alias so configs written by older\n// `neat skill` versions — which emitted `NEAT_API_URL` — still reach the daemon\n// (#488). `NEAT_CORE_URL` wins when both are set.\n//\n// Lives in its own module so the resolution is testable without importing\n// index.ts, which starts the stdio transport on load.\nimport { readFileSync } from 'node:fs'\nimport { dirname, join } from 'node:path'\n\nconst DEFAULT_BASE_URL = 'http://localhost:8080'\n\n// The slice of `neat-out/daemon.json` the MCP server depends on. The full record\n// (pid, projectPath, otlp/web ports, …) is owned by the daemon writer; the MCP\n// server only needs the REST port and the liveness status. We read the file as\n// plain JSON rather than importing the writer's type so this stays decoupled\n// from the daemon package that owns the schema.\ninterface DaemonRecordShape {\n status?: unknown\n ports?: { rest?: unknown }\n}\n\n// Read the REST base URL out of a project's `neat-out/daemon.json`, walking up\n// from `cwd` to the filesystem root to find the nearest one. Returns undefined\n// for every failure mode — no file, unreadable, malformed JSON, a stopped\n// daemon, or a missing/invalid REST port — so the caller falls through to the\n// next precedence level rather than the MCP server failing to start.\nfunction resolveFromDaemonRecord(cwd: string): string | undefined {\n let dir = cwd\n // Walk parents until the path stops changing (the filesystem root, where\n // dirname() is a fixed point).\n for (;;) {\n const url = readDaemonRecord(join(dir, 'neat-out', 'daemon.json'))\n if (url !== undefined) return url\n\n const parent = dirname(dir)\n if (parent === dir) return undefined\n dir = parent\n }\n}\n\nfunction readDaemonRecord(path: string): string | undefined {\n let raw: string\n try {\n raw = readFileSync(path, 'utf8')\n } catch {\n // No daemon.json here (the common case while walking up). Keep looking.\n return undefined\n }\n\n let record: DaemonRecordShape\n try {\n record = JSON.parse(raw) as DaemonRecordShape\n } catch {\n // A daemon.json that exists but is garbage: a daemon caught mid-write, a\n // truncated file. Treat it as absent rather than crashing the MCP server.\n return undefined\n }\n\n if (record == null || typeof record !== 'object') return undefined\n // A daemon that has marked itself stopped no longer answers on its ports.\n if (record.status === 'stopped') return undefined\n\n const rest = record.ports?.rest\n if (typeof rest !== 'number' || !Number.isInteger(rest) || rest <= 0 || rest > 65535) {\n return undefined\n }\n\n return `http://localhost:${rest}`\n}\n\n// How `resolveBaseUrl` arrived at its URL. The startup endpoint check\n// (index.ts / endpoint-check.ts) reads this to word a precise error when the\n// resolved URL turns out to be a foreign service: the :8080 fallback landing on\n// someone else's server reads very differently from an explicit NEAT_CORE_URL\n// pointing at the wrong place, and the fix differs too.\nexport type BaseUrlSource = 'env' | 'daemon-record' | 'default'\n\nexport interface ResolvedBaseUrl {\n url: string\n source: BaseUrlSource\n}\n\n// Same precedence and the same never-throws guarantee as `resolveBaseUrl`, but\n// it also reports which precedence level won so the caller can explain itself.\nexport function resolveBaseUrlWithSource(\n env: NodeJS.ProcessEnv = process.env,\n cwd: string = process.cwd(),\n): ResolvedBaseUrl {\n const override = env.NEAT_CORE_URL ?? env.NEAT_API_URL\n if (override) return { url: override, source: 'env' }\n\n const fromRecord = resolveFromDaemonRecord(cwd)\n if (fromRecord !== undefined) return { url: fromRecord, source: 'daemon-record' }\n\n return { url: DEFAULT_BASE_URL, source: 'default' }\n}\n\nexport function resolveBaseUrl(\n env: NodeJS.ProcessEnv = process.env,\n cwd: string = process.cwd(),\n): string {\n return resolveBaseUrlWithSource(env, cwd).url\n}\n","// Thin HTTP client for the neat-core REST surface. Tools call out via this\n// instead of fetch() directly so tests can swap in a stub implementation\n// without monkey-patching globals.\n\nexport interface HttpClient {\n get<T>(path: string): Promise<T>\n // POST is optional on the interface so test stubs that only need GET don't\n // have to implement it. Production createHttpClient always provides it.\n post?<T>(path: string, body: unknown): Promise<T>\n}\n\n// A daemon that has bound its port but isn't answering yet — mid-boot, wedged\n// mid-extraction, deadlocked, or sitting behind a proxy that black-holes the\n// request — accepts the TCP connection and then never writes a response. With\n// no deadline on the fetch, undici only gives up at its 5-minute headers\n// timeout, which to an interactive agent is indistinguishable from a hang. The\n// MCP surface must stay queryable \"at all times\": a slow or wedged daemon has\n// to surface as a clean, bounded error the agent can act on, never an open-\n// ended wait. So every request carries a deadline; when it trips we translate\n// the abort into a plain-language error the tool layer formats as isError.\nconst DEFAULT_TIMEOUT_MS = 30_000\n\nfunction resolveTimeoutMs(explicit?: number): number {\n if (typeof explicit === 'number' && explicit > 0) return explicit\n const fromEnv = Number(process.env.NEAT_CORE_TIMEOUT_MS)\n if (Number.isFinite(fromEnv) && fromEnv > 0) return fromEnv\n return DEFAULT_TIMEOUT_MS\n}\n\n// AbortSignal.timeout rejects the fetch with a DOMException named\n// 'TimeoutError'; a caller-triggered abort surfaces as 'AbortError'. Match on\n// the name rather than the type so this holds across Node's DOMException /\n// Error representations.\nfunction isTimeoutAbort(err: unknown): boolean {\n const name = (err as { name?: string } | null)?.name\n return name === 'TimeoutError' || name === 'AbortError'\n}\n\nasync function fetchWithTimeout(\n url: string,\n init: RequestInit,\n timeoutMs: number,\n method: string,\n path: string,\n): Promise<Response> {\n try {\n return await fetch(url, { ...init, signal: AbortSignal.timeout(timeoutMs) })\n } catch (err) {\n if (isTimeoutAbort(err)) {\n throw new RequestTimeoutError(\n `Timed out after ${timeoutMs}ms waiting for neat-core on ${method} ${path} — ` +\n `the daemon may be starting up, busy, or wedged. Confirm it is reachable ` +\n `(curl its /health endpoint) or raise NEAT_CORE_TIMEOUT_MS.`,\n )\n }\n throw err\n }\n}\n\n// ADR-073 §3 — the MCP server is a first-party read client, so it carries the\n// operator's bearer on every call the same way the CLI does. `bearerToken`\n// comes from `NEAT_AUTH_TOKEN` (sourced once in index.ts). Empty / undefined\n// keeps the header off, so an unauthenticated loopback dev daemon still works.\n// `timeoutMs` bounds every request; it defaults to NEAT_CORE_TIMEOUT_MS or 30s\n// and is overridable for tests.\nexport function createHttpClient(\n baseUrl: string,\n bearerToken?: string,\n timeoutMs?: number,\n): HttpClient {\n const root = baseUrl.replace(/\\/$/, '')\n const deadline = resolveTimeoutMs(timeoutMs)\n const authHeader: Record<string, string> =\n bearerToken && bearerToken.length > 0\n ? { authorization: `Bearer ${bearerToken}` }\n : {}\n return {\n async get<T>(path: string): Promise<T> {\n const res = await fetchWithTimeout(\n `${root}${path}`,\n { headers: { ...authHeader } },\n deadline,\n 'GET',\n path,\n )\n if (!res.ok) {\n const body = await res.text().catch(() => '')\n throw httpErrorFor(res.status, res.statusText, 'GET', path, body)\n }\n return (await res.json()) as T\n },\n async post<T>(path: string, body: unknown): Promise<T> {\n const res = await fetchWithTimeout(\n `${root}${path}`,\n {\n method: 'POST',\n headers: { 'content-type': 'application/json', ...authHeader },\n body: JSON.stringify(body),\n },\n deadline,\n 'POST',\n path,\n )\n if (!res.ok) {\n const text = await res.text().catch(() => '')\n throw httpErrorFor(res.status, res.statusText, 'POST', path, text)\n }\n return (await res.json()) as T\n },\n }\n}\n\nexport class HttpError extends Error {\n constructor(\n public readonly status: number,\n message: string,\n ) {\n super(message)\n this.name = 'HttpError'\n }\n}\n\n// A 404 whose body is the core's `{\"error\":\"project not found\"}` — the daemon\n// this MCP server is pointed at does not host that project (#884). This is a\n// different failure from a node-not-found 404: the tool layer must NOT swallow\n// it into an empty \"no results\" answer (which reads as a confident, wrong answer\n// about a codebase the core isn't even serving). It carries the project name so\n// the message can name it.\nexport class ProjectNotFoundError extends HttpError {\n constructor(public readonly project: string, where: string) {\n super(\n 404,\n `neat-core does not serve project \"${project}\" (on ${where}). This MCP server is pointed at a daemon for a different codebase — it cannot answer about \"${project}\". Point it at that project's daemon (set NEAT_CORE_URL, or run the agent from the project directory so it discovers the local daemon), then retry.`,\n )\n this.name = 'ProjectNotFoundError'\n }\n}\n\n// Distinguish a project-not-found 404 (the core doesn't host the project) from\n// any other error, so the client throws the right type once, centrally.\nfunction httpErrorFor(\n status: number,\n statusText: string,\n method: 'GET' | 'POST',\n path: string,\n body: string,\n): HttpError {\n if (status === 404) {\n try {\n const parsed = JSON.parse(body) as { error?: unknown; project?: unknown }\n if (parsed && parsed.error === 'project not found' && typeof parsed.project === 'string') {\n return new ProjectNotFoundError(parsed.project, `${method} ${path}`)\n }\n } catch {\n // Not JSON / not the project-not-found shape — fall through to a plain HttpError.\n }\n }\n return new HttpError(status, `${status} ${statusText} on ${method} ${path}: ${body}`)\n}\n\n// Thrown when a request exceeds its deadline. Not an HttpError — there was no\n// HTTP response — so the tool layer's 404 fallback doesn't swallow it; it lands\n// in the generic branch and surfaces as a formatted isError the agent can read.\nexport class RequestTimeoutError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'RequestTimeoutError'\n }\n}\n","// Startup guard: confirm the resolved daemon URL actually speaks NEAT before the\n// MCP server commits to it.\n//\n// `resolveBaseUrl` (base-url.ts) honors NEAT_CORE_URL/NEAT_API_URL, else walks up\n// to a project's `neat-out/daemon.json`, else falls back to the canonical\n// `http://localhost:8080`. That last fallback is a foot-gun: launched outside any\n// NEAT project, on a machine where some *other* service happens to own :8080 (an\n// otel-demo frontend, a stray dev server), resolution silently lands on a foreign\n// server. Every tool call then comes back as an opaque HTML/404 the agent can't\n// read — it looks like NEAT is broken when in fact the server never reached NEAT.\n//\n// So once, at boot, we probe the resolved URL's `/health`. NEAT's `/health` is a\n// stable identity signal: every daemon answers `{ ok: true, uptimeMs: <n>, ... }`\n// JSON (docs/contracts/rest-api.md, issue #343), it is mounted ahead of any\n// project route so a real daemon never 404s it, and it is cheap.\n\nimport type { BaseUrlSource } from './base-url.js'\n\n// A short, self-contained deadline for the boot probe — independent of the\n// per-tool NEAT_CORE_TIMEOUT_MS. If a daemon is too slow to answer /health in\n// this window we treat the endpoint as merely unreachable (not foreign) and let\n// the server start; the per-request path reports a clean, bounded error later.\nconst PROBE_TIMEOUT_MS = 2500\n\nexport type EndpointCheck =\n | { kind: 'neat' }\n | { kind: 'unreachable'; detail: string }\n | { kind: 'foreign'; status: number; contentType: string }\n\nexport interface CheckOptions {\n bearerToken?: string\n timeoutMs?: number\n // Injectable for tests; defaults to the global fetch.\n fetchImpl?: typeof fetch\n}\n\n// Probe the resolved endpoint's /health once and classify it. Never throws —\n// a boot check that itself blew up would be worse than the papercut it guards.\nexport async function checkEndpointIsNeat(\n baseUrl: string,\n opts: CheckOptions = {},\n): Promise<EndpointCheck> {\n const root = baseUrl.replace(/\\/$/, '')\n const doFetch = opts.fetchImpl ?? fetch\n const headers: Record<string, string> =\n opts.bearerToken && opts.bearerToken.length > 0\n ? { authorization: `Bearer ${opts.bearerToken}` }\n : {}\n\n let res: Response\n try {\n res = await doFetch(`${root}/health`, {\n headers,\n signal: AbortSignal.timeout(opts.timeoutMs ?? PROBE_TIMEOUT_MS),\n })\n } catch (err) {\n // Connection refused, DNS failure, or our own timeout — no HTTP response at\n // all. A daemon that isn't up yet lives here; never call this \"not NEAT\".\n return { kind: 'unreachable', detail: errMessage(err) }\n }\n\n // 401/403 means *something* is enforcing auth on this port — far more likely a\n // real NEAT daemon this server holds the wrong (or no) token for than a foreign\n // service. 5xx is an ambiguous gateway/boot hiccup. Neither is a foreign\n // signal, so don't fail startup on them.\n if (res.status === 401 || res.status === 403 || res.status >= 500) {\n return { kind: 'unreachable', detail: `HTTP ${res.status}` }\n }\n\n const contentType = res.headers.get('content-type') ?? 'unknown'\n const body = await res.text().catch(() => '')\n if (isNeatHealth(body)) return { kind: 'neat' }\n return { kind: 'foreign', status: res.status, contentType }\n}\n\n// NEAT's /health — daemon-wide and per-project alike — always answers\n// `{ ok: true, uptimeMs: <number>, ... }`. That pair is the signature: present on\n// every real daemon, absent from an arbitrary foreign body (HTML, or some other\n// service's JSON).\nfunction isNeatHealth(body: string): boolean {\n let parsed: unknown\n try {\n parsed = JSON.parse(body)\n } catch {\n return false\n }\n if (parsed === null || typeof parsed !== 'object') return false\n const rec = parsed as Record<string, unknown>\n return rec.ok === true && typeof rec.uptimeMs === 'number'\n}\n\nfunction errMessage(err: unknown): string {\n return err instanceof Error ? err.message : String(err)\n}\n\n// The actionable message the server prints (and exits on) when the resolved\n// endpoint answered but is not NEAT. Worded per resolution source so the fix is\n// specific — the :8080 fallback hitting a foreign server is the common case.\nexport function describeForeignEndpoint(\n url: string,\n source: BaseUrlSource,\n check: { status: number; contentType: string },\n): string {\n const how: Record<BaseUrlSource, string> = {\n env: 'from NEAT_CORE_URL / NEAT_API_URL',\n 'daemon-record':\n 'from a neat-out/daemon.json record found while walking up from the working directory',\n default:\n 'from the default http://localhost:8080 — no NEAT_CORE_URL was set and no neat-out/daemon.json was found walking up from the working directory',\n }\n const fix: Record<BaseUrlSource, string> = {\n env: 'Check that NEAT_CORE_URL points at a running NEAT daemon.',\n 'daemon-record':\n 'The REST port recorded in that daemon.json is now answered by something else — the record is stale. Restart the project daemon, or set NEAT_CORE_URL to its address.',\n default:\n \"Another service — not NEAT — is answering on :8080. Run the MCP server from inside a NEAT project so it can discover neat-out/daemon.json, or set NEAT_CORE_URL to your daemon's address.\",\n }\n return [\n `NEAT MCP server: resolved the daemon at ${url} (${how[source]}), but it does not look like NEAT — ` +\n `a probe of ${url}/health returned HTTP ${check.status} (${check.contentType}), not NEAT's health JSON.`,\n fix[source],\n 'If this really is your NEAT daemon (for example behind a proxy that rewrites /health), set NEAT_SKIP_ENDPOINT_CHECK=1 to bypass this check.',\n ].join('\\n\\n')\n}\n","// MCP Resources — additive surface alongside the eight tools. Two resources:\n//\n// neat://node/<id> — one resource per graph node. Read returns the\n// node attributes plus its outbound edges.\n// neat://incidents/recent — most recent error events. Pollable by the SDK\n// via subscribe; we send `notifications/resources/\n// updated` when /incidents grows.\n//\n// Pure read helpers are exported so tests can exercise them without spinning up\n// an MCP transport. `registerResources()` does the SDK wiring + the poll loop.\n\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport {\n ResourceTemplate,\n} from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type {\n ListResourcesResult,\n ReadResourceResult,\n} from '@modelcontextprotocol/sdk/types.js'\nimport type { ErrorEvent, GraphEdge, GraphNode, PolicyViolation } from '@neat.is/types'\nimport { HttpError, type HttpClient } from './client.js'\n\ninterface EdgesResponse {\n inbound: GraphEdge[]\n outbound: GraphEdge[]\n}\n\ninterface SerializedGraph {\n nodes: GraphNode[]\n edges: GraphEdge[]\n}\n\nconst NODE_RESOURCE_MIME = 'application/json'\nconst INCIDENTS_URI = 'neat://incidents/recent'\nconst INCIDENTS_DEFAULT_LIMIT = 50\nconst POLICY_VIOLATIONS_URI = 'neat://policies/violations'\nconst POLICY_VIOLATIONS_DEFAULT_LIMIT = 100\n\nfunction nodeUri(id: string): string {\n // Node ids contain `:` which RFC 6570 percent-encodes; doing it explicitly\n // here keeps the URI we hand the SDK identical to what `list` produces.\n return `neat://node/${encodeURIComponent(id)}`\n}\n\n// Project-aware URL prefix for the underlying core. When unset, hit the\n// legacy unprefixed routes (which the core resolves to project=`default`).\nfunction corePrefix(project: string | undefined): string {\n return project ? `/projects/${encodeURIComponent(project)}` : ''\n}\n\nfunction nameFromAttrs(attrs: GraphNode): string {\n return (attrs as { name?: string }).name ?? attrs.id\n}\n\nexport async function listNodeResources(\n client: HttpClient,\n project?: string,\n): Promise<ListResourcesResult> {\n const graph = await client.get<SerializedGraph>(`${corePrefix(project)}/graph`)\n return {\n resources: graph.nodes.map((n) => ({\n uri: nodeUri(n.id),\n name: nameFromAttrs(n),\n description: `${n.type} — ${nameFromAttrs(n)}`,\n mimeType: NODE_RESOURCE_MIME,\n })),\n }\n}\n\nexport async function readNodeResource(\n client: HttpClient,\n id: string,\n project?: string,\n): Promise<ReadResourceResult> {\n const uri = nodeUri(id)\n const prefix = corePrefix(project)\n try {\n const [nodeBody, edges] = await Promise.all([\n client.get<{ node: GraphNode }>(`${prefix}/graph/node/${encodeURIComponent(id)}`),\n client.get<EdgesResponse>(`${prefix}/graph/edges/${encodeURIComponent(id)}`),\n ])\n const body = {\n node: nodeBody.node,\n // Outbound only — the issue spec says \"attrs + outbound edges\". Inbound\n // edges are still reachable via the other endpoint and would double the\n // payload for hub nodes (e.g. a shared database).\n outboundEdges: edges.outbound,\n }\n return {\n contents: [\n {\n uri,\n mimeType: NODE_RESOURCE_MIME,\n text: JSON.stringify(body, null, 2),\n },\n ],\n }\n } catch (err) {\n if (err instanceof HttpError && err.status === 404) {\n return {\n contents: [\n {\n uri,\n mimeType: NODE_RESOURCE_MIME,\n text: JSON.stringify({ error: 'node not found', id }),\n },\n ],\n }\n }\n throw err\n }\n}\n\nexport async function readPolicyViolationsResource(\n client: HttpClient,\n limit: number = POLICY_VIOLATIONS_DEFAULT_LIMIT,\n project?: string,\n): Promise<ReadResourceResult> {\n const body = await client.get<{ violations: PolicyViolation[] }>(\n `${corePrefix(project)}/policies/violations`,\n )\n const violations = body.violations\n // Latest first; cap at limit so an exploding violations log doesn't blow\n // up the resource read. The full file is still on disk for forensic use.\n const ordered = [...violations].reverse().slice(0, limit)\n return {\n contents: [\n {\n uri: POLICY_VIOLATIONS_URI,\n mimeType: NODE_RESOURCE_MIME,\n text: JSON.stringify(\n { count: ordered.length, total: violations.length, violations: ordered },\n null,\n 2,\n ),\n },\n ],\n }\n}\n\nexport async function readRecentIncidentsResource(\n client: HttpClient,\n limit: number = INCIDENTS_DEFAULT_LIMIT,\n project?: string,\n): Promise<ReadResourceResult> {\n const body = await client.get<{ count: number; total: number; events: ErrorEvent[] }>(\n `${corePrefix(project)}/incidents`,\n )\n const events = body.events\n // ndjson order is append-time = oldest first. Reverse so most-recent leads.\n const ordered = [...events].reverse().slice(0, limit)\n return {\n contents: [\n {\n uri: INCIDENTS_URI,\n mimeType: NODE_RESOURCE_MIME,\n text: JSON.stringify(\n { count: ordered.length, total: events.length, events: ordered },\n null,\n 2,\n ),\n },\n ],\n }\n}\n\n// Pure helper so the poll loop can be tested without timers. Returns true when\n// the visible state of /incidents has changed in a way subscribers should hear\n// about. Compares total count + the id of the newest event — either is enough\n// on its own, but the pair makes deletes (if they ever happen) survive a\n// missed update.\nexport function incidentsChanged(\n prev: { total: number; lastId?: string } | null,\n next: { total: number; lastId?: string },\n): boolean {\n if (!prev) return false // first observation seeds, doesn't notify\n if (prev.total !== next.total) return true\n if (prev.lastId !== next.lastId) return true\n return false\n}\n\nexport interface RegisterResourcesOptions {\n // Poll interval for /incidents in ms. 5s by default; 0 disables polling.\n incidentsPollMs?: number\n // Project this MCP instance reports against. Unset → core's `default`\n // project via the legacy unprefixed URLs.\n project?: string\n}\n\nexport interface ResourceRegistration {\n // Stops the poll loop. The SDK keeps the registered resources around as\n // long as the server is alive — calling stop() doesn't unregister them.\n stop: () => void\n}\n\nexport function registerResources(\n server: McpServer,\n client: HttpClient,\n options: RegisterResourcesOptions = {},\n): ResourceRegistration {\n const pollMs = options.incidentsPollMs ?? 5000\n const project = options.project\n\n // neat://node/<id> — templated. The list callback enumerates current nodes;\n // the read callback resolves a specific id.\n server.registerResource(\n 'graph-node',\n new ResourceTemplate('neat://node/{id}', {\n list: async () => listNodeResources(client, project),\n }),\n {\n description:\n 'A single graph node by id. Reading returns the node attributes plus its outbound edges as JSON.',\n mimeType: NODE_RESOURCE_MIME,\n },\n async (_uri, variables) => {\n const raw = variables.id\n const id = Array.isArray(raw) ? raw[0] : raw\n if (typeof id !== 'string' || id.length === 0) {\n throw new Error('neat://node/{id} requires an id')\n }\n const decoded = id.includes('%') ? decodeURIComponent(id) : id\n return readNodeResource(client, decoded, project)\n },\n )\n\n // neat://incidents/recent — static. Subscribers get notifications/resources/\n // updated on each tick where /incidents has changed.\n server.registerResource(\n 'incidents-recent',\n INCIDENTS_URI,\n {\n description:\n 'Most recent error events recorded by neat-core, newest first. JSON: { count, total, events[] }.',\n mimeType: NODE_RESOURCE_MIME,\n },\n async () => readRecentIncidentsResource(client, INCIDENTS_DEFAULT_LIMIT, project),\n )\n\n // neat://policies/violations — static. Same poll-and-notify pattern as\n // incidents. Subscribers get resource-updated notifications when the\n // policy-violations.ndjson grows. ADR-045.\n server.registerResource(\n 'policies-violations',\n POLICY_VIOLATIONS_URI,\n {\n description:\n 'Current policy violations from policy-violations.ndjson, newest first. JSON: { count, total, violations[] }.',\n mimeType: NODE_RESOURCE_MIME,\n },\n async () => readPolicyViolationsResource(client, POLICY_VIOLATIONS_DEFAULT_LIMIT, project),\n )\n\n let stopped = false\n let timer: NodeJS.Timeout | null = null\n let lastIncidents: { total: number; lastId?: string } | null = null\n let lastViolations: { total: number; lastId?: string } | null = null\n\n const tick = async (): Promise<void> => {\n if (stopped) return\n // Incidents poll.\n try {\n const incidents = await client.get<{ count: number; total: number; events: ErrorEvent[] }>(\n `${corePrefix(project)}/incidents`,\n )\n const events = incidents.events\n const next = {\n total: incidents.total,\n lastId: events.length > 0 ? events[events.length - 1].id : undefined,\n }\n if (incidentsChanged(lastIncidents, next)) {\n await server.server.sendResourceUpdated({ uri: INCIDENTS_URI }).catch(() => {})\n }\n lastIncidents = next\n } catch {\n // Core down — keep polling, next tick will catch up.\n }\n // Policy-violations poll. Fires the alert action's notifications/\n // resources/updated for neat://policies/violations subscribers per\n // ADR-044 §alert. Same change-detection shape as incidents.\n try {\n const polBody = await client.get<{ violations: PolicyViolation[] }>(\n `${corePrefix(project)}/policies/violations`,\n )\n const violations = polBody.violations\n const next = {\n total: violations.length,\n lastId:\n violations.length > 0 ? violations[violations.length - 1].id : undefined,\n }\n if (incidentsChanged(lastViolations, next)) {\n await server.server\n .sendResourceUpdated({ uri: POLICY_VIOLATIONS_URI })\n .catch(() => {})\n }\n lastViolations = next\n } catch {\n // Core down or no policies yet — keep polling.\n }\n }\n\n if (pollMs > 0) {\n // Seed `last` on first tick so we don't fire an \"updated\" notification\n // when the server first comes up.\n timer = setInterval(() => {\n void tick()\n }, pollMs)\n if (typeof timer.unref === 'function') timer.unref()\n }\n\n return {\n stop: (): void => {\n stopped = true\n if (timer) clearInterval(timer)\n timer = null\n },\n }\n}\n","// Tool implementations. Each one takes an HttpClient + the validated input and\n// returns an MCP CallToolResult routed through formatToolResponse for the\n// three-part shape (NL + structured + footer) per ADR-039 / contract #12.\n// Keeping these as pure functions of (client, input) means tests don't need a\n// running server — just a stub client that returns canned JSON.\n\nimport type {\n ApplicablePoliciesResponse,\n AskResult,\n BlastRadiusAffectedNode,\n BlastRadiusResult,\n Divergence,\n DivergenceResult,\n DivergenceType,\n ErrorEvent,\n ExpandResult,\n GraphEdge,\n GraphNode,\n HypotheticalAction,\n ObservedDependenciesResult,\n PolicyViolation,\n RelateResult,\n RootCauseResult,\n TransitiveDependenciesResult,\n} from '@neat.is/types'\nimport { Provenance } from '@neat.is/types'\nimport { HttpError, ProjectNotFoundError, type HttpClient } from './client.js'\nimport {\n formatEmptyResponse,\n formatErrorResponse,\n formatToolResponse,\n type ToolResponse,\n} from './format.js'\n\nexport type { ToolResponse } from './format.js'\n\n// Project-aware path builder. When `project` is set, route through\n// /projects/<name>/...; otherwise hit the legacy root URL (which the core\n// resolves to project=`default`). Keeping the legacy path means callers\n// running an older core still talk to a known route.\nfunction projectPath(project: string | undefined, suffix: string): string {\n if (!project) return suffix\n return `/projects/${encodeURIComponent(project)}${suffix}`\n}\n\n// Most tools want \"node missing → friendly message, anything else → real error\".\nasync function withMissingNodeFallback(\n fn: () => Promise<ToolResponse>,\n notFoundMessage: string,\n): Promise<ToolResponse> {\n try {\n return await fn()\n } catch (err) {\n // A project-not-found 404 is NOT a missing node — the core doesn't serve\n // this project at all, so an empty \"no results\" would be a confident answer\n // about the wrong codebase (#884). Surface it as a real error. Checked\n // before the generic 404 since ProjectNotFoundError extends HttpError.\n if (err instanceof ProjectNotFoundError) {\n return formatErrorResponse(err.message)\n }\n if (err instanceof HttpError && err.status === 404) {\n return formatEmptyResponse(notFoundMessage)\n }\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nexport interface RootCauseInput {\n errorNode: string\n errorId?: string\n project?: string\n}\n\nexport async function getRootCause(client: HttpClient, input: RootCauseInput): Promise<ToolResponse> {\n const qs = input.errorId ? `?errorId=${encodeURIComponent(input.errorId)}` : ''\n const path = projectPath(\n input.project,\n `/graph/root-cause/${encodeURIComponent(input.errorNode)}${qs}`,\n )\n\n return withMissingNodeFallback(async () => {\n const result = await client.get<RootCauseResult>(path)\n const arrowPath = result.traversalPath.join(' ← ')\n const provenances = result.edgeProvenances.length\n ? result.edgeProvenances.join(', ')\n : '(direct, no edges traversed)'\n const summary =\n `Root cause for ${input.errorNode} is ${result.rootCauseNode}. ` +\n result.rootCauseReason +\n (result.fixRecommendation ? ` Recommended fix: ${result.fixRecommendation}.` : '')\n const blockLines = [\n `Traversal path: ${arrowPath}`,\n `Edge provenances: ${provenances}`,\n ]\n if (result.fixRecommendation) {\n blockLines.push(`Recommended fix: ${result.fixRecommendation}`)\n }\n // Navigation (ADR-189): show the ranked candidate set with per-node\n // classification so the agent can weigh alternatives, not just relay one\n // verdict. A symptom-only node is a downstream victim — not the cause.\n if (result.candidates && result.candidates.length > 0) {\n blockLines.push('', 'Candidates (ranked, most likely cause first):')\n for (const c of result.candidates) {\n blockLines.push(\n ` • ${c.node} — ${c.classification} (confidence ${c.confidence.toFixed(2)}): ${c.reason}`,\n )\n }\n }\n return formatToolResponse({\n summary,\n block: blockLines.join('\\n'),\n confidence: result.confidence,\n provenance: result.edgeProvenances.length ? result.edgeProvenances : undefined,\n })\n }, `No root cause found for ${input.errorNode}. The node may be healthy, or it may not exist in the graph.`)\n}\n\nexport interface BlastRadiusInput {\n nodeId: string\n depth?: number\n project?: string\n}\n\nexport async function getBlastRadius(\n client: HttpClient,\n input: BlastRadiusInput,\n): Promise<ToolResponse> {\n const qs = input.depth !== undefined ? `?depth=${input.depth}` : ''\n const path = projectPath(\n input.project,\n `/graph/blast-radius/${encodeURIComponent(input.nodeId)}${qs}`,\n )\n\n return withMissingNodeFallback(async () => {\n const result = await client.get<BlastRadiusResult>(path)\n if (result.totalAffected === 0) {\n return formatEmptyResponse(\n `${result.origin} has no dependents. Nothing else would break if it failed.`,\n )\n }\n const sorted = [...result.affectedNodes].sort(\n (a, b) => a.distance - b.distance || a.nodeId.localeCompare(b.nodeId),\n )\n const blockLines = sorted.map(formatBlastEntry)\n // Worst-case confidence — the path with the lowest cascaded confidence\n // is the headline number; agents should treat this as \"what's the\n // weakest reachability NEAT actually knows about?\"\n const minConfidence = sorted.reduce(\n (m, n) => Math.min(m, n.confidence),\n Number.POSITIVE_INFINITY,\n )\n const provenances = [...new Set(sorted.map((n) => n.edgeProvenance))]\n return formatToolResponse({\n summary: `Blast radius for ${result.origin}: ${result.totalAffected} dependent node${result.totalAffected === 1 ? '' : 's'} would break if it changed.`,\n block: blockLines.join('\\n'),\n confidence: Number.isFinite(minConfidence) ? minConfidence : undefined,\n provenance: provenances.length ? provenances : undefined,\n })\n }, `Node ${input.nodeId} not found in the graph.`)\n}\n\nfunction formatBlastEntry(n: BlastRadiusAffectedNode): string {\n const tag = n.edgeProvenance === Provenance.STALE ? ' [STALE — last seen too long ago]' : ''\n return ` • ${n.nodeId} (distance ${n.distance}, ${n.edgeProvenance})${tag}`\n}\n\nexport interface DependenciesInput {\n nodeId: string\n // BFS depth. Default 3; max 10. Direct-only consumers pass 1.\n depth?: number\n project?: string\n}\n\n// Transitive get_dependencies (issue #144). Calls the core endpoint\n// /graph/dependencies/:nodeId?depth=N which BFS-walks outbound. The output\n// groups results by hop so direct dependencies stand out from transitives —\n// agents asked \"what does X depend on?\" usually want the direct list with\n// transitives as context.\nexport async function getDependencies(\n client: HttpClient,\n input: DependenciesInput,\n): Promise<ToolResponse> {\n const depth = input.depth ?? 3\n const path = projectPath(\n input.project,\n `/graph/dependencies/${encodeURIComponent(input.nodeId)}?depth=${depth}`,\n )\n\n return withMissingNodeFallback(async () => {\n const result = await client.get<TransitiveDependenciesResult>(path)\n if (result.total === 0) {\n return formatEmptyResponse(\n depth === 1\n ? `${input.nodeId} has no direct dependencies in the graph.`\n : `${input.nodeId} has no dependencies (BFS to depth ${depth}).`,\n )\n }\n // Group by distance so the structured block reads as concentric rings.\n const byDistance = new Map<number, typeof result.dependencies>()\n for (const dep of result.dependencies) {\n const ring = byDistance.get(dep.distance) ?? []\n ring.push(dep)\n byDistance.set(dep.distance, ring)\n }\n const blockLines: string[] = []\n for (const distance of [...byDistance.keys()].sort((a, b) => a - b)) {\n const label = distance === 1 ? 'Direct (distance 1)' : `Distance ${distance}`\n blockLines.push(`${label}:`)\n for (const dep of byDistance.get(distance)!) {\n blockLines.push(` • ${dep.nodeId} — ${dep.edgeType} (${dep.provenance})`)\n }\n }\n const provenances = [...new Set(result.dependencies.map((d) => d.provenance))]\n const directCount = byDistance.get(1)?.length ?? 0\n const summary =\n depth === 1\n ? `${input.nodeId} has ${directCount} direct dependenc${directCount === 1 ? 'y' : 'ies'}.`\n : `${input.nodeId} has ${result.total} dependenc${result.total === 1 ? 'y' : 'ies'} reachable to depth ${depth} (${directCount} direct).`\n return formatToolResponse({\n summary,\n block: blockLines.join('\\n'),\n provenance: provenances,\n })\n }, `Node ${input.nodeId} not found in the graph.`)\n}\n\n// Render one OBSERVED dependency, file-grained. When the edge source isn't the\n// queried node — a service's owned file made the call — name that file, so the\n// answer stays file-first rather than a service rollup (file-awareness §3).\nfunction observedDepLine(nodeId: string, e: GraphEdge): string {\n const via = e.source !== nodeId ? ` (via ${e.source})` : ''\n return ` • ${e.target} — ${e.type}${via}${edgeMeta(e)}`\n}\n\nexport async function getObservedDependencies(\n client: HttpClient,\n input: DependenciesInput,\n): Promise<ToolResponse> {\n return withMissingNodeFallback(async () => {\n const result = await client.get<ObservedDependenciesResult>(\n projectPath(\n input.project,\n `/graph/observed-dependencies/${encodeURIComponent(input.nodeId)}`,\n ),\n )\n if (result.dependencies.length === 0) {\n // A pure receiver is fully observed — it just calls nothing downstream.\n // Reporting \"is OTel running?\" at it would be wrong; that note is honest\n // only when nothing has been observed at all and static deps exist.\n if (result.observed) {\n return formatToolResponse({\n summary:\n `${input.nodeId} makes no outbound runtime calls, but OTel has observed it ` +\n `receiving traffic on ${result.inboundObservedCount} inbound call ` +\n `path${result.inboundObservedCount === 1 ? '' : 's'} — it's a pure receiver.`,\n provenance: Provenance.OBSERVED,\n })\n }\n const note = result.hasExtractedOutbound\n ? ' Static (EXTRACTED) dependencies exist but no runtime traffic has been seen — is OTel running?'\n : ''\n return formatEmptyResponse(`No OBSERVED dependencies for ${input.nodeId}.${note}`)\n }\n const blockLines = result.dependencies.map((e) => observedDepLine(input.nodeId, e))\n return formatToolResponse({\n summary: `${input.nodeId} has ${result.dependencies.length} runtime dependenc${result.dependencies.length === 1 ? 'y' : 'ies'} confirmed by OTel.`,\n block: blockLines.join('\\n'),\n provenance: Provenance.OBSERVED,\n })\n }, `Node ${input.nodeId} not found in the graph.`)\n}\n\nfunction edgeMeta(e: GraphEdge): string {\n const bits: string[] = []\n if (e.signal) {\n // Prefer the runtime signal numbers — \"saw 1,247 calls, 3 errors\" reads\n // better than a derived 0.94 confidence.\n bits.push(`spans=${e.signal.spanCount}`)\n if (e.signal.errorCount > 0) bits.push(`errors=${e.signal.errorCount}`)\n if (e.signal.lastObservedAgeMs !== undefined) {\n bits.push(`age=${formatDuration(e.signal.lastObservedAgeMs)}`)\n }\n } else if (e.callCount !== undefined) {\n bits.push(`callCount=${e.callCount}`)\n }\n if (e.lastObserved) bits.push(`lastObserved=${e.lastObserved}`)\n if (e.confidence !== undefined) bits.push(`confidence=${e.confidence}`)\n return bits.length ? ` [${bits.join(', ')}]` : ''\n}\n\nfunction formatDuration(ms: number): string {\n if (ms < 1000) return `${Math.round(ms)}ms`\n const s = Math.round(ms / 1000)\n if (s < 60) return `${s}s`\n const m = Math.round(s / 60)\n if (m < 60) return `${m}m`\n const h = Math.round(m / 60)\n if (h < 48) return `${h}h`\n return `${Math.round(h / 24)}d`\n}\n\n// Expand — one bidirectional navigation step (ADR-189). The agent walks the\n// failure neighbourhood one legible hop at a time instead of relaying a verdict.\nexport interface ExpandInput {\n nodeId: string\n direction: 'up' | 'down'\n project?: string\n}\n\nexport async function expandNode(client: HttpClient, input: ExpandInput): Promise<ToolResponse> {\n const path = projectPath(\n input.project,\n `/graph/expand/${encodeURIComponent(input.nodeId)}?direction=${input.direction}`,\n )\n return withMissingNodeFallback(async () => {\n const result = await client.get<ExpandResult>(path)\n const dirWord =\n input.direction === 'up' ? 'callers/dependents (up)' : 'callees/dependencies (down)'\n const summary =\n `${result.node.id} is ${result.node.classification}. ` +\n `${result.neighbours.length} ${dirWord}.`\n const blockLines = result.neighbours.map(\n (n) => ` • ${n.node} — ${n.classification} via ${n.edgeType} (${n.provenance})`,\n )\n return formatToolResponse({\n summary,\n block: blockLines.length ? blockLines.join('\\n') : '(no runtime neighbours in this direction)',\n })\n }, `Node ${input.nodeId} not found in the graph.`)\n}\n\n// Relate — pairwise directed link-confirmation (ADR-189). Confirms a hypothesised\n// cause→symptom link and whether the connecting path carries the failure.\nexport interface RelateInput {\n a: string\n b: string\n maxDepth?: number\n project?: string\n}\n\nexport async function relate(client: HttpClient, input: RelateInput): Promise<ToolResponse> {\n const qs = input.maxDepth !== undefined ? `&maxDepth=${input.maxDepth}` : ''\n const path = projectPath(\n input.project,\n `/graph/relate?a=${encodeURIComponent(input.a)}&b=${encodeURIComponent(input.b)}${qs}`,\n )\n try {\n const result = await client.get<RelateResult>(path)\n if (!result.related) {\n return formatEmptyResponse(\n `${input.a} and ${input.b} are not related — ${result.note ?? 'no path found'}.`,\n )\n }\n const arrow =\n result.direction === 'a->b' ? `${input.a} → ${input.b}` : `${input.b} → ${input.a}`\n const carries = result.paths[0]?.carriesSignal\n ? 'and the path carries the failure end to end'\n : 'but the path carries no failure signal'\n const gap = result.grainGap ? ' (grain gap — only a coarser link is in evidence)' : ''\n const summary = `${arrow}: a path exists ${carries}${gap}.`\n const blockLines = result.paths.map(\n (p) => ` ${p.nodes.join(' → ')} [${p.edgeTypes.join(', ')}] carriesSignal=${p.carriesSignal}`,\n )\n return formatToolResponse({ summary, block: blockLines.join('\\n') })\n } catch (err) {\n if (err instanceof ProjectNotFoundError) return formatErrorResponse(err.message)\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\n// ask — the plain-language door over the whole tool surface (ADR-198). One\n// natural-language question in; one compact, provenance-tagged answer out. The\n// core resolves the question to nodes and routes it to the right traversal, so\n// the agent never has to know WHICH structured tool or the exact node id first.\nexport interface AskInput {\n question: string\n project?: string\n}\n\nexport async function ask(client: HttpClient, input: AskInput): Promise<ToolResponse> {\n const question = input.question.trim()\n if (!question) return formatEmptyResponse('ask: the question was empty.')\n return withMissingNodeFallback(async () => {\n const result = await client.get<AskResult>(\n projectPath(input.project, `/graph/ask?q=${encodeURIComponent(question)}`),\n )\n const blockLines: string[] = []\n if (result.matched.length > 0) {\n blockLines.push(\n `Matched (${result.intent}): ` +\n result.matched.map((m) => `${m.nodeId} [${m.via} ${m.score.toFixed(2)}]`).join(', '),\n )\n } else if (result.scope === 'global') {\n // A graph-wide answer to an entity-less question — no node was named.\n blockLines.push(`Graph-wide answer (${result.intent}) — no entity named.`)\n }\n for (const section of result.sections) {\n blockLines.push('', `${section.heading}:`)\n for (const fact of section.facts) {\n const tag = fact.provenance\n ? ` [${fact.provenance}${fact.confidence !== undefined ? ` ${fact.confidence.toFixed(2)}` : ''}]`\n : fact.confidence !== undefined\n ? ` [confidence ${fact.confidence.toFixed(2)}]`\n : ''\n blockLines.push(` • ${fact.text}${tag}`)\n }\n }\n return formatToolResponse({\n summary: result.answer,\n block: blockLines.join('\\n').trim(),\n ...(result.confidence !== undefined ? { confidence: result.confidence } : {}),\n ...(result.provenance.length > 0 ? { provenance: result.provenance } : {}),\n })\n }, `ask: nothing in \"${question}\" resolved to a node in the graph.`)\n}\n\nexport interface IncidentHistoryInput {\n nodeId: string\n limit?: number\n project?: string\n}\n\nexport async function getIncidentHistory(\n client: HttpClient,\n input: IncidentHistoryInput,\n): Promise<ToolResponse> {\n return withMissingNodeFallback(async () => {\n const body = await client.get<{ count: number; total: number; events: ErrorEvent[] }>(\n projectPath(input.project, `/incidents/${encodeURIComponent(input.nodeId)}`),\n )\n const events = body.events\n if (events.length === 0) {\n return formatEmptyResponse(`No incidents recorded against ${input.nodeId}.`)\n }\n // ndjson order is append-time = oldest first. Reverse so the most recent\n // event leads, then trim to the requested limit.\n const ordered = [...events].reverse().slice(0, input.limit ?? 20)\n const blockLines: string[] = []\n for (const ev of ordered) {\n blockLines.push(` ${ev.timestamp} — ${ev.service}: ${ev.errorMessage}`)\n blockLines.push(` trace=${ev.traceId} span=${ev.spanId}`)\n }\n return formatToolResponse({\n summary: `${input.nodeId} has ${body.total} recorded incident${body.total === 1 ? '' : 's'}; showing the ${ordered.length} most recent.`,\n block: blockLines.join('\\n'),\n // ErrorEvents are observation records, not graph edges — provenance is\n // OBSERVED by definition (the OTel span happened).\n provenance: Provenance.OBSERVED,\n })\n }, `Node ${input.nodeId} not found in the graph.`)\n}\n\nexport interface SemanticSearchInput {\n query: string\n project?: string\n}\n\ninterface SearchResponse {\n query: string\n provider?: 'ollama' | 'transformers' | 'substring'\n matches: (GraphNode & { score?: number })[]\n}\n\nexport async function semanticSearch(\n client: HttpClient,\n input: SemanticSearchInput,\n): Promise<ToolResponse> {\n try {\n const result = await client.get<SearchResponse>(\n projectPath(input.project, `/search?q=${encodeURIComponent(input.query)}`),\n )\n if (result.matches.length === 0) {\n return formatEmptyResponse(`No matches for \"${input.query}\".`)\n }\n const provider = result.provider ?? 'substring'\n const blockLines: string[] = []\n let topScore: number | undefined\n for (const n of result.matches) {\n // Embedding tiers attach a cosine score in [0,1]; substring fallback\n // doesn't, so we elide the score when it's the placeholder 1.\n const score = provider !== 'substring' && typeof n.score === 'number' ? n.score : undefined\n const scoreBit = score !== undefined ? ` [score=${score.toFixed(2)}]` : ''\n if (score !== undefined && (topScore === undefined || score > topScore)) topScore = score\n blockLines.push(\n ` • ${n.id} (${n.type}) — ${(n as { name?: string }).name ?? n.id}${scoreBit}`,\n )\n }\n return formatToolResponse({\n summary: `Found ${result.matches.length} match${result.matches.length === 1 ? '' : 'es'} for \"${input.query}\" via ${provider} provider.`,\n block: blockLines.join('\\n'),\n // Top similarity score doubles as a \"how confident is the embedder\n // about the best match\" signal. Substring provider returns no score —\n // the footer shows n/a in that case.\n confidence: topScore,\n })\n } catch (err) {\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nexport interface GraphDiffInput {\n againstSnapshot: string\n project?: string\n}\n\ninterface GraphDiffResponse {\n base: { exportedAt?: string }\n current: { exportedAt: string }\n added: { nodes: GraphNode[]; edges: GraphEdge[] }\n removed: { nodes: GraphNode[]; edges: GraphEdge[] }\n changed: {\n nodes: { id: string; before: GraphNode; after: GraphNode }[]\n edges: { id: string; before: GraphEdge; after: GraphEdge }[]\n }\n}\n\nexport async function getGraphDiff(\n client: HttpClient,\n input: GraphDiffInput,\n): Promise<ToolResponse> {\n try {\n const result = await client.get<GraphDiffResponse>(\n projectPath(\n input.project,\n `/graph/diff?against=${encodeURIComponent(input.againstSnapshot)}`,\n ),\n )\n const total =\n result.added.nodes.length +\n result.added.edges.length +\n result.removed.nodes.length +\n result.removed.edges.length +\n result.changed.nodes.length +\n result.changed.edges.length\n const baseLabel = result.base.exportedAt ?? 'unknown'\n if (total === 0) {\n return formatEmptyResponse(\n `No differences between the current graph and ${input.againstSnapshot} (base exportedAt=${baseLabel}).`,\n )\n }\n const blockLines: string[] = [\n ` base exportedAt: ${baseLabel}`,\n ` current exportedAt: ${result.current.exportedAt}`,\n '',\n ]\n if (result.added.nodes.length || result.added.edges.length) {\n blockLines.push('Added:')\n for (const n of result.added.nodes) blockLines.push(` + node ${n.id} (${n.type})`)\n for (const e of result.added.edges)\n blockLines.push(` + edge ${e.id} — ${e.source} -> ${e.target} (${e.type}, ${e.provenance})`)\n blockLines.push('')\n }\n if (result.removed.nodes.length || result.removed.edges.length) {\n blockLines.push('Removed:')\n for (const n of result.removed.nodes) blockLines.push(` - node ${n.id} (${n.type})`)\n for (const e of result.removed.edges)\n blockLines.push(` - edge ${e.id} — ${e.source} -> ${e.target} (${e.type}, ${e.provenance})`)\n blockLines.push('')\n }\n if (result.changed.nodes.length || result.changed.edges.length) {\n blockLines.push('Changed:')\n for (const c of result.changed.nodes) {\n blockLines.push(` ~ node ${c.id} — ${summariseAttrDiff(c.before, c.after)}`)\n }\n for (const c of result.changed.edges) {\n const provBit =\n c.before.provenance !== c.after.provenance\n ? `provenance ${c.before.provenance} → ${c.after.provenance}`\n : summariseAttrDiff(c.before, c.after)\n blockLines.push(` ~ edge ${c.id} — ${provBit}`)\n }\n }\n return formatToolResponse({\n summary: `Diff against ${input.againstSnapshot}: ${total} change${total === 1 ? '' : 's'} between the snapshot and the live graph.`,\n block: blockLines.join('\\n').trimEnd(),\n // Diff results don't have a per-result provenance — the diff spans\n // every edge type and provenance kind. Footer shows n/a.\n })\n } catch (err) {\n if (err instanceof HttpError && err.status === 400) {\n return formatErrorResponse(\n `Could not load snapshot ${input.againstSnapshot}: ${err.message}`,\n )\n }\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nfunction summariseAttrDiff(\n before: Record<string, unknown>,\n after: Record<string, unknown>,\n): string {\n const keys = new Set([...Object.keys(before), ...Object.keys(after)])\n const changed: string[] = []\n for (const k of keys) {\n if (JSON.stringify(before[k]) !== JSON.stringify(after[k])) changed.push(k)\n }\n return changed.length === 0\n ? 'attributes differ'\n : `fields changed: ${changed.sort().join(', ')}`\n}\n\nexport interface RecentStaleEdgesInput {\n limit?: number\n edgeType?: string\n project?: string\n}\n\ninterface StaleEventResponse {\n edgeId: string\n source: string\n target: string\n edgeType: string\n thresholdMs: number\n ageMs: number\n lastObserved: string\n transitionedAt: string\n}\n\nexport async function getRecentStaleEdges(\n client: HttpClient,\n input: RecentStaleEdgesInput,\n): Promise<ToolResponse> {\n const params = new URLSearchParams()\n if (input.limit !== undefined) params.set('limit', String(input.limit))\n if (input.edgeType) params.set('edgeType', input.edgeType)\n const qs = params.size > 0 ? `?${params.toString()}` : ''\n\n try {\n const body = await client.get<{ count: number; total: number; events: StaleEventResponse[] }>(\n projectPath(input.project, `/stale-events${qs}`),\n )\n const events = body.events\n if (events.length === 0) {\n return formatEmptyResponse(\n input.edgeType\n ? `No stale ${input.edgeType} edges recorded.`\n : 'No stale-edge transitions recorded yet.',\n )\n }\n const blockLines = events.map(\n (e) =>\n ` ${e.transitionedAt} — ${e.source} -[${e.edgeType}]-> ${e.target}` +\n ` (last seen ${e.lastObserved}, threshold ${formatDuration(e.thresholdMs)})`,\n )\n return formatToolResponse({\n summary: `${events.length} stale-edge transition${events.length === 1 ? '' : 's'} recorded${input.edgeType ? ` for ${input.edgeType}` : ''}.`,\n block: blockLines.join('\\n'),\n // STALE by definition — every event is a transition into STALE.\n provenance: Provenance.STALE,\n })\n } catch (err) {\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nexport interface CheckPoliciesInput {\n // 'all' (default) returns every current violation. 'unresolved' is reserved\n // for future resolution tracking — for the MVP it behaves the same as 'all'.\n // { policyId } narrows to violations of one named policy.\n scope?: 'all' | 'unresolved' | { policyId: string }\n // When provided, dry-run evaluation: return violations that *would* result\n // if the action were applied. Without it, return current violations.\n hypotheticalAction?: HypotheticalAction\n // Soft guardrail (ADR-108). When provided, return the policies APPLICABLE to\n // this node — the rules the agent should keep in mind while editing it,\n // surfaced as context. Informs only; never blocks. Takes precedence over the\n // violation-read and dry-run modes.\n applicableTo?: string\n project?: string\n}\n\ninterface PoliciesCheckResponse {\n allowed: boolean\n hypotheticalAction?: HypotheticalAction\n violations: PolicyViolation[]\n}\n\n// check_policies — single MCP tool covering both state-read and dry-run modes\n// per ADR-045. The contract explicitly rejects the audit's two-tool split\n// (evaluate_policy + get_policy_violations); both modes route through here.\nexport async function checkPolicies(\n client: HttpClient,\n input: CheckPoliciesInput,\n): Promise<ToolResponse> {\n try {\n // Soft guardrail mode (ADR-108). Surface the policies that govern the node\n // the agent is working at, as a labeled context block. It informs; it does\n // not block — there is no allowed/denied verdict on this path.\n if (input.applicableTo) {\n const body = await client.get<ApplicablePoliciesResponse>(\n projectPath(\n input.project,\n `/policies/applicable?node=${encodeURIComponent(input.applicableTo)}`,\n ),\n )\n return formatApplicablePolicies(body)\n }\n\n let violations: PolicyViolation[]\n let allowed = true\n let hypothetical: HypotheticalAction | undefined\n\n if (input.hypotheticalAction) {\n // Dry-run via POST /policies/check.\n const body = await postJson<PoliciesCheckResponse>(\n client,\n projectPath(input.project, '/policies/check'),\n { hypotheticalAction: input.hypotheticalAction },\n )\n violations = body.violations\n allowed = body.allowed\n hypothetical = body.hypotheticalAction\n } else {\n // State read via GET /policies/violations. Optional scope filters via\n // ?policyId=, severity isn't surfaced in the tool input today.\n const qsParams = new URLSearchParams()\n if (typeof input.scope === 'object' && 'policyId' in input.scope) {\n qsParams.set('policyId', input.scope.policyId)\n }\n const qs = qsParams.size > 0 ? `?${qsParams.toString()}` : ''\n const body = await client.get<{ violations: PolicyViolation[] }>(\n projectPath(input.project, `/policies/violations${qs}`),\n )\n violations = body.violations\n allowed = violations.every((v) => v.onViolation !== 'block')\n }\n\n if (violations.length === 0) {\n return formatEmptyResponse(\n hypothetical\n ? `No violations would result from the hypothetical action (${hypothetical.kind}).`\n : 'No policy violations recorded.',\n )\n }\n\n const blockCount = violations.filter((v) => v.onViolation === 'block').length\n const summaryParts: string[] = []\n if (hypothetical) {\n summaryParts.push(\n `Hypothetical ${hypothetical.kind} would surface ${violations.length} violation${violations.length === 1 ? '' : 's'}`,\n )\n } else {\n summaryParts.push(\n `${violations.length} policy violation${violations.length === 1 ? '' : 's'} currently recorded`,\n )\n }\n if (blockCount > 0) {\n summaryParts.push(`${blockCount} of which block`)\n }\n if (!allowed && hypothetical) {\n summaryParts.push('action denied')\n }\n const summary = summaryParts.join('; ') + '.'\n\n const blockLines = violations.map((v) => {\n const subject = v.subject.nodeId ?? v.subject.edgeId ?? v.subject.path?.[0] ?? '(global)'\n return ` • [${v.severity}/${v.onViolation}] ${v.policyName}: ${v.message} — ${subject}`\n })\n const severities = [...new Set(violations.map((v) => v.severity))]\n return formatToolResponse({\n summary,\n block: blockLines.join('\\n'),\n // Confidence: hypothetical results inherit a 0.7 cap (the engine\n // can't fully simulate every action shape in MVP); confirmed\n // violations report 1.00 since the engine ran against current state.\n confidence: hypothetical ? 0.7 : 1,\n provenance: severities.join(' '),\n })\n } catch (err) {\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\n// The soft-guardrail context block (ADR-108). This is the \"hook to the top of\n// agent memory\": the policies that govern where the agent is working, surfaced\n// so the rules ride along as it edits. It INFORMS — there is deliberately no\n// allowed/denied verdict and no blocking language here. The post-launch kernel\n// gate (ADR-093) is the only surface that refuses an action; this is not it.\nfunction formatApplicablePolicies(body: ApplicablePoliciesResponse): ToolResponse {\n const { node, applicable } = body\n if (applicable.length === 0) {\n return formatEmptyResponse(\n `No policies apply to ${node}. Nothing to keep inside the lines here — and note this is advisory: NEAT surfaces policies for awareness, it never blocks your edit.`,\n )\n }\n const summary =\n `APPLICABLE POLICIES — ${applicable.length} ${applicable.length === 1 ? 'policy applies' : 'policies apply'} where you're working (${node}). ` +\n `Keep these in mind as you edit. They inform; they do not block. Nothing here gates or stops your change.`\n const lines = applicable.map((p) => {\n const tail = p.match === 'region' ? ' [nearby]' : ''\n return ` • [${p.severity}/${p.onViolation}] ${p.policyName}${tail}: ${p.reason}`\n })\n return formatToolResponse({\n summary,\n block: lines.join('\\n'),\n // The policies themselves are declared in policy.json — EXTRACTED, fully\n // known; the confidence is in the rule's existence, not a guess.\n confidence: 1,\n provenance: 'EXTRACTED (policy.json)',\n })\n}\n\n// ──────────────────────────────────────────────────────────────────────────\n// get_divergences (ADR-060) — the thesis surface\n// ──────────────────────────────────────────────────────────────────────────\n\nexport interface DivergencesInput {\n type?: ReadonlyArray<DivergenceType>\n minConfidence?: number\n node?: string\n project?: string\n}\n\nfunction buildDivergencesPath(input: DivergencesInput): string {\n const params = new URLSearchParams()\n if (input.type && input.type.length > 0) params.set('type', input.type.join(','))\n if (input.minConfidence !== undefined) {\n params.set('minConfidence', String(input.minConfidence))\n }\n if (input.node) params.set('node', input.node)\n const qs = params.size > 0 ? `?${params.toString()}` : ''\n return projectPath(input.project, `/graph/divergences${qs}`)\n}\n\nfunction formatDivergenceLine(d: Divergence): string {\n switch (d.type) {\n case 'missing-observed':\n case 'missing-extracted':\n // Column locus (ADR-157 §4) — a column-grain drift on one `sql-table` node,\n // no edge. Edge locus — the declared/observed edge triple.\n if (d.column) {\n return ` • [${d.type}] ${d.table ?? d.source} column ${d.column} — confidence ${d.confidence.toFixed(2)}`\n }\n return ` • [${d.type}] ${d.source} → ${d.target} (${d.edgeType}) — confidence ${d.confidence.toFixed(2)}`\n case 'version-mismatch':\n return ` • [${d.type}] ${d.source} → ${d.target} — declared ${d.extractedVersion}, observed engine ${d.observedVersion} (${d.compatibility})`\n case 'host-mismatch':\n return ` • [${d.type}] ${d.source} → ${d.target} — declared host ${d.extractedHost}, observed host ${d.observedHost}`\n case 'compat-violation':\n return ` • [${d.type}] ${d.source} → ${d.target} — ${d.rule.kind}${d.rule.package ? ` (${d.rule.package})` : ''}`\n }\n}\n\nexport async function getDivergences(\n client: HttpClient,\n input: DivergencesInput,\n): Promise<ToolResponse> {\n try {\n const result = await client.get<DivergenceResult>(buildDivergencesPath(input))\n if (result.totalAffected === 0) {\n return formatEmptyResponse(\n 'No divergences found between the declared (EXTRACTED) and observed (OBSERVED) views of the graph.',\n )\n }\n // Sorted by confidence descending already; first entry is the headline.\n const headline = result.divergences[0]!\n const summary =\n `Found ${result.totalAffected} divergence${result.totalAffected === 1 ? '' : 's'} between code and production. ` +\n `Highest-confidence: ${headline.type} on ${headline.source} → ${headline.target}. ${headline.reason}`\n const blockLines: string[] = []\n for (const d of result.divergences) {\n blockLines.push(formatDivergenceLine(d))\n blockLines.push(` reason: ${d.reason}`)\n blockLines.push(` recommendation: ${d.recommendation}`)\n }\n const maxConfidence = result.divergences.reduce(\n (m, d) => Math.max(m, d.confidence),\n 0,\n )\n return formatToolResponse({\n summary,\n block: blockLines.join('\\n'),\n confidence: maxConfidence,\n // Composite provenance — divergences sit between EXTRACTED and\n // OBSERVED by construction; that's what makes them divergences.\n provenance: 'composite (EXTRACTED + OBSERVED)',\n })\n } catch (err) {\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nasync function postJson<T>(\n client: HttpClient,\n path: string,\n body: unknown,\n): Promise<T> {\n // The base HttpClient interface only exposes get(). For POST we need to\n // reach into the underlying transport. Most callers pass the client built\n // by createHttpClient which has post; types are kept minimal so test\n // stubs don't have to implement post unless the tool needs it.\n const c = client as HttpClient & { post?: <U>(p: string, b: unknown) => Promise<U> }\n if (typeof c.post !== 'function') {\n throw new Error('HttpClient does not support POST — required for check_policies dry-run')\n }\n return c.post<T>(path, body)\n}\n\n// ── /neat extend tools (ADR-081, ADR-086) ────────────────────────────────\n\nexport interface ListUninstrumentedInput {\n project?: string\n}\n\ninterface LibraryCoverageResult {\n library: string\n coverage: string\n installedVersion?: string\n instrumentation_package?: string\n package_version?: string\n registration?: string\n notes?: string\n}\n\nexport async function neatListUninstrumented(\n client: HttpClient,\n input: ListUninstrumentedInput,\n): Promise<ToolResponse> {\n try {\n const result = await client.get<{ libraries: LibraryCoverageResult[] }>(\n projectPath(input.project, '/extend/list-uninstrumented'),\n )\n const libs = result.libraries\n if (libs.length === 0) {\n return formatEmptyResponse(\n 'All detected libraries are covered by the auto-instrumentations bundle or the HTTP fallback. No extension needed.',\n )\n }\n const blockLines = libs.map((l) => {\n const pkgBit = l.instrumentation_package ? ` → ${l.instrumentation_package}@${l.package_version ?? '*'}` : ' → no registry entry'\n return ` • ${l.library} [${l.coverage}]${pkgBit}${l.notes ? ` — ${l.notes}` : ''}`\n })\n return formatToolResponse({\n summary: `${libs.length} librar${libs.length === 1 ? 'y needs' : 'ies need'} instrumentation beyond the auto-instrumentations bundle.`,\n block: blockLines.join('\\n'),\n })\n } catch (err) {\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nexport interface LookupInstrumentationInput {\n library: string\n installedVersion?: string\n project?: string\n}\n\nexport async function neatLookupInstrumentation(\n client: HttpClient,\n input: LookupInstrumentationInput,\n): Promise<ToolResponse> {\n const qs = input.installedVersion ? `?library=${encodeURIComponent(input.library)}&version=${encodeURIComponent(input.installedVersion)}` : `?library=${encodeURIComponent(input.library)}`\n try {\n const result = await client.get<LibraryCoverageResult>(\n projectPath(input.project, `/extend/lookup${qs}`),\n )\n const lines = [\n ` coverage: ${result.coverage}`,\n ...(result.instrumentation_package ? [` instrumentation_package: ${result.instrumentation_package}@${result.package_version ?? '*'}`] : []),\n ...(result.registration ? [` registration: ${result.registration}`] : []),\n ...(result.notes ? [` notes: ${result.notes}`] : []),\n ]\n return formatToolResponse({\n summary: `Registry entry for ${input.library}: coverage is ${result.coverage}.`,\n block: lines.join('\\n'),\n })\n } catch (err) {\n if (err instanceof HttpError && err.status === 404) {\n return formatEmptyResponse(`${input.library} is not in the instrumentation registry.`)\n }\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nexport interface DescribeProjectInstrumentationInput {\n project?: string\n}\n\ninterface ProjectInstrumentationState {\n hookFiles: string[]\n envNeat: boolean\n installedDeps: Record<string, string>\n}\n\nexport async function neatDescribeProjectInstrumentation(\n client: HttpClient,\n input: DescribeProjectInstrumentationInput,\n): Promise<ToolResponse> {\n try {\n const state = await client.get<ProjectInstrumentationState>(\n projectPath(input.project, '/extend/describe'),\n )\n const lines: string[] = [\n ` hook files: ${state.hookFiles.length > 0 ? state.hookFiles.join(', ') : '(none — run neat init first)'}`,\n ` .env.neat: ${state.envNeat ? 'present' : 'absent'}`,\n ]\n const depEntries = Object.entries(state.installedDeps)\n if (depEntries.length > 0) {\n lines.push(' installed OTel deps:')\n for (const [pkg, ver] of depEntries) {\n lines.push(` ${pkg}@${ver}`)\n }\n } else {\n lines.push(' installed OTel deps: (none)')\n }\n const ready = state.hookFiles.length > 0\n return formatToolResponse({\n summary: ready\n ? `Project has ${state.hookFiles.length} instrumentation hook file${state.hookFiles.length === 1 ? '' : 's'} and is ready for neat_apply_extension.`\n : 'Project has no instrumentation hook files. Run neat init before extending.',\n block: lines.join('\\n'),\n })\n } catch (err) {\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nexport interface ApplyExtensionInput {\n library: string\n instrumentation_package: string\n version: string\n registration_snippet: string\n project?: string\n}\n\ninterface ExtensionApplyResult {\n library: string\n filesTouched: string[]\n depsAdded: string[]\n installOutput: string\n alreadyApplied: boolean\n}\n\nexport async function neatApplyExtension(\n client: HttpClient,\n input: ApplyExtensionInput,\n): Promise<ToolResponse> {\n try {\n const result = await postJson<ExtensionApplyResult>(\n client,\n projectPath(input.project, '/extend/apply'),\n {\n library: input.library,\n instrumentation_package: input.instrumentation_package,\n version: input.version,\n registration_snippet: input.registration_snippet,\n },\n )\n if (result.alreadyApplied) {\n return formatEmptyResponse(\n `${input.library} instrumentation is already applied — no changes made.`,\n )\n }\n const lines = [\n ` files touched: ${result.filesTouched.join(', ') || '(none)'}`,\n ` deps added: ${result.depsAdded.join(', ') || '(none)'}`,\n ` install: ${result.installOutput}`,\n ]\n return formatToolResponse({\n summary: `Applied ${input.instrumentation_package} for ${input.library}. ${result.filesTouched.length} file${result.filesTouched.length === 1 ? '' : 's'} touched, logged to ~/.neat/extend-log.ndjson.`,\n block: lines.join('\\n'),\n })\n } catch (err) {\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nexport interface DryRunExtensionInput {\n library: string\n instrumentation_package: string\n version: string\n registration_snippet: string\n project?: string\n}\n\ninterface ExtensionDiff {\n library: string\n filesTouched: string[]\n depsToAdd: string[]\n packageJsonPatch: object\n templatePatch: string\n}\n\nexport async function neatDryRunExtension(\n client: HttpClient,\n input: DryRunExtensionInput,\n): Promise<ToolResponse> {\n try {\n const result = await postJson<ExtensionDiff>(\n client,\n projectPath(input.project, '/extend/dry-run'),\n {\n library: input.library,\n instrumentation_package: input.instrumentation_package,\n version: input.version,\n registration_snippet: input.registration_snippet,\n },\n )\n const lines = [\n ` files that would be touched: ${result.filesTouched.join(', ') || '(none)'}`,\n ` deps to add: ${result.depsToAdd.join(', ') || '(none)'}`,\n ` hook file patch: ${result.templatePatch}`,\n ]\n return formatToolResponse({\n summary: `Dry run for ${input.library}: ${result.filesTouched.length} file${result.filesTouched.length === 1 ? '' : 's'} would be touched. No changes made.`,\n block: lines.join('\\n'),\n })\n } catch (err) {\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n\nexport interface RollbackExtensionInput {\n library: string\n project?: string\n}\n\nexport async function neatRollbackExtension(\n client: HttpClient,\n input: RollbackExtensionInput,\n): Promise<ToolResponse> {\n try {\n const result = await postJson<{ undone: boolean; message: string }>(\n client,\n projectPath(input.project, '/extend/rollback'),\n { library: input.library },\n )\n if (!result.undone) {\n return formatEmptyResponse(\n `No prior apply found for ${input.library} — nothing to roll back.`,\n )\n }\n return formatToolResponse({\n summary: `Rolled back instrumentation for ${input.library}. ${result.message}. Run your package manager install to sync the lockfile.`,\n block: ` result: ${result.message}`,\n })\n } catch (err) {\n return formatErrorResponse(`Error talking to neat-core: ${(err as Error).message}`)\n }\n}\n","// Standardized three-part response format for every MCP tool (ADR-039,\n// issue #143). Output shape:\n//\n// {summary — NL paragraph: what was found, why it matters}\n//\n// {block — typed payload, formatted}\n//\n// confidence: 0.94 · provenance: OBSERVED\n//\n// Empty result → footer reads \"confidence: n/a · provenance: n/a\". Every tool\n// in packages/mcp/src/tools.ts routes through this helper so consumers get a\n// consistent shape — agents can pattern-match on the footer to know how much\n// to trust the answer.\n\nexport interface ToolResponse {\n [x: string]: unknown\n content: { type: 'text'; text: string }[]\n isError?: boolean\n}\n\nexport interface FormatToolResponseInput {\n // NL paragraph. One or two sentences. What was found and why it matters.\n summary: string\n // Structured block. The formatted typed payload — usually a bullet list,\n // sometimes a multi-section breakdown. May be empty when the summary\n // already conveys everything.\n block?: string\n // Per-result confidence in [0, 1]. Undefined → footer reads \"n/a\".\n confidence?: number\n // Per-result provenance. Single value, or an array if the result spans\n // mixed provenances (e.g. a path of OBSERVED + EXTRACTED edges). Undefined\n // → footer reads \"n/a\".\n provenance?: string | string[]\n // Set on transport / 5xx errors. Routes through ToolResponse.isError so\n // MCP clients can surface a non-\"normal\" return.\n isError?: boolean\n}\n\nfunction formatFooter(\n confidence: number | undefined,\n provenance: string | string[] | undefined,\n): string {\n const c = confidence === undefined ? 'n/a' : confidence.toFixed(2)\n const p =\n provenance === undefined\n ? 'n/a'\n : Array.isArray(provenance)\n ? [...new Set(provenance)].join(', ')\n : provenance\n return `confidence: ${c} · provenance: ${p}`\n}\n\nexport function formatToolResponse(input: FormatToolResponseInput): ToolResponse {\n const sections: string[] = [input.summary.trim()]\n if (input.block && input.block.trim().length > 0) {\n sections.push(input.block.trimEnd())\n }\n sections.push(formatFooter(input.confidence, input.provenance))\n const text = sections.join('\\n\\n')\n return {\n content: [{ type: 'text', text }],\n ...(input.isError ? { isError: true } : {}),\n }\n}\n\n// Convenience for the \"node not found / empty graph\" path. Keeps the\n// three-part shape (summary still landed) but sets the footer to n/a / n/a\n// since there's nothing to confidence-tag or provenance-tag.\nexport function formatEmptyResponse(summary: string): ToolResponse {\n return formatToolResponse({ summary })\n}\n\n// Convenience for transport / 5xx errors at the MCP boundary. isError set\n// so MCP clients route the response into their error path.\nexport function formatErrorResponse(message: string): ToolResponse {\n return formatToolResponse({ summary: message, isError: true })\n}\n"],"mappings":";;;;AAEA,IAAAA,cAA6C;AAC7C,mBAAqC;AACrC,iBAAkB;AAClB,IAAAC,gBAKO;;;ACOP,qBAA6B;AAC7B,uBAA8B;AAE9B,IAAM,mBAAmB;AAiBzB,SAAS,wBAAwB,KAAiC;AAChE,MAAI,MAAM;AAGV,aAAS;AACP,UAAM,MAAM,qBAAiB,uBAAK,KAAK,YAAY,aAAa,CAAC;AACjE,QAAI,QAAQ,OAAW,QAAO;AA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