@hydradb/mcp 1.1.0 → 1.2.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.
@@ -16,6 +16,29 @@
16
16
  import { HydraDBClient } from "@hydradb/sdk";
17
17
  import type { HydraDB as SDK } from "@hydradb/sdk";
18
18
  export type ContextKind = "memory" | "knowledge";
19
+ /**
20
+ * Sized to fit inside a typical MCP host's tool timeout rather than outlast it,
21
+ * so a stalled call fails with a HydraDB diagnostic the caller can act on
22
+ * instead of a generic host-side timeout carrying no information.
23
+ */
24
+ export declare const DEFAULT_TIMEOUT_SECONDS = 30;
25
+ export declare const DEFAULT_MAX_RETRIES = 2;
26
+ /**
27
+ * Per-call transport controls, separate from the domain params.
28
+ *
29
+ * `signal` carries the host's cancellation into the SDK. Without it a cancelled
30
+ * MCP tool call leaves the outbound HTTP request in flight: the caller has given
31
+ * up, and the process keeps working and keeps retrying on its behalf.
32
+ */
33
+ export interface RequestOptions {
34
+ signal?: AbortSignal;
35
+ }
36
+ /**
37
+ * Retrieval accepts a third corpus selector the write/list paths do not: `all`,
38
+ * which searches memories and knowledge together. Only `context.query` takes it
39
+ * — ingesting or deleting "all" is meaningless, so those stay `ContextKind`.
40
+ */
41
+ export type QueryKind = ContextKind | "all";
19
42
  export interface HydraConfig {
20
43
  /** Bearer token (the HydraDB API key). */
21
44
  token: string;
@@ -25,16 +48,35 @@ export interface HydraConfig {
25
48
  collection?: string;
26
49
  /** Optional base URL override; defaults to the SDK's environment. */
27
50
  baseUrl?: string;
51
+ /**
52
+ * Per-attempt deadline. The SDK's own default is 60s, which combined with its
53
+ * 2 retries means a persistently failing endpoint can occupy a caller for
54
+ * ~3 minutes with no output — far longer than any MCP host waits, so in
55
+ * practice the host times out first and the caller gets a generic error with
56
+ * no HydraDB diagnostic while this process keeps retrying.
57
+ */
58
+ timeoutSeconds?: number;
59
+ /** Retries per call. The SDK defaults to 2; set explicitly so it is a choice. */
60
+ maxRetries?: number;
28
61
  }
29
62
  export interface QueryParams {
30
63
  query: string;
31
- kind?: ContextKind;
64
+ kind?: QueryKind;
32
65
  operator?: "or" | "and" | "phrase";
33
66
  maxResults?: number;
34
67
  mode?: "fast" | "thinking" | "auto";
35
68
  graphContext?: boolean;
36
69
  alpha?: number;
37
70
  recencyBias?: number;
71
+ /**
72
+ * Restrict retrieval to these source ids. A hard pre-filter: the server
73
+ * returns nothing rather than widening when none match.
74
+ */
75
+ ids?: string[];
76
+ /** Exact-match filters over stored metadata. No ranges, no partial matches. */
77
+ metadataFilters?: Record<string, unknown>;
78
+ /** Adjacent chunks pulled in alongside each match, for surrounding context. */
79
+ numRelatedChunks?: number;
38
80
  /** Per-call collection override. */
39
81
  collection?: string;
40
82
  }
@@ -56,6 +98,19 @@ export interface IngestParams {
56
98
  /** Passed through only when `infer` is truthy (host-owned default text). */
57
99
  customInstructions?: string;
58
100
  upsert?: boolean;
101
+ /**
102
+ * Tenant metadata stored alongside the memory, and matchable later via
103
+ * `metadataFilters` on query.
104
+ *
105
+ * Accepted by the backend (`domain/memories/models.go`) but absent from the
106
+ * generated SDK request type, which is why the wrapper carries it explicitly
107
+ * inside the memory item rather than as a typed field.
108
+ */
109
+ metadata?: Record<string, unknown>;
110
+ /** Document-level metadata, matchable via `additional_metadata`. */
111
+ additionalMetadata?: Record<string, unknown>;
112
+ /** When the fact was true, as opposed to when it was stored (RFC3339 date). */
113
+ observationDate?: string;
59
114
  /** Filename to attach when ingesting knowledge text as a document. */
60
115
  filename?: string;
61
116
  collection?: string;
@@ -109,19 +164,25 @@ declare abstract class Resource {
109
164
  export declare class ContextResource extends Resource {
110
165
  constructor(sdk: HydraDBClient, database: string, collection?: string);
111
166
  /** The single retrieval entry point (SDK `client.query`). */
112
- query(params: QueryParams): Promise<SDK.SearchV2RetrievalResult>;
113
- /** Ingest a memory or knowledge item (SDK `context.ingest`, multipart). */
114
- ingest(params: IngestParams): Promise<SDK.IngestionV2SourceUploadResponse>;
167
+ query(params: QueryParams, opts?: RequestOptions): Promise<SDK.SearchV2RetrievalResult>;
168
+ /**
169
+ * Ingest a memory or knowledge item (SDK `context.ingest`, multipart).
170
+ *
171
+ * `async` so the knowledge-path validation below surfaces as a rejection.
172
+ * Every other failure in this wrapper rejects, and a caller that only handles
173
+ * `.catch()` would otherwise see this one escape as a synchronous throw.
174
+ */
175
+ ingest(params: IngestParams, opts?: RequestOptions): Promise<SDK.IngestionV2SourceUploadResponse>;
115
176
  /** List memories or knowledge sources (SDK `context.list`). */
116
- list(params?: ListParams): Promise<SDK.ListV2SourceListResponse>;
177
+ list(params?: ListParams, opts?: RequestOptions): Promise<SDK.ListV2SourceListResponse>;
117
178
  /** Fetch a source's content (SDK `context.inspect`; was "fetch content"). */
118
- inspect(params: InspectParams): Promise<SDK.FetchV2SourceFetchResponse>;
179
+ inspect(params: InspectParams, opts?: RequestOptions): Promise<SDK.FetchV2SourceFetchResponse>;
119
180
  /** Per-source indexing progress (SDK `context.status`). */
120
- ingestionStatus(params: IngestionStatusParams): Promise<SDK.IngestionV2BatchProcessingStatus>;
181
+ ingestionStatus(params: IngestionStatusParams, opts?: RequestOptions): Promise<SDK.IngestionV2BatchProcessingStatus>;
121
182
  /** Knowledge-graph relations (SDK `context.relations`). */
122
183
  relations(params?: RelationsParams): Promise<SDK.GraphGraphRelationsResponse>;
123
184
  /** Delete memories or knowledge sources (SDK `context.delete`). */
124
- delete(params: DeleteParams): Promise<SDK.SourcesMemoryDeleteResponse>;
185
+ delete(params: DeleteParams, opts?: RequestOptions): Promise<SDK.SourcesMemoryDeleteResponse>;
125
186
  }
126
187
  export declare class DatabasesResource extends Resource {
127
188
  constructor(sdk: HydraDBClient, database: string, collection?: string);
@@ -17,8 +17,34 @@ import { Buffer } from "node:buffer";
17
17
  import { HydraDBClient } from "@hydradb/sdk";
18
18
  import { unwrap } from "./envelope.js";
19
19
  import { translateError } from "./errors.js";
20
- function kindToType(kind) {
21
- return kind;
20
+ /**
21
+ * Sized to fit inside a typical MCP host's tool timeout rather than outlast it,
22
+ * so a stalled call fails with a HydraDB diagnostic the caller can act on
23
+ * instead of a generic host-side timeout carrying no information.
24
+ */
25
+ export const DEFAULT_TIMEOUT_SECONDS = 30;
26
+ export const DEFAULT_MAX_RETRIES = 2;
27
+ /**
28
+ * An SDK logger that cannot corrupt the stdio transport.
29
+ *
30
+ * The SDK's own `ConsoleLogger` implements `debug`/`info` via `console.debug` /
31
+ * `console.info`, which are stdout aliases in Node. On stdio transport stdout IS
32
+ * the JSON-RPC channel, so a single SDK log line would break the session.
33
+ *
34
+ * Not currently live — the SDK's default logger is constructed `silent: true` —
35
+ * but the exposure is one `logging: { level: "debug" }` away, which is precisely
36
+ * what someone debugging a production incident reaches for. Passing an explicit
37
+ * logger pins the safe behaviour instead of inheriting it.
38
+ */
39
+ const STDERR_LOGGER = {
40
+ debug: (message, ...args) => console.error("[hydradb-sdk]", message, ...args),
41
+ info: (message, ...args) => console.error("[hydradb-sdk]", message, ...args),
42
+ warn: (message, ...args) => console.error("[hydradb-sdk]", message, ...args),
43
+ error: (message, ...args) => console.error("[hydradb-sdk]", message, ...args),
44
+ };
45
+ /** Wrapper options → the SDK's per-request options, omitted when there is nothing to say. */
46
+ function req(opts) {
47
+ return opts?.signal ? { abortSignal: opts.signal } : undefined;
22
48
  }
23
49
  class Resource {
24
50
  constructor(sdk, database, collection) {
@@ -42,28 +68,40 @@ class Resource {
42
68
  }
43
69
  }
44
70
  export class ContextResource extends Resource {
71
+ // The base constructor is `protected`, so this one is what makes the class
72
+ // instantiable from outside the file. Removing it fails with TS2674.
73
+ // biome-ignore lint/complexity/noUselessConstructor: widens visibility
45
74
  constructor(sdk, database, collection) {
46
75
  super(sdk, database, collection);
47
76
  }
48
77
  /** The single retrieval entry point (SDK `client.query`). */
49
- query(params) {
78
+ query(params, opts) {
50
79
  return this.call("/query", () => this.sdk.query({
51
80
  ...this.scope(params.collection),
52
81
  query: params.query,
53
- type: kindToType(params.kind),
82
+ type: params.kind,
54
83
  operator: params.operator,
55
84
  maxResults: params.maxResults,
56
85
  mode: params.mode,
57
86
  graphContext: params.graphContext,
58
87
  alpha: params.alpha,
59
88
  recencyBias: params.recencyBias,
60
- }));
89
+ ids: params.ids,
90
+ metadataFilters: params.metadataFilters,
91
+ numRelatedChunks: params.numRelatedChunks,
92
+ }, req(opts)));
61
93
  }
62
- /** Ingest a memory or knowledge item (SDK `context.ingest`, multipart). */
63
- ingest(params) {
94
+ /**
95
+ * Ingest a memory or knowledge item (SDK `context.ingest`, multipart).
96
+ *
97
+ * `async` so the knowledge-path validation below surfaces as a rejection.
98
+ * Every other failure in this wrapper rejects, and a caller that only handles
99
+ * `.catch()` would otherwise see this one escape as a synchronous throw.
100
+ */
101
+ async ingest(params, opts) {
64
102
  const request = {
65
103
  ...this.scope(params.collection),
66
- type: kindToType(params.kind),
104
+ type: params.kind,
67
105
  };
68
106
  if (params.upsert != null) {
69
107
  request.upsert = String(params.upsert);
@@ -88,9 +126,41 @@ export class ContextResource extends Resource {
88
126
  item.title = params.title;
89
127
  if (params.userName != null)
90
128
  item.user_name = params.userName;
129
+ if (params.metadata != null)
130
+ item.metadata = params.metadata;
131
+ if (params.additionalMetadata != null) {
132
+ item.additional_metadata = params.additionalMetadata;
133
+ }
134
+ if (params.observationDate != null) {
135
+ item.observation_date = params.observationDate;
136
+ }
91
137
  request.memories = JSON.stringify([item]);
92
138
  }
93
139
  else {
140
+ // The knowledge path can only carry the document itself and its
141
+ // filename. Everything below belongs to the memory item shape and has
142
+ // nowhere to go here — so reject rather than accept and discard. A
143
+ // caller that sets `infer: true` on a knowledge write and is answered
144
+ // "success: 1, failed: 0" has been told its instruction was honoured
145
+ // when it was dropped on the floor.
146
+ const unsupported = [
147
+ ["pairs", params.pairs],
148
+ ["sourceId", params.sourceId],
149
+ ["infer", params.infer],
150
+ ["isMarkdown", params.isMarkdown],
151
+ ["customInstructions", params.customInstructions],
152
+ ["userName", params.userName],
153
+ ["metadata", params.metadata],
154
+ ["additionalMetadata", params.additionalMetadata],
155
+ ["observationDate", params.observationDate],
156
+ ]
157
+ .filter(([, value]) => value != null)
158
+ .map(([name]) => name);
159
+ if (unsupported.length > 0) {
160
+ throw new Error(`Knowledge ingestion does not support ${unsupported.join(", ")} — ` +
161
+ `those apply to memory ingestion only. Pass kind "memory" instead, ` +
162
+ `or drop them.`);
163
+ }
94
164
  // Knowledge is multipart with the document as a file part — never the
95
165
  // `app_knowledge` JSON field (guards the DX-G-002 class of bug).
96
166
  if (params.text != null) {
@@ -103,54 +173,57 @@ export class ContextResource extends Resource {
103
173
  };
104
174
  }
105
175
  }
106
- return this.call("/context/ingest", () => this.sdk.context.ingest(request));
176
+ return this.call("/context/ingest", () => this.sdk.context.ingest(request, req(opts)));
107
177
  }
108
178
  /** List memories or knowledge sources (SDK `context.list`). */
109
- list(params = {}) {
179
+ list(params = {}, opts) {
110
180
  return this.call("/context/list", () => this.sdk.context.list({
111
181
  ...this.scope(params.collection),
112
- type: kindToType(params.kind),
182
+ type: params.kind,
113
183
  ids: params.ids,
114
184
  page: params.page,
115
185
  pageSize: params.pageSize,
116
- }));
186
+ }, req(opts)));
117
187
  }
118
188
  /** Fetch a source's content (SDK `context.inspect`; was "fetch content"). */
119
- inspect(params) {
189
+ inspect(params, opts) {
120
190
  return this.call("/context/inspect", () => this.sdk.context.inspect({
121
191
  ...this.scope(params.collection),
122
192
  id: params.id,
123
193
  mode: params.mode,
124
194
  expirySeconds: params.expirySeconds,
125
- }));
195
+ }, req(opts)));
126
196
  }
127
197
  /** Per-source indexing progress (SDK `context.status`). */
128
- ingestionStatus(params) {
198
+ ingestionStatus(params, opts) {
129
199
  return this.call("/context/status", () => this.sdk.context.status({
130
200
  ...this.scope(params.collection),
131
201
  ids: params.ids,
132
- }));
202
+ }, req(opts)));
133
203
  }
134
204
  /** Knowledge-graph relations (SDK `context.relations`). */
135
205
  relations(params = {}) {
136
206
  return this.call("/context/relations", () => this.sdk.context.relations({
137
207
  ...this.scope(params.collection),
138
208
  id: params.id,
139
- type: kindToType(params.kind),
209
+ type: params.kind,
140
210
  limit: params.limit,
141
211
  cursor: params.cursor,
142
212
  }));
143
213
  }
144
214
  /** Delete memories or knowledge sources (SDK `context.delete`). */
145
- delete(params) {
215
+ delete(params, opts) {
146
216
  return this.call("/context", () => this.sdk.context.delete({
147
217
  ...this.scope(params.collection),
148
218
  ids: params.ids,
149
- type: kindToType(params.kind),
150
- }));
219
+ type: params.kind,
220
+ }, req(opts)));
151
221
  }
152
222
  }
153
223
  export class DatabasesResource extends Resource {
224
+ // The base constructor is `protected`, so this one is what makes the class
225
+ // instantiable from outside the file. Removing it fails with TS2674.
226
+ // biome-ignore lint/complexity/noUselessConstructor: widens visibility
154
227
  constructor(sdk, database, collection) {
155
228
  super(sdk, database, collection);
156
229
  }
@@ -189,6 +262,15 @@ export class HydraDB {
189
262
  new HydraDBClient({
190
263
  token: config.token,
191
264
  ...(config.baseUrl != null ? { baseUrl: config.baseUrl } : {}),
265
+ // Both are stated rather than inherited. The SDK's defaults (60s,
266
+ // 2 retries) were never chosen by this server, and their product is
267
+ // a ~3 minute worst case on the slowest tool it exposes.
268
+ timeoutInSeconds: config.timeoutSeconds ?? DEFAULT_TIMEOUT_SECONDS,
269
+ maxRetries: config.maxRetries ?? DEFAULT_MAX_RETRIES,
270
+ // Never inherit the SDK's console logger: it writes to stdout, which
271
+ // on stdio transport is the JSON-RPC channel. Only the sink is
272
+ // overridden — level and silencing keep the SDK's own defaults.
273
+ logging: { logger: STDERR_LOGGER },
192
274
  });
193
275
  this.context = new ContextResource(client, config.database, config.collection);
194
276
  this.databases = new DatabasesResource(client, config.database, config.collection);
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/hydra/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAA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C;QAC/E,IAAI,CAAC,SAAS,GAAG,IAAI,iBAAiB,CACrC,MAAM,EACN,MAAM,CAAC,QAAQ,EACf,MAAM,CAAC,UAAU,CACjB,CAAC;IACH,CAAC;CACD"}
@@ -27,17 +27,102 @@ export class HydraWrapperError extends Error {
27
27
  Object.setPrototypeOf(this, HydraWrapperError.prototype);
28
28
  }
29
29
  }
30
+ /** Anything past this is not diagnosis, it is payload. */
31
+ const MAX_BODY_CHARS = 512;
32
+ /**
33
+ * Credential-shaped substrings, scrubbed before an error body is shown.
34
+ *
35
+ * Defence in depth for bodies we did not write. HydraDB's own error path is
36
+ * clean — every 401 message is a static string literal and backend failures
37
+ * collapse to "Internal server error" — but this string also carries whatever a
38
+ * CDN, load balancer, WAF or corporate proxy returns, and those are not ours to
39
+ * vouch for. The SDK already redacts sensitive headers and query params before
40
+ * logging; response bodies are the one place it does not.
41
+ */
42
+ const SECRET_PATTERNS = [
43
+ [/\bBearer\s+\S+/gi, "Bearer [redacted]"],
44
+ [/\b(sk|hdb|key|tok)[-_][A-Za-z0-9_-]{16,}/g, "[redacted]"],
45
+ [
46
+ /("(?:api[-_]?key|token|authorization|password|secret)"\s*:\s*)"[^"]*"/gi,
47
+ '$1"[redacted]"',
48
+ ],
49
+ ];
50
+ function scrub(text) {
51
+ let out = text;
52
+ for (const [pattern, replacement] of SECRET_PATTERNS) {
53
+ out = out.replace(pattern, replacement);
54
+ }
55
+ return out;
56
+ }
57
+ /** Reduce an HTML error page to its readable text, so the cap spends its budget well. */
58
+ function stripMarkup(text) {
59
+ if (!/^\s*</.test(text))
60
+ return text;
61
+ const title = text.match(/<title[^>]*>([\s\S]*?)<\/title>/i)?.[1]?.trim();
62
+ const stripped = text
63
+ .replace(/<script[\s\S]*?<\/script>/gi, " ")
64
+ .replace(/<style[\s\S]*?<\/style>/gi, " ")
65
+ .replace(/<[^>]+>/g, " ")
66
+ .replace(/\s+/g, " ")
67
+ .trim();
68
+ return title ? `${title} — ${stripped}` : stripped;
69
+ }
70
+ /**
71
+ * The v2 envelope, when the body is one.
72
+ *
73
+ * Rendering `error.code` / `error.message` / `meta.request_id` instead of the
74
+ * whole JSON blob makes the common case both shorter AND more useful: the
75
+ * request id is exactly what a user needs to file a support ticket, and it was
76
+ * previously buried in a stringified object.
77
+ */
78
+ function fromEnvelope(body) {
79
+ if (body == null || typeof body !== "object")
80
+ return undefined;
81
+ const record = body;
82
+ const error = record.error;
83
+ if (error == null || typeof error !== "object")
84
+ return undefined;
85
+ const { code, message } = error;
86
+ const parts = [];
87
+ if (typeof code === "string" && code !== "")
88
+ parts.push(code);
89
+ if (typeof message === "string" && message !== "")
90
+ parts.push(message);
91
+ if (parts.length === 0)
92
+ return undefined;
93
+ const meta = record.meta;
94
+ const requestId = meta != null && typeof meta === "object"
95
+ ? meta.request_id
96
+ : undefined;
97
+ const trailer = typeof requestId === "string" && requestId !== ""
98
+ ? ` (request_id: ${requestId})`
99
+ : "";
100
+ return `${parts.join(": ")}${trailer}`;
101
+ }
30
102
  function bodyToString(body) {
31
103
  if (body == null)
32
104
  return "";
33
- if (typeof body === "string")
34
- return body;
35
- try {
36
- return JSON.stringify(body);
105
+ const structured = fromEnvelope(body);
106
+ if (structured != null)
107
+ return truncate(scrub(structured));
108
+ let raw;
109
+ if (typeof body === "string") {
110
+ raw = body;
37
111
  }
38
- catch {
39
- return String(body);
112
+ else {
113
+ try {
114
+ raw = JSON.stringify(body);
115
+ }
116
+ catch {
117
+ raw = String(body);
118
+ }
40
119
  }
120
+ return truncate(scrub(stripMarkup(raw)));
121
+ }
122
+ function truncate(text) {
123
+ if (text.length <= MAX_BODY_CHARS)
124
+ return text;
125
+ return `${text.slice(0, MAX_BODY_CHARS)}… (truncated, ${text.length} chars)`;
41
126
  }
42
127
  /**
43
128
  * Translate any error thrown by an SDK call into a `HydraWrapperError` carrying
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/hydra/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;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CAAC;IACD,OAAO,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC7B,IAAI,IAAI,CAAC,MAAM,IAAI,cAAc;QAAE,OAAO,IAAI,CAAC;IAC/C,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,iBAAiB,IAAI,CAAC,MAAM,SAAS,CAAC;AAC9E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,GAAY;IACxD,IAAI,GAAG,YAAY,YAAY,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,GAAG,CAAC,UAAU,CAAC;QAC9B,MAAM,UAAU,GAAG,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAC3D,OAAO,IAAI,iBAAiB,CAC3B,YAAY,IAAI,MAAM,UAAU,KAAK,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAC7D,IAAI,EACJ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,CACtC,CAAC;IACH,CAAC;IAED,sEAAsE;IACtE,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjE,OAAO,IAAI,iBAAiB,CAAC,YAAY,IAAI,WAAW,OAAO,EAAE,EAAE,IAAI,EAAE;QACxE,KAAK,EAAE,GAAG;KACV,CAAC,CAAC;AACJ,CAAC"}
@@ -5,7 +5,7 @@
5
5
  * It is intentionally self-contained so the same pattern can be ported to the
6
6
  * other client repos (per CONTRACT.md).
7
7
  */
8
- export { HydraDB, ContextResource, DatabasesResource } from "./client.js";
9
- export type { HydraConfig, ContextKind, ConversationTurn, QueryParams, IngestParams, ListParams, InspectParams, IngestionStatusParams, RelationsParams, DeleteParams, CreateDatabaseParams, } from "./client.js";
8
+ export { HydraDB, ContextResource, DatabasesResource, DEFAULT_TIMEOUT_SECONDS, DEFAULT_MAX_RETRIES, } from "./client.js";
9
+ export type { HydraConfig, ContextKind, RequestOptions, QueryKind, ConversationTurn, QueryParams, IngestParams, ListParams, InspectParams, IngestionStatusParams, RelationsParams, DeleteParams, CreateDatabaseParams, } from "./client.js";
10
10
  export { HydraWrapperError, translateError } from "./errors.js";
11
11
  export { unwrap } from "./envelope.js";
@@ -5,7 +5,7 @@
5
5
  * It is intentionally self-contained so the same pattern can be ported to the
6
6
  * other client repos (per CONTRACT.md).
7
7
  */
8
- export { HydraDB, ContextResource, DatabasesResource } from "./client.js";
8
+ export { HydraDB, ContextResource, DatabasesResource, DEFAULT_TIMEOUT_SECONDS, DEFAULT_MAX_RETRIES, } from "./client.js";
9
9
  export { HydraWrapperError, translateError } from "./errors.js";
10
10
  export { unwrap } from "./envelope.js";
11
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hydra/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAc1E,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hydra/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACN,OAAO,EACP,eAAe,EACf,iBAAiB,EACjB,uBAAuB,EACvB,mBAAmB,GACnB,MAAM,aAAa,CAAC;AAgBrB,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
3
  import { resolveConfig } from "./config.js";
4
- import { createHydraDBServer } from "./server.js";
4
+ import { logger } from "./logger.js";
5
+ import { awaitInFlight, beginShutdown, createHydraDBServer, inFlightCount, } from "./server.js";
5
6
  // Fail fast with a clean message if required config is missing. Honours the
6
7
  // canonical HYDRADB_* names (and the deprecated HYDRA_DB_* aliases).
7
8
  try {
@@ -11,16 +12,102 @@ catch (error) {
11
12
  console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
12
13
  process.exit(1);
13
14
  }
14
- async function main() {
15
- try {
16
- const server = createHydraDBServer();
17
- const transport = new StdioServerTransport();
18
- await server.connect(transport);
19
- }
20
- catch (error) {
21
- console.error("Fatal error running server:", error);
15
+ /**
16
+ * How long to let in-flight work finish after a stop signal.
17
+ *
18
+ * SIGTERM is how most MCP hosts and container runtimes stop a server, and an
19
+ * ingest that has been accepted but not yet answered is the case worth
20
+ * protecting: dropping it leaves the caller unable to tell whether the write
21
+ * committed. Short enough that nothing hangs a shutdown.
22
+ */
23
+ const SHUTDOWN_GRACE_MS = 5000;
24
+ /** Stack included when there is one — this is the last thing logged before exit. */
25
+ function describe(error) {
26
+ if (error instanceof Error)
27
+ return error.stack ?? `${error.name}: ${error.message}`;
28
+ return String(error);
29
+ }
30
+ /**
31
+ * Wire process-level lifecycle handling.
32
+ *
33
+ * Before this the server had none: no SIGINT/SIGTERM handling, no
34
+ * unhandledRejection, no uncaughtException, and no transport close handling.
35
+ * SIGTERM terminated the process immediately, dropping any in-flight request
36
+ * with no log line; and after `connect()` resolved, a stray rejection killed the
37
+ * process with a raw stack on stderr and no MCP-level notice, so the host simply
38
+ * saw the server vanish mid-session.
39
+ *
40
+ * Everything here writes to stderr only. On stdio transport, stdout is the
41
+ * JSON-RPC channel and any stray byte on it corrupts the stream.
42
+ */
43
+ function installLifecycle(server) {
44
+ let shuttingDown = false;
45
+ const shutdown = async (signal) => {
46
+ // A second signal means the operator is impatient; honour that rather
47
+ // than waiting out the grace period twice.
48
+ if (shuttingDown) {
49
+ logger.warn(`${signal} received again — exiting immediately`);
50
+ process.exit(130);
51
+ }
52
+ shuttingDown = true;
53
+ // Stop accepting NEW calls before draining. Without this, a call arriving
54
+ // after the drain resolves but before the transport closes is accepted and
55
+ // then aborted, which is the failure draining exists to prevent.
56
+ beginShutdown();
57
+ logger.info(`${signal} received — shutting down`);
58
+ const timer = setTimeout(() => {
59
+ logger.warn(`in-flight work did not finish within ${SHUTDOWN_GRACE_MS}ms — exiting anyway`);
60
+ process.exit(0);
61
+ }, SHUTDOWN_GRACE_MS);
62
+ // Do not let the grace timer itself hold the process open.
63
+ timer.unref();
64
+ try {
65
+ // Drain BEFORE closing. `server.close()` tears down the transport; it
66
+ // does not wait for handlers already running, so closing first would
67
+ // cut an accepted ingest off mid-write and leave the caller unable to
68
+ // tell whether it committed.
69
+ const pending = inFlightCount();
70
+ if (pending > 0) {
71
+ logger.info(`waiting for ${pending} in-flight tool call(s)`);
72
+ await awaitInFlight();
73
+ }
74
+ await server.close();
75
+ }
76
+ catch (error) {
77
+ logger.error("error while closing the server", { error: describe(error) });
78
+ }
79
+ clearTimeout(timer);
80
+ process.exit(0);
81
+ };
82
+ process.on("SIGINT", () => void shutdown("SIGINT"));
83
+ process.on("SIGTERM", () => void shutdown("SIGTERM"));
84
+ // The host closing the pipe is a normal end of session, not a failure.
85
+ server.onclose = () => {
86
+ if (shuttingDown)
87
+ return;
88
+ logger.info("transport closed — exiting");
89
+ process.exit(0);
90
+ };
91
+ server.onerror = (error) => {
92
+ logger.error("transport error", { error: describe(error) });
93
+ };
94
+ // Node terminates on an unhandled rejection by default, with a raw stack and
95
+ // no explanation of which server it came from. Log it in our own format, then
96
+ // exit non-zero so a supervisor restarts rather than silently continuing.
97
+ process.on("unhandledRejection", (reason) => {
98
+ logger.error("unhandled promise rejection", { error: describe(reason) });
99
+ process.exit(1);
100
+ });
101
+ process.on("uncaughtException", (error) => {
102
+ logger.error("uncaught exception", { error: describe(error) });
22
103
  process.exit(1);
23
- }
104
+ });
105
+ }
106
+ async function main() {
107
+ const server = createHydraDBServer();
108
+ installLifecycle(server);
109
+ const transport = new StdioServerTransport();
110
+ await server.connect(transport);
24
111
  }
25
112
  main().catch((error) => {
26
113
  console.error("Fatal error running server:", error);