@3ngram/server 0.7.0

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.
Files changed (116) hide show
  1. package/LICENSE +202 -0
  2. package/dist/app.d.ts +72 -0
  3. package/dist/app.js +273 -0
  4. package/dist/app.js.map +1 -0
  5. package/dist/boot.d.ts +37 -0
  6. package/dist/boot.js +53 -0
  7. package/dist/boot.js.map +1 -0
  8. package/dist/composition/extension.d.ts +50 -0
  9. package/dist/composition/extension.js +16 -0
  10. package/dist/composition/extension.js.map +1 -0
  11. package/dist/index.d.ts +1 -0
  12. package/dist/index.js +10 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/links.d.ts +17 -0
  15. package/dist/links.js +46 -0
  16. package/dist/links.js.map +1 -0
  17. package/dist/mailer.d.ts +58 -0
  18. package/dist/mailer.js +187 -0
  19. package/dist/mailer.js.map +1 -0
  20. package/dist/mcp/errors.d.ts +14 -0
  21. package/dist/mcp/errors.js +175 -0
  22. package/dist/mcp/errors.js.map +1 -0
  23. package/dist/mcp/prompts.d.ts +29 -0
  24. package/dist/mcp/prompts.js +180 -0
  25. package/dist/mcp/prompts.js.map +1 -0
  26. package/dist/mcp/server.d.ts +14 -0
  27. package/dist/mcp/server.js +34 -0
  28. package/dist/mcp/server.js.map +1 -0
  29. package/dist/mcp/tools-admin.d.ts +8 -0
  30. package/dist/mcp/tools-admin.js +260 -0
  31. package/dist/mcp/tools-admin.js.map +1 -0
  32. package/dist/mcp/tools-orient.d.ts +6 -0
  33. package/dist/mcp/tools-orient.js +110 -0
  34. package/dist/mcp/tools-orient.js.map +1 -0
  35. package/dist/mcp/tools.d.ts +88 -0
  36. package/dist/mcp/tools.js +375 -0
  37. package/dist/mcp/tools.js.map +1 -0
  38. package/dist/middleware/api-key.d.ts +13 -0
  39. package/dist/middleware/api-key.js +83 -0
  40. package/dist/middleware/api-key.js.map +1 -0
  41. package/dist/middleware/api-or-session.d.ts +9 -0
  42. package/dist/middleware/api-or-session.js +22 -0
  43. package/dist/middleware/api-or-session.js.map +1 -0
  44. package/dist/middleware/authenticate.d.ts +21 -0
  45. package/dist/middleware/authenticate.js +51 -0
  46. package/dist/middleware/authenticate.js.map +1 -0
  47. package/dist/middleware/index.d.ts +1 -0
  48. package/dist/middleware/index.js +9 -0
  49. package/dist/middleware/index.js.map +1 -0
  50. package/dist/middleware/oauth-bearer.d.ts +8 -0
  51. package/dist/middleware/oauth-bearer.js +117 -0
  52. package/dist/middleware/oauth-bearer.js.map +1 -0
  53. package/dist/middleware/rate-limit.d.ts +58 -0
  54. package/dist/middleware/rate-limit.js +139 -0
  55. package/dist/middleware/rate-limit.js.map +1 -0
  56. package/dist/middleware/request-context.d.ts +7 -0
  57. package/dist/middleware/request-context.js +14 -0
  58. package/dist/middleware/request-context.js.map +1 -0
  59. package/dist/output-validation.d.ts +18 -0
  60. package/dist/output-validation.js +30 -0
  61. package/dist/output-validation.js.map +1 -0
  62. package/dist/redis.d.ts +9 -0
  63. package/dist/redis.js +37 -0
  64. package/dist/redis.js.map +1 -0
  65. package/dist/rest/cursor.d.ts +14 -0
  66. package/dist/rest/cursor.js +38 -0
  67. package/dist/rest/cursor.js.map +1 -0
  68. package/dist/rest/errors.d.ts +14 -0
  69. package/dist/rest/errors.js +119 -0
  70. package/dist/rest/errors.js.map +1 -0
  71. package/dist/rest/router.d.ts +33 -0
  72. package/dist/rest/router.js +846 -0
  73. package/dist/rest/router.js.map +1 -0
  74. package/dist/rest/scope.d.ts +14 -0
  75. package/dist/rest/scope.js +45 -0
  76. package/dist/rest/scope.js.map +1 -0
  77. package/dist/routes/api-keys.d.ts +2 -0
  78. package/dist/routes/api-keys.js +77 -0
  79. package/dist/routes/api-keys.js.map +1 -0
  80. package/dist/routes/auth.d.ts +20 -0
  81. package/dist/routes/auth.js +325 -0
  82. package/dist/routes/auth.js.map +1 -0
  83. package/dist/routes/capabilities.d.ts +10 -0
  84. package/dist/routes/capabilities.js +17 -0
  85. package/dist/routes/capabilities.js.map +1 -0
  86. package/dist/routes/health.d.ts +7 -0
  87. package/dist/routes/health.js +12 -0
  88. package/dist/routes/health.js.map +1 -0
  89. package/dist/routes/mcp.d.ts +27 -0
  90. package/dist/routes/mcp.js +81 -0
  91. package/dist/routes/mcp.js.map +1 -0
  92. package/dist/routes/oauth-authorize.d.ts +8 -0
  93. package/dist/routes/oauth-authorize.js +245 -0
  94. package/dist/routes/oauth-authorize.js.map +1 -0
  95. package/dist/routes/oauth-clients.d.ts +2 -0
  96. package/dist/routes/oauth-clients.js +59 -0
  97. package/dist/routes/oauth-clients.js.map +1 -0
  98. package/dist/routes/oauth-register.d.ts +8 -0
  99. package/dist/routes/oauth-register.js +59 -0
  100. package/dist/routes/oauth-register.js.map +1 -0
  101. package/dist/routes/oauth-token.d.ts +30 -0
  102. package/dist/routes/oauth-token.js +451 -0
  103. package/dist/routes/oauth-token.js.map +1 -0
  104. package/dist/routes/onboarding.d.ts +2 -0
  105. package/dist/routes/onboarding.js +47 -0
  106. package/dist/routes/onboarding.js.map +1 -0
  107. package/dist/routes/profile.d.ts +2 -0
  108. package/dist/routes/profile.js +35 -0
  109. package/dist/routes/profile.js.map +1 -0
  110. package/dist/routes/well-known.d.ts +2 -0
  111. package/dist/routes/well-known.js +77 -0
  112. package/dist/routes/well-known.js.map +1 -0
  113. package/dist/version.d.ts +1 -0
  114. package/dist/version.js +17 -0
  115. package/dist/version.js.map +1 -0
  116. package/package.json +67 -0
@@ -0,0 +1,29 @@
1
+ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ /**
3
+ * A code-defined prompt, erased to a name + a server-bound registrar. The arg
4
+ * shape is captured at the typed {@link definePrompt} call site, so the
5
+ * heterogeneous {@link PROMPTS} registry stays name-typed without an `any`-typed
6
+ * arg shape leaking across distinct prompts.
7
+ */
8
+ interface RegisterablePrompt {
9
+ name: string;
10
+ register: (server: McpServer) => void;
11
+ }
12
+ /**
13
+ * THE code-defined prompt surface. Length === registered count; the v1 cap
14
+ * (EXACTLY 2 — briefing, debrief; mcp-design.md) is auditable from this one
15
+ * array. Each entry carries its name (auditable) and a server-bound registrar,
16
+ * so the registry stays type-safe over heterogeneous arg shapes without an `any`.
17
+ */
18
+ export declare const PROMPTS: readonly RegisterablePrompt[];
19
+ /** Hard ceiling per mcp-design.md (v1: exactly 2; resources deferred). */
20
+ export declare const MAX_PROMPTS = 2;
21
+ /**
22
+ * Register every code-defined prompt on the McpServer. Called from
23
+ * {@link createMcpServer} alongside the registerTool loop; registerPrompt
24
+ * auto-enables the `prompts` capability, so prompts/list + prompts/get are served
25
+ * with no transport-route change. The render callback is synchronous and reads
26
+ * only its validated args (no tenant context needed — a prompt carries no data).
27
+ */
28
+ export declare function registerPrompts(server: McpServer): void;
29
+ export {};
@@ -0,0 +1,180 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // MCP PROMPTS — code-defined templates: start with 2 (briefing, debrief).
3
+ //
4
+ // A PROMPT is a reusable, parameterised message template the client surfaces to
5
+ // its user (a slash command, a menu entry); selecting it returns bounded text
6
+ // that ORIENTS the agent. It is NOT a tool: a prompt NEVER queries, never touches
7
+ // the DB, carries NO tenant data and NO secrets — its only output is the static
8
+ // (arg-interpolated) instruction text below. The actual memory work happens when
9
+ // the agent, so oriented, calls the briefing/remember TOOLS.
10
+ //
11
+ // CAPABILITY: McpServer.registerPrompt AUTO-ENABLES the `prompts` capability, so
12
+ // prompts/list + prompts/get become available the moment this runs — no edit to
13
+ // routes/mcp.ts. That route mounts oauthBearerAuth on router.all('/mcp', ...), so
14
+ // prompts/list and prompts/get are Bearer-gated at the transport layer exactly
15
+ // like tools/* (prompts have no per-tool scope concept — there is no MCP notion
16
+ // of a per-prompt scope, and these templates expose no data, so transport-level
17
+ // Bearer auth is the complete access control). Confirmed in routes/mcp.ts.
18
+ //
19
+ // V1 CAP (mcp-design.md): EXACTLY 2 prompts (briefing, debrief). Resources are
20
+ // deferred. {@link PROMPTS}.length is the auditable count; {@link MAX_PROMPTS}
21
+ // is the ceiling.
22
+ //
23
+ // ARG TYPING: MCP delivers prompt arguments as STRINGS over the wire, so every
24
+ // arg shape is string-valued — z.enum for the bounded selectors/modes, the SDK
25
+ // validates inbound args against the raw shape (mirrors registerTool).
26
+ //
27
+ // SCHEMA ALIGNMENT (hard rule 2 — constraints live in @3ngram/schema): the
28
+ // rendered text instructs the agent to call the briefing/remember TOOLS, so the
29
+ // prompt's argument vocabulary MUST be exactly what those tools accept. The flat,
30
+ // string-valued prompt args cannot be a Zod object, so instead of a hand-rolled
31
+ // local enum (which could DRIFT and tell the agent to call a tool with a value it
32
+ // rejects) we DERIVE the selector vocabulary from the canonical
33
+ // {@link briefingSelectorSchema} discriminator and validate the debrief `scope`
34
+ // against the canonical {@link scopeSchema} before rendering.
35
+ import { briefingModeSchema, briefingSelectorSchema, scopeSchema } from '@3ngram/schema';
36
+ import { z } from 'zod';
37
+ /**
38
+ * Define a code-defined prompt. `argsSchema` is a Zod RAW SHAPE (the SDK 1.x
39
+ * `registerPrompt` contract: it wraps the shape in z.object internally and
40
+ * validates the inbound, string-valued arguments against it — the same shape
41
+ * convention as `registerTool`). `render` returns the bounded
42
+ * {@link GetPromptResult}: a single user message whose text orients the agent;
43
+ * it receives the SDK-VALIDATED, re-parsed args and reads NOTHING else (no DB,
44
+ * no env). The returned registrar binds the prompt onto an McpServer;
45
+ * registerPrompt auto-enables the `prompts` capability.
46
+ */
47
+ function definePrompt(prompt) {
48
+ // The SDK already validates inbound args against `argsSchema` before invoking
49
+ // the callback; re-parsing through the same z.object is a zero-risk TYPE BRIDGE
50
+ // that yields the exact `z.infer<z.ZodObject<Args>>` `render` declares (the
51
+ // SDK's structurally-equal arg type does not generically unify with zod's).
52
+ const argsObject = z.object(prompt.config.argsSchema);
53
+ // Widen the config's argsSchema to the non-generic ZodRawShape so registerPrompt
54
+ // infers a CONCRETE `Args` (mirrors how server.ts calls registerTool with the
55
+ // wide tool config): a callback taking `unknown` is then assignable to the
56
+ // resolved PromptCallback. A conditional PromptCallback over an UNRESOLVED
57
+ // generic `Args` blocks assignability, so we must register non-generically.
58
+ const config = prompt.config;
59
+ return {
60
+ name: prompt.name,
61
+ register: (server) => server.registerPrompt(prompt.name, config, (args) => prompt.render(argsObject.parse(args))),
62
+ };
63
+ }
64
+ /** Wrap orienting text as the single-user-message prompt result. */
65
+ function userMessage(text) {
66
+ return { messages: [{ role: 'user', content: { type: 'text', text } }] };
67
+ }
68
+ // The selector vocabulary the briefing TOOL accepts (no-firehose: a briefing
69
+ // REQUIRES an explicit selector). DERIVED from the canonical, discriminated
70
+ // {@link briefingSelectorSchema} `kind` literals so the prompt's flat,
71
+ // string-valued arg can NEVER drift from the values the tool actually accepts:
72
+ // adding/removing a selector kind in @3ngram/schema flows through here for free.
73
+ const SELECTOR_KINDS = briefingSelectorSchema.options.map((option) => option.shape.kind.value);
74
+ const selectorArgSchema = z
75
+ .enum(SELECTOR_KINDS)
76
+ .describe('Which slice to brief over: a single scope, a single project, or all memories.');
77
+ // DERIVED from the canonical {@link briefingModeSchema} so the prompt offers
78
+ // exactly the detail levels the briefing TOOL understands.
79
+ const modeArgSchema = briefingModeSchema.describe('brief (counts + top items, the default) or full (the bounded lists).');
80
+ /**
81
+ * briefing — orient the agent to START a session by calling the briefing TOOL
82
+ * with an EXPLICIT selector (no-firehose, mcp-design.md). The prompt TEXT only
83
+ * orients; it does NOT query — the agent then issues the tool call itself. The
84
+ * `selector`/`mode` args interpolate into a concrete, copy-ready instruction.
85
+ */
86
+ const briefingPrompt = definePrompt({
87
+ name: 'briefing',
88
+ config: {
89
+ title: 'Session briefing',
90
+ description: 'Orient yourself at the start of a session: call the briefing TOOL with an explicit selector (no unfiltered default) to surface open/overdue commitments, blockers, stale candidates, recent decisions, and preferences.',
91
+ argsSchema: {
92
+ selector: selectorArgSchema,
93
+ mode: modeArgSchema.optional(),
94
+ },
95
+ },
96
+ render({ selector, mode }) {
97
+ const mode_ = mode ?? 'brief';
98
+ const selectorHint = selector === 'all'
99
+ ? '{ "kind": "all" }'
100
+ : selector === 'scope'
101
+ ? '{ "kind": "scope", "scope": "<your-scope>" }'
102
+ : '{ "kind": "project", "project": "<your-project>" }';
103
+ return userMessage([
104
+ 'Start this session oriented. Call the `briefing` TOOL with an EXPLICIT selector',
105
+ '— there is no unfiltered default (the no-firehose rule), so a selector is required.',
106
+ '',
107
+ `Use selector ${selectorHint} and mode "${mode_}".`,
108
+ '',
109
+ 'The tool returns size-disciplined sections: open and overdue commitments,',
110
+ 'blockers, stale candidates, recent decisions, and preferences. In "brief" mode',
111
+ 'you get counts plus a top slice per section; in "full" mode you get the bounded',
112
+ 'lists. Read the result, then proceed with the work already in flight before',
113
+ 'starting anything new.',
114
+ ].join('\n'));
115
+ },
116
+ });
117
+ /**
118
+ * debrief — orient the agent to CLOSE a session by extracting what is worth
119
+ * persisting (decisions, commitments, follow-ups) and writing each via the
120
+ * `remember` TOOL, mirroring the spirit of the debrief skill. The optional
121
+ * `scope` arg names the slice the work belonged to so the persisted memories
122
+ * land tagged correctly. The text orients; it does NOT itself persist anything.
123
+ */
124
+ const debriefPrompt = definePrompt({
125
+ name: 'debrief',
126
+ config: {
127
+ title: 'Session debrief',
128
+ description: 'Close a session cleanly: review what happened, then persist what is worth keeping — decisions, commitments, and follow-ups — by calling the remember TOOL for each, and resolve any completed commitments.',
129
+ argsSchema: {
130
+ // VALIDATED against the canonical {@link scopeSchema} (kebab-case), the SAME
131
+ // constraint the `remember` TOOL enforces — so a scope the prompt accepts is
132
+ // a scope `remember` accepts, and the rendered "tag with scope X" line can
133
+ // never instruct a value the tool would reject (e.g. "Work Notes").
134
+ scope: scopeSchema
135
+ .optional()
136
+ .describe('Optional scope (kebab-case, e.g. work, personal) the session belonged to.'),
137
+ },
138
+ },
139
+ render({ scope }) {
140
+ const scopeLine = scope === undefined
141
+ ? 'Tag each memory with the scope the work belonged to.'
142
+ : `Tag each memory with scope "${scope}".`;
143
+ return userMessage([
144
+ 'Debrief this session before closing. Review the conversation and extract what a',
145
+ 'future session needs, then PERSIST each item by calling the `remember` TOOL:',
146
+ '',
147
+ '- Decisions: architectural choices and resolved tradeoffs (memoryType "decision").',
148
+ '- Commitments: things promised for later, with a due date if known (memoryType "commitment").',
149
+ '- Follow-ups & notes: blockers and handoff state to continue from (memoryType "note").',
150
+ '- Preferences & patterns: conventions or gotchas worth reusing.',
151
+ '',
152
+ scopeLine,
153
+ '',
154
+ 'For any commitment COMPLETED this session, call the `resolve` TOOL on its memory id.',
155
+ 'Keep each memory atomic and self-contained; do not persist secrets or raw credentials.',
156
+ ].join('\n'));
157
+ },
158
+ });
159
+ /**
160
+ * THE code-defined prompt surface. Length === registered count; the v1 cap
161
+ * (EXACTLY 2 — briefing, debrief; mcp-design.md) is auditable from this one
162
+ * array. Each entry carries its name (auditable) and a server-bound registrar,
163
+ * so the registry stays type-safe over heterogeneous arg shapes without an `any`.
164
+ */
165
+ export const PROMPTS = [briefingPrompt, debriefPrompt];
166
+ /** Hard ceiling per mcp-design.md (v1: exactly 2; resources deferred). */
167
+ export const MAX_PROMPTS = 2;
168
+ /**
169
+ * Register every code-defined prompt on the McpServer. Called from
170
+ * {@link createMcpServer} alongside the registerTool loop; registerPrompt
171
+ * auto-enables the `prompts` capability, so prompts/list + prompts/get are served
172
+ * with no transport-route change. The render callback is synchronous and reads
173
+ * only its validated args (no tenant context needed — a prompt carries no data).
174
+ */
175
+ export function registerPrompts(server) {
176
+ for (const prompt of PROMPTS) {
177
+ prompt.register(server);
178
+ }
179
+ }
180
+ //# sourceMappingURL=prompts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/mcp/prompts.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,0EAA0E;AAC1E,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,kFAAkF;AAClF,gFAAgF;AAChF,iFAAiF;AACjF,6DAA6D;AAC7D,EAAE;AACF,iFAAiF;AACjF,gFAAgF;AAChF,kFAAkF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AMG;AACH,MAAM,aAAa,GAAG,YAAY,CAAC;IACjC,IAAI,EAAE,SAAS;IACf,MAAM,EAAE;QACN,KAAK,EAAE,iBAAiB;QACxB,WAAW,EACT,4MAA4M;QAC9M,UAAU,EAAE;YACV,6EAA6E;YAC7E,6EAA6E;YAC7E,2EAA2E;YAC3E,oEAAoE;YACpE,KAAK,EAAE,WAAW;iBACf,QAAQ,EAAE;iBACV,QAAQ,CAAC,2EAA2E,CAAC;SACzF;KACF;IACD,MAAM,CAAC,EAAE,KAAK,EAAE;QACd,MAAM,SAAS,GACb,KAAK,KAAK,SAAS;YACjB,CAAC,CAAC,sDAAsD;YACxD,CAAC,CAAC,+BAA+B,KAAK,IAAI,CAAA;QAC9C,OAAO,WAAW,CAChB;YACE,iFAAiF;YACjF,8EAA8E;YAC9E,EAAE;YACF,oFAAoF;YACpF,+FAA+F;YAC/F,wFAAwF;YACxF,iEAAiE;YACjE,EAAE;YACF,SAAS;YACT,EAAE;YACF,sFAAsF;YACtF,wFAAwF;SACzF,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAkC,CAAC,cAAc,EAAE,aAAa,CAAC,CAAA;AAErF,0EAA0E;AAC1E,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAA;AAE5B;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,MAAiB;IAC/C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;IACzB,CAAC;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { type ToolContext } from './tools.js';
3
+ /**
4
+ * Build an McpServer with every registry tool registered, bound to one request's
5
+ * {@link ToolContext}. Each tool registers its Zod input/output RAW SHAPES (the
6
+ * SDK validates inbound args against inputSchema and the structured result
7
+ * against outputSchema), and delegates to {@link runTool} for uniform metrics +
8
+ * typed-error mapping. The code-defined PROMPTS (briefing, debrief — slice D5)
9
+ * are registered alongside; registerPrompt auto-enables the `prompts` capability,
10
+ * so prompts/list + prompts/get are served with no transport-route change (both
11
+ * stay Bearer-gated by routes/mcp.ts). Prompts carry no tenant data, so they need
12
+ * no {@link ToolContext}.
13
+ */
14
+ export declare function createMcpServer(ctx: ToolContext): McpServer;
@@ -0,0 +1,34 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // MCP server factory — builds a per-request McpServer from the {@link TOOLS}
3
+ // registry. STATELESS (mcp-design.md): a fresh server + transport per request
4
+ // (sessionIdGenerator: undefined), so NO in-process session state survives a
5
+ // request — any instance serves any request and a Railway redeploy is a
6
+ // non-event. The authenticated tenant + optional embedding gateway are captured
7
+ // in the handler closure (the per-request context), never stored on the server.
8
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
9
+ import { SERVER_VERSION } from '../version.js';
10
+ import { registerPrompts } from './prompts.js';
11
+ import { runTool, TOOLS } from './tools.js';
12
+ // `version` derives from package.json (see ../version.ts) so the `initialize`
13
+ // result always matches the published package version and never skews.
14
+ const SERVER_INFO = { name: '3ngram', version: SERVER_VERSION };
15
+ /**
16
+ * Build an McpServer with every registry tool registered, bound to one request's
17
+ * {@link ToolContext}. Each tool registers its Zod input/output RAW SHAPES (the
18
+ * SDK validates inbound args against inputSchema and the structured result
19
+ * against outputSchema), and delegates to {@link runTool} for uniform metrics +
20
+ * typed-error mapping. The code-defined PROMPTS (briefing, debrief — slice D5)
21
+ * are registered alongside; registerPrompt auto-enables the `prompts` capability,
22
+ * so prompts/list + prompts/get are served with no transport-route change (both
23
+ * stay Bearer-gated by routes/mcp.ts). Prompts carry no tenant data, so they need
24
+ * no {@link ToolContext}.
25
+ */
26
+ export function createMcpServer(ctx) {
27
+ const server = new McpServer(SERVER_INFO);
28
+ for (const tool of TOOLS) {
29
+ server.registerTool(tool.name, tool.config, (args) => runTool(tool, args, ctx));
30
+ }
31
+ registerPrompts(server);
32
+ return server;
33
+ }
34
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,6EAA6E;AAC7E,8EAA8E;AAC9E,6EAA6E;AAC7E,wEAAwE;AACxE,gFAAgF;AAChF,gFAAgF;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAA;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAoB,MAAM,YAAY,CAAA;AAE7D,8EAA8E;AAC9E,uEAAuE;AACvE,MAAM,WAAW,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAW,CAAA;AAExE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,eAAe,CAAC,GAAgB;IAC9C,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,WAAW,CAAC,CAAA;IACzC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,IAAa,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,CAAA;IAC1F,CAAC;IACD,eAAe,CAAC,MAAM,CAAC,CAAA;IACvB,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { ToolDefinition } from './tools.js';
2
+ /**
3
+ * Build the three admin tool definitions. `toolNames` is injected by the
4
+ * registry (tools.ts) so describe_environment can report the FULL surface
5
+ * (including itself) without a circular import — tools.ts owns TOOLS; this module
6
+ * is imported BY it, so it cannot read the final array at module load.
7
+ */
8
+ export declare function createAdminTools(toolNames: () => readonly string[]): ToolDefinition[];
@@ -0,0 +1,260 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // MCP ADMIN tools: configure_scope, describe_environment,
3
+ // review_proposals — completing the 10-tool v1 surface. THIN
4
+ // adapters: each validates at the ONE schema boundary
5
+ // (packages/schema), calls the COMPLETE core service, shapes the structured
6
+ // result, and holds zero business logic.
7
+ //
8
+ // TWO-LAYER SCOPE MODEL (orchestrator decision). The registry-level
9
+ // requiredScope is the PRE-handler floor (runTool checks it before the handler
10
+ // runs). configure_scope and review_proposals span BOTH a read action (list) and
11
+ // write actions, so they declare an `anyOf: [memory:read, memory:write]` floor:
12
+ // runTool admits a token carrying EITHER scope. read is NOT a superset of write,
13
+ // so a single memory:read floor would wrongly lock a WRITE-ONLY token out of its
14
+ // mutations before the handler could run — anyOf fixes that while staying
15
+ // fail-closed (an empty token-scope set satisfies no floor). The HANDLER then
16
+ // asserts the action-specific scope from ctx.scopes: list needs memory:read,
17
+ // every MUTATING action (create/rename/set_aliases/delete; reject/accept) needs
18
+ // memory:write, returning the SAME insufficient_scope error shape runTool uses.
19
+ // The split is exercised at BOTH layers in the contract tests.
20
+ //
21
+ // REDACTION: describe_environment carries capabilities (tool
22
+ // NAMES + count + version), the scope registry, and bounded COUNTS only — never
23
+ // an env value, DSN, key, or base URL. The output schema has no field for one and
24
+ // no handler here reads process.env or a secret.
25
+ //
26
+ // REGISTRATION SHAPES: configure_scope and review_proposals are action
27
+ // discriminated unions, which the SDK's registerTool (ZodRawShape contract)
28
+ // cannot take directly. They register a PERMISSIVE flat raw shape (every field
29
+ // optional) and re-parse with the STRICT union in the handler — the precise
30
+ // per-action validation still happens, at the one boundary.
31
+ import { log, mcpToolErrors } from '@3ngram/config';
32
+ import { applyProposal, createScope, deleteScope, describeEnvironment, listProposals, listScopes, rejectProposal, renameScope, setScopeAliases, } from '@3ngram/core';
33
+ import { MEMORY_READ_SCOPE, MEMORY_WRITE_SCOPE } from '@3ngram/core/auth';
34
+ import { configureScopeInputSchema, configureScopeOutputSchema, configureScopeRegisterOutputShape, configureScopeRegisterShape, describeEnvironmentInputSchema, describeEnvironmentOutputSchema, reviewProposalsInputSchema, reviewProposalsOutputSchema, reviewProposalsRegisterOutputShape, reviewProposalsRegisterShape, } from '@3ngram/schema';
35
+ import { parseOutput } from '../output-validation.js';
36
+ import { SERVER_VERSION } from '../version.js';
37
+ /** Wrap a structured payload as a tool success result (text mirror + structured). */
38
+ function ok(structured) {
39
+ return {
40
+ content: [{ type: 'text', text: JSON.stringify(structured) }],
41
+ structuredContent: structured,
42
+ };
43
+ }
44
+ /** Wrap a typed failure as an isError result. The message names the class only. */
45
+ function fail(message) {
46
+ return { content: [{ type: 'text', text: message }], isError: true };
47
+ }
48
+ /**
49
+ * Per-action scope gate (layer 2 of the two-layer model). The registry `anyOf`
50
+ * floor (layer 1, runTool) admits a token carrying EITHER read or write; the
51
+ * action then needs its EXACT scope — list → memory:read, mutations →
52
+ * memory:write. Returns an isError matching runTool's insufficient_scope shape
53
+ * (and counts the same metric) when the token lacks the action scope; undefined
54
+ * to proceed. Fail-closed: an empty ctx.scopes carries no scope.
55
+ */
56
+ function requireScope(toolName, ctx, scope) {
57
+ if (ctx.scopes.includes(scope))
58
+ return undefined;
59
+ mcpToolErrors.add(1, { tool_name: toolName, reason_code: 'insufficient_scope' });
60
+ log().warn({ tool_name: toolName, required_scope: scope }, 'mcp: action rejected for insufficient scope');
61
+ return fail(`insufficient scope: ${scope} required`);
62
+ }
63
+ /** Shape a core scope record for the structured output (Date -> ISO string). */
64
+ function toScopeOutput(s) {
65
+ return { id: s.id, name: s.name, aliases: s.aliases, createdAt: s.createdAt.toISOString() };
66
+ }
67
+ /** Shape a core proposal record for the structured output (Dates -> ISO strings). */
68
+ function toProposalOutput(p) {
69
+ return {
70
+ id: p.id,
71
+ fromId: p.fromId,
72
+ toId: p.toId,
73
+ edgeType: p.edgeType,
74
+ memoryType: p.memoryType,
75
+ similarity: p.similarity,
76
+ rationale: p.rationale,
77
+ status: p.status,
78
+ decidedAt: p.decidedAt === null ? null : p.decidedAt.toISOString(),
79
+ createdAt: p.createdAt.toISOString(),
80
+ };
81
+ }
82
+ /**
83
+ * Dispatch a configure_scope ACTION to the right core call. The `anyOf` registry
84
+ * floor admits read OR write; this handler gates the EXACT action scope (layer 2)
85
+ * before any core call: list → memory:read, mutations → memory:write.
86
+ */
87
+ async function runConfigureScope(input, ctx) {
88
+ if (input.action === 'list') {
89
+ const denied = requireScope('configure_scope', ctx, MEMORY_READ_SCOPE);
90
+ if (denied !== undefined)
91
+ return denied;
92
+ // ACCESS GUARD: listing the tenant scope registry is a READ of user data — read
93
+ // access is asserted BEFORE the db op (self-host allowAllAccess allows all).
94
+ if (ctx.access)
95
+ await ctx.access.assertRead(ctx.userId);
96
+ const scopes = await listScopes(ctx.userId);
97
+ return ok(parseOutput('configure_scope', configureScopeOutputSchema, {
98
+ action: 'list',
99
+ scopes: scopes.map(toScopeOutput),
100
+ count: scopes.length,
101
+ }));
102
+ }
103
+ const denied = requireScope('configure_scope', ctx, MEMORY_WRITE_SCOPE);
104
+ if (denied !== undefined)
105
+ return denied;
106
+ // ACCESS GUARD: every mutating scope action (create/rename/set_aliases/delete) is
107
+ // a WRITE — write access is asserted BEFORE the db op (self-host allowAllAccess
108
+ // allows all).
109
+ if (ctx.access)
110
+ await ctx.access.assertWrite(ctx.userId);
111
+ switch (input.action) {
112
+ case 'create': {
113
+ const scope = await createScope(ctx.userId, input.name, input.aliases);
114
+ return upserted(scope);
115
+ }
116
+ case 'rename': {
117
+ const scope = await renameScope(ctx.userId, input.name, input.newName);
118
+ return upserted(scope);
119
+ }
120
+ case 'set_aliases': {
121
+ const scope = await setScopeAliases(ctx.userId, input.name, input.aliases);
122
+ return upserted(scope);
123
+ }
124
+ case 'delete': {
125
+ await deleteScope(ctx.userId, input.name);
126
+ return ok(parseOutput('configure_scope', configureScopeOutputSchema, {
127
+ action: 'deleted',
128
+ name: input.name,
129
+ }));
130
+ }
131
+ default:
132
+ // Exhaustiveness guard: every mutating action is handled above. The strict
133
+ // union makes this unreachable; it pins the compiler to flag a NEW action.
134
+ return input;
135
+ }
136
+ }
137
+ function upserted(scope) {
138
+ return ok(parseOutput('configure_scope', configureScopeOutputSchema, {
139
+ action: 'upserted',
140
+ scope: toScopeOutput(scope),
141
+ }));
142
+ }
143
+ /**
144
+ * Dispatch a review_proposals ACTION. The `anyOf` registry floor admits read OR
145
+ * write; this handler gates the EXACT action scope (layer 2): list →
146
+ * memory:read, reject/accept → memory:write. accept calls core applyProposal,
147
+ * which materializes the proposed edge and (for supersedes/updates) closes the
148
+ * predecessor, returning the `applied` result variant.
149
+ */
150
+ async function runReviewProposals(input, ctx) {
151
+ if (input.action === 'list') {
152
+ const denied = requireScope('review_proposals', ctx, MEMORY_READ_SCOPE);
153
+ if (denied !== undefined)
154
+ return denied;
155
+ // ACCESS GUARD: proposals are memory-derived, so listing them is a READ — read
156
+ // access is asserted BEFORE the db op (self-host allowAllAccess allows all).
157
+ if (ctx.access)
158
+ await ctx.access.assertRead(ctx.userId);
159
+ const proposals = await listProposals(ctx.userId, { status: input.status, limit: input.limit });
160
+ return ok(parseOutput('review_proposals', reviewProposalsOutputSchema, {
161
+ action: 'list',
162
+ proposals: proposals.map(toProposalOutput),
163
+ count: proposals.length,
164
+ }));
165
+ }
166
+ const denied = requireScope('review_proposals', ctx, MEMORY_WRITE_SCOPE);
167
+ if (denied !== undefined)
168
+ return denied;
169
+ // ACCESS GUARD: accept/reject materialize or close edges over the tenant's
170
+ // memories — a WRITE. Write access is asserted BEFORE the db op (self-host
171
+ // allowAllAccess allows all).
172
+ if (ctx.access)
173
+ await ctx.access.assertWrite(ctx.userId);
174
+ if (input.action === 'accept') {
175
+ const proposal = await applyProposal(ctx.userId, input.proposalId, 'user_mcp');
176
+ return ok(parseOutput('review_proposals', reviewProposalsOutputSchema, {
177
+ action: 'applied',
178
+ proposal: toProposalOutput(proposal),
179
+ }));
180
+ }
181
+ const proposal = await rejectProposal(ctx.userId, input.proposalId);
182
+ return ok(parseOutput('review_proposals', reviewProposalsOutputSchema, {
183
+ action: 'rejected',
184
+ proposal: toProposalOutput(proposal),
185
+ }));
186
+ }
187
+ /**
188
+ * Build the three admin tool definitions. `toolNames` is injected by the
189
+ * registry (tools.ts) so describe_environment can report the FULL surface
190
+ * (including itself) without a circular import — tools.ts owns TOOLS; this module
191
+ * is imported BY it, so it cannot read the final array at module load.
192
+ */
193
+ export function createAdminTools(toolNames) {
194
+ const configureScopeTool = {
195
+ name: 'configure_scope',
196
+ // Layer-1 floor: anyOf read|write, so a read-only token can `list` AND a
197
+ // write-only token can mutate. The handler gates the exact action scope.
198
+ requiredScope: { anyOf: [MEMORY_READ_SCOPE, MEMORY_WRITE_SCOPE] },
199
+ config: {
200
+ title: 'Configure Scope',
201
+ description: 'Manage your memory scopes: list, create, rename, set aliases, or delete (registry only — existing memories keep their scope). Mutating actions require the write scope.',
202
+ inputSchema: configureScopeRegisterShape,
203
+ outputSchema: configureScopeRegisterOutputShape,
204
+ },
205
+ async handler(args, ctx) {
206
+ const input = configureScopeInputSchema.parse(args);
207
+ return runConfigureScope(input, ctx);
208
+ },
209
+ };
210
+ const describeEnvironmentTool = {
211
+ name: 'describe_environment',
212
+ requiredScope: MEMORY_READ_SCOPE,
213
+ config: {
214
+ title: 'Describe Environment',
215
+ description: 'Report server capabilities (tool names, count, version), your registered scopes, and bounded memory/commitment counts. Exposes no secrets or configuration values.',
216
+ inputSchema: describeEnvironmentInputSchema.shape,
217
+ outputSchema: describeEnvironmentOutputSchema.shape,
218
+ },
219
+ async handler(args, ctx) {
220
+ describeEnvironmentInputSchema.parse(args);
221
+ // ACCESS GUARD: the report exposes the tenant's scope registry + per-tenant
222
+ // memory/commitment COUNTS (memory-derived), so read access is asserted BEFORE
223
+ // the db op (self-host allowAllAccess allows all). The static capabilities half
224
+ // is not reached on a denial — the whole tool is a tenant-data read.
225
+ if (ctx.access)
226
+ await ctx.access.assertRead(ctx.userId);
227
+ const report = await describeEnvironment(ctx.userId);
228
+ const names = toolNames();
229
+ const output = parseOutput('describe_environment', describeEnvironmentOutputSchema, {
230
+ capabilities: { tools: [...names], toolCount: names.length, version: SERVER_VERSION },
231
+ scopes: report.scopes.map(toScopeOutput),
232
+ stats: {
233
+ memoriesByType: report.stats.memoriesByType,
234
+ activeMemories: report.stats.activeMemories,
235
+ supersededMemories: report.stats.supersededMemories,
236
+ archivedMemories: report.stats.archivedMemories,
237
+ commitmentsByStatus: report.stats.commitmentsByStatus,
238
+ },
239
+ });
240
+ return ok(output);
241
+ },
242
+ };
243
+ const reviewProposalsTool = {
244
+ name: 'review_proposals',
245
+ // Layer-1 floor: anyOf read|write (list is read, reject/accept are write).
246
+ requiredScope: { anyOf: [MEMORY_READ_SCOPE, MEMORY_WRITE_SCOPE] },
247
+ config: {
248
+ title: 'Review Proposals',
249
+ description: 'List consolidation proposals (optionally by status), reject one, or accept one (materializes the proposed edge; a supersedes/updates edge also closes the predecessor). Reject and accept require the write scope.',
250
+ inputSchema: reviewProposalsRegisterShape,
251
+ outputSchema: reviewProposalsRegisterOutputShape,
252
+ },
253
+ async handler(args, ctx) {
254
+ const input = reviewProposalsInputSchema.parse(args);
255
+ return runReviewProposals(input, ctx);
256
+ },
257
+ };
258
+ return [configureScopeTool, describeEnvironmentTool, reviewProposalsTool];
259
+ }
260
+ //# sourceMappingURL=tools-admin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools-admin.js","sourceRoot":"","sources":["../../src/mcp/tools-admin.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,0DAA0D;AAC1D,6DAA6D;AAC7D,sDAAsD;AACtD,4EAA4E;AAC5E,yCAAyC;AACzC,EAAE;AACF,oEAAoE;AACpE,+EAA+E;AAC/E,iFAAiF;AACjF,gFAAgF;AAChF,iFAAiF;AACjF,iFAAiF;AACjF,0EAA0E;AAC1E,8EAA8E;AAC9E,6EAA6E;AAC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C3E,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { ToolDefinition } from './tools.js';
2
+ /**
3
+ * The orientation tools, appended to the {@link TOOLS} registry by tools.ts. A
4
+ * readonly array so the registry stays the single auditable surface.
5
+ */
6
+ export declare const ORIENT_TOOLS: readonly ToolDefinition[];