driggsby 0.1.11 → 0.1.13
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/.gitignore +2 -0
- package/README.md +16 -11
- package/binary-install.js +212 -0
- package/binary.js +128 -0
- package/install.js +4 -0
- package/npm-shrinkwrap.json +545 -0
- package/package.json +53 -41
- package/run-driggsby.js +4 -0
- package/dist/auth/browser.js +0 -31
- package/dist/auth/config.js +0 -23
- package/dist/auth/discovery.js +0 -42
- package/dist/auth/dpop.js +0 -44
- package/dist/auth/login.js +0 -126
- package/dist/auth/loopback.js +0 -157
- package/dist/auth/oauth.js +0 -136
- package/dist/auth/pkce.js +0 -12
- package/dist/auth/url-security.js +0 -16
- package/dist/broker/authentication.js +0 -49
- package/dist/broker/client.js +0 -148
- package/dist/broker/daemon.js +0 -65
- package/dist/broker/file-secret-store.js +0 -130
- package/dist/broker/installation.js +0 -154
- package/dist/broker/ipc.js +0 -12
- package/dist/broker/keyring-secret-store.js +0 -34
- package/dist/broker/launch.js +0 -35
- package/dist/broker/lock.js +0 -84
- package/dist/broker/remote-mcp.js +0 -129
- package/dist/broker/remote-session.js +0 -173
- package/dist/broker/resolve-secret-store.js +0 -52
- package/dist/broker/secret-store.js +0 -13
- package/dist/broker/server.js +0 -177
- package/dist/broker/session.js +0 -31
- package/dist/broker/test-support.js +0 -258
- package/dist/broker/types.js +0 -1
- package/dist/cli/commands/broker-daemon.js +0 -4
- package/dist/cli/commands/login.js +0 -35
- package/dist/cli/commands/logout.js +0 -20
- package/dist/cli/commands/status.js +0 -13
- package/dist/cli/format.js +0 -84
- package/dist/index.js +0 -39
- package/dist/lib/json-file.js +0 -36
- package/dist/lib/retry.js +0 -22
- package/dist/lib/runtime-paths.js +0 -62
- package/dist/lib/user-guidance.js +0 -19
- package/dist/shim/server.js +0 -143
- package/dist/shim/stdio-transport.js +0 -106
package/dist/shim/server.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-deprecated */
|
|
2
|
-
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
|
-
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
-
import { ensureBrokerRunning } from "../broker/launch.js";
|
|
5
|
-
import { callBrokerTool, getBrokerStatus, listBrokerTools, } from "../broker/client.js";
|
|
6
|
-
import { resolveBrokerStatusForDisplay } from "../broker/installation.js";
|
|
7
|
-
import { resolveSecretStore } from "../broker/resolve-secret-store.js";
|
|
8
|
-
import { retryOperation } from "../lib/retry.js";
|
|
9
|
-
import { buildBrokerInvestigationMessage, errorMessageIncludesReauthenticationCommand, formatRetryWindow, } from "../lib/user-guidance.js";
|
|
10
|
-
import { formatStatusText, } from "../cli/format.js";
|
|
11
|
-
import { LifecycleAwareStdioServerTransport } from "./stdio-transport.js";
|
|
12
|
-
const LOCAL_STATUS_TOOL = {
|
|
13
|
-
description: "Report readiness and connectivity for the shared local Driggsby broker.",
|
|
14
|
-
inputSchema: {
|
|
15
|
-
additionalProperties: false,
|
|
16
|
-
properties: {},
|
|
17
|
-
type: "object",
|
|
18
|
-
},
|
|
19
|
-
name: "get_local_broker_status",
|
|
20
|
-
};
|
|
21
|
-
const BROKER_OPERATION_RETRY_DELAYS_MS = [0, 250, 500, 1_000, 2_000];
|
|
22
|
-
export async function runMcpServerCommand(runtimePaths, entrypointPath) {
|
|
23
|
-
const secretStore = (await resolveSecretStore(runtimePaths)).store;
|
|
24
|
-
await ensureBrokerRunning({
|
|
25
|
-
entrypointPath,
|
|
26
|
-
runtimePaths,
|
|
27
|
-
secretStore,
|
|
28
|
-
});
|
|
29
|
-
const server = createLocalShimServer(runtimePaths, secretStore);
|
|
30
|
-
const transport = new LifecycleAwareStdioServerTransport();
|
|
31
|
-
await server.connect(transport);
|
|
32
|
-
}
|
|
33
|
-
export function createLocalShimServer(runtimePaths, secretStore) {
|
|
34
|
-
const server = new Server({
|
|
35
|
-
name: "driggsby-local-broker",
|
|
36
|
-
version: "0.1.0",
|
|
37
|
-
}, {
|
|
38
|
-
capabilities: {
|
|
39
|
-
tools: {},
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
43
|
-
const remoteTools = await loadRemoteToolsOrThrow(runtimePaths, secretStore);
|
|
44
|
-
return {
|
|
45
|
-
tools: [LOCAL_STATUS_TOOL, ...remoteTools],
|
|
46
|
-
};
|
|
47
|
-
});
|
|
48
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
49
|
-
if (request.params.name === LOCAL_STATUS_TOOL.name) {
|
|
50
|
-
return await buildLocalStatusToolResult(runtimePaths, secretStore);
|
|
51
|
-
}
|
|
52
|
-
const remoteTools = await loadRemoteToolsOrThrow(runtimePaths, secretStore);
|
|
53
|
-
if (!remoteTools.some((tool) => tool.name === request.params.name)) {
|
|
54
|
-
throw new Error("That Driggsby tool is not available in this session anymore. Ask the client to refresh its tool list and try again.");
|
|
55
|
-
}
|
|
56
|
-
const toolResult = await callBrokerToolOrThrow(runtimePaths, secretStore, request.params.name, asToolArguments(request.params.arguments));
|
|
57
|
-
return toolResult;
|
|
58
|
-
});
|
|
59
|
-
return server;
|
|
60
|
-
}
|
|
61
|
-
async function buildLocalStatusToolResult(runtimePaths, secretStore) {
|
|
62
|
-
const liveStatus = await getBrokerStatus({ runtimePaths, secretStore });
|
|
63
|
-
const status = await resolveBrokerStatusForDisplay(runtimePaths, secretStore, liveStatus);
|
|
64
|
-
return {
|
|
65
|
-
content: [
|
|
66
|
-
{
|
|
67
|
-
text: formatStatusText(status).trimEnd(),
|
|
68
|
-
type: "text",
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
function asToolArguments(argumentsValue) {
|
|
74
|
-
if (argumentsValue === undefined) {
|
|
75
|
-
return undefined;
|
|
76
|
-
}
|
|
77
|
-
if (typeof argumentsValue !== "object" ||
|
|
78
|
-
argumentsValue === null ||
|
|
79
|
-
Array.isArray(argumentsValue)) {
|
|
80
|
-
throw new Error("Driggsby received invalid tool arguments.");
|
|
81
|
-
}
|
|
82
|
-
return argumentsValue;
|
|
83
|
-
}
|
|
84
|
-
async function loadRemoteToolsOrThrow(runtimePaths, secretStore) {
|
|
85
|
-
try {
|
|
86
|
-
return await retryOperation(async () => {
|
|
87
|
-
const remoteTools = await listBrokerTools({
|
|
88
|
-
runtimePaths,
|
|
89
|
-
secretStore,
|
|
90
|
-
});
|
|
91
|
-
if (remoteTools === null) {
|
|
92
|
-
throw new Error("The local Driggsby broker is not responding yet.");
|
|
93
|
-
}
|
|
94
|
-
return remoteTools;
|
|
95
|
-
}, {
|
|
96
|
-
delaysMs: BROKER_OPERATION_RETRY_DELAYS_MS,
|
|
97
|
-
shouldRetry: shouldRetryBrokerOperation,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
if (errorMessageIncludesReauthenticationCommand(error)) {
|
|
102
|
-
throw error;
|
|
103
|
-
}
|
|
104
|
-
throw new Error(buildBrokerInvestigationMessage(`The local Driggsby broker could not load the Driggsby tool list after ${BROKER_OPERATION_RETRY_DELAYS_MS.length} attempts over ${formatRetryWindow(BROKER_OPERATION_RETRY_DELAYS_MS)}`));
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
async function callBrokerToolOrThrow(runtimePaths, secretStore, toolName, args) {
|
|
108
|
-
try {
|
|
109
|
-
return await retryOperation(async () => {
|
|
110
|
-
const toolResult = await callBrokerTool({
|
|
111
|
-
runtimePaths,
|
|
112
|
-
secretStore,
|
|
113
|
-
}, toolName, args);
|
|
114
|
-
if (toolResult === null) {
|
|
115
|
-
throw new Error("The local Driggsby broker is not responding yet.");
|
|
116
|
-
}
|
|
117
|
-
return toolResult;
|
|
118
|
-
}, {
|
|
119
|
-
delaysMs: BROKER_OPERATION_RETRY_DELAYS_MS,
|
|
120
|
-
shouldRetry: shouldRetryBrokerOperation,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
if (errorMessageIncludesReauthenticationCommand(error)) {
|
|
125
|
-
throw error;
|
|
126
|
-
}
|
|
127
|
-
if (error instanceof Error && error.message.includes("not available in this session anymore")) {
|
|
128
|
-
throw error;
|
|
129
|
-
}
|
|
130
|
-
throw new Error(buildBrokerInvestigationMessage(`The local Driggsby broker could not run \`${toolName}\` after ${BROKER_OPERATION_RETRY_DELAYS_MS.length} attempts over ${formatRetryWindow(BROKER_OPERATION_RETRY_DELAYS_MS)}`));
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
function shouldRetryBrokerOperation(error) {
|
|
134
|
-
if (errorMessageIncludesReauthenticationCommand(error)) {
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
if (!(error instanceof Error)) {
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
const message = error.message.toLowerCase();
|
|
141
|
-
return (!message.includes("not available in this session anymore") &&
|
|
142
|
-
!message.includes("invalid tool arguments"));
|
|
143
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import process from "node:process";
|
|
2
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
-
export class LifecycleAwareStdioServerTransport {
|
|
4
|
-
delegate;
|
|
5
|
-
stdin;
|
|
6
|
-
parentPollIntervalMs;
|
|
7
|
-
parentProcess;
|
|
8
|
-
startingParentPid;
|
|
9
|
-
closingPromise = null;
|
|
10
|
-
parentPollHandle = null;
|
|
11
|
-
started = false;
|
|
12
|
-
onclose;
|
|
13
|
-
onerror;
|
|
14
|
-
onmessage;
|
|
15
|
-
handleInputClosed = () => {
|
|
16
|
-
this.closeForLifecycleEnd("input stream closed");
|
|
17
|
-
};
|
|
18
|
-
handleParentProcessChanged = () => {
|
|
19
|
-
if (this.parentProcess.ppid === this.startingParentPid) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
this.closeForLifecycleEnd("parent process exited");
|
|
23
|
-
};
|
|
24
|
-
constructor(stdin = process.stdin, stdout = process.stdout, options = {}) {
|
|
25
|
-
this.stdin = stdin;
|
|
26
|
-
this.parentPollIntervalMs = options.parentPollIntervalMs ?? 1_000;
|
|
27
|
-
this.parentProcess = options.parentProcess ?? process;
|
|
28
|
-
this.startingParentPid = this.parentProcess.ppid;
|
|
29
|
-
this.delegate = new StdioServerTransport(stdin, stdout);
|
|
30
|
-
this.delegate.onclose = () => {
|
|
31
|
-
this.onclose?.();
|
|
32
|
-
};
|
|
33
|
-
this.delegate.onerror = (error) => {
|
|
34
|
-
this.onerror?.(error);
|
|
35
|
-
};
|
|
36
|
-
this.delegate.onmessage = (message) => {
|
|
37
|
-
this.onmessage?.(message);
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
async start() {
|
|
41
|
-
if (this.started) {
|
|
42
|
-
throw new Error("LifecycleAwareStdioServerTransport already started.");
|
|
43
|
-
}
|
|
44
|
-
this.started = true;
|
|
45
|
-
this.stdin.once("close", this.handleInputClosed);
|
|
46
|
-
this.stdin.once("end", this.handleInputClosed);
|
|
47
|
-
this.startParentWatchdog();
|
|
48
|
-
try {
|
|
49
|
-
await this.delegate.start();
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
this.removeInputListeners();
|
|
53
|
-
this.stopParentWatchdog();
|
|
54
|
-
this.started = false;
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
async close() {
|
|
59
|
-
if (this.closingPromise !== null) {
|
|
60
|
-
await this.closingPromise;
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
this.closingPromise = (async () => {
|
|
64
|
-
if (!this.started) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
this.started = false;
|
|
68
|
-
this.removeInputListeners();
|
|
69
|
-
this.stopParentWatchdog();
|
|
70
|
-
await this.delegate.close();
|
|
71
|
-
})();
|
|
72
|
-
try {
|
|
73
|
-
await this.closingPromise;
|
|
74
|
-
}
|
|
75
|
-
finally {
|
|
76
|
-
this.closingPromise = null;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
async send(message) {
|
|
80
|
-
await this.delegate.send(message);
|
|
81
|
-
}
|
|
82
|
-
closeForLifecycleEnd(reason) {
|
|
83
|
-
void this.close().catch((error) => {
|
|
84
|
-
this.onerror?.(error instanceof Error
|
|
85
|
-
? error
|
|
86
|
-
: new Error(`The Driggsby MCP transport could not close cleanly after ${reason}.`));
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
removeInputListeners() {
|
|
90
|
-
this.stdin.off("close", this.handleInputClosed);
|
|
91
|
-
this.stdin.off("end", this.handleInputClosed);
|
|
92
|
-
}
|
|
93
|
-
startParentWatchdog() {
|
|
94
|
-
this.parentPollHandle = setInterval(() => {
|
|
95
|
-
this.handleParentProcessChanged();
|
|
96
|
-
}, this.parentPollIntervalMs);
|
|
97
|
-
this.parentPollHandle.unref();
|
|
98
|
-
}
|
|
99
|
-
stopParentWatchdog() {
|
|
100
|
-
if (this.parentPollHandle === null) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
clearInterval(this.parentPollHandle);
|
|
104
|
-
this.parentPollHandle = null;
|
|
105
|
-
}
|
|
106
|
-
}
|