conductor-node-mcp 14.24.3 → 15.0.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.
- package/README.md +2 -2
- package/agent-errors.d.mts +3 -0
- package/agent-errors.d.mts.map +1 -0
- package/agent-errors.d.ts +3 -0
- package/agent-errors.d.ts.map +1 -0
- package/agent-errors.js +97 -0
- package/agent-errors.js.map +1 -0
- package/agent-errors.mjs +93 -0
- package/agent-errors.mjs.map +1 -0
- package/code-tool-worker.d.mts.map +1 -1
- package/code-tool-worker.d.ts.map +1 -1
- package/code-tool-worker.js +3 -0
- package/code-tool-worker.js.map +1 -1
- package/code-tool-worker.mjs +3 -0
- package/code-tool-worker.mjs.map +1 -1
- package/code-tool.d.mts.map +1 -1
- package/code-tool.d.ts.map +1 -1
- package/code-tool.js +73 -14
- package/code-tool.js.map +1 -1
- package/code-tool.mjs +73 -14
- package/code-tool.mjs.map +1 -1
- package/http.d.mts.map +1 -1
- package/http.d.ts.map +1 -1
- package/http.js +38 -22
- package/http.js.map +1 -1
- package/http.mjs +37 -21
- package/http.mjs.map +1 -1
- package/local-docs-search.js +55 -55
- package/local-docs-search.js.map +1 -1
- package/local-docs-search.mjs +55 -55
- package/local-docs-search.mjs.map +1 -1
- package/oauth.d.mts +26 -0
- package/oauth.d.mts.map +1 -0
- package/oauth.d.ts +26 -0
- package/oauth.d.ts.map +1 -0
- package/oauth.js +446 -0
- package/oauth.js.map +1 -0
- package/oauth.mjs +433 -0
- package/oauth.mjs.map +1 -0
- package/package.json +32 -2
- package/server.d.mts +2 -1
- package/server.d.mts.map +1 -1
- package/server.d.ts +2 -1
- package/server.d.ts.map +1 -1
- package/server.js +7 -3
- package/server.js.map +1 -1
- package/server.mjs +7 -3
- package/server.mjs.map +1 -1
- package/src/agent-errors.ts +98 -0
- package/src/code-tool-worker.ts +3 -0
- package/src/code-tool.ts +78 -18
- package/src/http.ts +35 -30
- package/src/local-docs-search.ts +55 -55
- package/src/oauth.ts +540 -0
- package/src/server.ts +8 -3
- package/src/telemetry.ts +110 -0
- package/src/types.ts +4 -0
- package/telemetry.d.mts +18 -0
- package/telemetry.d.mts.map +1 -0
- package/telemetry.d.ts +18 -0
- package/telemetry.d.ts.map +1 -0
- package/telemetry.js +105 -0
- package/telemetry.js.map +1 -0
- package/telemetry.mjs +96 -0
- package/telemetry.mjs.map +1 -0
- package/types.d.mts +2 -0
- package/types.d.mts.map +1 -1
- package/types.d.ts +2 -0
- package/types.d.ts.map +1 -1
- package/types.js.map +1 -1
- package/types.mjs.map +1 -1
package/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;AAoDtF,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;AAoDtF,sCA0IC;AAKD,kCAeC;AAKD,wCAUC;AA9ND,oEAAoE;AACpE,iEAI4C;AAE5C,oEAAuC;AACvC,8CAAuC;AACvC,6EAAgD;AAChD,4DAAoD;AACpD,8DAAsD;AACtD,oDAAiD;AAEjD,0CAAsD;AAGzC,QAAA,OAAO,GAAG,QAAQ,CAAC,CAAC,2BAA2B;AAErD,MAAM,YAAY,GAAG,KAAK,EAAE,EACjC,eAAe,EACf,sBAAsB,GAIvB,EAAE,EAAE,CACH,IAAI,kBAAS,CACX;IACE,IAAI,EAAE,oBAAoB;IAC1B,OAAO,EAAE,QAAQ,EAAE,2BAA2B;CAC/C,EACD;IACE,YAAY,EAAE,MAAM,IAAA,8BAAe,EAAC,EAAE,eAAe,EAAE,sBAAsB,EAAE,CAAC;IAChF,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;CACzC,CACF,CAAC;AAhBS,QAAA,YAAY,gBAgBrB;AAEJ,4EAA4E;AAC5E,yEAAyE;AACzE,4EAA4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,EAAE,EAAE,CAAC,CAAC;AACzD,CAAC"}
|
package/server.mjs
CHANGED
|
@@ -8,10 +8,10 @@ import { setLocalSearch } from "./docs-search-tool.mjs";
|
|
|
8
8
|
import { LocalDocsSearch } from "./local-docs-search.mjs";
|
|
9
9
|
import { getInstructions } from "./instructions.mjs";
|
|
10
10
|
import { blockedMethodsForCodeTool } from "./methods.mjs";
|
|
11
|
-
export const VERSION = '
|
|
11
|
+
export const VERSION = '15.0.0'; // x-release-please-version
|
|
12
12
|
export const newMcpServer = async ({ stainlessApiKey, customInstructionsPath, }) => new McpServer({
|
|
13
13
|
name: 'conductor_node_api',
|
|
14
|
-
version: '
|
|
14
|
+
version: '15.0.0', // x-release-please-version
|
|
15
15
|
}, {
|
|
16
16
|
instructions: await getInstructions({ stainlessApiKey, customInstructionsPath }),
|
|
17
17
|
capabilities: { tools: {}, logging: {} },
|
|
@@ -83,7 +83,9 @@ export async function initMcpServer(params) {
|
|
|
83
83
|
tools: providedTools.map((mcpTool) => mcpTool.tool),
|
|
84
84
|
};
|
|
85
85
|
});
|
|
86
|
-
|
|
86
|
+
// Conductor patch: `extra.signal` is the SDK's per-request abort signal, which fires when http.ts closes
|
|
87
|
+
// the transport on the client's socket close; the execute tool races its Deno worker against it.
|
|
88
|
+
server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
87
89
|
const { name, arguments: args } = request.params;
|
|
88
90
|
const mcpTool = toolMap[name];
|
|
89
91
|
if (!mcpTool) {
|
|
@@ -112,6 +114,8 @@ export async function initMcpServer(params) {
|
|
|
112
114
|
upstreamClientEnvs: params.upstreamClientEnvs,
|
|
113
115
|
mcpSessionId: params.mcpSessionId,
|
|
114
116
|
mcpClientInfo: params.mcpClientInfo,
|
|
117
|
+
signal: extra.signal, // conductor patch
|
|
118
|
+
userAgent: params.userAgent, // conductor patch
|
|
115
119
|
},
|
|
116
120
|
args,
|
|
117
121
|
});
|
package/server.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.mjs","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAGtF,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,wBAAoB;AACvC,OAAO,cAAc,+BAA2B;AAChD,OAAO,EAAE,cAAc,EAAE,+BAA2B;AACpD,OAAO,EAAE,eAAe,EAAE,gCAA4B;AACtD,OAAO,EAAE,eAAe,EAAE,2BAAuB;AAEjD,OAAO,EAAE,yBAAyB,EAAE,sBAAkB;AAGtD,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"server.mjs","sourceRoot":"","sources":["src/server.ts"],"names":[],"mappings":"AAAA,sFAAsF;AAGtF,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,wBAAoB;AACvC,OAAO,cAAc,+BAA2B;AAChD,OAAO,EAAE,cAAc,EAAE,+BAA2B;AACpD,OAAO,EAAE,eAAe,EAAE,gCAA4B;AACtD,OAAO,EAAE,eAAe,EAAE,2BAAuB;AAEjD,OAAO,EAAE,yBAAyB,EAAE,sBAAkB;AAGtD,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,2BAA2B;AAE5D,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,EACjC,eAAe,EACf,sBAAsB,GAIvB,EAAE,EAAE,CACH,IAAI,SAAS,CACX;IACE,IAAI,EAAE,oBAAoB;IAC1B,OAAO,EAAE,QAAQ,EAAE,2B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cAAc,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EACnC,OAAO,EACP,UAAU,EACV,IAAI,GAKL;IACC,OAAO,MAAM,OAAO,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Conductor patch: what the model reads when an API call inside the execute sandbox fails. Custom file
|
|
2
|
+
// (not generated), imported by code-tool-worker.ts, so it runs inside the Deno worker and must stay free
|
|
3
|
+
// of Node-only imports.
|
|
4
|
+
//
|
|
5
|
+
// The SDK builds an APIError's message from the response body, and because Conductor nests the message
|
|
6
|
+
// under `error`, that is `<status> <the entire JSON body>`: the misleading status first, the message
|
|
7
|
+
// twice for QuickBooks errors, and on every developer 4xx the masked "An internal server error occurred"
|
|
8
|
+
// userFacingMessage next to the real message. The audit of 2026-10-27 found agents reading those bodies
|
|
9
|
+
// as "reconnect" (a wrong Web Connector password answered 401) and guessing again instead of looking
|
|
10
|
+
// parameters up. This rewrites only `message`, to `<CODE>: <message> (HTTP <status>, request <id>)`
|
|
11
|
+
// plus, for a few codes and types, one hint saying what to do next. The error's class, `status`,
|
|
12
|
+
// `headers` and `error` (the full body) are untouched, so code that branches on them keeps working.
|
|
13
|
+
// Hints are keyed on the envelope's `code` and `type`, never on message text, except the one
|
|
14
|
+
// `No such end-user` prefix, which is stable API copy; a renamed code only drops its hint.
|
|
15
|
+
|
|
16
|
+
type ErrorEnvelope = { code: string; message: string; type?: string };
|
|
17
|
+
|
|
18
|
+
const CONNECTION_HINT =
|
|
19
|
+
'The Conductor API key and sign-in are working, so do not reconnect the AI tool or create a new key; the fix is on the computer that runs QuickBooks Desktop. Tell the user the message above. Do not retry in this call; retry at most once in a later call, and stop if it fails again.';
|
|
20
|
+
const NOT_SET_UP_HINT =
|
|
21
|
+
"This company file has never connected to this Conductor project; the fix is on the computer that runs QuickBooks Desktop, so tell the user the message above. If the user's company file is connected in a different Conductor project, signing in again and choosing that project fixes it. Do not retry in this call; retry at most once in a later call, and stop if it fails again.";
|
|
22
|
+
const END_USER_ID_HINT =
|
|
23
|
+
'Pass `conductorEndUserId` from `conductor.endUsers.list()`. End-user ids belong to one Conductor project, so an id from another project or an earlier key does not work here.';
|
|
24
|
+
const INVALID_REQUEST_HINT =
|
|
25
|
+
'Call `search_docs` with the method name to read its parameters instead of guessing again.';
|
|
26
|
+
|
|
27
|
+
// Replaces makeStatusError on the prototype that owns it (the SDK calls it as `this.makeStatusError` for
|
|
28
|
+
// every non-2xx response) with a wrapper that rewrites the resulting error's message. The prototype, not
|
|
29
|
+
// the instance, so clients derived with `withOptions(...)` are covered too; applied once per process.
|
|
30
|
+
// Anything unexpected leaves the SDK's own error untouched.
|
|
31
|
+
const PATCHED = Symbol.for('conductor.agentErrorsPatched');
|
|
32
|
+
|
|
33
|
+
export function formatErrorsForAgents(client: object): void {
|
|
34
|
+
let owner: object | null = Object.getPrototypeOf(client);
|
|
35
|
+
while (owner !== null && !Object.prototype.hasOwnProperty.call(owner, 'makeStatusError')) {
|
|
36
|
+
owner = Object.getPrototypeOf(owner);
|
|
37
|
+
}
|
|
38
|
+
if (owner === null) return;
|
|
39
|
+
const target = owner as { makeStatusError?: (...args: unknown[]) => Error; [PATCHED]?: boolean };
|
|
40
|
+
const original = target.makeStatusError;
|
|
41
|
+
if (typeof original !== 'function' || target[PATCHED]) return;
|
|
42
|
+
target[PATCHED] = true;
|
|
43
|
+
target.makeStatusError = function (this: unknown, ...args: unknown[]): Error {
|
|
44
|
+
const error = original.apply(this, args);
|
|
45
|
+
try {
|
|
46
|
+
const [status, body, , headers] = args;
|
|
47
|
+
const formatted = formatAgentErrorMessage(status, body, headers);
|
|
48
|
+
if (formatted !== undefined) error.message = formatted;
|
|
49
|
+
} catch {
|
|
50
|
+
// Keep the SDK's message.
|
|
51
|
+
}
|
|
52
|
+
return error;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// The rewritten message for a Conductor error envelope, or undefined when the body is not one (an edge
|
|
57
|
+
// HTML page, a network failure, another service), in which case the SDK's text stands.
|
|
58
|
+
export function formatAgentErrorMessage(
|
|
59
|
+
status: unknown,
|
|
60
|
+
body: unknown,
|
|
61
|
+
headers: unknown,
|
|
62
|
+
): string | undefined {
|
|
63
|
+
const envelope = envelopeOf(body);
|
|
64
|
+
if (envelope === undefined) return undefined;
|
|
65
|
+
const requestId = requestIdOf(headers);
|
|
66
|
+
const statusText = typeof status === 'number' ? `HTTP ${status}` : 'no HTTP status';
|
|
67
|
+
const head = `${envelope.code}: ${envelope.message} (${statusText}${
|
|
68
|
+
requestId ? `, request ${requestId}` : ''
|
|
69
|
+
})`;
|
|
70
|
+
const hint = hintFor(envelope);
|
|
71
|
+
return hint === undefined ? head : `${head}\n${hint}`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function hintFor({ code, message, type }: ErrorEnvelope): string | undefined {
|
|
75
|
+
if (code === 'INTEGRATION_CONNECTION_NOT_SET_UP') return NOT_SET_UP_HINT;
|
|
76
|
+
if (type === 'INTEGRATION_CONNECTION_ERROR') return CONNECTION_HINT;
|
|
77
|
+
if (code === 'END_USER_ID_HEADER_MISSING') return END_USER_ID_HINT;
|
|
78
|
+
if (code === 'RESOURCE_MISSING')
|
|
79
|
+
return message.startsWith('No such end-user') ? END_USER_ID_HINT : undefined;
|
|
80
|
+
if (type === 'INVALID_REQUEST_ERROR') return INVALID_REQUEST_HINT;
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function envelopeOf(body: unknown): ErrorEnvelope | undefined {
|
|
85
|
+
if (typeof body !== 'object' || body === null) return undefined;
|
|
86
|
+
const error = (body as { error?: unknown }).error;
|
|
87
|
+
if (typeof error !== 'object' || error === null) return undefined;
|
|
88
|
+
const { code, message, type } = error as { code?: unknown; message?: unknown; type?: unknown };
|
|
89
|
+
if (typeof code !== 'string' || code === '' || typeof message !== 'string') return undefined;
|
|
90
|
+
return { code, message, ...(typeof type === 'string' && { type }) };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function requestIdOf(headers: unknown): string | undefined {
|
|
94
|
+
const get = (headers as { get?: (name: string) => string | null } | null)?.get;
|
|
95
|
+
if (typeof get !== 'function') return undefined;
|
|
96
|
+
const value = get.call(headers, 'conductor-request-id');
|
|
97
|
+
return typeof value === 'string' && value !== '' ? value : undefined;
|
|
98
|
+
}
|
package/src/code-tool-worker.ts
CHANGED
|
@@ -6,6 +6,7 @@ import Fuse from 'fuse.js';
|
|
|
6
6
|
import ts from 'typescript';
|
|
7
7
|
import { WorkerOutput } from './code-tool-types';
|
|
8
8
|
import { Conductor, ClientOptions } from 'conductor-node';
|
|
9
|
+
import { formatErrorsForAgents } from './agent-errors'; // conductor patch
|
|
9
10
|
|
|
10
11
|
async function tseval(code: string) {
|
|
11
12
|
return import('data:application/typescript;charset=utf-8;base64,' + Buffer.from(code).toString('base64'));
|
|
@@ -500,6 +501,8 @@ const fetch = async (req: Request): Promise<Response> => {
|
|
|
500
501
|
const conductor = new Conductor({
|
|
501
502
|
...opts,
|
|
502
503
|
});
|
|
504
|
+
// Conductor patch: one line per API error for the model, plus a next step for a few codes.
|
|
505
|
+
formatErrorsForAgents(conductor);
|
|
503
506
|
|
|
504
507
|
const log_lines: string[] = [];
|
|
505
508
|
const err_lines: string[] = [];
|
package/src/code-tool.ts
CHANGED
|
@@ -9,7 +9,18 @@ import { SdkMethod } from './methods';
|
|
|
9
9
|
import { McpCodeExecutionMode } from './options';
|
|
10
10
|
import { ClientOptions } from 'conductor-node';
|
|
11
11
|
import { newDenoHTTPWorker } from './deno-http-worker';
|
|
12
|
-
|
|
12
|
+
// Conductor patch (see telemetry.ts): per-call id and headers, the abort-on-disconnect race, kill switches.
|
|
13
|
+
import { randomUUID } from 'node:crypto';
|
|
14
|
+
import {
|
|
15
|
+
CLIENT_CLOSED_MESSAGE,
|
|
16
|
+
CodeExecutionAbortedError,
|
|
17
|
+
classifyExecuteError,
|
|
18
|
+
executeTelemetryHeaders,
|
|
19
|
+
} from './telemetry';
|
|
20
|
+
|
|
21
|
+
// The four lines after "You will be returned..." and the loop clause on the try-catch line are a Conductor
|
|
22
|
+
// patch: this description is the one text every MCP client shows the model (some skip initialize or never
|
|
23
|
+
// surface server instructions), so the rules that must bind everyone live here (instructions.md explains).
|
|
13
24
|
const prompt = `Runs JavaScript code to interact with the Conductor API.
|
|
14
25
|
|
|
15
26
|
You are a skilled TypeScript programmer writing code to interface with the service.
|
|
@@ -26,7 +37,10 @@ async function run(conductor) {
|
|
|
26
37
|
\`\`\`
|
|
27
38
|
|
|
28
39
|
You will be returned anything that your function returns, plus the results of any console.log statements.
|
|
29
|
-
|
|
40
|
+
Every conductor.qbd method needs conductorEndUserId from conductor.endUsers.list(); never guess it.
|
|
41
|
+
QuickBooks Desktop handles one request at a time: await each request before starting the next (in a for loop, never Promise.all), pass several ids returned by an earlier call in one request instead of one request per id, and finish all requests for one conductorEndUserId before starting another.
|
|
42
|
+
Keep each tool call under about a minute: some clients stop waiting at 60 seconds, and a call that times out returns only the error, so narrow lists with filters and split a large job into several short calls.
|
|
43
|
+
Do not add try-catch blocks for single API calls. The tool will handle errors for you. In a loop of writes, make the code stop at the first QuickBooks Desktop error it has not seen before and fix the input; never resend a request unchanged after QuickBooks Desktop rejected it (a timeout or connection error is not a rejection).
|
|
30
44
|
Do not add comments unless necessary for generating better code.
|
|
31
45
|
Code will run in a container, and cannot interact with the network outside of the given SDK client.
|
|
32
46
|
Variables will not persist between calls, so make sure to return or log any data you might need later.
|
|
@@ -83,34 +97,45 @@ export function codeTool({
|
|
|
83
97
|
args: any;
|
|
84
98
|
}): Promise<ToolCallResult> => {
|
|
85
99
|
const code = args.code as string;
|
|
100
|
+
// Conductor patch: one id per call, sent to the API on every request the code makes (telemetry.ts) and
|
|
101
|
+
// written to the result line below, so Better Stack can join each relayed request to this call.
|
|
102
|
+
const callId = randomUUID();
|
|
103
|
+
const startTime = Date.now();
|
|
104
|
+
let result: ToolCallResult;
|
|
86
105
|
// Do very basic blocking of code that includes forbidden method names.
|
|
87
106
|
//
|
|
88
107
|
// WARNING: This is not secure against obfuscation and other evasion methods. If
|
|
89
108
|
// stronger security blocks are required, then these should be enforced in the downstream
|
|
90
109
|
// API (e.g., by having users call the MCP server with API keys with limited permissions).
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
110
|
+
const blockedMatches =
|
|
111
|
+
blockedMethods ? blockedMethods.filter((method) => code.includes(method.fullyQualifiedName)) : [];
|
|
112
|
+
if (blockedMatches.length > 0) {
|
|
113
|
+
result = asErrorResult(
|
|
114
|
+
`The following methods have been blocked by the MCP server and cannot be used in code execution: ${blockedMatches
|
|
115
|
+
.map((m) => m.fullyQualifiedName)
|
|
116
|
+
.join(', ')}`,
|
|
117
|
+
);
|
|
118
|
+
} else {
|
|
119
|
+
logger.debug('Executing code in local Deno environment');
|
|
120
|
+
result = await localDenoHandler({ reqContext, args, callId });
|
|
100
121
|
}
|
|
101
122
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
logger.info(
|
|
123
|
+
// Conductor patch: one line per call, at warn when the client had left (abortedBy); never the code,
|
|
124
|
+
// intent or result text, and errorKind is a fixed label.
|
|
125
|
+
const errorKind = result.isError ? classifyExecuteError(result) : undefined;
|
|
126
|
+
const aborted = errorKind === 'client_closed';
|
|
127
|
+
logger[aborted ? 'warn' : 'info'](
|
|
109
128
|
{
|
|
110
129
|
codeExecutionMode,
|
|
111
130
|
durationMs: Date.now() - startTime,
|
|
112
131
|
isError: result.isError,
|
|
113
132
|
contentRows: result.content?.length ?? 0,
|
|
133
|
+
mcpSessionId: reqContext.mcpSessionId,
|
|
134
|
+
callId,
|
|
135
|
+
tool: 'execute',
|
|
136
|
+
userAgent: reqContext.userAgent,
|
|
137
|
+
...(errorKind !== undefined && { errorKind }),
|
|
138
|
+
...(aborted && { abortedBy: 'client_closed' }),
|
|
114
139
|
},
|
|
115
140
|
'Got code tool execution result',
|
|
116
141
|
);
|
|
@@ -171,21 +196,34 @@ function releaseLocalExecutionSlot(): void {
|
|
|
171
196
|
const localDenoHandler = async (params: {
|
|
172
197
|
reqContext: McpRequestContext;
|
|
173
198
|
args: unknown;
|
|
199
|
+
callId: string;
|
|
174
200
|
}): Promise<ToolCallResult> => {
|
|
201
|
+
// Conductor patch: a client that already left (its POST socket closed, see http.ts) gets no Deno worker
|
|
202
|
+
// and takes no slot; checked again after the wait because the queue can be long.
|
|
203
|
+
if (params.reqContext.signal?.aborted) return abortedResult();
|
|
175
204
|
await acquireLocalExecutionSlot();
|
|
176
205
|
try {
|
|
206
|
+
if (params.reqContext.signal?.aborted) return abortedResult();
|
|
177
207
|
return await localDenoHandlerInner(params);
|
|
178
208
|
} finally {
|
|
179
209
|
releaseLocalExecutionSlot();
|
|
180
210
|
}
|
|
181
211
|
};
|
|
182
212
|
|
|
213
|
+
// Conductor patch: the result for a call whose client closed its connection; nobody receives it, and the
|
|
214
|
+
// handler's result line (abortedBy: 'client_closed') is how abandoned calls are counted.
|
|
215
|
+
function abortedResult(): ToolCallResult {
|
|
216
|
+
return asErrorResult(CLIENT_CLOSED_MESSAGE);
|
|
217
|
+
}
|
|
218
|
+
|
|
183
219
|
const localDenoHandlerInner = async ({
|
|
184
220
|
reqContext,
|
|
185
221
|
args,
|
|
222
|
+
callId,
|
|
186
223
|
}: {
|
|
187
224
|
reqContext: McpRequestContext;
|
|
188
225
|
args: unknown;
|
|
226
|
+
callId: string;
|
|
189
227
|
}): Promise<ToolCallResult> => {
|
|
190
228
|
const fs = await import('node:fs');
|
|
191
229
|
const path = await import('node:path');
|
|
@@ -266,6 +304,16 @@ const localDenoHandlerInner = async ({
|
|
|
266
304
|
|
|
267
305
|
const timeoutMs = getCodeExecutionTimeoutMs();
|
|
268
306
|
let timeoutHandle: ReturnType<typeof setTimeout> | undefined;
|
|
307
|
+
// Conductor patch: the third racer below rejects when the MCP request's abort signal fires (the client
|
|
308
|
+
// closed its connection); the listener is removed in finally so a finished call leaves nothing behind.
|
|
309
|
+
const signal = reqContext.signal;
|
|
310
|
+
let onAbort: (() => void) | undefined;
|
|
311
|
+
const abortPromise = new Promise<never>((_, reject) => {
|
|
312
|
+
if (!signal) return;
|
|
313
|
+
onAbort = () => reject(new CodeExecutionAbortedError(CLIENT_CLOSED_MESSAGE));
|
|
314
|
+
if (signal.aborted) onAbort();
|
|
315
|
+
else signal.addEventListener('abort', onAbort, { once: true });
|
|
316
|
+
});
|
|
269
317
|
try {
|
|
270
318
|
const respPromise = new Promise<Response>((resolve, reject) => {
|
|
271
319
|
worker.addEventListener('exit', (exitCode) => {
|
|
@@ -279,6 +327,12 @@ const localDenoHandlerInner = async ({
|
|
|
279
327
|
...(client.apiKey != null ? { apiKey: client.apiKey } : undefined),
|
|
280
328
|
defaultHeaders: {
|
|
281
329
|
'X-Stainless-MCP': 'true',
|
|
330
|
+
// Conductor patch: the call id, session id and client, logged by the API with every request.
|
|
331
|
+
...executeTelemetryHeaders({
|
|
332
|
+
callId,
|
|
333
|
+
mcpSessionId: reqContext.mcpSessionId,
|
|
334
|
+
userAgent: reqContext.userAgent,
|
|
335
|
+
}),
|
|
282
336
|
},
|
|
283
337
|
} satisfies Partial<ClientOptions> as ClientOptions;
|
|
284
338
|
|
|
@@ -334,6 +388,7 @@ const localDenoHandlerInner = async ({
|
|
|
334
388
|
|
|
335
389
|
const resp = await Promise.race([
|
|
336
390
|
respPromise,
|
|
391
|
+
abortPromise, // conductor patch
|
|
337
392
|
new Promise<never>((_, reject) => {
|
|
338
393
|
timeoutHandle = setTimeout(() => {
|
|
339
394
|
reject(
|
|
@@ -405,11 +460,16 @@ const localDenoHandlerInner = async ({
|
|
|
405
460
|
if (error instanceof CodeExecutionTimeoutError) {
|
|
406
461
|
return asErrorResult(error.message);
|
|
407
462
|
}
|
|
463
|
+
// Conductor patch: the client left while the code ran; finally terminates the worker.
|
|
464
|
+
if (error instanceof CodeExecutionAbortedError) {
|
|
465
|
+
return asErrorResult(error.message);
|
|
466
|
+
}
|
|
408
467
|
throw error;
|
|
409
468
|
} finally {
|
|
410
469
|
if (timeoutHandle !== undefined) {
|
|
411
470
|
clearTimeout(timeoutHandle);
|
|
412
471
|
}
|
|
472
|
+
if (signal && onAbort) signal.removeEventListener('abort', onAbort); // conductor patch
|
|
413
473
|
worker.terminate();
|
|
414
474
|
}
|
|
415
475
|
};
|
package/src/http.ts
CHANGED
|
@@ -8,6 +8,8 @@ import pino from 'pino';
|
|
|
8
8
|
import pinoHttp from 'pino-http';
|
|
9
9
|
import { getStainlessApiKey, parseClientAuthHeaders } from './auth';
|
|
10
10
|
import { getLogger } from './logger';
|
|
11
|
+
import { mountProtectedResourceMetadata, parseClientPermissions, requireCredential } from './oauth'; // conductor patch
|
|
12
|
+
import { rpcMethodProps, sanitizeUserAgent } from './telemetry'; // conductor patch
|
|
11
13
|
import { McpOptions } from './options';
|
|
12
14
|
import { initMcpServer, newMcpServer } from './server';
|
|
13
15
|
|
|
@@ -104,6 +106,7 @@ const newServer = async ({
|
|
|
104
106
|
upstreamClientEnvs,
|
|
105
107
|
mcpSessionId: (req as any).mcpSessionId,
|
|
106
108
|
mcpClientInfo,
|
|
109
|
+
userAgent: sanitizeUserAgent(req.headers['user-agent']), // conductor patch
|
|
107
110
|
});
|
|
108
111
|
|
|
109
112
|
if (mcpClientInfo) {
|
|
@@ -116,10 +119,22 @@ const newServer = async ({
|
|
|
116
119
|
const post =
|
|
117
120
|
(options: { clientOptions: ClientOptions; mcpOptions: McpOptions }) =>
|
|
118
121
|
async (req: express.Request, res: express.Response) => {
|
|
122
|
+
const transport = new StreamableHTTPServerTransport();
|
|
123
|
+
// Conductor patch: every client gives up on a long tools/call before the server's own limit (mcp-remote
|
|
124
|
+
// at 60 s, Cursor at 120 s, hosted Claude at 240 s), and the closed socket is the only signal the origin
|
|
125
|
+
// gets. Closing the transport runs the SDK's onclose, which aborts each in-flight request handler's
|
|
126
|
+
// signal (Protocol._onclose), which the execute tool races its Deno worker against (code-tool.ts). The
|
|
127
|
+
// listener goes on before any await so a disconnect while the server is built is still seen, and a
|
|
128
|
+
// client that left during the gate's key probe (before this handler ran) is caught by res.closed. After
|
|
129
|
+
// a normal finish the same event finds nothing to abort.
|
|
130
|
+
res.on('close', () => {
|
|
131
|
+
void transport.close().catch(() => undefined);
|
|
132
|
+
});
|
|
133
|
+
if (res.closed) return;
|
|
119
134
|
const server = await newServer({ ...options, req, res });
|
|
120
135
|
// If we return null, we already set the authorization error.
|
|
121
136
|
if (server === null) return;
|
|
122
|
-
|
|
137
|
+
if (res.closed) return;
|
|
123
138
|
await server.connect(transport as any);
|
|
124
139
|
await transport.handleRequest(req, res, req.body);
|
|
125
140
|
};
|
|
@@ -144,34 +159,6 @@ const del = async (req: express.Request, res: express.Response) => {
|
|
|
144
159
|
});
|
|
145
160
|
};
|
|
146
161
|
|
|
147
|
-
type ClientPermissions = {
|
|
148
|
-
allow_http_gets?: boolean;
|
|
149
|
-
allowed_methods?: string[];
|
|
150
|
-
blocked_methods?: string[];
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
// Returns null unless the header is a JSON object holding only known keys of the right types, so a
|
|
154
|
-
// typo such as {"allow_http_gets":"true"} or {"read_only":true} is refused instead of ignored.
|
|
155
|
-
const parseClientPermissions = (header: string): ClientPermissions | null => {
|
|
156
|
-
let parsed: unknown;
|
|
157
|
-
try {
|
|
158
|
-
parsed = JSON.parse(header);
|
|
159
|
-
} catch {
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
const isStringArray = (value: unknown) =>
|
|
166
|
-
Array.isArray(value) && value.every((item) => typeof item === 'string');
|
|
167
|
-
const isValid = Object.entries(parsed).every(([key, value]) =>
|
|
168
|
-
key === 'allow_http_gets' ? typeof value === 'boolean'
|
|
169
|
-
: key === 'allowed_methods' || key === 'blocked_methods' ? isStringArray(value)
|
|
170
|
-
: false,
|
|
171
|
-
);
|
|
172
|
-
return isValid ? (parsed as ClientPermissions) : null;
|
|
173
|
-
};
|
|
174
|
-
|
|
175
162
|
const redactHeaders = (headers: Record<string, any>) => {
|
|
176
163
|
const hiddenHeaders = /auth|cookie|key|token|x-stainless-mcp-client-envs/i;
|
|
177
164
|
const filtered = { ...headers };
|
|
@@ -209,6 +196,9 @@ export const streamableHTTPApp = ({
|
|
|
209
196
|
logger: getLogger(),
|
|
210
197
|
customProps: (req) => ({
|
|
211
198
|
mcpSessionId: (req as any).mcpSessionId,
|
|
199
|
+
// Conductor patch: the JSON-RPC method and tool name, so the request line says initialize versus
|
|
200
|
+
// tools/call and execute versus search_docs for every client (express.json() has run by now).
|
|
201
|
+
...rpcMethodProps((req as any).body),
|
|
212
202
|
}),
|
|
213
203
|
customLogLevel: (req, res) => {
|
|
214
204
|
if (res.statusCode >= 500) {
|
|
@@ -244,9 +234,24 @@ export const streamableHTTPApp = ({
|
|
|
244
234
|
app.get('/health', async (req: express.Request, res: express.Response) => {
|
|
245
235
|
res.status(200).send('OK');
|
|
246
236
|
});
|
|
237
|
+
// OAuth 2.1 resource server (conductor patch, see src/oauth.ts): RFC 9728 metadata for both resources,
|
|
238
|
+
// and the 401 + WWW-Authenticate that makes Claude and other OAuth clients start sign-in. /read-only is
|
|
239
|
+
// the read-only connector URL: its gate rewrites the client permissions header to the client's own
|
|
240
|
+
// permissions minus every write, so a client value can never loosen it.
|
|
241
|
+
mountProtectedResourceMetadata(app);
|
|
247
242
|
app.get('/', get);
|
|
248
|
-
app.post('/', post({ clientOptions, mcpOptions }));
|
|
243
|
+
app.post('/', requireCredential(), post({ clientOptions, mcpOptions }));
|
|
249
244
|
app.delete('/', del);
|
|
245
|
+
// /mcp is the root under a second name (conductor patch): Microsoft Copilot Studio's MCP tools POSTed to
|
|
246
|
+
// /mcp on this server (41 initialize 404s from one customer on 2026-11-05, whose server URL had no path)
|
|
247
|
+
// and to /read-only as typed, so /read-only needs no alias. Same gate, challenge and permissions as the
|
|
248
|
+
// root; the seal test pins the three literals.
|
|
249
|
+
app.get('/mcp', get);
|
|
250
|
+
app.post('/mcp', requireCredential(), post({ clientOptions, mcpOptions }));
|
|
251
|
+
app.delete('/mcp', del);
|
|
252
|
+
app.get('/read-only', get);
|
|
253
|
+
app.post('/read-only', requireCredential('read-only'), post({ clientOptions, mcpOptions }));
|
|
254
|
+
app.delete('/read-only', del);
|
|
250
255
|
|
|
251
256
|
return app;
|
|
252
257
|
};
|