@neat.is/mcp 0.4.16 → 0.4.18
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 +42 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +42 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -7,6 +7,47 @@ var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
|
7
7
|
var import_zod = require("zod");
|
|
8
8
|
var import_types2 = require("@neat.is/types");
|
|
9
9
|
|
|
10
|
+
// src/base-url.ts
|
|
11
|
+
var import_node_fs = require("fs");
|
|
12
|
+
var import_node_path = require("path");
|
|
13
|
+
var DEFAULT_BASE_URL = "http://localhost:8080";
|
|
14
|
+
function resolveFromDaemonRecord(cwd) {
|
|
15
|
+
let dir = cwd;
|
|
16
|
+
for (; ; ) {
|
|
17
|
+
const url = readDaemonRecord((0, import_node_path.join)(dir, "neat-out", "daemon.json"));
|
|
18
|
+
if (url !== void 0) return url;
|
|
19
|
+
const parent = (0, import_node_path.dirname)(dir);
|
|
20
|
+
if (parent === dir) return void 0;
|
|
21
|
+
dir = parent;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function readDaemonRecord(path) {
|
|
25
|
+
let raw;
|
|
26
|
+
try {
|
|
27
|
+
raw = (0, import_node_fs.readFileSync)(path, "utf8");
|
|
28
|
+
} catch {
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
let record;
|
|
32
|
+
try {
|
|
33
|
+
record = JSON.parse(raw);
|
|
34
|
+
} catch {
|
|
35
|
+
return void 0;
|
|
36
|
+
}
|
|
37
|
+
if (record == null || typeof record !== "object") return void 0;
|
|
38
|
+
if (record.status === "stopped") return void 0;
|
|
39
|
+
const rest = record.ports?.rest;
|
|
40
|
+
if (typeof rest !== "number" || !Number.isInteger(rest) || rest <= 0 || rest > 65535) {
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
43
|
+
return `http://localhost:${rest}`;
|
|
44
|
+
}
|
|
45
|
+
function resolveBaseUrl(env = process.env, cwd = process.cwd()) {
|
|
46
|
+
const override = env.NEAT_CORE_URL ?? env.NEAT_API_URL;
|
|
47
|
+
if (override) return override;
|
|
48
|
+
return resolveFromDaemonRecord(cwd) ?? DEFAULT_BASE_URL;
|
|
49
|
+
}
|
|
50
|
+
|
|
10
51
|
// src/client.ts
|
|
11
52
|
function createHttpClient(baseUrl2, bearerToken) {
|
|
12
53
|
const root = baseUrl2.replace(/\/$/, "");
|
|
@@ -863,7 +904,7 @@ async function neatRollbackExtension(client2, input) {
|
|
|
863
904
|
}
|
|
864
905
|
|
|
865
906
|
// src/index.ts
|
|
866
|
-
var baseUrl =
|
|
907
|
+
var baseUrl = resolveBaseUrl();
|
|
867
908
|
var authToken = process.env.NEAT_AUTH_TOKEN;
|
|
868
909
|
var client = createHttpClient(baseUrl, authToken && authToken.length > 0 ? authToken : void 0);
|
|
869
910
|
var defaultProject = process.env.NEAT_DEFAULT_PROJECT;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/client.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 { createHttpClient } from './client.js'\nimport { registerResources } from './resources.js'\nimport {\n checkPolicies,\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 semanticSearch,\n} from './tools.js'\n\nconst baseUrl = process.env.NEAT_CORE_URL ?? 'http://localhost:8080'\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 client = createHttpClient(baseUrl, authToken && authToken.length > 0 ? authToken : undefined)\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\nconst server = new McpServer({\n name: 'neat',\n version: '0.1.0',\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 downstream of 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 '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 or dry-run the project\\'s policy.json. Without hypotheticalAction, 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 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\nasync function main(): Promise<void> {\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","// 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// 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.\nexport function createHttpClient(baseUrl: string, bearerToken?: string): HttpClient {\n const root = baseUrl.replace(/\\/$/, '')\n const authHeader =\n bearerToken && bearerToken.length > 0\n ? { authorization: `Bearer ${bearerToken}` }\n : {}\n return {\n async get<T>(path: string): Promise<T> {\n const res = await fetch(`${root}${path}`, { headers: { ...authHeader } })\n if (!res.ok) {\n const body = await res.text().catch(() => '')\n throw new HttpError(res.status, `${res.status} ${res.statusText} on 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 fetch(`${root}${path}`, {\n method: 'POST',\n headers: { 'content-type': 'application/json', ...authHeader },\n body: JSON.stringify(body),\n })\n if (!res.ok) {\n const text = await res.text().catch(() => '')\n throw new HttpError(res.status, `${res.status} ${res.statusText} on 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","// 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 BlastRadiusAffectedNode,\n BlastRadiusResult,\n Divergence,\n DivergenceResult,\n DivergenceType,\n ErrorEvent,\n GraphEdge,\n GraphNode,\n HypotheticalAction,\n PolicyViolation,\n RootCauseResult,\n TransitiveDependenciesResult,\n} from '@neat.is/types'\nimport { Provenance } from '@neat.is/types'\nimport { HttpError, 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 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 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 downstream dependencies. 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} affected node${result.totalAffected === 1 ? '' : 's'} reachable downstream.`,\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\ninterface EdgesResponse {\n inbound: GraphEdge[]\n outbound: GraphEdge[]\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\nexport async function getObservedDependencies(\n client: HttpClient,\n input: DependenciesInput,\n): Promise<ToolResponse> {\n return withMissingNodeFallback(async () => {\n const edges = await client.get<EdgesResponse>(\n projectPath(input.project, `/graph/edges/${encodeURIComponent(input.nodeId)}`),\n )\n const observed = edges.outbound.filter((e) => e.provenance === Provenance.OBSERVED)\n if (observed.length === 0) {\n const hasExtracted = edges.outbound.some((e) => e.provenance === Provenance.EXTRACTED)\n const note = hasExtracted\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 = observed.map((e) => ` • ${e.target} — ${e.type}${edgeMeta(e)}`)\n return formatToolResponse({\n summary: `${input.nodeId} has ${observed.length} runtime dependenc${observed.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\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 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 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// ──────────────────────────────────────────────────────────────────────────\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 return ` • [${d.type}] ${d.source} → ${d.target} (${d.edgeType}) — confidence ${d.confidence.toFixed(2)}`\n case 'missing-extracted':\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"],"m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AAW;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","client","server","client"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/base-url.ts","../src/client.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 { resolveBaseUrl } from './base-url.js'\nimport { createHttpClient } from './client.js'\nimport { registerResources } from './resources.js'\nimport {\n checkPolicies,\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 semanticSearch,\n} from './tools.js'\n\nconst baseUrl = resolveBaseUrl()\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 client = createHttpClient(baseUrl, authToken && authToken.length > 0 ? authToken : undefined)\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\nconst server = new McpServer({\n name: 'neat',\n version: '0.1.0',\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 downstream of 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 '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 or dry-run the project\\'s policy.json. Without hypotheticalAction, 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 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\nasync function main(): Promise<void> {\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\nexport function resolveBaseUrl(\n env: NodeJS.ProcessEnv = process.env,\n cwd: string = process.cwd(),\n): string {\n const override = env.NEAT_CORE_URL ?? env.NEAT_API_URL\n if (override) return override\n\n return resolveFromDaemonRecord(cwd) ?? DEFAULT_BASE_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// 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.\nexport function createHttpClient(baseUrl: string, bearerToken?: string): HttpClient {\n const root = baseUrl.replace(/\\/$/, '')\n const authHeader =\n bearerToken && bearerToken.length > 0\n ? { authorization: `Bearer ${bearerToken}` }\n : {}\n return {\n async get<T>(path: string): Promise<T> {\n const res = await fetch(`${root}${path}`, { headers: { ...authHeader } })\n if (!res.ok) {\n const body = await res.text().catch(() => '')\n throw new HttpError(res.status, `${res.status} ${res.statusText} on 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 fetch(`${root}${path}`, {\n method: 'POST',\n headers: { 'content-type': 'application/json', ...authHeader },\n body: JSON.stringify(body),\n })\n if (!res.ok) {\n const text = await res.text().catch(() => '')\n throw new HttpError(res.status, `${res.status} ${res.statusText} on 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","// 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 BlastRadiusAffectedNode,\n BlastRadiusResult,\n Divergence,\n DivergenceResult,\n DivergenceType,\n ErrorEvent,\n GraphEdge,\n GraphNode,\n HypotheticalAction,\n PolicyViolation,\n RootCauseResult,\n TransitiveDependenciesResult,\n} from '@neat.is/types'\nimport { Provenance } from '@neat.is/types'\nimport { HttpError, 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 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 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 downstream dependencies. 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} affected node${result.totalAffected === 1 ? '' : 's'} reachable downstream.`,\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\ninterface EdgesResponse {\n inbound: GraphEdge[]\n outbound: GraphEdge[]\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\nexport async function getObservedDependencies(\n client: HttpClient,\n input: DependenciesInput,\n): Promise<ToolResponse> {\n return withMissingNodeFallback(async () => {\n const edges = await client.get<EdgesResponse>(\n projectPath(input.project, `/graph/edges/${encodeURIComponent(input.nodeId)}`),\n )\n const observed = edges.outbound.filter((e) => e.provenance === Provenance.OBSERVED)\n if (observed.length === 0) {\n const hasExtracted = edges.outbound.some((e) => e.provenance === Provenance.EXTRACTED)\n const note = hasExtracted\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 = observed.map((e) => ` • ${e.target} — ${e.type}${edgeMeta(e)}`)\n return formatToolResponse({\n summary: `${input.nodeId} has ${observed.length} runtime dependenc${observed.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\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 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 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// ──────────────────────────────────────────────────────────────────────────\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 return ` • [${d.type}] ${d.source} → ${d.target} (${d.edgeType}) — confidence ${d.confidence.toFixed(2)}`\n case 'missing-extracted':\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 formatTo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AAAA,IACE,SAAS,aAAE,OAAO,EAAE,SAAS,uDAAuD;AAAA,IACpF,yBAAyB,aAAE,OAAO,EAAE,SAAS,iEAAiE;AAAA,IAC9G,SAAS,aAAE,OAAO,EAAE,SAAS,6DAA6D;AAAA,IAC1F,sBAAsB,aAAE,OAAO,EAAE,SAAS,6DAA6D;AAAA,IACvG,SAAS;AAAA,EACX;AAAA,EACA,OAAO,UAAU,oBAAoB,QAAQ,EAAE,GAAG,OAAO,SAAS,WAAW,KAAK,EAAE,CAAC;AACvF;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,IACE,SAAS,aAAE,OAAO,EAAE,SAAS,yDAAyD;AAAA,IACtF,SAAS;AAAA,EACX;AAAA,EACA,OAAO,UAAU,sBAAsB,QAAQ,EAAE,GAAG,OAAO,SAAS,WAAW,KAAK,EAAE,CAAC;AACzF;AAKA,IAAM,kBAAkB,QAAQ,IAAI,wBAChC,OAAO,QAAQ,IAAI,qBAAqB,IACxC;AACJ,IAAM,uBAAuB,kBAAkB,QAAQ,QAAQ;AAAA,EAC7D,GAAI,oBAAoB,SAAY,EAAE,gBAAgB,IAAI,CAAC;AAAA,EAC3D,GAAI,iBAAiB,EAAE,SAAS,eAAe,IAAI,CAAC;AACtD,CAAC;AAED,eAAe,OAAsB;AACnC,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","client","server","client"]}
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,47 @@ import {
|
|
|
10
10
|
HypotheticalActionSchema
|
|
11
11
|
} from "@neat.is/types";
|
|
12
12
|
|
|
13
|
+
// src/base-url.ts
|
|
14
|
+
import { readFileSync } from "fs";
|
|
15
|
+
import { dirname, join } from "path";
|
|
16
|
+
var DEFAULT_BASE_URL = "http://localhost:8080";
|
|
17
|
+
function resolveFromDaemonRecord(cwd) {
|
|
18
|
+
let dir = cwd;
|
|
19
|
+
for (; ; ) {
|
|
20
|
+
const url = readDaemonRecord(join(dir, "neat-out", "daemon.json"));
|
|
21
|
+
if (url !== void 0) return url;
|
|
22
|
+
const parent = dirname(dir);
|
|
23
|
+
if (parent === dir) return void 0;
|
|
24
|
+
dir = parent;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function readDaemonRecord(path) {
|
|
28
|
+
let raw;
|
|
29
|
+
try {
|
|
30
|
+
raw = readFileSync(path, "utf8");
|
|
31
|
+
} catch {
|
|
32
|
+
return void 0;
|
|
33
|
+
}
|
|
34
|
+
let record;
|
|
35
|
+
try {
|
|
36
|
+
record = JSON.parse(raw);
|
|
37
|
+
} catch {
|
|
38
|
+
return void 0;
|
|
39
|
+
}
|
|
40
|
+
if (record == null || typeof record !== "object") return void 0;
|
|
41
|
+
if (record.status === "stopped") return void 0;
|
|
42
|
+
const rest = record.ports?.rest;
|
|
43
|
+
if (typeof rest !== "number" || !Number.isInteger(rest) || rest <= 0 || rest > 65535) {
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
return `http://localhost:${rest}`;
|
|
47
|
+
}
|
|
48
|
+
function resolveBaseUrl(env = process.env, cwd = process.cwd()) {
|
|
49
|
+
const override = env.NEAT_CORE_URL ?? env.NEAT_API_URL;
|
|
50
|
+
if (override) return override;
|
|
51
|
+
return resolveFromDaemonRecord(cwd) ?? DEFAULT_BASE_URL;
|
|
52
|
+
}
|
|
53
|
+
|
|
13
54
|
// src/client.ts
|
|
14
55
|
function createHttpClient(baseUrl2, bearerToken) {
|
|
15
56
|
const root = baseUrl2.replace(/\/$/, "");
|
|
@@ -868,7 +909,7 @@ async function neatRollbackExtension(client2, input) {
|
|
|
868
909
|
}
|
|
869
910
|
|
|
870
911
|
// src/index.ts
|
|
871
|
-
var baseUrl =
|
|
912
|
+
var baseUrl = resolveBaseUrl();
|
|
872
913
|
var authToken = process.env.NEAT_AUTH_TOKEN;
|
|
873
914
|
var client = createHttpClient(baseUrl, authToken && authToken.length > 0 ? authToken : void 0);
|
|
874
915
|
var defaultProject = process.env.NEAT_DEFAULT_PROJECT;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/client.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 { createHttpClient } from './client.js'\nimport { registerResources } from './resources.js'\nimport {\n checkPolicies,\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 semanticSearch,\n} from './tools.js'\n\nconst baseUrl = process.env.NEAT_CORE_URL ?? 'http://localhost:8080'\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 client = createHttpClient(baseUrl, authToken && authToken.length > 0 ? authToken : undefined)\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\nconst server = new McpServer({\n name: 'neat',\n version: '0.1.0',\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 downstream of 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 '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 or dry-run the project\\'s policy.json. Without hypotheticalAction, 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 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\nasync function main(): Promise<void> {\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","// 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// 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.\nexport function createHttpClient(baseUrl: string, bearerToken?: string): HttpClient {\n const root = baseUrl.replace(/\\/$/, '')\n const authHeader =\n bearerToken && bearerToken.length > 0\n ? { authorization: `Bearer ${bearerToken}` }\n : {}\n return {\n async get<T>(path: string): Promise<T> {\n const res = await fetch(`${root}${path}`, { headers: { ...authHeader } })\n if (!res.ok) {\n const body = await res.text().catch(() => '')\n throw new HttpError(res.status, `${res.status} ${res.statusText} on 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 fetch(`${root}${path}`, {\n method: 'POST',\n headers: { 'content-type': 'application/json', ...authHeader },\n body: JSON.stringify(body),\n })\n if (!res.ok) {\n const text = await res.text().catch(() => '')\n throw new HttpError(res.status, `${res.status} ${res.statusText} on 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","// 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 BlastRadiusAffectedNode,\n BlastRadiusResult,\n Divergence,\n DivergenceResult,\n DivergenceType,\n ErrorEvent,\n GraphEdge,\n GraphNode,\n HypotheticalAction,\n PolicyViolation,\n RootCauseResult,\n TransitiveDependenciesResult,\n} from '@neat.is/types'\nimport { Provenance } from '@neat.is/types'\nimport { HttpError, 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 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 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 downstream dependencies. 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} affected node${result.totalAffected === 1 ? '' : 's'} reachable downstream.`,\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\ninterface EdgesResponse {\n inbound: GraphEdge[]\n outbound: GraphEdge[]\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\nexport async function getObservedDependencies(\n client: HttpClient,\n input: DependenciesInput,\n): Promise<ToolResponse> {\n return withMissingNodeFallback(async () => {\n const edges = await client.get<EdgesResponse>(\n projectPath(input.project, `/graph/edges/${encodeURIComponent(input.nodeId)}`),\n )\n const observed = edges.outbound.filter((e) => e.provenance === Provenance.OBSERVED)\n if (observed.length === 0) {\n const hasExtracted = edges.outbound.some((e) => e.provenance === Provenance.EXTRACTED)\n const note = hasExtracted\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 = observed.map((e) => ` • ${e.target} — ${e.type}${edgeMeta(e)}`)\n return formatToolResponse({\n summary: `${input.nodeId} has ${observed.length} runtime dependenc${observed.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\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 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 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// ──────────────────────────────────────────────────────────────────────────\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 return ` • [${d.type}] ${d.source} → ${d.target} (${d.edgeType}) — confidence ${d.confidence.toFixed(2)}`\n case 'missing-extracted':\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,SAAS,iBAAoC;AAC7C,SAAS,4BAA4B;AACrC,SAAS,SAAS;AAClB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;;;ACKA,SAAS,iBAAiBA,UAAiB,aAAkC;AAClF,QAAM,OAAOA,SAAQ,QAAQ,OAAO,EAAE;AACtC,QAAM,aACJ,eAAe,YAAY,SAAS,IAChC,EAAE,eAAe,UAAU,WAAW,GAAG,IACzC,CAAC;AACP,SAAO;AAAA,IACL,MAAM,IAAO,MAA0B;AACrC,YAAM,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,IAAI,IAAI,EAAE,S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yB,EAAE,OAAO,EAAE,SAAS,iEAAiE;AAAA,IAC9G,SAAS,EAAE,OAAO,EAAE,SAAS,6DAA6D;AAAA,IAC1F,sBAAsB,EAAE,OAAO,EAAE,SAAS,6DAA6D;AAAA,IACvG,SAAS;AAAA,EACX;AAAA,EACA,OAAO,UAAU,oBAAoB,QAAQ,EAAE,GAAG,OAAO,SAAS,WAAW,KAAK,EAAE,CAAC;AACvF;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,IACE,SAAS,EAAE,OAAO,EAAE,SAAS,yDAAyD;AAAA,IACtF,SAAS;AAAA,EACX;AAAA,EACA,OAAO,UAAU,sBAAsB,QAAQ,EAAE,GAAG,OAAO,SAAS,WAAW,KAAK,EAAE,CAAC;AACzF;AAKA,IAAM,kBAAkB,QAAQ,IAAI,wBAChC,OAAO,QAAQ,IAAI,qBAAqB,IACxC;AACJ,IAAM,uBAAuB,kBAAkB,QAAQ,QAAQ;AAAA,EAC7D,GAAI,oBAAoB,SAAY,EAAE,gBAAgB,IAAI,CAAC;AAAA,EAC3D,GAAI,iBAAiB,EAAE,SAAS,eAAe,IAAI,CAAC;AACtD,CAAC;AAED,eAAe,OAAsB;AACnC,QAAM,YAAY,IAAI,qBAAqB;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":["baseUrl","client","server","client"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/base-url.ts","../src/client.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 { resolveBaseUrl } from './base-url.js'\nimport { createHttpClient } from './client.js'\nimport { registerResources } from './resources.js'\nimport {\n checkPolicies,\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 semanticSearch,\n} from './tools.js'\n\nconst baseUrl = resolveBaseUrl()\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 client = createHttpClient(baseUrl, authToken && authToken.length > 0 ? authToken : undefined)\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\nconst server = new McpServer({\n name: 'neat',\n version: '0.1.0',\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 downstream of 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 '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 or dry-run the project\\'s policy.json. Without hypotheticalAction, 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 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\nasync function main(): Promise<void> {\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\nexport function resolveBaseUrl(\n env: NodeJS.ProcessEnv = process.env,\n cwd: string = process.cwd(),\n): string {\n const override = env.NEAT_CORE_URL ?? env.NEAT_API_URL\n if (override) return override\n\n return resolveFromDaemonRecord(cwd) ?? DEFAULT_BASE_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// 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.\nexport function createHttpClient(baseUrl: string, bearerToken?: string): HttpClient {\n const root = baseUrl.replace(/\\/$/, '')\n const authHeader =\n bearerToken && bearerToken.length > 0\n ? { authorization: `Bearer ${bearerToken}` }\n : {}\n return {\n async get<T>(path: string): Promise<T> {\n const res = await fetch(`${root}${path}`, { headers: { ...authHeader } })\n if (!res.ok) {\n const body = await res.text().catch(() => '')\n throw new HttpError(res.status, `${res.status} ${res.statusText} on 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 fetch(`${root}${path}`, {\n method: 'POST',\n headers: { 'content-type': 'application/json', ...authHeader },\n body: JSON.stringify(body),\n })\n if (!res.ok) {\n const text = await res.text().catch(() => '')\n throw new HttpError(res.status, `${res.status} ${res.statusText} on 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","// 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 BlastRadiusAffectedNode,\n BlastRadiusResult,\n Divergence,\n DivergenceResult,\n DivergenceType,\n ErrorEvent,\n GraphEdge,\n GraphNode,\n HypotheticalAction,\n PolicyViolation,\n RootCauseResult,\n TransitiveDependenciesResult,\n} from '@neat.is/types'\nimport { Provenance } from '@neat.is/types'\nimport { HttpError, 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 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 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 downstream dependencies. 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} affected node${result.totalAffected === 1 ? '' : 's'} reachable downstream.`,\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\ninterface EdgesResponse {\n inbound: GraphEdge[]\n outbound: GraphEdge[]\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\nexport async function getObservedDependencies(\n client: HttpClient,\n input: DependenciesInput,\n): Promise<ToolResponse> {\n return withMissingNodeFallback(async () => {\n const edges = await client.get<EdgesResponse>(\n projectPath(input.project, `/graph/edges/${encodeURIComponent(input.nodeId)}`),\n )\n const observed = edges.outbound.filter((e) => e.provenance === Provenance.OBSERVED)\n if (observed.length === 0) {\n const hasExtracted = edges.outbound.some((e) => e.provenance === Provenance.EXTRACTED)\n const note = hasExtracted\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 = observed.map((e) => ` • ${e.target} — ${e.type}${edgeMeta(e)}`)\n return formatToolResponse({\n summary: `${input.nodeId} has ${observed.length} runtime dependenc${observed.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\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 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 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// ──────────────────────────────────────────────────────────────────────────\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 return ` • [${d.type}] ${d.source} → ${d.target} (${d.edgeType}) — confidence ${d.confidence.toFixed(2)}`\n case 'missing-extracted':\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,SAAS,iBAAoC;AAC7C,SAAS,4BAA4B;AACrC,SAAS,SAAS;AAClB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;;;ACOP,SAAS,oBAAoB;AAC7B,SAAS,SAAS,YAAY;AAE9B,IAAM,mBAAmB;AAiBzB,SAAS,wBAAwB,KAAiC;AAChE,MAAI,MAAM;AAGV,aAAS;AACP,UAAM,MAAM,iBAAiB,KAAK,KAAK,YAAY,aAAa,CAAC;AACjE,QAAI,QAAQ,OAA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SAAS,WAAW,KAAK,EAAE,CAAC;AACvF;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,IACE,SAAS,EAAE,OAAO,EAAE,SAAS,yDAAyD;AAAA,IACtF,SAAS;AAAA,EACX;AAAA,EACA,OAAO,UAAU,sBAAsB,QAAQ,EAAE,GAAG,OAAO,SAAS,WAAW,KAAK,EAAE,CAAC;AACzF;AAKA,IAAM,kBAAkB,QAAQ,IAAI,wBAChC,OAAO,QAAQ,IAAI,qBAAqB,IACxC;AACJ,IAAM,uBAAuB,kBAAkB,QAAQ,QAAQ;AAAA,EAC7D,GAAI,oBAAoB,SAAY,EAAE,gBAAgB,IAAI,CAAC;AAAA,EAC3D,GAAI,iBAAiB,EAAE,SAAS,eAAe,IAAI,CAAC;AACtD,CAAC;AAED,eAAe,OAAsB;AACnC,QAAM,YAAY,IAAI,qBAAqB;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":["baseUrl","client","server","client"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neat.is/mcp",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.18",
|
|
4
4
|
"description": "NEAT MCP server: exposes graph queries to AI agents over stdio",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"homepage": "https://neat.is",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
47
|
-
"@neat.is/types": "^0.4.
|
|
47
|
+
"@neat.is/types": "^0.4.18",
|
|
48
48
|
"zod": "^3.23.8"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|