@3ngram/server 1.3.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mcp/prompts.d.ts +5 -6
- package/dist/mcp/prompts.js +12 -10
- package/dist/mcp/prompts.js.map +1 -1
- package/dist/mcp/resources.js +4 -2
- package/dist/mcp/resources.js.map +1 -1
- package/dist/mcp/server.d.ts +1 -1
- package/dist/mcp/server.js +4 -2
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools-admin.js +61 -18
- package/dist/mcp/tools-admin.js.map +1 -1
- package/dist/mcp/tools-search.js +184 -83
- package/dist/mcp/tools-search.js.map +1 -1
- package/dist/mcp/tools.d.ts +4 -6
- package/dist/mcp/tools.js +43 -22
- package/dist/mcp/tools.js.map +1 -1
- package/dist/rest/route-helpers.d.ts +6 -1
- package/dist/rest/route-helpers.js +9 -0
- package/dist/rest/route-helpers.js.map +1 -1
- package/dist/rest/router.js +42 -13
- package/dist/rest/router.js.map +1 -1
- package/dist/rest/search-router.js +22 -8
- package/dist/rest/search-router.js.map +1 -1
- package/dist/routes/capabilities.js.map +1 -1
- package/package.json +4 -4
package/dist/mcp/tools-search.js
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
// (packages/schema Zod), call the COMPLETE core service (which runs withTenant
|
|
9
9
|
// internally), shape the structured result. A read -> requiredScope
|
|
10
10
|
// memory:read; runTool enforces the scope BEFORE the handler runs.
|
|
11
|
-
import { applyPolicyToScopeFilter, searchDashboardPage } from '@3ngram/core';
|
|
11
|
+
import { applyPolicyToScopeFilter, searchChronological, searchDashboardPage, } from '@3ngram/core';
|
|
12
12
|
import { MEMORY_READ_SCOPE } from '@3ngram/core/auth';
|
|
13
|
-
import {
|
|
13
|
+
import { searchQueryV4Schema, searchToolOutputV3Schema, } from '@3ngram/schema';
|
|
14
14
|
import { decodeSearchCursor, encodeCursor, searchFingerprint } from '../cursor.js';
|
|
15
15
|
import { parseOutput } from '../output-validation.js';
|
|
16
16
|
import { READ_ONLY_ANNOTATIONS } from './tool-annotations.js';
|
|
@@ -72,7 +72,13 @@ function toFilters(input) {
|
|
|
72
72
|
* the interesting ids with get_memories.
|
|
73
73
|
*/
|
|
74
74
|
function projectHit(hit, projection) {
|
|
75
|
-
const compact = {
|
|
75
|
+
const compact = {
|
|
76
|
+
id: hit.id,
|
|
77
|
+
memoryType: hit.memoryType,
|
|
78
|
+
topic: hit.topic,
|
|
79
|
+
score: hit.score,
|
|
80
|
+
superseded: hit.superseded,
|
|
81
|
+
};
|
|
76
82
|
if (projection === 'compact')
|
|
77
83
|
return compact;
|
|
78
84
|
return {
|
|
@@ -83,51 +89,186 @@ function projectHit(hit, projection) {
|
|
|
83
89
|
};
|
|
84
90
|
}
|
|
85
91
|
/**
|
|
86
|
-
* search
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* `cursor` (opaque frozen-ordering token) + `projection` (full/compact). Each
|
|
94
|
-
* filter NARROWS the candidate set BEFORE fusion; none alters the fusion
|
|
95
|
-
* weights or the supersession ranking (docs/concepts/memory-model.mdx
|
|
96
|
-
* live-first stays the default). The tool registers the FULL `.strict()`
|
|
97
|
-
* object (not its raw shape), so the SDK parses inbound args strictly at the
|
|
98
|
-
* transport boundary and an UNKNOWN key is REJECTED there — never silently
|
|
99
|
-
* dropped.
|
|
100
|
-
*
|
|
101
|
-
* PAGINATION routes through the SAME frozen-ordering machinery the dashboard
|
|
102
|
-
* uses (core searchDashboardPage + the shared ../cursor.js codec): page 1 ranks
|
|
103
|
-
* the bounded candidate pool once and freezes the ordering into `nextCursor`;
|
|
104
|
-
* a continuation pages BY POSITION within it (fetchHitsByIds), immune to
|
|
105
|
-
* duplicate/skip under mid-walk corpus drift. Page-1 ranking is identical to
|
|
106
|
-
* the pre-cursor path (returnFullPool ranks the same pool), so the eval floors
|
|
107
|
-
* are untouched. A garbled cursor throws a ZodError -> runTool's ladder labels
|
|
108
|
-
* it invalid input (never a 500); a stale pre-v2 cursor decodes to undefined
|
|
109
|
-
* and restarts at page 1. The cursor is BOUND to the query+filters that issued
|
|
92
|
+
* Ranked (relevance-order) search: the shipped fused-retrieval path, byte-
|
|
93
|
+
* compatible with the pre-V4 tool behavior. PAGINATION routes through the
|
|
94
|
+
* SAME frozen-ordering machinery the dashboard uses (core searchDashboardPage
|
|
95
|
+
* + the shared ../cursor.js codec): page 1 ranks the bounded candidate pool
|
|
96
|
+
* once and freezes the ordering into `nextCursor`; a continuation pages BY
|
|
97
|
+
* POSITION within it (fetchHitsByIds), immune to duplicate/skip under
|
|
98
|
+
* mid-walk corpus drift. The cursor is BOUND to the query+filters that issued
|
|
110
99
|
* it (the shared codec's fingerprint, verified in decodeSearchCursor): a
|
|
111
|
-
* continuation under a CHANGED query/filters is a typed
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
100
|
+
* continuation under a CHANGED query/filters is a typed CursorQueryMismatchError
|
|
101
|
+
* -> invalid_input, never a silent re-page of the old search's frozen
|
|
102
|
+
* ordering. Fingerprint-less cursors minted before the binding stay valid
|
|
103
|
+
* (verify-when-present); the fingerprint computation here is BYTE-IDENTICAL
|
|
104
|
+
* to the pre-V4 tool (no `order` folded in), so a cursor minted before
|
|
105
|
+
* chronological order existed keeps verifying.
|
|
106
|
+
*/
|
|
107
|
+
async function handleRelevanceSearch(input, filters, policyScope, retrievalPolicy, ctx) {
|
|
108
|
+
if (ctx.gateway === undefined) {
|
|
109
|
+
return fail('embedding gateway not configured');
|
|
110
|
+
}
|
|
111
|
+
const fingerprint = searchFingerprint(input.query, filters, policyScope.scope, policyScope.appliedScope !== null);
|
|
112
|
+
const decodedRaw = input.cursor === undefined ? undefined : decodeSearchCursor(input.cursor, fingerprint);
|
|
113
|
+
// Relevance (ranked) search only ever mints/consumes the v2 frozen-ordering
|
|
114
|
+
// cursor — the v3 chronological keyset cursor belongs to order:
|
|
115
|
+
// 'chronological' only. A well-formed v3 token is NEVER reachable here at
|
|
116
|
+
// all: cursorPayloadV3Schema requires `fp` (packages/schema/src/cursor.ts —
|
|
117
|
+
// v3 has no legacy fp-less tokens to carve out, unlike v2), so
|
|
118
|
+
// decodeSearchCursor above has ALREADY thrown a typed mismatch for any real
|
|
119
|
+
// v3 token (its fingerprint folds in `order: 'chronological'`, which a
|
|
120
|
+
// relevance fingerprint never does, so the hashes can never coincidentally
|
|
121
|
+
// collide). This shape guard is therefore UNREACHABLE for any cursor that
|
|
122
|
+
// successfully decodes — it stays purely as defense in depth (the same
|
|
123
|
+
// two-layer posture this codebase applies elsewhere) against a malformed or
|
|
124
|
+
// hand-crafted v3-shaped payload reaching this line: without it, `.ids`/
|
|
125
|
+
// `.scores` below would read as `undefined` off the wrong shape instead of
|
|
126
|
+
// restarting cleanly at page 1.
|
|
127
|
+
const decoded = decodedRaw !== undefined && decodedRaw.v === 2 ? decodedRaw : undefined;
|
|
128
|
+
const frozen = decoded === undefined
|
|
129
|
+
? undefined
|
|
130
|
+
: {
|
|
131
|
+
ids: decoded.ids,
|
|
132
|
+
scores: decoded.scores,
|
|
133
|
+
off: decoded.off,
|
|
134
|
+
...(decoded.policyScope === undefined ? {} : { policyScope: decoded.policyScope }),
|
|
135
|
+
};
|
|
136
|
+
const page = await searchDashboardPage(ctx.userId, input.query, { gateway: ctx.gateway }, defined({
|
|
137
|
+
limit: input.limit,
|
|
138
|
+
filters,
|
|
139
|
+
frozen,
|
|
140
|
+
budget: ctx.budget,
|
|
141
|
+
retrievalPolicy,
|
|
142
|
+
}));
|
|
143
|
+
// Emit a cursor ONLY when a further page exists (searchToolOutputV2Schema
|
|
144
|
+
// ENFORCES nextCursor <-> hasMore, so a drifting pair can never ship).
|
|
145
|
+
const nextCursor = page.hasMore
|
|
146
|
+
? encodeCursor({
|
|
147
|
+
v: 2,
|
|
148
|
+
ids: page.frozen.ids,
|
|
149
|
+
scores: page.frozen.scores,
|
|
150
|
+
off: page.nextOffset,
|
|
151
|
+
fp: fingerprint,
|
|
152
|
+
policyScope: page.frozen.policyScope,
|
|
153
|
+
})
|
|
154
|
+
: undefined;
|
|
155
|
+
const output = parseOutput('search', searchToolOutputV3Schema, defined({
|
|
156
|
+
hits: page.hits.map((hit) => projectHit(hit, input.projection)),
|
|
157
|
+
count: page.hits.length,
|
|
158
|
+
hasMore: page.hasMore,
|
|
159
|
+
nextCursor,
|
|
160
|
+
// Present exactly when the policy narrowed this call (never silent);
|
|
161
|
+
// omitted otherwise so an off/no-policy response stays byte-identical.
|
|
162
|
+
appliedScope: page.appliedScope ?? undefined,
|
|
163
|
+
}));
|
|
164
|
+
return ok(output);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Chronological (list-mode) search: an exhaustive, unranked recorded_at DESC
|
|
168
|
+
* enumeration (packages/core/src/read/search-list.ts). Skips the embedding
|
|
169
|
+
* gateway ENTIRELY — no gateway call, no query-embed cost row — and skips the
|
|
170
|
+
* abstention path by construction: nothing here ever reads `vectorScore`
|
|
171
|
+
* (that field only exists on the ranked path's hits), so there is no cosine
|
|
172
|
+
* signal to abstain on.
|
|
173
|
+
*
|
|
174
|
+
* The v3 keyset cursor (recordedAt, id) is DRIFT-FREE, unlike the ranked
|
|
175
|
+
* path's frozen-pool cursor, so it needs no frozen candidate set — tiny by
|
|
176
|
+
* comparison. `recordedAt` is OPAQUE full-precision text, never a JS `Date`
|
|
177
|
+
* (packages/db/src/search-list.ts's ChronologicalCursor doc: a `Date` cannot
|
|
178
|
+
* represent Postgres's microsecond resolution, and truncating it can silently
|
|
179
|
+
* strand rows that tie on a same-transaction timestamp). Its fingerprint
|
|
180
|
+
* folds `order: 'chronological'` into the hashed filter set, which the ranked
|
|
181
|
+
* path's fingerprint (byte-identical to pre-V4) does NOT do — so a v2
|
|
182
|
+
* (ranked) cursor carrying `fp`, replayed here, is REJECTED as a typed
|
|
183
|
+
* CursorQueryMismatchError (invalid_input) by decodeSearchCursor, never
|
|
184
|
+
* silently misread. Only a fingerprint-LESS LEGACY v2 token (pre-binding,
|
|
185
|
+
* before `fp` existed) skips that check and reaches the shape guard below —
|
|
186
|
+
* v3 has no fp-less analogue, since `fp` is REQUIRED on cursorPayloadV3Schema
|
|
187
|
+
* (packages/schema/src/cursor.ts: v3 is introduced in this same change, so no
|
|
188
|
+
* legacy fp-less v3 token has ever legitimately existed).
|
|
189
|
+
*/
|
|
190
|
+
async function handleChronologicalSearch(input, filters, policyScope, retrievalPolicy, ctx) {
|
|
191
|
+
const fingerprint = searchFingerprint(
|
|
192
|
+
// PINNED EMPTY, not `input.query ?? ''`: the V4 chronological variant
|
|
193
|
+
// REJECTS a present `query` at the schema boundary, so nothing can reach
|
|
194
|
+
// here with one. Reading the field would imply a query leg this ordering
|
|
195
|
+
// does not have and would let a fingerprint vary on an input that cannot
|
|
196
|
+
// exist — the constant keeps the hashed identity exactly the filter set.
|
|
197
|
+
'', { ...filters, order: 'chronological' }, policyScope.scope, policyScope.appliedScope !== null);
|
|
198
|
+
const decodedRaw = input.cursor === undefined ? undefined : decodeSearchCursor(input.cursor, fingerprint);
|
|
199
|
+
// UNLIKE the relevance handler's symmetric guard, this shape check IS
|
|
200
|
+
// reachable in a legitimate case: a fingerprint-LESS LEGACY v2 token
|
|
201
|
+
// (minted before `fp` existed) skips decodeSearchCursor's mismatch check
|
|
202
|
+
// entirely (verify-when-present) and reaches here with `v: 2` — `decoded`
|
|
203
|
+
// correctly resolves to undefined (restart at page 1) rather than
|
|
204
|
+
// misreading a v2 payload's `ids`/`scores` shape as `recordedAt`/`id`. A
|
|
205
|
+
// well-formed v3 token can never reach this branch already-mismatched: `fp`
|
|
206
|
+
// is required on it (packages/schema/src/cursor.ts), so any real v3 token
|
|
207
|
+
// either matches (falls through, `v: 3`) or was already rejected above.
|
|
208
|
+
const decoded = decodedRaw !== undefined && decodedRaw.v === 3 ? decodedRaw : undefined;
|
|
209
|
+
// recordedAt is OPAQUE full-precision text end to end — NEVER parsed
|
|
210
|
+
// through `new Date()` here, which would floor it to millisecond precision
|
|
211
|
+
// and could silently re-admit rows a same-transaction batch insert already
|
|
212
|
+
// returned (see db/search-list.ts's ChronologicalCursor doc for the full
|
|
213
|
+
// mechanism this must not reintroduce).
|
|
214
|
+
const cursor = decoded === undefined ? undefined : { recordedAt: decoded.recordedAt, id: decoded.id };
|
|
215
|
+
const page = await searchChronological(ctx.userId, defined({
|
|
216
|
+
limit: input.limit,
|
|
217
|
+
filters,
|
|
218
|
+
cursor,
|
|
219
|
+
retrievalPolicy,
|
|
220
|
+
}));
|
|
221
|
+
const nextCursor = page.hasMore && page.nextCursor !== undefined
|
|
222
|
+
? encodeCursor({
|
|
223
|
+
v: 3,
|
|
224
|
+
recordedAt: page.nextCursor.recordedAt,
|
|
225
|
+
id: page.nextCursor.id,
|
|
226
|
+
fp: fingerprint,
|
|
227
|
+
})
|
|
228
|
+
: undefined;
|
|
229
|
+
const output = parseOutput('search', searchToolOutputV3Schema, defined({
|
|
230
|
+
hits: page.hits.map((hit) => projectHit(hit, input.projection)),
|
|
231
|
+
count: page.hits.length,
|
|
232
|
+
hasMore: page.hasMore,
|
|
233
|
+
nextCursor,
|
|
234
|
+
appliedScope: page.appliedScope ?? undefined,
|
|
235
|
+
}));
|
|
236
|
+
return ok(output);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* search — unified fused retrieval (docs/concepts/mcp-design.mdx JTBD "find what I know"),
|
|
240
|
+
* plus an exhaustive chronological list mode. The input contract is the V4
|
|
241
|
+
* composition ({@link searchQueryV4Schema}, hard rule 2): query + limit, the
|
|
242
|
+
* candidate-narrowing filters (V1 memoryType/scope/project/status/asOf + V2
|
|
243
|
+
* memoryTypes[]/recordedAfter/recordedBefore), the continuation pair —
|
|
244
|
+
* `cursor` (opaque token) + `projection` (full/compact) — and `order`
|
|
245
|
+
* (relevance default | chronological). Each filter NARROWS the candidate set
|
|
246
|
+
* BEFORE fusion/ordering; none alters the fusion weights or the supersession
|
|
247
|
+
* ranking (docs/concepts/memory-model.mdx live-first stays the default). The
|
|
248
|
+
* tool registers the FULL `.strict()` object (not its raw shape), so the SDK
|
|
249
|
+
* parses inbound args strictly at the transport boundary and an UNKNOWN key
|
|
250
|
+
* is REJECTED there — never silently dropped.
|
|
251
|
+
*
|
|
252
|
+
* `order: 'relevance'` (default) requires a gateway-configured embedding
|
|
253
|
+
* source and a `query`; `order: 'chronological'` requires NEITHER — it never
|
|
254
|
+
* calls the gateway, and it REJECTS a `query` outright (this path ranks
|
|
255
|
+
* nothing, so a query could only be ignored) while requiring >=1 filter to
|
|
256
|
+
* bound the scan. The two orders mint DIFFERENT cursor shapes (see
|
|
257
|
+
* {@link handleRelevanceSearch} / {@link handleChronologicalSearch}); each
|
|
258
|
+
* rejects/restarts on the other's cursor rather than misreading it.
|
|
115
259
|
*/
|
|
116
260
|
const searchTool = {
|
|
117
261
|
name: 'search',
|
|
118
262
|
requiredScope: MEMORY_READ_SCOPE,
|
|
119
263
|
config: {
|
|
120
264
|
title: 'Search',
|
|
121
|
-
description: 'Unified semantic + keyword retrieval over your memories, supersession-aware. Accepts a query and an optional result limit, plus optional filters that narrow the candidate set BEFORE fusion (no change to ranking weights): memoryType OR memoryTypes (a list of types, mutually exclusive with memoryType), scope, project, status, asOf (bi-temporal time travel with validAt/asKnownAt), and recordedAfter/recordedBefore (an inclusive recorded-at range over the live view — not time travel). Omit a filter to leave that axis unconstrained. If a retrieval-scope policy is set (configure_scope set_retrieval_default), an unscoped search may be narrowed to your default scope (the result then reports appliedScope) or rejected until you pass a scope filter. Hit content is a bounded excerpt — when a hit reports truncated: true, call get_memories with its id to read the full content. To page: pass nextCursor back as cursor with the SAME query and
|
|
122
|
-
inputSchema:
|
|
265
|
+
description: 'Unified semantic + keyword retrieval over your memories, supersession-aware. Accepts a query and an optional result limit, plus optional filters that narrow the candidate set BEFORE fusion (no change to ranking weights): memoryType OR memoryTypes (a list of types, mutually exclusive with memoryType), scope, project, status, asOf (bi-temporal time travel with validAt/asKnownAt), and recordedAfter/recordedBefore (an inclusive recorded-at range over the live view — not time travel). Omit a filter to leave that axis unconstrained. Set order: "chronological" for an exhaustive, unranked recorded_at-descending listing instead of the fused ranking — no embedding call, no gateway required; query is RELEVANCE-ONLY and is rejected in chronological order (that mode ranks nothing, so a query could only be ignored), and chronological instead REQUIRES at least one filter to bound the scan. Default order "relevance" is the fused ranked search and still requires a query. If a retrieval-scope policy is set (configure_scope set_retrieval_default), an unscoped search may be narrowed to your default scope (the result then reports appliedScope) or rejected until you pass a scope filter. Hit content is a bounded excerpt — when a hit reports truncated: true, call get_memories with its id to read the full content. Superseded predecessors are never filtered out, only ranked below their successor — a hit reports superseded: true when it is one, so you can tell a demoted result from a current one; superseded is recomputed live on every page (including continuations of a frozen relevance walk), so a hit\'s rank and score stay frozen across pages of one walk but its superseded flag can still flip if it is revised mid-session. To page: pass nextCursor back as cursor with the SAME query, filters, and order; pages come from the ordering frozen (relevance) or the keyset position (chronological) on the first page, so a mid-walk write or archive can never duplicate or skip a hit. The cursor is bound to the query, filters, and order that issued it: passing it with any of those changed is rejected as invalid input — omit the cursor to start a new search. The relevance cursor token is a real context cost (~4-6 KB — it carries the frozen ids+scores of the candidate pool); the chronological cursor is tiny (a single row position) by comparison. Paging stops at the frozen pool (relevance) or the live corpus (chronological): hasMore: false means there is nothing more to page to. For broad scans set projection: "compact" to omit content/contentLength/truncated per hit (~5x fewer tokens), then batch-fetch the interesting ids with get_memories.',
|
|
266
|
+
inputSchema: searchQueryV4Schema,
|
|
123
267
|
outputSchema: searchToolOutputV3Schema,
|
|
124
268
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
125
269
|
},
|
|
126
270
|
async handler(args, ctx) {
|
|
127
|
-
|
|
128
|
-
return fail('embedding gateway not configured');
|
|
129
|
-
}
|
|
130
|
-
const input = searchQueryV3Schema.parse(args);
|
|
271
|
+
const input = searchQueryV4Schema.parse(args);
|
|
131
272
|
const filters = toFilters(input);
|
|
132
273
|
// Assert platform read access before policy resolution performs its tenant
|
|
133
274
|
// lookup. The core call is therefore not given the gate a second time.
|
|
@@ -136,54 +277,14 @@ const searchTool = {
|
|
|
136
277
|
// RETRIEVAL-SCOPE POLICY (issue #47): resolved at most once per request
|
|
137
278
|
// (the route's memoized thunk) and INJECTED into core, which owns the
|
|
138
279
|
// enforcement (default fills a missing scope filter; require throws the
|
|
139
|
-
// typed UnscopedRetrievalError mapped by errors.ts).
|
|
280
|
+
// typed UnscopedRetrievalError mapped by errors.ts). Shared across both
|
|
281
|
+
// order branches so neither pays a second lookup.
|
|
140
282
|
const retrievalPolicy = ctx.retrievalPolicy === undefined ? undefined : await ctx.retrievalPolicy();
|
|
141
283
|
const policyScope = applyPolicyToScopeFilter(retrievalPolicy, filters.scope);
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
// (mapped to invalid_input), never silently paging the old frozen ids.
|
|
147
|
-
// Fingerprint-less cursors stay valid (verify-when-present).
|
|
148
|
-
const fingerprint = searchFingerprint(input.query, filters, policyScope.scope, policyScope.appliedScope !== null);
|
|
149
|
-
const decoded = input.cursor === undefined ? undefined : decodeSearchCursor(input.cursor, fingerprint);
|
|
150
|
-
const frozen = decoded === undefined
|
|
151
|
-
? undefined
|
|
152
|
-
: {
|
|
153
|
-
ids: decoded.ids,
|
|
154
|
-
scores: decoded.scores,
|
|
155
|
-
off: decoded.off,
|
|
156
|
-
...(decoded.policyScope === undefined ? {} : { policyScope: decoded.policyScope }),
|
|
157
|
-
};
|
|
158
|
-
const page = await searchDashboardPage(ctx.userId, input.query, { gateway: ctx.gateway }, defined({
|
|
159
|
-
limit: input.limit,
|
|
160
|
-
filters,
|
|
161
|
-
frozen,
|
|
162
|
-
budget: ctx.budget,
|
|
163
|
-
retrievalPolicy,
|
|
164
|
-
}));
|
|
165
|
-
// Emit a cursor ONLY when a further page exists (searchToolOutputV2Schema
|
|
166
|
-
// ENFORCES nextCursor <-> hasMore, so a drifting pair can never ship).
|
|
167
|
-
const nextCursor = page.hasMore
|
|
168
|
-
? encodeCursor({
|
|
169
|
-
v: 2,
|
|
170
|
-
ids: page.frozen.ids,
|
|
171
|
-
scores: page.frozen.scores,
|
|
172
|
-
off: page.nextOffset,
|
|
173
|
-
fp: fingerprint,
|
|
174
|
-
policyScope: page.frozen.policyScope,
|
|
175
|
-
})
|
|
176
|
-
: undefined;
|
|
177
|
-
const output = parseOutput('search', searchToolOutputV3Schema, defined({
|
|
178
|
-
hits: page.hits.map((hit) => projectHit(hit, input.projection)),
|
|
179
|
-
count: page.hits.length,
|
|
180
|
-
hasMore: page.hasMore,
|
|
181
|
-
nextCursor,
|
|
182
|
-
// Present exactly when the policy narrowed this call (never silent);
|
|
183
|
-
// omitted otherwise so an off/no-policy response stays byte-identical.
|
|
184
|
-
appliedScope: page.appliedScope ?? undefined,
|
|
185
|
-
}));
|
|
186
|
-
return ok(output);
|
|
284
|
+
if (input.order === 'chronological') {
|
|
285
|
+
return handleChronologicalSearch(input, filters, policyScope, retrievalPolicy, ctx);
|
|
286
|
+
}
|
|
287
|
+
return handleRelevanceSearch(input, filters, policyScope, retrievalPolicy, ctx);
|
|
187
288
|
},
|
|
188
289
|
};
|
|
189
290
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools-search.js","sourceRoot":"","sources":["../../src/mcp/tools-search.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,8EAA8E;AAC9E,4EAA4E;AAC5E,+EAA+E;AAC/E,uCAAuC;AACvC,EAAE;AACF,yEAAyE;AACzE,+EAA+E;AAC/E,oEAAoE;AACpE,mEAAmE;AACnE,OAAO,
|
|
1
|
+
{"version":3,"file":"tools-search.js","sourceRoot":"","sources":["../../src/mcp/tools-search.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,8EAA8E;AAC9E,4EAA4E;AAC5E,+EAA+E;AAC/E,uCAAuC;AACvC,EAAE;AACF,yEAAyE;AACzE,+EAA+E;AAC/E,oE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GAAG,CAAC,eAAe,EAAE,CAAA;QAC7E,MAAM,WAAW,GAAG,wBAAwB,CAAC,eAAe,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;QAE5E,IAAI,KAAK,CAAC,KAAK,KAAK,eAAe,EAAE,CAAC;YACpC,OAAO,yBAAyB,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,GAAG,CAAC,CAAA;QACrF,CAAC;QACD,OAAO,qBAAqB,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,GAAG,CAAC,CAAA;IACjF,CAAC;CACF,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAA8B,CAAC,UAAU,CAAC,CAAA"}
|
package/dist/mcp/tools.d.ts
CHANGED
|
@@ -86,10 +86,10 @@ export interface ToolContext {
|
|
|
86
86
|
retrievalPolicy?: (() => Promise<RetrievalPolicy>) | undefined;
|
|
87
87
|
}
|
|
88
88
|
/**
|
|
89
|
-
* THE registered tool surface. Length === registered count
|
|
90
|
-
* rule 8)
|
|
91
|
-
*
|
|
92
|
-
*
|
|
89
|
+
* THE registered tool surface. Length === registered count, auditable from this
|
|
90
|
+
* one array (hard rule 8). D0: 3; D1 adds revise + resolve -> 5; D2 orient
|
|
91
|
+
* (briefing, handoff) -> 7; D3 admin (configure_scope, describe_environment,
|
|
92
|
+
* review_proposals) -> 10; get_memories (inspect) -> 11.
|
|
93
93
|
*
|
|
94
94
|
* The admin tools are created via a FACTORY given a thunk over {@link TOOLS}, so
|
|
95
95
|
* describe_environment can report the FULL surface (itself included) without a
|
|
@@ -97,8 +97,6 @@ export interface ToolContext {
|
|
|
97
97
|
* time, long after this assignment completes.
|
|
98
98
|
*/
|
|
99
99
|
export declare const TOOLS: readonly ToolDefinition[];
|
|
100
|
-
/** Hard ceiling per docs/concepts/mcp-design.mdx / hard rule 8. LEDGER: 11/12 registered; the LAST slot is reserved for the future `manage_context` tool. */
|
|
101
|
-
export declare const MAX_TOOLS = 12;
|
|
102
100
|
/**
|
|
103
101
|
* Run a tool handler with uniform metrics + typed-error mapping. A KNOWN typed
|
|
104
102
|
* core error (bad input, missing embedding source) becomes an isError result
|
package/dist/mcp/tools.js
CHANGED
|
@@ -6,10 +6,14 @@
|
|
|
6
6
|
// every core call (which runs withTenant internally) — a tool can only ever
|
|
7
7
|
// touch the caller's own rows (hard rule 3).
|
|
8
8
|
//
|
|
9
|
-
// TOOL-
|
|
10
|
-
// TOOLS} array is the auditable surface — its length IS the registered
|
|
11
|
-
// count.
|
|
12
|
-
//
|
|
9
|
+
// TOOL-SURFACE DISCIPLINE (docs/concepts/mcp-design.mdx, hard rule 8): the single
|
|
10
|
+
// {@link TOOLS} array is the auditable surface — its length IS the registered
|
|
11
|
+
// tool count. There is no numeric ceiling: what a count was ever a proxy for is
|
|
12
|
+
// selection accuracy and description overlap, and those are now MEASURED and
|
|
13
|
+
// gated by eval/src/tool-selection.mjs against eval/fixtures/floors.json. Adding
|
|
14
|
+
// a tool requires a JTBD no existing tool covers, a regenerated surface snapshot,
|
|
15
|
+
// and scenarios in eval/fixtures/tool-selection.json that cover it — a tool whose
|
|
16
|
+
// description blurs into a neighbour's fails the gate.
|
|
13
17
|
//
|
|
14
18
|
// Observability (hard rule 6): no memory content, query text, subject/value, or
|
|
15
19
|
// credential enters a log. A tool error returns a typed isError result to the
|
|
@@ -17,7 +21,7 @@
|
|
|
17
21
|
import { log, mcpToolCalls, mcpToolErrors } from '@3ngram/config';
|
|
18
22
|
import { getFacts, remember, resolveByMemoryId, revise, } from '@3ngram/core';
|
|
19
23
|
import { MEMORY_READ_SCOPE, MEMORY_WRITE_SCOPE } from '@3ngram/core/auth';
|
|
20
|
-
import {
|
|
24
|
+
import { factsQueryInputV2Schema, factsToolOutputSchema, MAX_CONTENT_LENGTH, rememberToolInputV2Schema, rememberToolOutputV2Schema, resolveToolInputSchema, resolveToolOutputSchema, reviseToolInputSchema, reviseToolOutputSchema, } from '@3ngram/schema';
|
|
21
25
|
import { parseOutput } from '../output-validation.js';
|
|
22
26
|
import { mapToolError } from './errors.js';
|
|
23
27
|
import { READ_ONLY_ANNOTATIONS } from './tool-annotations.js';
|
|
@@ -81,6 +85,12 @@ function toAsOf(asOf) {
|
|
|
81
85
|
return undefined;
|
|
82
86
|
return defined({ validAt: toDate(asOf.validAt), asKnownAt: toDate(asOf.asKnownAt) });
|
|
83
87
|
}
|
|
88
|
+
/** Coerce a range's optional ISO-8601 bounds to Dates for the bi-temporal core query (range read). */
|
|
89
|
+
function toRange(range) {
|
|
90
|
+
if (range === undefined)
|
|
91
|
+
return undefined;
|
|
92
|
+
return defined({ from: toDate(range.from), to: toDate(range.to) });
|
|
93
|
+
}
|
|
84
94
|
/**
|
|
85
95
|
* remember — append a memory (docs/concepts/mcp-design.mdx JTBD "persist something worth
|
|
86
96
|
* keeping"). Validates via the canonical write schema, calls core remember()
|
|
@@ -96,9 +106,9 @@ const rememberTool = {
|
|
|
96
106
|
requiredScope: MEMORY_WRITE_SCOPE,
|
|
97
107
|
config: {
|
|
98
108
|
title: 'Remember',
|
|
99
|
-
description: `Append a new memory (decision, fact, preference, blocker, commitment, ...). Never merges; append-only. Content is capped at ${MAX_CONTENT_LENGTH} characters. To surface a commitment or blocker in a PROJECT-scoped briefing, pass \`project\` — a memory written with a NULL project never matches the bare project selector; only the scope_project selector's includeUnscoped: true opts it back in.`,
|
|
100
|
-
inputSchema:
|
|
101
|
-
outputSchema:
|
|
109
|
+
description: `Append a new memory (decision, fact, preference, blocker, commitment, ...). Never merges; append-only. Content is capped at ${MAX_CONTENT_LENGTH} characters. To surface a commitment or blocker in a PROJECT-scoped briefing, pass \`project\` — a memory written with a NULL project never matches the bare project selector; only the scope_project selector's includeUnscoped: true opts it back in. Optionally pass \`facts\`: the measurable claims the memory states, as subject/predicate/value triples that \`get_facts\` can then read back directly instead of re-reading the prose. Values are text, so put the unit in the predicate and keep one measure per fact (subject \`lift.back_squat\`, predicate \`top_set.weight_kg\`, value \`98\`). Give a fact a \`validFrom\` when it became true, if that is not now.`,
|
|
110
|
+
inputSchema: rememberToolInputV2Schema,
|
|
111
|
+
outputSchema: rememberToolOutputV2Schema,
|
|
102
112
|
// Appends a NEW row on every call, so repeating it is not a no-op —
|
|
103
113
|
// idempotentHint: false. destructiveHint: false is a real product claim:
|
|
104
114
|
// remember never merges into or overwrites an existing memory (hard rule 1).
|
|
@@ -114,7 +124,7 @@ const rememberTool = {
|
|
|
114
124
|
// It returns the new id only, so the structured output echoes the NORMALIZED
|
|
115
125
|
// write input (scope default + null project applied here) for the rest.
|
|
116
126
|
// Embedding is on iff a gateway is configured — best-effort, never blocks.
|
|
117
|
-
const input =
|
|
127
|
+
const input = rememberToolInputV2Schema.parse(args);
|
|
118
128
|
const gatewayOpts = ctx.gateway === undefined
|
|
119
129
|
? { access: ctx.access, limits: ctx.limits }
|
|
120
130
|
: { gateway: ctx.gateway, budget: ctx.budget, access: ctx.access, limits: ctx.limits };
|
|
@@ -132,7 +142,7 @@ const rememberTool = {
|
|
|
132
142
|
// A commitment-type memory auto-creates an 'open' commitment in the same
|
|
133
143
|
// write tx; surface its id so the caller can `resolve`
|
|
134
144
|
// it without a follow-up lookup. Undefined (omitted) for every other type.
|
|
135
|
-
const output = parseOutput('remember',
|
|
145
|
+
const output = parseOutput('remember', rememberToolOutputV2Schema, defined({
|
|
136
146
|
memory: {
|
|
137
147
|
id: written.id,
|
|
138
148
|
memoryType: input.memoryType,
|
|
@@ -142,28 +152,39 @@ const rememberTool = {
|
|
|
142
152
|
},
|
|
143
153
|
embedded,
|
|
144
154
|
commitmentId: written.commitmentId,
|
|
155
|
+
// Ids only, and only when facts were written: `defined()` drops the key
|
|
156
|
+
// when undefined, so a write without facts returns the V1 response
|
|
157
|
+
// byte-for-byte. The triples themselves are memory content and are not
|
|
158
|
+
// echoed back (hard rule 6).
|
|
159
|
+
factIds: written.factIds,
|
|
145
160
|
}));
|
|
146
161
|
return ok(output);
|
|
147
162
|
},
|
|
148
163
|
};
|
|
149
164
|
/**
|
|
150
165
|
* get_facts — currently-valid facts for a subject, bi-temporally (docs/concepts/mcp-design.mdx
|
|
151
|
-
* JTBD "what is currently true about X")
|
|
152
|
-
*
|
|
153
|
-
*
|
|
166
|
+
* JTBD "what is currently true about X"), OR a chronological time-series read
|
|
167
|
+
* across a valid-time window (`range`). Calls core getFacts() with the
|
|
168
|
+
* subject/predicate filters and either the as_of coordinates or the range
|
|
169
|
+
* bounds (ISO strings coerced to Date at this boundary) — `range` and `asOf`
|
|
170
|
+
* are mutually exclusive, enforced by factsQueryInputV2Schema.
|
|
171
|
+
*
|
|
172
|
+
* get_facts has NO scope axis (issue #47, reaffirmed for the range read): the
|
|
173
|
+
* facts table carries no scope column, so a range read is not policy-enforced
|
|
174
|
+
* either — deliberately deferred again, not silently dropped.
|
|
154
175
|
*/
|
|
155
176
|
const getFactsTool = {
|
|
156
177
|
name: 'get_facts',
|
|
157
178
|
requiredScope: MEMORY_READ_SCOPE,
|
|
158
179
|
config: {
|
|
159
180
|
title: 'Get Facts',
|
|
160
|
-
description: 'Currently-valid facts for a subject, with optional bi-temporal time travel. List mode (no subject) returns the most recent facts, bounded by an optional limit (default 50, max 200).',
|
|
161
|
-
inputSchema:
|
|
181
|
+
description: 'Currently-valid facts for a subject, with optional bi-temporal time travel, OR a chronological time-series read across a valid-time window (range: {from?, to?} — half-open [from, to), surfaces superseded generations inside it). range and asOf are mutually exclusive. List/range mode (no subject) returns the most recent (or earliest-in-window) facts, bounded by an optional limit (default 50, max 200).',
|
|
182
|
+
inputSchema: factsQueryInputV2Schema,
|
|
162
183
|
outputSchema: factsToolOutputSchema,
|
|
163
184
|
annotations: READ_ONLY_ANNOTATIONS,
|
|
164
185
|
},
|
|
165
186
|
async handler(args, ctx) {
|
|
166
|
-
const input =
|
|
187
|
+
const input = factsQueryInputV2Schema.parse(args);
|
|
167
188
|
// ACCESS GUARD: get_facts is a READ, so read access is asserted BEFORE the db
|
|
168
189
|
// op (self-host allowAllAccess allows all; back-compat when no gate is wired).
|
|
169
190
|
// Mirrors search (which asserts this inside core) and the REST /api/v1/facts
|
|
@@ -174,6 +195,7 @@ const getFactsTool = {
|
|
|
174
195
|
subject: input.subject,
|
|
175
196
|
predicate: input.predicate,
|
|
176
197
|
asOf: toAsOf(input.asOf),
|
|
198
|
+
range: toRange(input.range),
|
|
177
199
|
// Always forward the bounded limit (schema default 50, max 200) so list
|
|
178
200
|
// mode never returns every fact (no-firehose, docs/concepts/mcp-design.mdx).
|
|
179
201
|
limit: input.limit,
|
|
@@ -187,6 +209,7 @@ const getFactsTool = {
|
|
|
187
209
|
confidence: fact.confidence,
|
|
188
210
|
validFrom: fact.validFrom.toISOString(),
|
|
189
211
|
validTo: fact.validTo?.toISOString() ?? null,
|
|
212
|
+
recordedAt: fact.recordedAt.toISOString(),
|
|
190
213
|
})),
|
|
191
214
|
count: facts.length,
|
|
192
215
|
});
|
|
@@ -309,10 +332,10 @@ const resolveTool = {
|
|
|
309
332
|
},
|
|
310
333
|
};
|
|
311
334
|
/**
|
|
312
|
-
* THE registered tool surface. Length === registered count
|
|
313
|
-
* rule 8)
|
|
314
|
-
*
|
|
315
|
-
*
|
|
335
|
+
* THE registered tool surface. Length === registered count, auditable from this
|
|
336
|
+
* one array (hard rule 8). D0: 3; D1 adds revise + resolve -> 5; D2 orient
|
|
337
|
+
* (briefing, handoff) -> 7; D3 admin (configure_scope, describe_environment,
|
|
338
|
+
* review_proposals) -> 10; get_memories (inspect) -> 11.
|
|
316
339
|
*
|
|
317
340
|
* The admin tools are created via a FACTORY given a thunk over {@link TOOLS}, so
|
|
318
341
|
* describe_environment can report the FULL surface (itself included) without a
|
|
@@ -336,8 +359,6 @@ export const TOOLS = [
|
|
|
336
359
|
// surface (itself included) without a circular import.
|
|
337
360
|
...createAdminTools(() => TOOLS.map((t) => t.name)),
|
|
338
361
|
];
|
|
339
|
-
/** Hard ceiling per docs/concepts/mcp-design.mdx / hard rule 8. LEDGER: 11/12 registered; the LAST slot is reserved for the future `manage_context` tool. */
|
|
340
|
-
export const MAX_TOOLS = 12;
|
|
341
362
|
/**
|
|
342
363
|
* Run a tool handler with uniform metrics + typed-error mapping. A KNOWN typed
|
|
343
364
|
* core error (bad input, missing embedding source) becomes an isError result
|
package/dist/mcp/tools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,gFAAgF;AAChF,qEAAqE;AACrE,yEAAyE;AACzE,gFAAgF;AAChF,4EAA4E;AAC5E,6CAA6C;AAC7C,EAAE;AACF,
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,gFAAgF;AAChF,qEAAqE;AACrE,yEAAyE;AACzE,gFAAgF;AAChF,4EAA4E;AAC5E,6CAA6C;AAC7C,EAAE;AACF,kFAAkF;AAClF,8EAA8E;AAC9E,gFAAgF;AAChF,6EAA6E;AAC7E,iFAAiF;AACjF,kFAAkF;AAClF,kFAAkF;AAClF,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,kEAAkE;AAClE,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACjE,OAAO,EAGL,QAAQ,EAGR,QAAQ,EACR,iBAAiB,EACjB,MAAM,GACP,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAoB,MAAM,mBAAmB,CAAA;AAE3F,OAAO,EAGL,uBAAuB,EACvB,qBAAqB,EACrB,kBAAkB,EAClB,yBAAyB,EACzB,0BAA0B,EAC1B,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,gBAAgB,CAAA;AAGvB,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD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EAAE,GAAG,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EAAE,EAC1E,0BAA0B,CAC3B,CAAA;QACD,OAAO,IAAI,CAAC,gBAAgB,CAAC,CAAA;IAC/B,CAAC;AACH,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AsOfInput } from '@3ngram/schema';
|
|
1
|
+
import type { AsOfInput, FactsRangeInput } from '@3ngram/schema';
|
|
2
2
|
import type { Request, Response } from 'express';
|
|
3
3
|
/** Drop undefined values so exact-optional core parameters remain absent. */
|
|
4
4
|
export declare function defined<T extends Record<string, unknown>>(obj: T): {
|
|
@@ -9,6 +9,11 @@ export declare function toAsOf(asOf: AsOfInput | undefined): {
|
|
|
9
9
|
validAt?: Date;
|
|
10
10
|
asKnownAt?: Date;
|
|
11
11
|
} | undefined;
|
|
12
|
+
/** Map an optional {from,to} range's ISO bounds to core Date values (range read). */
|
|
13
|
+
export declare function toRange(range: FactsRangeInput | undefined): {
|
|
14
|
+
from?: Date;
|
|
15
|
+
to?: Date;
|
|
16
|
+
} | undefined;
|
|
12
17
|
/** The authenticated tenant bound by apiOrSessionAuth. */
|
|
13
18
|
export declare function tenant(req: Request): string;
|
|
14
19
|
/** Apply the shared typed-error mapping without logging request content. */
|
|
@@ -17,6 +17,15 @@ export function toAsOf(asOf) {
|
|
|
17
17
|
asKnownAt: asOf.asKnownAt === undefined ? undefined : new Date(asOf.asKnownAt),
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
+
/** Map an optional {from,to} range's ISO bounds to core Date values (range read). */
|
|
21
|
+
export function toRange(range) {
|
|
22
|
+
if (range === undefined)
|
|
23
|
+
return undefined;
|
|
24
|
+
return defined({
|
|
25
|
+
from: range.from === undefined ? undefined : new Date(range.from),
|
|
26
|
+
to: range.to === undefined ? undefined : new Date(range.to),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
20
29
|
/** The authenticated tenant bound by apiOrSessionAuth. */
|
|
21
30
|
export function tenant(req) {
|
|
22
31
|
return req.userId;
|