driggsby 0.1.6 → 0.1.7
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/shim/server.js +3 -2
- package/dist/shim/stdio-transport.js +74 -0
- package/package.json +1 -1
package/dist/shim/server.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-deprecated */
|
|
2
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
2
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
4
3
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
5
4
|
import { ensureBrokerRunning } from "../broker/launch.js";
|
|
@@ -9,6 +8,7 @@ import { KeyringSecretStore } from "../broker/secret-store.js";
|
|
|
9
8
|
import { retryOperation } from "../lib/retry.js";
|
|
10
9
|
import { buildBrokerInvestigationMessage, errorMessageIncludesReauthenticationCommand, formatRetryWindow, } from "../lib/user-guidance.js";
|
|
11
10
|
import { formatStatusText } from "../cli/format.js";
|
|
11
|
+
import { LifecycleAwareStdioServerTransport } from "./stdio-transport.js";
|
|
12
12
|
const LOCAL_STATUS_TOOL = {
|
|
13
13
|
description: "Report readiness and connectivity for the shared local Driggsby broker.",
|
|
14
14
|
inputSchema: {
|
|
@@ -27,7 +27,8 @@ export async function runMcpServerCommand(runtimePaths, entrypointPath) {
|
|
|
27
27
|
secretStore,
|
|
28
28
|
});
|
|
29
29
|
const server = createLocalShimServer(runtimePaths, secretStore);
|
|
30
|
-
|
|
30
|
+
const transport = new LifecycleAwareStdioServerTransport();
|
|
31
|
+
await server.connect(transport);
|
|
31
32
|
}
|
|
32
33
|
export function createLocalShimServer(runtimePaths, secretStore) {
|
|
33
34
|
const server = new Server({
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
export class LifecycleAwareStdioServerTransport {
|
|
4
|
+
delegate;
|
|
5
|
+
stdin;
|
|
6
|
+
closingPromise = null;
|
|
7
|
+
started = false;
|
|
8
|
+
onclose;
|
|
9
|
+
onerror;
|
|
10
|
+
onmessage;
|
|
11
|
+
handleInputClosed = () => {
|
|
12
|
+
void this.close().catch((error) => {
|
|
13
|
+
this.onerror?.(error instanceof Error
|
|
14
|
+
? error
|
|
15
|
+
: new Error("The Driggsby MCP transport could not close cleanly."));
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
constructor(stdin = process.stdin, stdout = process.stdout) {
|
|
19
|
+
this.stdin = stdin;
|
|
20
|
+
this.delegate = new StdioServerTransport(stdin, stdout);
|
|
21
|
+
this.delegate.onclose = () => {
|
|
22
|
+
this.onclose?.();
|
|
23
|
+
};
|
|
24
|
+
this.delegate.onerror = (error) => {
|
|
25
|
+
this.onerror?.(error);
|
|
26
|
+
};
|
|
27
|
+
this.delegate.onmessage = (message) => {
|
|
28
|
+
this.onmessage?.(message);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async start() {
|
|
32
|
+
if (this.started) {
|
|
33
|
+
throw new Error("LifecycleAwareStdioServerTransport already started.");
|
|
34
|
+
}
|
|
35
|
+
this.started = true;
|
|
36
|
+
this.stdin.once("close", this.handleInputClosed);
|
|
37
|
+
this.stdin.once("end", this.handleInputClosed);
|
|
38
|
+
try {
|
|
39
|
+
await this.delegate.start();
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
this.removeInputListeners();
|
|
43
|
+
this.started = false;
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async close() {
|
|
48
|
+
if (this.closingPromise !== null) {
|
|
49
|
+
await this.closingPromise;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
this.closingPromise = (async () => {
|
|
53
|
+
if (!this.started) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
this.started = false;
|
|
57
|
+
this.removeInputListeners();
|
|
58
|
+
await this.delegate.close();
|
|
59
|
+
})();
|
|
60
|
+
try {
|
|
61
|
+
await this.closingPromise;
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
this.closingPromise = null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async send(message) {
|
|
68
|
+
await this.delegate.send(message);
|
|
69
|
+
}
|
|
70
|
+
removeInputListeners() {
|
|
71
|
+
this.stdin.off("close", this.handleInputClosed);
|
|
72
|
+
this.stdin.off("end", this.handleInputClosed);
|
|
73
|
+
}
|
|
74
|
+
}
|