@revealui/mcp 0.6.2 → 0.7.1

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.
@@ -0,0 +1,272 @@
1
+ /**
2
+ * Factory for the `knowledge-graph` MCP server (GAP-349 P2 — agent surfaces for
3
+ * the fleet knowledge graph; P1 shipped the schema + `@revealui/knowledge-graph`
4
+ * core in revealui#1858).
5
+ *
6
+ * Tools exposed:
7
+ * kg_search — hybrid retrieval (vector + FTS + BFS traversal, RRF-fused)
8
+ * kg_get_node — fetch a node + its current facts by natural key
9
+ * kg_neighbors — BFS neighbors of a node (current or point-in-time)
10
+ * kg_add_episode — THE ONLY WRITE TOOL. Additive ingestion (never a rescan).
11
+ * kg_path — shortest path between two nodes
12
+ * kg_at_time — a node's facts as of a point-in-time timestamp
13
+ * kg_context — budgeted context assembly (design spec §8.4): BFS from an
14
+ * anchor, rerank by node-distance + episode-mentions, pack
15
+ * node summaries + edge facts (with provenance episode ids)
16
+ * into a text block capped at `charBudget` characters.
17
+ *
18
+ * All tools operate over a `KgExecutor` (the driver-agnostic query interface
19
+ * `@revealui/knowledge-graph` already exposes for Neon-in-prod / PGlite-in-tests
20
+ * parity). Production resolves a pooled executor lazily from `@revealui/db/pool`
21
+ * (the same connection pattern `revkg`'s CLI uses — extend, not duplicate); tests
22
+ * inject a PGlite-backed executor via `CreateKnowledgeGraphServerOptions.executor`.
23
+ *
24
+ * Read tools degrade gracefully with no pgvector and no embeddings present:
25
+ * `kgSearch`'s vector channel is skipped whenever no query embedding is
26
+ * supplied, and query-embedding generation here is best-effort — an
27
+ * `@revealui/ai` import failure or an Ollama-down `generateEmbedding()` call
28
+ * both fall back to FTS + BFS only, never a hard failure.
29
+ *
30
+ * `kg_add_episode` is the only write tool. It always calls the additive
31
+ * `ingestEpisode` (never `applyScan`, which is the deterministic-rescan path
32
+ * reserved for `revkg scan`), Zod-validates `episodeType` plus every node kind
33
+ * and edge relation against the ontology enums, and accepts no raw SQL or
34
+ * table-name input of any kind.
35
+ */
36
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
37
+ import { type Embedder, type KgExecutor } from '@revealui/knowledge-graph';
38
+ import { z } from 'zod/v4';
39
+ export declare const KgSearchArgsSchema: z.ZodObject<{
40
+ query: z.ZodString;
41
+ anchor: z.ZodOptional<z.ZodString>;
42
+ kinds: z.ZodOptional<z.ZodArray<z.ZodEnum<{
43
+ symbol: "symbol";
44
+ file: "file";
45
+ skill: "skill";
46
+ agent: "agent";
47
+ dependency: "dependency";
48
+ rule: "rule";
49
+ repo: "repo";
50
+ package: "package";
51
+ app: "app";
52
+ "db-table": "db-table";
53
+ route: "route";
54
+ "mcp-tool": "mcp-tool";
55
+ hook: "hook";
56
+ gap: "gap";
57
+ lane: "lane";
58
+ adr: "adr";
59
+ "secret-path": "secret-path";
60
+ workflow: "workflow";
61
+ concept: "concept";
62
+ }>>>;
63
+ relations: z.ZodOptional<z.ZodArray<z.ZodEnum<{
64
+ blocks: "blocks";
65
+ exports: "exports";
66
+ contains: "contains";
67
+ imports: "imports";
68
+ "depends-on": "depends-on";
69
+ documents: "documents";
70
+ decides: "decides";
71
+ tracks: "tracks";
72
+ implements: "implements";
73
+ supersedes: "supersedes";
74
+ guards: "guards";
75
+ invokes: "invokes";
76
+ "stores-in": "stores-in";
77
+ syncs: "syncs";
78
+ mentions: "mentions";
79
+ discovered: "discovered";
80
+ "relates-to": "relates-to";
81
+ }>>>;
82
+ at: z.ZodOptional<z.ZodString>;
83
+ limit: z.ZodOptional<z.ZodNumber>;
84
+ bfsDepth: z.ZodOptional<z.ZodNumber>;
85
+ }, z.core.$strict>;
86
+ export declare const KgGetNodeArgsSchema: z.ZodObject<{
87
+ naturalKey: z.ZodString;
88
+ }, z.core.$strict>;
89
+ export declare const KgNeighborsArgsSchema: z.ZodObject<{
90
+ naturalKey: z.ZodString;
91
+ depth: z.ZodOptional<z.ZodNumber>;
92
+ relations: z.ZodOptional<z.ZodArray<z.ZodEnum<{
93
+ blocks: "blocks";
94
+ exports: "exports";
95
+ contains: "contains";
96
+ imports: "imports";
97
+ "depends-on": "depends-on";
98
+ documents: "documents";
99
+ decides: "decides";
100
+ tracks: "tracks";
101
+ implements: "implements";
102
+ supersedes: "supersedes";
103
+ guards: "guards";
104
+ invokes: "invokes";
105
+ "stores-in": "stores-in";
106
+ syncs: "syncs";
107
+ mentions: "mentions";
108
+ discovered: "discovered";
109
+ "relates-to": "relates-to";
110
+ }>>>;
111
+ at: z.ZodOptional<z.ZodString>;
112
+ }, z.core.$strict>;
113
+ export declare const KgAddEpisodeArgsSchema: z.ZodObject<{
114
+ episodeType: z.ZodEnum<{
115
+ json: "json";
116
+ manual: "manual";
117
+ "code-scan": "code-scan";
118
+ "git-commit": "git-commit";
119
+ doc: "doc";
120
+ "agent-fact": "agent-fact";
121
+ memory: "memory";
122
+ }>;
123
+ source: z.ZodString;
124
+ content: z.ZodOptional<z.ZodString>;
125
+ contentRef: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
126
+ referenceTime: z.ZodOptional<z.ZodString>;
127
+ siteId: z.ZodOptional<z.ZodString>;
128
+ nodes: z.ZodDefault<z.ZodArray<z.ZodObject<{
129
+ kind: z.ZodEnum<{
130
+ symbol: "symbol";
131
+ file: "file";
132
+ skill: "skill";
133
+ agent: "agent";
134
+ dependency: "dependency";
135
+ rule: "rule";
136
+ repo: "repo";
137
+ package: "package";
138
+ app: "app";
139
+ "db-table": "db-table";
140
+ route: "route";
141
+ "mcp-tool": "mcp-tool";
142
+ hook: "hook";
143
+ gap: "gap";
144
+ lane: "lane";
145
+ adr: "adr";
146
+ "secret-path": "secret-path";
147
+ workflow: "workflow";
148
+ concept: "concept";
149
+ }>;
150
+ name: z.ZodString;
151
+ naturalKey: z.ZodString;
152
+ repo: z.ZodOptional<z.ZodString>;
153
+ summary: z.ZodOptional<z.ZodString>;
154
+ attributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
155
+ }, z.core.$strict>>>;
156
+ edges: z.ZodDefault<z.ZodArray<z.ZodObject<{
157
+ source: z.ZodObject<{
158
+ kind: z.ZodEnum<{
159
+ symbol: "symbol";
160
+ file: "file";
161
+ skill: "skill";
162
+ agent: "agent";
163
+ dependency: "dependency";
164
+ rule: "rule";
165
+ repo: "repo";
166
+ package: "package";
167
+ app: "app";
168
+ "db-table": "db-table";
169
+ route: "route";
170
+ "mcp-tool": "mcp-tool";
171
+ hook: "hook";
172
+ gap: "gap";
173
+ lane: "lane";
174
+ adr: "adr";
175
+ "secret-path": "secret-path";
176
+ workflow: "workflow";
177
+ concept: "concept";
178
+ }>;
179
+ naturalKey: z.ZodString;
180
+ }, z.core.$strict>;
181
+ target: z.ZodObject<{
182
+ kind: z.ZodEnum<{
183
+ symbol: "symbol";
184
+ file: "file";
185
+ skill: "skill";
186
+ agent: "agent";
187
+ dependency: "dependency";
188
+ rule: "rule";
189
+ repo: "repo";
190
+ package: "package";
191
+ app: "app";
192
+ "db-table": "db-table";
193
+ route: "route";
194
+ "mcp-tool": "mcp-tool";
195
+ hook: "hook";
196
+ gap: "gap";
197
+ lane: "lane";
198
+ adr: "adr";
199
+ "secret-path": "secret-path";
200
+ workflow: "workflow";
201
+ concept: "concept";
202
+ }>;
203
+ naturalKey: z.ZodString;
204
+ }, z.core.$strict>;
205
+ relation: z.ZodEnum<{
206
+ blocks: "blocks";
207
+ exports: "exports";
208
+ contains: "contains";
209
+ imports: "imports";
210
+ "depends-on": "depends-on";
211
+ documents: "documents";
212
+ decides: "decides";
213
+ tracks: "tracks";
214
+ implements: "implements";
215
+ supersedes: "supersedes";
216
+ guards: "guards";
217
+ invokes: "invokes";
218
+ "stores-in": "stores-in";
219
+ syncs: "syncs";
220
+ mentions: "mentions";
221
+ discovered: "discovered";
222
+ "relates-to": "relates-to";
223
+ }>;
224
+ fact: z.ZodString;
225
+ repo: z.ZodOptional<z.ZodString>;
226
+ validAt: z.ZodOptional<z.ZodString>;
227
+ attributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
228
+ }, z.core.$strict>>>;
229
+ }, z.core.$strict>;
230
+ export declare const KgPathArgsSchema: z.ZodObject<{
231
+ fromNaturalKey: z.ZodString;
232
+ toNaturalKey: z.ZodString;
233
+ at: z.ZodOptional<z.ZodString>;
234
+ maxDepth: z.ZodOptional<z.ZodNumber>;
235
+ }, z.core.$strict>;
236
+ export declare const KgAtTimeArgsSchema: z.ZodObject<{
237
+ naturalKey: z.ZodString;
238
+ at: z.ZodString;
239
+ }, z.core.$strict>;
240
+ export declare const KgContextArgsSchema: z.ZodObject<{
241
+ naturalKey: z.ZodString;
242
+ charBudget: z.ZodOptional<z.ZodNumber>;
243
+ depth: z.ZodOptional<z.ZodNumber>;
244
+ at: z.ZodOptional<z.ZodString>;
245
+ }, z.core.$strict>;
246
+ export interface AssembledContext {
247
+ context: string;
248
+ anchor: {
249
+ id: string;
250
+ naturalKey: string;
251
+ };
252
+ nodeCount: number;
253
+ factCount: number;
254
+ charBudget: number;
255
+ charsUsed: number;
256
+ truncated: boolean;
257
+ }
258
+ export interface CreateKnowledgeGraphServerOptions {
259
+ /** Injected executor. Tests pass a PGlite-backed `KgExecutor`; production omits this and resolves lazily from `@revealui/db/pool`. */
260
+ executor?: KgExecutor;
261
+ /** Injected embedder. Tests can stub; production omits this and resolves lazily from `@revealui/ai/embeddings`, degrading to `undefined` (no vector channel) when unavailable. */
262
+ embedder?: Embedder;
263
+ /** siteId stamped on episodes ingested via `kg_add_episode`. Defaults to `os.hostname()`. */
264
+ siteId?: string;
265
+ }
266
+ /**
267
+ * Create a fresh `knowledge-graph` MCP Server instance. Safe to call multiple
268
+ * times — each call returns an independent Server with its own request
269
+ * handlers and its own lazily-resolved executor/embedder cache.
270
+ */
271
+ export declare function createKnowledgeGraphServer(options?: CreateKnowledgeGraphServerOptions): Server;
272
+ //# sourceMappingURL=knowledge-graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"knowledge-graph.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