@remnic/core 9.3.767 → 9.3.769

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.
@@ -23,13 +23,13 @@ import "./chunk-ABP6QMVM.js";
23
23
  import "./chunk-HW5EF6LV.js";
24
24
  import "./chunk-QPTP6SKC.js";
25
25
  import "./chunk-JRZV3767.js";
26
- import "./chunk-4DLFJJOQ.js";
26
+ import "./chunk-QMN3CIFS.js";
27
27
  import "./chunk-V5OCT34X.js";
28
28
  import "./chunk-LXOM6IQU.js";
29
29
  import "./chunk-VOUOLGIP.js";
30
30
  import "./chunk-S75M5ZRK.js";
31
31
  import "./chunk-ECZU5BJH.js";
32
- import "./chunk-UG274TNV.js";
32
+ import "./chunk-E2SPGGUI.js";
33
33
  import "./chunk-UHGBNIOS.js";
34
34
  import "./chunk-BCDKBDSY.js";
35
35
  import "./chunk-YN2UN7N3.js";
@@ -80,7 +80,7 @@ import "./chunk-LUPVCGYK.js";
80
80
  import "./chunk-PYPOFEMK.js";
81
81
  import "./chunk-LOPZ2DWR.js";
82
82
  import "./chunk-VEWZZM3H.js";
83
- import "./chunk-HBOPSFQQ.js";
83
+ import "./chunk-EVXI2I6G.js";
84
84
  import "./chunk-MC4FJXPA.js";
85
85
  import "./chunk-LQHDIS7L.js";
86
86
  import "./chunk-7F7Z6MOS.js";
@@ -175,7 +175,7 @@ import "./chunk-KD3QD3A5.js";
175
175
  import "./chunk-VGUOEDTU.js";
176
176
  import "./chunk-H3FZVNRN.js";
177
177
  import "./chunk-OADWQ5CR.js";
178
- import "./chunk-J3UJJZKI.js";
178
+ import "./chunk-SIPZ5UMK.js";
179
179
  import "./chunk-7WV3F5DQ.js";
180
180
  import "./chunk-SEDEKFYQ.js";
181
181
  import "./chunk-JBPKEARU.js";
@@ -184,7 +184,7 @@ import "./chunk-J64TK33U.js";
184
184
  import "./chunk-RSUYKGGZ.js";
185
185
  import "./chunk-42NQ7AVG.js";
186
186
  import "./chunk-7RXCMVFQ.js";
187
- import "./chunk-TVLN5EZZ.js";
187
+ import "./chunk-CNXMWYLA.js";
188
188
  import "./chunk-D24OXEPB.js";
189
189
  import "./chunk-4JG55YV3.js";
190
190
  import "./chunk-GLERZDM7.js";
@@ -1,4 +1,4 @@
1
- import { IncomingMessage } from 'node:http';
1
+ import { IncomingMessage, ServerResponse } from 'node:http';
2
2
  import { F as EngramAccessService } from './access-service-CdW6B2qQ.js';
3
3
  import { ResolvedIdentity } from './adapters/types.js';
4
4
  import { AdapterRegistry } from './adapters/registry.js';
@@ -109,6 +109,24 @@ interface EngramAccessHttpServerOptions {
109
109
  authTokens?: string[];
110
110
  /** Dynamic token loader — called on each auth check so new/revoked tokens take effect without restart. */
111
111
  authTokensGetter?: () => string[];
112
+ /**
113
+ * Dynamic token-ENTRY loader ({token, connector} pairs from one coherent
114
+ * snapshot). Preferred over `authTokensGetter` when a `tokenPathPolicy`
115
+ * is set: the connector used for the policy decision comes from the SAME
116
+ * entry that validated, so identity can never lag validation.
117
+ */
118
+ authTokenEntriesGetter?: () => ReadonlyArray<{
119
+ token: string;
120
+ connector?: string;
121
+ }>;
122
+ /**
123
+ * Optional per-request scope policy for tokens sourced from
124
+ * `authTokenEntriesGetter`. Return false to deny the (validated) token
125
+ * for this pathname. Static `authToken`/`authTokens` (operator-supplied)
126
+ * bypass the policy. Entries whose connector is missing FAIL CLOSED when
127
+ * a policy is configured.
128
+ */
129
+ tokenPathPolicy?: (connector: string, pathname: string | undefined) => boolean;
112
130
  principal?: string;
113
131
  maxBodyBytes?: number;
114
132
  adminConsoleEnabled?: boolean;
@@ -133,6 +151,26 @@ interface EngramAccessHttpServerOptions {
133
151
  * existing health behavior.
134
152
  */
135
153
  readiness?: () => AccessHttpReadinessState;
154
+ /**
155
+ * When set, every 401 response includes
156
+ * `WWW-Authenticate: Bearer resource_metadata="<value>"` so MCP clients
157
+ * can discover the OAuth 2.0 protected-resource metadata document
158
+ * (RFC 9728). Must be an absolute http(s) URL; constructor throws on
159
+ * anything else. Unset → bare `Bearer`.
160
+ */
161
+ resourceMetadataUrl?: string;
162
+ /**
163
+ * Optional pre-auth request handler (e.g. OAuth facade mounted by
164
+ * `@remnic/server`). Runs after the admin-console handler and BEFORE
165
+ * bearer authorization. Return true if the request was fully handled
166
+ * (response ended). `ctx.authorized` reports whether the request
167
+ * carries a valid operator bearer token, so the handler can gate
168
+ * operator-only endpoints without owning token validation.
169
+ * Errors thrown by the handler flow into the existing error handling.
170
+ */
171
+ externalRequestHandler?: (req: IncomingMessage, res: ServerResponse, ctx: {
172
+ authorized: boolean;
173
+ }) => Promise<boolean>;
136
174
  }
137
175
  interface EngramAccessHttpServerStatus {
138
176
  running: boolean;
@@ -191,6 +229,8 @@ declare class EngramAccessHttpServer {
191
229
  private readonly authToken?;
192
230
  private readonly authTokens;
193
231
  private readonly authTokensGetter?;
232
+ private readonly authTokenEntriesGetter?;
233
+ private readonly tokenPathPolicy?;
194
234
  private readonly authenticatedPrincipal?;
195
235
  private readonly maxBodyBytes;
196
236
  private readonly adminConsoleEnabled;
@@ -200,6 +240,8 @@ declare class EngramAccessHttpServer {
200
240
  private readonly trustPrincipalHeader;
201
241
  private readonly adapterRegistry;
202
242
  private readonly readiness;
243
+ private readonly resourceMetadataUrl?;
244
+ private readonly externalRequestHandler?;
203
245
  private readonly writeRequestTimestamps;
204
246
  private readonly mcpServer;
205
247
  private server;
@@ -297,6 +339,14 @@ declare class EngramAccessHttpServer {
297
339
  private readRequiredNumberHeader;
298
340
  private parseOptionalBooleanHeader;
299
341
  private readValidatedBody;
342
+ /**
343
+ * Build the WWW-Authenticate challenge string for 401 responses.
344
+ * When `resourceMetadataUrl` is configured, includes the RFC 9728
345
+ * `resource_metadata` parameter so MCP clients (e.g. ChatGPT) can
346
+ * discover the OAuth 2.0 protected-resource metadata document.
347
+ * Otherwise the bare `Bearer` challenge is returned (unchanged).
348
+ */
349
+ private bearerChallenge;
300
350
  private isAuthorized;
301
351
  private timingSafeStringEqual;
302
352
  private encodeSecret;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  EngramAccessHttpServer
3
- } from "./chunk-J3UJJZKI.js";
3
+ } from "./chunk-SIPZ5UMK.js";
4
4
  import "./chunk-7WV3F5DQ.js";
5
5
  import "./chunk-SEDEKFYQ.js";
6
6
  import "./chunk-JBPKEARU.js";
@@ -9,7 +9,7 @@ import "./chunk-J64TK33U.js";
9
9
  import "./chunk-RSUYKGGZ.js";
10
10
  import "./chunk-42NQ7AVG.js";
11
11
  import "./chunk-7RXCMVFQ.js";
12
- import "./chunk-TVLN5EZZ.js";
12
+ import "./chunk-CNXMWYLA.js";
13
13
  import "./chunk-D24OXEPB.js";
14
14
  import "./chunk-4JG55YV3.js";
15
15
  import "./chunk-GLERZDM7.js";
@@ -113,6 +113,12 @@ type McpRequestOptions = {
113
113
  */
114
114
  enforceWriteQuota?: () => void | Promise<void>;
115
115
  };
116
+ /**
117
+ * MCP protocol versions this server understands, ordered newest → oldest.
118
+ * Exported so the HTTP transport can validate the `MCP-Protocol-Version`
119
+ * header and reject requests advertising an unknown version.
120
+ */
121
+ declare const MCP_SUPPORTED_PROTOCOL_VERSIONS: readonly string[];
116
122
  declare class EngramMcpServer {
117
123
  private readonly service;
118
124
  private buffer;
@@ -226,4 +232,4 @@ declare class EngramMcpServer {
226
232
  private callTool;
227
233
  }
228
234
 
229
- export { EngramMcpServer };
235
+ export { EngramMcpServer, MCP_SUPPORTED_PROTOCOL_VERSIONS };
@@ -1,6 +1,7 @@
1
1
  import {
2
- EngramMcpServer
3
- } from "./chunk-TVLN5EZZ.js";
2
+ EngramMcpServer,
3
+ MCP_SUPPORTED_PROTOCOL_VERSIONS
4
+ } from "./chunk-CNXMWYLA.js";
4
5
  import "./chunk-D24OXEPB.js";
5
6
  import "./chunk-4JG55YV3.js";
6
7
  import "./chunk-GLERZDM7.js";
@@ -136,6 +137,7 @@ import "./chunk-LBLXEFWK.js";
136
137
  import "./chunk-VFUEZZBS.js";
137
138
  import "./chunk-PZ5AY32C.js";
138
139
  export {
139
- EngramMcpServer
140
+ EngramMcpServer,
141
+ MCP_SUPPORTED_PROTOCOL_VERSIONS
140
142
  };
141
143
  //# sourceMappingURL=access-mcp.js.map
@@ -1119,7 +1119,60 @@ async function processChatMessage(opts) {
1119
1119
  }
1120
1120
 
1121
1121
  // src/access-mcp.ts
1122
- var MCP_PROTOCOL_VERSION = "2024-11-05";
1122
+ var MCP_READ_ONLY_TOOL_SUFFIXES = {
1123
+ recall: true,
1124
+ recall_explain: true,
1125
+ recall_tier_explain: true,
1126
+ recall_xray: true,
1127
+ briefing: true,
1128
+ wearables_status: true,
1129
+ transcript_day: true,
1130
+ transcript_search: true,
1131
+ transcript_memories: true,
1132
+ action_confidence: true,
1133
+ capsule_list: true,
1134
+ procedural_stats: true,
1135
+ memory_get: true,
1136
+ memory_timeline: true,
1137
+ entity_get: true,
1138
+ review_queue_list: true,
1139
+ lcm_search: true,
1140
+ continuity_incident_list: true,
1141
+ identity_anchor_get: true,
1142
+ memory_identity: true,
1143
+ memory_search: true,
1144
+ memory_profile: true,
1145
+ memory_entities_list: true,
1146
+ memory_questions: true,
1147
+ memory_last_recall: true,
1148
+ memory_intent_debug: true,
1149
+ memory_qmd_debug: true,
1150
+ memory_graph_explain: true,
1151
+ graph_snapshot: true,
1152
+ review_list: true,
1153
+ profiling_report: true,
1154
+ peer_list: true,
1155
+ peer_get: true,
1156
+ peer_profile_get: true,
1157
+ console_state: true,
1158
+ dreams_status: true,
1159
+ codegraph_list_projects: true,
1160
+ codegraph_index_status: true,
1161
+ codegraph_search_graph: true,
1162
+ codegraph_trace_path: true,
1163
+ codegraph_detect_changes: true,
1164
+ codegraph_query_graph: true,
1165
+ codegraph_get_schema: true,
1166
+ codegraph_get_snippet: true,
1167
+ codegraph_get_architecture: true,
1168
+ codegraph_search_code: true
1169
+ };
1170
+ var MCP_SUPPORTED_PROTOCOL_VERSIONS = [
1171
+ "2025-06-18",
1172
+ "2025-03-26",
1173
+ "2024-11-05"
1174
+ ];
1175
+ var MCP_DEFAULT_PROTOCOL_VERSION = MCP_SUPPORTED_PROTOCOL_VERSIONS[0] ?? "2025-06-18";
1123
1176
  var LEGACY_MCP_PREFIX = "engram.";
1124
1177
  var CANONICAL_MCP_PREFIX = "remnic.";
1125
1178
  function toCanonicalToolName(name) {
@@ -1128,6 +1181,14 @@ function toCanonicalToolName(name) {
1128
1181
  function toLegacyToolName(name) {
1129
1182
  return name.startsWith(CANONICAL_MCP_PREFIX) ? `${LEGACY_MCP_PREFIX}${name.slice(CANONICAL_MCP_PREFIX.length)}` : name;
1130
1183
  }
1184
+ function isReadOnlyToolName(name) {
1185
+ for (const prefix of [CANONICAL_MCP_PREFIX, LEGACY_MCP_PREFIX]) {
1186
+ if (name.startsWith(prefix)) {
1187
+ return MCP_READ_ONLY_TOOL_SUFFIXES[name.slice(prefix.length)] === true;
1188
+ }
1189
+ }
1190
+ return false;
1191
+ }
1131
1192
  function withToolAliases(tool, emitLegacyTools = true) {
1132
1193
  const canonicalName = toCanonicalToolName(tool.name);
1133
1194
  const canonicalTool = canonicalName === tool.name ? tool : { ...tool, name: canonicalName };
@@ -3158,6 +3219,9 @@ var EngramMcpServer = class {
3158
3219
  );
3159
3220
  this.tools = [...this.tools, ...chatTools];
3160
3221
  }
3222
+ this.tools = this.tools.map(
3223
+ (tool) => isReadOnlyToolName(tool.name) && tool.annotations?.readOnlyHint !== true ? { ...tool, annotations: { ...tool.annotations ?? {}, readOnlyHint: true } } : tool
3224
+ );
3161
3225
  }
3162
3226
  service;
3163
3227
  buffer = Buffer.alloc(0);
@@ -3247,6 +3311,16 @@ var EngramMcpServer = class {
3247
3311
  }
3248
3312
  if (method === "initialize") {
3249
3313
  const params = request.params ?? {};
3314
+ if (typeof params.protocolVersion !== "string" || params.protocolVersion.length === 0) {
3315
+ return {
3316
+ jsonrpc: "2.0",
3317
+ id,
3318
+ error: {
3319
+ code: -32602,
3320
+ message: `initialize requires params.protocolVersion (string); supported versions: ${MCP_SUPPORTED_PROTOCOL_VERSIONS.join(", ")}`
3321
+ }
3322
+ };
3323
+ }
3250
3324
  const rawClientInfo = params.clientInfo;
3251
3325
  const newSessionId = randomUUID2();
3252
3326
  if (rawClientInfo && typeof rawClientInfo.name === "string") {
@@ -3264,7 +3338,7 @@ var EngramMcpServer = class {
3264
3338
  jsonrpc: "2.0",
3265
3339
  id,
3266
3340
  result: {
3267
- protocolVersion: MCP_PROTOCOL_VERSION,
3341
+ protocolVersion: MCP_SUPPORTED_PROTOCOL_VERSIONS.includes(params.protocolVersion) ? params.protocolVersion : MCP_DEFAULT_PROTOCOL_VERSION,
3268
3342
  capabilities: {
3269
3343
  tools: {},
3270
3344
  resources: {}
@@ -3617,6 +3691,7 @@ export {
3617
3691
  cleanupExpiredChatSessions,
3618
3692
  sessionBelongsToPrincipal,
3619
3693
  processChatMessage,
3694
+ MCP_SUPPORTED_PROTOCOL_VERSIONS,
3620
3695
  EngramMcpServer
3621
3696
  };
3622
- //# sourceMappingURL=chunk-TVLN5EZZ.js.map
3697
+ //# sourceMappingURL=chunk-CNXMWYLA.js.map