@hydradb/mcp 1.1.1 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +204 -0
- package/README.md +92 -34
- package/dist/adapters.d.ts +27 -16
- package/dist/adapters.js +58 -54
- package/dist/adapters.js.map +1 -1
- package/dist/config.d.ts +2 -0
- package/dist/config.js +27 -1
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts +43 -3
- package/dist/context.js +374 -34
- package/dist/context.js.map +1 -1
- package/dist/descriptions.d.ts +55 -28
- package/dist/descriptions.js +206 -52
- package/dist/descriptions.js.map +1 -1
- package/dist/hydra/client.d.ts +77 -8
- package/dist/hydra/client.js +127 -21
- package/dist/hydra/client.js.map +1 -1
- package/dist/hydra/errors.js +91 -6
- package/dist/hydra/errors.js.map +1 -1
- package/dist/hydra/index.d.ts +2 -2
- package/dist/hydra/index.js +1 -1
- package/dist/hydra/index.js.map +1 -1
- package/dist/index.js +97 -10
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +18 -1
- package/dist/server.js +1001 -104
- package/dist/server.js.map +1 -1
- package/dist/tool-names.d.ts +2 -1
- package/dist/tool-names.js +2 -0
- package/dist/tool-names.js.map +1 -1
- package/dist/types.d.ts +8 -51
- package/dist/types.js +6 -5
- package/dist/types.js.map +1 -1
- package/package.json +11 -6
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 {
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACN,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,aAAa,GACb,MAAM,aAAa,CAAC;AAErB,4EAA4E;AAC5E,qEAAqE;AACrE,IAAI,CAAC;IACJ,aAAa,EAAE,CAAC;AACjB,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IAChB,OAAO,CAAC,KAAK,CAAC,UAAU,KAAK,YAAY,KAA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AE,EAAE;QAC3C,MAAM,CAAC,KAAK,CAAC,6BAA6B,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACzE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,KAAK,EAAE,EAAE;QACzC,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC/D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,IAAI;IAClB,MAAM,MAAM,GAAG,mBAAmB,EAAE,CAAC;IACrC,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACzB,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AACjC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACtB,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;IACpD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC,CAAC,CAAC"}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
import { HydraDB } from "./hydra/index.js";
|
|
2
|
+
/** Stop accepting tool calls. Idempotent. */
|
|
3
|
+
export declare function beginShutdown(): void;
|
|
4
|
+
/** Test-only: allow a fresh server in the same process after a shutdown test. */
|
|
5
|
+
export declare function __resetShutdown(): void;
|
|
6
|
+
/** Resolves once no tool call is running, or immediately if none is. */
|
|
7
|
+
export declare function awaitInFlight(): Promise<void>;
|
|
8
|
+
/** How many tool calls are currently running. Exported for tests and logging. */
|
|
9
|
+
export declare function inFlightCount(): number;
|
|
10
|
+
/**
|
|
11
|
+
* Whether the deprecated tool aliases are registered.
|
|
12
|
+
*
|
|
13
|
+
* Off by default as of 1.2.0. Anyone whose mcp.json still calls the old names
|
|
14
|
+
* sets HYDRADB_MCP_LEGACY_TOOLS=1 to restore them — one env var, no code change,
|
|
15
|
+
* and the opt-in is itself the adoption signal that a later removal needs and
|
|
16
|
+
* that nothing here could previously collect.
|
|
17
|
+
*/
|
|
18
|
+
export declare function legacyToolsEnabled(env?: NodeJS.ProcessEnv): boolean;
|
|
2
19
|
/** Test-only: reset the once-per-process alias warning dedupe. */
|
|
3
20
|
export declare function __resetAliasWarnings(): void;
|
|
4
|
-
export declare function createHydraDBServer(hydraOverride?: HydraDB): import("@modelcontextprotocol/sdk/server
|
|
21
|
+
export declare function createHydraDBServer(hydraOverride?: HydraDB): import("@modelcontextprotocol/sdk/server").Server<{
|
|
5
22
|
method: string;
|
|
6
23
|
params?: {
|
|
7
24
|
[x: string]: unknown;
|