@j0hanz/fetch-url-mcp 1.12.4 → 1.12.6
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/http/auth.d.ts.map +1 -1
- package/dist/http/auth.js +44 -29
- package/dist/http/helpers.d.ts.map +1 -1
- package/dist/http/helpers.js +22 -12
- package/dist/http/native.d.ts.map +1 -1
- package/dist/http/native.js +30 -29
- package/dist/http/rate-limit.d.ts.map +1 -1
- package/dist/http/rate-limit.js +5 -3
- package/dist/index.js +3 -2
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +11 -7
- package/dist/lib/core.d.ts.map +1 -1
- package/dist/lib/core.js +12 -9
- package/dist/lib/error-codes.d.ts +11 -0
- package/dist/lib/error-codes.d.ts.map +1 -0
- package/dist/lib/error-codes.js +15 -0
- package/dist/lib/error-messages.d.ts +13 -0
- package/dist/lib/error-messages.d.ts.map +1 -0
- package/dist/lib/error-messages.js +51 -0
- package/dist/lib/fetch-pipeline.d.ts.map +1 -1
- package/dist/lib/fetch-pipeline.js +5 -4
- package/dist/lib/http.d.ts.map +1 -1
- package/dist/lib/http.js +74 -41
- package/dist/lib/logger-names.d.ts +14 -0
- package/dist/lib/logger-names.d.ts.map +1 -0
- package/dist/lib/logger-names.js +13 -0
- package/dist/lib/mcp-interop.d.ts +1 -11
- package/dist/lib/mcp-interop.d.ts.map +1 -1
- package/dist/lib/mcp-interop.js +10 -73
- package/dist/lib/session.d.ts.map +1 -1
- package/dist/lib/session.js +2 -1
- package/dist/lib/tool-errors.d.ts +39 -0
- package/dist/lib/tool-errors.d.ts.map +1 -0
- package/dist/lib/tool-errors.js +252 -0
- package/dist/lib/url.d.ts.map +1 -1
- package/dist/lib/url.js +18 -15
- package/dist/lib/utils.d.ts +4 -1
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +18 -9
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +3 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +7 -6
- package/dist/tasks/call-contract.d.ts.map +1 -1
- package/dist/tasks/call-contract.js +8 -10
- package/dist/tasks/execution.d.ts.map +1 -1
- package/dist/tasks/execution.js +17 -14
- package/dist/tasks/handlers.d.ts.map +1 -1
- package/dist/tasks/handlers.js +9 -8
- package/dist/tasks/manager.d.ts.map +1 -1
- package/dist/tasks/manager.js +14 -13
- package/dist/tasks/owner.d.ts +0 -1
- package/dist/tasks/owner.d.ts.map +1 -1
- package/dist/tasks/owner.js +0 -25
- package/dist/tools/fetch-url.d.ts.map +1 -1
- package/dist/tools/fetch-url.js +14 -26
- package/dist/transform/dom-prep.d.ts.map +1 -1
- package/dist/transform/dom-prep.js +10 -8
- package/dist/transform/shared.d.ts.map +1 -1
- package/dist/transform/shared.js +2 -1
- package/dist/transform/transform.d.ts.map +1 -1
- package/dist/transform/transform.js +29 -21
- package/dist/transform/worker-pool.d.ts.map +1 -1
- package/dist/transform/worker-pool.js +16 -12
- package/package.json +1 -1
package/dist/lib/utils.js
CHANGED
|
@@ -3,6 +3,8 @@ import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
|
3
3
|
import { setInterval as setIntervalPromise, setTimeout as setTimeoutPromise, } from 'node:timers/promises';
|
|
4
4
|
import { inspect } from 'node:util';
|
|
5
5
|
import { config, logDebug, logWarn } from './core.js';
|
|
6
|
+
import { FETCH_ERROR } from './error-codes.js';
|
|
7
|
+
import { LOG_HTTP } from './logger-names.js';
|
|
6
8
|
const textEncoder = new TextEncoder();
|
|
7
9
|
const UNKNOWN_ERROR_MESSAGE = 'Unknown error';
|
|
8
10
|
export function composeAbortSignal(signal, timeoutMs) {
|
|
@@ -19,18 +21,20 @@ export function throwIfAborted(signal, url, stage) {
|
|
|
19
21
|
if (!signal?.aborted)
|
|
20
22
|
return;
|
|
21
23
|
if (signal.reason instanceof Error && signal.reason.name === 'TimeoutError') {
|
|
22
|
-
|
|
24
|
+
const error = new FetchError('Request timeout', url, 504, {
|
|
23
25
|
reason: 'timeout',
|
|
24
26
|
stage,
|
|
25
27
|
});
|
|
28
|
+
throw error;
|
|
26
29
|
}
|
|
27
30
|
throw createAbortError(url, stage);
|
|
28
31
|
}
|
|
29
32
|
export function createAbortError(url, stage) {
|
|
30
|
-
|
|
33
|
+
const error = new FetchError('Request was canceled', url, 499, {
|
|
31
34
|
reason: 'aborted',
|
|
32
35
|
stage,
|
|
33
36
|
});
|
|
37
|
+
return error;
|
|
34
38
|
}
|
|
35
39
|
export function timingSafeEqualUtf8(a, b) {
|
|
36
40
|
const aBuf = textEncoder.encode(a);
|
|
@@ -62,7 +66,7 @@ export class FetchError extends Error {
|
|
|
62
66
|
this.code = `HTTP_${httpStatus}`;
|
|
63
67
|
}
|
|
64
68
|
else {
|
|
65
|
-
this.code =
|
|
69
|
+
this.code = FETCH_ERROR;
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
}
|
|
@@ -97,9 +101,13 @@ export function toError(error) {
|
|
|
97
101
|
export function isAbortError(error) {
|
|
98
102
|
return isError(error) && error.name === 'AbortError';
|
|
99
103
|
}
|
|
100
|
-
export
|
|
101
|
-
|
|
102
|
-
|
|
104
|
+
export class CodedError extends Error {
|
|
105
|
+
code;
|
|
106
|
+
constructor(message, code, options) {
|
|
107
|
+
super(message, options);
|
|
108
|
+
this.code = code;
|
|
109
|
+
this.name = 'CodedError';
|
|
110
|
+
}
|
|
103
111
|
}
|
|
104
112
|
export function isSystemError(error) {
|
|
105
113
|
if (!isError(error))
|
|
@@ -137,7 +145,7 @@ export function applyHttpServerTuning(server) {
|
|
|
137
145
|
maxConnections,
|
|
138
146
|
dropped: droppedSinceLastLog,
|
|
139
147
|
data,
|
|
140
|
-
},
|
|
148
|
+
}, LOG_HTTP);
|
|
141
149
|
lastLoggedAt = now;
|
|
142
150
|
droppedSinceLastLog = 0;
|
|
143
151
|
};
|
|
@@ -148,7 +156,7 @@ export function applyHttpServerTuning(server) {
|
|
|
148
156
|
export function drainConnectionsOnShutdown(server) {
|
|
149
157
|
if (typeof server.closeIdleConnections === 'function') {
|
|
150
158
|
server.closeIdleConnections();
|
|
151
|
-
logDebug('Closed idle HTTP connections during shutdown', undefined,
|
|
159
|
+
logDebug('Closed idle HTTP connections during shutdown', undefined, LOG_HTTP);
|
|
152
160
|
}
|
|
153
161
|
}
|
|
154
162
|
function createAbortSafeTimeoutPromise(timeoutMs, value, signal) {
|
|
@@ -157,7 +165,8 @@ function createAbortSafeTimeoutPromise(timeoutMs, value, signal) {
|
|
|
157
165
|
signal,
|
|
158
166
|
}).catch((err) => {
|
|
159
167
|
if (isAbortError(err)) {
|
|
160
|
-
|
|
168
|
+
const pending = new Promise(() => { });
|
|
169
|
+
return pending;
|
|
161
170
|
}
|
|
162
171
|
throw err;
|
|
163
172
|
});
|
package/dist/schemas.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAoD9D,eAAO,MAAM,uBAAuB,EAAE,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAG9D,CAAC;AAgBJ,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,OAAO,GACb,iBAAiB,GAAG,SAAS,CAQ/B;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAErE;AAED,eAAO,MAAM,mBAAmB;;
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAoD9D,eAAO,MAAM,uBAAuB,EAAE,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAG9D,CAAC;AAgBJ,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,OAAO,GACb,iBAAiB,GAAG,SAAS,CAQ/B;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAErE;AAED,eAAO,MAAM,mBAAmB;;kBAS9B,CAAC;AAEH,eAAO,MAAM,oBAAoB;;;;;;;;;;;kBAkC/B,CAAC"}
|
package/dist/schemas.js
CHANGED
|
@@ -51,11 +51,11 @@ export function normalizePageTitle(value) {
|
|
|
51
51
|
}
|
|
52
52
|
export const fetchUrlInputSchema = z.strictObject({
|
|
53
53
|
url: z
|
|
54
|
-
.httpUrl(
|
|
54
|
+
.httpUrl()
|
|
55
55
|
.min(1, 'URL required')
|
|
56
56
|
.max(config.constants.maxUrlLength, `URL exceeds ${config.constants.maxUrlLength} chars`)
|
|
57
|
-
.describe(`Target URL. Max ${config.constants.maxUrlLength} chars
|
|
58
|
-
}
|
|
57
|
+
.describe(`Target URL. Max ${config.constants.maxUrlLength} chars`),
|
|
58
|
+
});
|
|
59
59
|
export const fetchUrlOutputSchema = z.strictObject({
|
|
60
60
|
url: z
|
|
61
61
|
.httpUrl()
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAgHpE,wBAAsB,eAAe,IAAI,OAAO,CAAC,SAAS,CAAC,CAE1D;AAkDD,wBAAsB,6BAA6B,IAAI,OAAO,CAAC,SAAS,CAAC,CAExE;AAgHD,wBAAsB,gBAAgB,IAAI,OAAO,CAAC;IAChD,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C,CAAC,CASD"}
|
package/dist/server.js
CHANGED
|
@@ -5,6 +5,7 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
|
5
5
|
import { SetLevelRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
6
6
|
import { config } from './lib/core.js';
|
|
7
7
|
import { getSessionId, logError, logInfo, logNotice, setLogLevel, setMcpServer, } from './lib/core.js';
|
|
8
|
+
import { LOG_SERVER } from './lib/logger-names.js';
|
|
8
9
|
import { setTaskToolCallCapability } from './lib/mcp-interop.js';
|
|
9
10
|
import { toError } from './lib/utils.js';
|
|
10
11
|
import { buildServerInstructions, registerGetHelpPrompt, registerInstructionResource, } from './resources/index.js';
|
|
@@ -120,7 +121,7 @@ function registerLoggingSetLevelHandler(server) {
|
|
|
120
121
|
}
|
|
121
122
|
function attachServerErrorHandler(server) {
|
|
122
123
|
server.server.onerror = (error) => {
|
|
123
|
-
logError('MCP server error', toError(error),
|
|
124
|
+
logError('MCP server error', toError(error), LOG_SERVER);
|
|
124
125
|
};
|
|
125
126
|
}
|
|
126
127
|
async function shutdownServer(server, signal) {
|
|
@@ -135,7 +136,7 @@ async function shutdownServer(server, signal) {
|
|
|
135
136
|
]);
|
|
136
137
|
for (const result of results) {
|
|
137
138
|
if (result.status === 'rejected') {
|
|
138
|
-
logError('Shutdown step failed', toError(result.reason),
|
|
139
|
+
logError('Shutdown step failed', toError(result.reason), LOG_SERVER);
|
|
139
140
|
}
|
|
140
141
|
}
|
|
141
142
|
}
|
|
@@ -148,7 +149,7 @@ function createShutdownHandler(server) {
|
|
|
148
149
|
logInfo('Shutdown already in progress; ignoring signal', {
|
|
149
150
|
signal,
|
|
150
151
|
initialSignal,
|
|
151
|
-
},
|
|
152
|
+
}, LOG_SERVER);
|
|
152
153
|
return shutdownPromise ?? Promise.resolve();
|
|
153
154
|
}
|
|
154
155
|
shuttingDown = true;
|
|
@@ -157,7 +158,7 @@ function createShutdownHandler(server) {
|
|
|
157
158
|
.then(() => shutdownServer(server, signal))
|
|
158
159
|
.catch((err) => {
|
|
159
160
|
const error = toError(err);
|
|
160
|
-
logError('Error during shutdown', error,
|
|
161
|
+
logError('Error during shutdown', error, LOG_SERVER);
|
|
161
162
|
process.exitCode = 1;
|
|
162
163
|
})
|
|
163
164
|
.finally(() => {
|
|
@@ -177,11 +178,11 @@ function registerSignalHandlers(handler) {
|
|
|
177
178
|
async function connectStdioServer(server, transport) {
|
|
178
179
|
try {
|
|
179
180
|
await server.connect(transport);
|
|
180
|
-
logInfo('Fetch URL MCP server running on stdio', undefined,
|
|
181
|
+
logInfo('Fetch URL MCP server running on stdio', undefined, LOG_SERVER);
|
|
181
182
|
}
|
|
182
183
|
catch (error) {
|
|
183
184
|
const err = toError(error);
|
|
184
|
-
throw
|
|
185
|
+
throw Error(`Failed to start stdio server: ${err.message}`, {
|
|
185
186
|
cause: error,
|
|
186
187
|
});
|
|
187
188
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call-contract.d.ts","sourceRoot":"","sources":["../../src/tasks/call-contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAEvE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAiBxB,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"call-contract.d.ts","sourceRoot":"","sources":["../../src/tasks/call-contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAEvE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAiBxB,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;iBAiBxC,CAAC;AAEH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,6BAA6B,CACrC,CAAC;AACF,MAAM,MAAM,mBAAmB,GAAG,uBAAuB,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC;AAE7E,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,OAAO,GACf,uBAAuB,CAKzB;AAED,wBAAgB,oBAAoB,CAClC,IAAI,CAAC,EAAE,mBAAmB,GACzB,mBAAmB,GAAG,SAAS,CAMjC;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,mBAAmB,GACzB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAKzB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,GACb,YAAY,CAQd"}
|
|
@@ -12,25 +12,23 @@ const toolCallMetaSchema = z.looseObject({
|
|
|
12
12
|
'io.modelcontextprotocol/related-task': relatedTaskMetaSchema.optional(),
|
|
13
13
|
});
|
|
14
14
|
export const extendedCallToolRequestSchema = z.looseObject({
|
|
15
|
-
method: z.literal('tools/call'
|
|
15
|
+
method: z.literal('tools/call'),
|
|
16
16
|
params: z.strictObject({
|
|
17
|
-
name: z.string(
|
|
18
|
-
arguments: z
|
|
19
|
-
.record(z.string(), z.unknown(), 'Expected object')
|
|
20
|
-
.optional(),
|
|
17
|
+
name: z.string().min(1, 'Tool name required'),
|
|
18
|
+
arguments: z.record(z.string(), z.unknown()).optional(),
|
|
21
19
|
task: z
|
|
22
20
|
.strictObject({
|
|
23
21
|
ttl: z
|
|
24
|
-
.number(
|
|
25
|
-
.int(
|
|
22
|
+
.number()
|
|
23
|
+
.int()
|
|
26
24
|
.min(MIN_TASK_TTL_MS, `Minimum ${MIN_TASK_TTL_MS}ms`)
|
|
27
25
|
.max(MAX_TASK_TTL_MS, `Maximum ${MAX_TASK_TTL_MS}ms`)
|
|
28
26
|
.optional(),
|
|
29
|
-
}
|
|
27
|
+
})
|
|
30
28
|
.optional(),
|
|
31
29
|
_meta: toolCallMetaSchema.optional(),
|
|
32
|
-
}
|
|
33
|
-
}
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
34
32
|
export function parseExtendedCallToolRequest(request) {
|
|
35
33
|
const parsed = extendedCallToolRequestSchema.safeParse(request);
|
|
36
34
|
if (parsed.success)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../../src/tasks/execution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../../src/tasks/execution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,oCAAoC,CAAC;AAiB5C,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,KAAK,gBAAgB,EAErB,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,YAAY,CAAC;AAkCpB,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAGvD;AAED,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,EAChB,aAAa,SAA4D,GACxE,MAAM,CAOR;AAED,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C;AAMD,KAAK,WAAW,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAC5C,KAAK,uBAAuB,GAAG,IAAI,CACjC,SAAS,EACP,QAAQ,GACR,QAAQ,GACR,eAAe,GACf,UAAU,GACV,OAAO,GACP,WAAW,GACX,eAAe,GACf,KAAK,GACL,cAAc,CACjB,CAAC;AAEF,wBAAgB,aAAa,CAAC,IAAI,EAAE,uBAAuB,GAAG,WAAW,CAYxE;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,SAAS,GACd,IAAI,CAmBN;AAED,wBAAgB,iBAAiB,IAAI,KAAK,CAEzC;AAgKD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,YAAY,CAAC,CAwFvB"}
|
package/dist/tasks/execution.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { ErrorCode, McpError, } from '@modelcontextprotocol/sdk/types.js';
|
|
2
2
|
import { config } from '../lib/core.js';
|
|
3
3
|
import { logDebug, logError, logInfo, logWarn, runWithRequestContext, } from '../lib/core.js';
|
|
4
|
+
import { LOG_TASKS } from '../lib/logger-names.js';
|
|
4
5
|
import { createMcpError } from '../lib/mcp-interop.js';
|
|
5
6
|
import {} from '../lib/mcp-interop.js';
|
|
7
|
+
import { tryReadToolErrorMessage } from '../lib/tool-errors.js';
|
|
6
8
|
import { getErrorMessage } from '../lib/utils.js';
|
|
7
9
|
import { isObject } from '../lib/utils.js';
|
|
8
10
|
import { buildRelatedTaskMeta, } from './call-contract.js';
|
|
9
11
|
import { taskManager, } from './manager.js';
|
|
10
|
-
import { buildToolHandlerExtra, compact,
|
|
12
|
+
import { buildToolHandlerExtra, compact, } from './owner.js';
|
|
11
13
|
import { getTaskCapableTool, getTaskCapableToolSupport, } from './registry.js';
|
|
12
14
|
/* -------------------------------------------------------------------------------------------------
|
|
13
15
|
* Abort-controller management for in-flight task executions
|
|
@@ -21,7 +23,7 @@ function attachAbortController(taskId) {
|
|
|
21
23
|
logWarn('Abort controller map reached task capacity — possible leak', {
|
|
22
24
|
size: taskAbortControllers.size,
|
|
23
25
|
maxTotal: config.tasks.maxTotal,
|
|
24
|
-
},
|
|
26
|
+
}, LOG_TASKS);
|
|
25
27
|
}
|
|
26
28
|
const controller = new AbortController();
|
|
27
29
|
taskAbortControllers.set(taskId, controller);
|
|
@@ -70,7 +72,7 @@ export function emitTaskStatusNotification(server, task) {
|
|
|
70
72
|
taskId: task.taskId,
|
|
71
73
|
status: task.status,
|
|
72
74
|
error: getErrorMessage(error),
|
|
73
|
-
},
|
|
75
|
+
}, LOG_TASKS);
|
|
74
76
|
});
|
|
75
77
|
}
|
|
76
78
|
export function throwTaskNotFound() {
|
|
@@ -87,7 +89,8 @@ function updateTaskAndEmitStatus(server, taskId, update) {
|
|
|
87
89
|
}
|
|
88
90
|
function buildTaskFailureState(error) {
|
|
89
91
|
const mcpErrorMessage = error instanceof McpError
|
|
90
|
-
? (/^MCP
|
|
92
|
+
? (/^(?:MCP )?[Ee]rror -?\d+:\s*(.*)$/s.exec(error.message)?.[1] ??
|
|
93
|
+
error.message)
|
|
91
94
|
: undefined;
|
|
92
95
|
const statusMessage = mcpErrorMessage ?? getErrorMessage(error);
|
|
93
96
|
if (error instanceof McpError) {
|
|
@@ -115,7 +118,7 @@ function buildTaskCompletionUpdate(result, tool) {
|
|
|
115
118
|
return {
|
|
116
119
|
status: isError ? 'failed' : 'completed',
|
|
117
120
|
statusMessage: isError
|
|
118
|
-
? (
|
|
121
|
+
? (tryReadToolErrorMessage(result) ?? 'Execution failed')
|
|
119
122
|
: (tool.getCompletionStatusMessage?.(result) ??
|
|
120
123
|
'Task completed successfully.'),
|
|
121
124
|
result,
|
|
@@ -131,7 +134,7 @@ async function runTaskToolExecution(params) {
|
|
|
131
134
|
const controller = attachAbortController(taskId);
|
|
132
135
|
const progressState = { closed: false };
|
|
133
136
|
try {
|
|
134
|
-
logInfo('Task execution started', { taskId, tool: tool.name },
|
|
137
|
+
logInfo('Task execution started', { taskId, tool: tool.name }, LOG_TASKS);
|
|
135
138
|
const relatedMeta = buildRelatedTaskMeta(taskId, meta);
|
|
136
139
|
const result = await tool.execute(args, {
|
|
137
140
|
signal: controller.signal,
|
|
@@ -157,10 +160,10 @@ async function runTaskToolExecution(params) {
|
|
|
157
160
|
const completionUpdate = buildTaskCompletionUpdate(result, tool);
|
|
158
161
|
updateTaskAndEmitStatus(server, taskId, completionUpdate);
|
|
159
162
|
if (completionUpdate.status === 'completed') {
|
|
160
|
-
logInfo('Task execution completed', { taskId, tool: tool.name },
|
|
163
|
+
logInfo('Task execution completed', { taskId, tool: tool.name }, LOG_TASKS);
|
|
161
164
|
}
|
|
162
165
|
else {
|
|
163
|
-
logWarn('Task execution completed with tool error result', { taskId, tool: tool.name },
|
|
166
|
+
logWarn('Task execution completed with tool error result', { taskId, tool: tool.name }, LOG_TASKS);
|
|
164
167
|
}
|
|
165
168
|
}
|
|
166
169
|
catch (error) {
|
|
@@ -168,7 +171,7 @@ async function runTaskToolExecution(params) {
|
|
|
168
171
|
taskId,
|
|
169
172
|
tool: tool.name,
|
|
170
173
|
error: getErrorMessage(error),
|
|
171
|
-
},
|
|
174
|
+
}, LOG_TASKS);
|
|
172
175
|
updateTaskAndEmitStatus(server, taskId, buildTaskFailureState(error));
|
|
173
176
|
}
|
|
174
177
|
finally {
|
|
@@ -182,11 +185,11 @@ export async function handleToolCallRequest(server, request, context) {
|
|
|
182
185
|
// Validate the tool name first so an unknown tool always produces MethodNotFound
|
|
183
186
|
const tool = getTaskCapableTool(server, params.name);
|
|
184
187
|
if (!tool) {
|
|
185
|
-
throw createMcpError(ErrorCode.MethodNotFound, `Unknown tool:
|
|
188
|
+
throw createMcpError(ErrorCode.MethodNotFound, `Unknown tool: ${params.name}`);
|
|
186
189
|
}
|
|
187
190
|
if (params.task) {
|
|
188
191
|
if (getTaskCapableToolSupport(server, params.name) === 'forbidden') {
|
|
189
|
-
throw createMcpError(ErrorCode.MethodNotFound, `Task
|
|
192
|
+
throw createMcpError(ErrorCode.MethodNotFound, `Task mode is not supported for tool: ${params.name}`);
|
|
190
193
|
}
|
|
191
194
|
const args = tool.parseArguments(params.arguments);
|
|
192
195
|
const task = taskManager.createTask(params.task.ttl !== undefined ? { ttl: params.task.ttl } : undefined, 'Task started', context.ownerKey);
|
|
@@ -194,7 +197,7 @@ export async function handleToolCallRequest(server, request, context) {
|
|
|
194
197
|
taskId: task.taskId,
|
|
195
198
|
tool: params.name,
|
|
196
199
|
...(params.task.ttl !== undefined ? { ttl: params.task.ttl } : {}),
|
|
197
|
-
},
|
|
200
|
+
}, LOG_TASKS);
|
|
198
201
|
void runTaskToolExecution({
|
|
199
202
|
server,
|
|
200
203
|
taskId: task.taskId,
|
|
@@ -218,14 +221,14 @@ export async function handleToolCallRequest(server, request, context) {
|
|
|
218
221
|
};
|
|
219
222
|
}
|
|
220
223
|
if (getTaskCapableToolSupport(server, params.name) === 'required') {
|
|
221
|
-
throw createMcpError(ErrorCode.MethodNotFound, `Task
|
|
224
|
+
throw createMcpError(ErrorCode.MethodNotFound, `Task mode is required for tool: ${params.name}`);
|
|
222
225
|
}
|
|
223
226
|
const args = tool.parseArguments(params.arguments);
|
|
224
227
|
const progressState = { closed: false };
|
|
225
228
|
logDebug('Executing task-capable tool inline', {
|
|
226
229
|
tool: params.name,
|
|
227
230
|
hasProgressToken: params._meta?.progressToken !== undefined,
|
|
228
|
-
},
|
|
231
|
+
}, LOG_TASKS);
|
|
229
232
|
try {
|
|
230
233
|
return await tool.execute(args, {
|
|
231
234
|
...buildToolHandlerExtra(context, params._meta),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/tasks/handlers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/tasks/handlers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAmCzE,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AA4D7E,UAAU,8BAA8B;IACtC,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,UAAU,6BAA6B;IACrC,oBAAoB,EAAE,OAAO,CAAC;IAC9B,0BAA0B,EAAE,OAAO,CAAC;CACrC;AAkBD,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,EACjB,OAAO,CAAC,EAAE,8BAA8B,GACvC,6BAA6B,CAoK/B"}
|
package/dist/tasks/handlers.js
CHANGED
|
@@ -3,6 +3,7 @@ import {} from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
|
3
3
|
import { CallToolRequestSchema, ErrorCode, } from '@modelcontextprotocol/sdk/types.js';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { logDebug, logWarn, runWithRequestContext } from '../lib/core.js';
|
|
6
|
+
import { LOG_TASKS } from '../lib/logger-names.js';
|
|
6
7
|
import { createMcpError, getSdkCallToolHandler } from '../lib/mcp-interop.js';
|
|
7
8
|
import { parseExtendedCallToolRequest, withRelatedTaskMeta, } from './call-contract.js';
|
|
8
9
|
import { abortTaskExecution, emitTaskStatusNotification, handleToolCallRequest, throwTaskNotFound, toTaskSummary, } from './execution.js';
|
|
@@ -44,7 +45,7 @@ function throwStoredTaskError(task) {
|
|
|
44
45
|
if (task.error) {
|
|
45
46
|
throw createMcpError(task.error.code, task.error.message, task.error.data);
|
|
46
47
|
}
|
|
47
|
-
throw createMcpError(ErrorCode.InternalError, task.statusMessage ?? '
|
|
48
|
+
throw createMcpError(ErrorCode.InternalError, task.statusMessage ?? 'Execution failed', { taskId: task.taskId });
|
|
48
49
|
}
|
|
49
50
|
export function registerTaskHandlers(server, options) {
|
|
50
51
|
const sdkCallToolHandler = getSdkCallToolHandler(server);
|
|
@@ -52,9 +53,9 @@ export function registerTaskHandlers(server, options) {
|
|
|
52
53
|
const requireInterception = options?.requireInterception ?? true;
|
|
53
54
|
if (!sdkCallToolHandler) {
|
|
54
55
|
if (taskCapableToolsRegistered && requireInterception) {
|
|
55
|
-
throw
|
|
56
|
+
throw Error('Task-capable tools are registered but SDK tools/call interception is unavailable. Upgrade compatibility or disable strict interception with TASKS_REQUIRE_INTERCEPTION=false.');
|
|
56
57
|
}
|
|
57
|
-
logWarn('Task call interception disabled: SDK tools/call handler unavailable; task-capable tools require MCP SDK compatibility update', { sdkVersion: 'unknown' },
|
|
58
|
+
logWarn('Task call interception disabled: SDK tools/call handler unavailable; task-capable tools require MCP SDK compatibility update', { sdkVersion: 'unknown' }, LOG_TASKS);
|
|
58
59
|
}
|
|
59
60
|
if (sdkCallToolHandler) {
|
|
60
61
|
server.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
@@ -81,7 +82,7 @@ export function registerTaskHandlers(server, options) {
|
|
|
81
82
|
tool: toolName,
|
|
82
83
|
taskRequested: parsed.params.task !== undefined,
|
|
83
84
|
hasProgressToken: parsed.params._meta?.progressToken !== undefined,
|
|
84
|
-
},
|
|
85
|
+
}, LOG_TASKS);
|
|
85
86
|
return handleToolCallRequest(server, parsed, context);
|
|
86
87
|
});
|
|
87
88
|
});
|
|
@@ -89,7 +90,7 @@ export function registerTaskHandlers(server, options) {
|
|
|
89
90
|
server.server.setRequestHandler(TaskGetSchema, (request, extra) => {
|
|
90
91
|
const { taskId } = request.params;
|
|
91
92
|
const { ownerKey } = resolveOwnerScopedExtra(extra);
|
|
92
|
-
logDebug('tasks/get requested', { taskId },
|
|
93
|
+
logDebug('tasks/get requested', { taskId }, LOG_TASKS);
|
|
93
94
|
const task = taskManager.getTask(taskId, ownerKey);
|
|
94
95
|
if (!task)
|
|
95
96
|
throwTaskNotFound();
|
|
@@ -98,7 +99,7 @@ export function registerTaskHandlers(server, options) {
|
|
|
98
99
|
server.server.setRequestHandler(TaskResultSchema, async (request, extra) => {
|
|
99
100
|
const { taskId } = request.params;
|
|
100
101
|
const { parsedExtra, ownerKey } = resolveOwnerScopedExtra(extra);
|
|
101
|
-
logDebug('tasks/result requested', { taskId },
|
|
102
|
+
logDebug('tasks/result requested', { taskId }, LOG_TASKS);
|
|
102
103
|
const task = await taskManager.waitForTerminalTask(taskId, ownerKey, parsedExtra?.signal);
|
|
103
104
|
if (!task)
|
|
104
105
|
throwTaskNotFound();
|
|
@@ -131,7 +132,7 @@ export function registerTaskHandlers(server, options) {
|
|
|
131
132
|
server.server.setRequestHandler(TaskListSchema, (request, extra) => {
|
|
132
133
|
const { ownerKey } = resolveOwnerScopedExtra(extra);
|
|
133
134
|
const cursor = request.params?.cursor;
|
|
134
|
-
logDebug('tasks/list requested', { hasCursor: cursor !== undefined },
|
|
135
|
+
logDebug('tasks/list requested', { hasCursor: cursor !== undefined }, LOG_TASKS);
|
|
135
136
|
const { tasks, nextCursor } = taskManager.listTasks(cursor === undefined ? { ownerKey } : { ownerKey, cursor });
|
|
136
137
|
return {
|
|
137
138
|
tasks: tasks.map((task) => toTaskSummary(task)),
|
|
@@ -141,7 +142,7 @@ export function registerTaskHandlers(server, options) {
|
|
|
141
142
|
server.server.setRequestHandler(TaskCancelSchema, (request, extra) => {
|
|
142
143
|
const { taskId } = request.params;
|
|
143
144
|
const { ownerKey } = resolveOwnerScopedExtra(extra);
|
|
144
|
-
logDebug('tasks/cancel requested', { taskId },
|
|
145
|
+
logDebug('tasks/cancel requested', { taskId }, LOG_TASKS);
|
|
145
146
|
const task = taskManager.cancelTask(taskId, ownerKey);
|
|
146
147
|
if (!task)
|
|
147
148
|
throwTaskNotFound();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/tasks/manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/tasks/manager.ts"],"names":[],"mappings":"AAgBA,MAAM,MAAM,UAAU,GAClB,SAAS,GACT,gBAAgB,GAChB,WAAW,GACX,QAAQ,GACR,WAAW,CAAC;AAEhB,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WA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AAG,IAAI,CA0BjC"}
|
package/dist/tasks/manager.js
CHANGED
|
@@ -3,6 +3,7 @@ import { createHmac, randomBytes } from 'node:crypto';
|
|
|
3
3
|
import { setInterval } from 'node:timers';
|
|
4
4
|
import { ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
5
5
|
import { config, logInfo, logWarn } from '../lib/core.js';
|
|
6
|
+
import { LOG_TASKS } from '../lib/logger-names.js';
|
|
6
7
|
import { createMcpError } from '../lib/mcp-interop.js';
|
|
7
8
|
import { isObject, timingSafeEqualUtf8 } from '../lib/utils.js';
|
|
8
9
|
import { TaskWaiterRegistry, waitForTerminalTask as waitForTerminalTaskWithDeadline, } from './waiters.js';
|
|
@@ -34,10 +35,10 @@ function resolveNextTaskStatus(task, updates) {
|
|
|
34
35
|
if (!nextStatus || nextStatus === task.status)
|
|
35
36
|
return task.status;
|
|
36
37
|
if (!TASK_STATUS_VALUES.has(nextStatus)) {
|
|
37
|
-
throw createMcpError(ErrorCode.InternalError, `Invalid task status
|
|
38
|
+
throw createMcpError(ErrorCode.InternalError, `Invalid task status: ${nextStatus}`);
|
|
38
39
|
}
|
|
39
40
|
if (isTerminalStatus(task.status)) {
|
|
40
|
-
throw createMcpError(ErrorCode.InternalError, `
|
|
41
|
+
throw createMcpError(ErrorCode.InternalError, `Cannot transition task from ${task.status} to ${nextStatus}`);
|
|
41
42
|
}
|
|
42
43
|
return nextStatus;
|
|
43
44
|
}
|
|
@@ -57,10 +58,10 @@ function logTaskStatusTransition(task, previousStatus, nextStatus) {
|
|
|
57
58
|
...(task.statusMessage ? { statusMessage: task.statusMessage } : {}),
|
|
58
59
|
};
|
|
59
60
|
if (nextStatus === 'failed') {
|
|
60
|
-
logWarn('Task status changed to failed', meta,
|
|
61
|
+
logWarn('Task status changed to failed', meta, LOG_TASKS);
|
|
61
62
|
return;
|
|
62
63
|
}
|
|
63
|
-
logInfo('Task status changed', meta,
|
|
64
|
+
logInfo('Task status changed', meta, LOG_TASKS);
|
|
64
65
|
}
|
|
65
66
|
class TaskManager {
|
|
66
67
|
tasks = new Map();
|
|
@@ -93,7 +94,7 @@ class TaskManager {
|
|
|
93
94
|
taskId: task.taskId,
|
|
94
95
|
ownerKey: task.ownerKey,
|
|
95
96
|
status: task.status,
|
|
96
|
-
},
|
|
97
|
+
}, LOG_TASKS);
|
|
97
98
|
this.removeTask(task.taskId);
|
|
98
99
|
}
|
|
99
100
|
}
|
|
@@ -141,10 +142,10 @@ class TaskManager {
|
|
|
141
142
|
reserveTaskCapacity(ownerKey) {
|
|
142
143
|
const { maxPerOwner, maxTotal } = config.tasks;
|
|
143
144
|
if (this.tasks.size >= maxTotal) {
|
|
144
|
-
throw createMcpError(ErrorCode.InvalidRequest, `
|
|
145
|
+
throw createMcpError(ErrorCode.InvalidRequest, `Server task limit reached (${maxTotal})`);
|
|
145
146
|
}
|
|
146
147
|
if ((this.ownerCounts.get(ownerKey) ?? 0) >= maxPerOwner) {
|
|
147
|
-
throw createMcpError(ErrorCode.InvalidRequest, `Task
|
|
148
|
+
throw createMcpError(ErrorCode.InvalidRequest, `Task limit reached for this session (${maxPerOwner})`);
|
|
148
149
|
}
|
|
149
150
|
this.ownerCounts.set(ownerKey, (this.ownerCounts.get(ownerKey) ?? 0) + 1);
|
|
150
151
|
}
|
|
@@ -170,7 +171,7 @@ class TaskManager {
|
|
|
170
171
|
taskId: task.taskId,
|
|
171
172
|
ownerKey,
|
|
172
173
|
ttl: task.ttl,
|
|
173
|
-
},
|
|
174
|
+
}, LOG_TASKS);
|
|
174
175
|
return task;
|
|
175
176
|
}
|
|
176
177
|
lookupActiveTask(taskId, ownerKey) {
|
|
@@ -191,14 +192,14 @@ class TaskManager {
|
|
|
191
192
|
updateTask(taskId, updates) {
|
|
192
193
|
const task = this.tasks.get(taskId);
|
|
193
194
|
if (!task) {
|
|
194
|
-
logWarn('updateTask called for unknown task', { taskId },
|
|
195
|
+
logWarn('updateTask called for unknown task', { taskId }, LOG_TASKS);
|
|
195
196
|
return;
|
|
196
197
|
}
|
|
197
198
|
if (isTerminalStatus(task.status)) {
|
|
198
199
|
logWarn('updateTask called for terminal task', {
|
|
199
200
|
taskId,
|
|
200
201
|
currentStatus: task.status,
|
|
201
|
-
},
|
|
202
|
+
}, LOG_TASKS);
|
|
202
203
|
return;
|
|
203
204
|
}
|
|
204
205
|
const nextStatus = resolveNextTaskStatus(task, updates);
|
|
@@ -215,13 +216,13 @@ class TaskManager {
|
|
|
215
216
|
if (!task)
|
|
216
217
|
return undefined;
|
|
217
218
|
if (isTerminalStatus(task.status)) {
|
|
218
|
-
throw createMcpError(ErrorCode.InvalidParams, `Cannot cancel task: already
|
|
219
|
+
throw createMcpError(ErrorCode.InvalidParams, `Cannot cancel task: already ${task.status}`);
|
|
219
220
|
}
|
|
220
221
|
this.cancelActiveTask(task, 'The task was cancelled by request.');
|
|
221
222
|
logInfo('Task cancelled by request', {
|
|
222
223
|
taskId: task.taskId,
|
|
223
224
|
ownerKey: task.ownerKey,
|
|
224
|
-
},
|
|
225
|
+
}, LOG_TASKS);
|
|
225
226
|
return task;
|
|
226
227
|
}
|
|
227
228
|
cancelTasksByOwner(ownerKey, statusMessage = 'The task was cancelled because its owner is no longer active.') {
|
|
@@ -238,7 +239,7 @@ class TaskManager {
|
|
|
238
239
|
logInfo('Tasks cancelled for owner', {
|
|
239
240
|
ownerKey,
|
|
240
241
|
count: cancelled.length,
|
|
241
|
-
},
|
|
242
|
+
}, LOG_TASKS);
|
|
242
243
|
}
|
|
243
244
|
return cancelled;
|
|
244
245
|
}
|
package/dist/tasks/owner.d.ts
CHANGED
|
@@ -39,6 +39,5 @@ export declare function resolveToolCallContext(extra?: HandlerExtra, requestMeta
|
|
|
39
39
|
export declare function buildToolHandlerExtra(context: ToolExecutionContext, requestMeta?: ToolCallRequestMeta): ToolHandlerExtra;
|
|
40
40
|
export declare function withRequestContextIfMissing<TParams, TResult, TExtra = unknown>(handler: (params: TParams, extra?: TExtra) => Promise<TResult>): (params: TParams, extra?: TExtra) => Promise<TResult>;
|
|
41
41
|
export declare function isServerResult(value: unknown): value is ServerResult;
|
|
42
|
-
export declare function tryReadToolStructuredError(value: unknown): string | undefined;
|
|
43
42
|
export {};
|
|
44
43
|
//# sourceMappingURL=owner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"owner.d.ts","sourceRoot":"","sources":["../../src/tasks/owner.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"owner.d.ts","sourceRoot":"","sources":["../../src/tasks/owner.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAOvE,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,oBAAoB,CAAC;AAM5B,UAAU,YAAY;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACjD,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,gBAAgB,CAAC,EAAE,CAAC,YAAY,EAAE,oBAAoB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzE,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,gBAAgB,CAAC,EAAE,CAAC,YAAY,EAAE,oBAAoB,KAAK,OAAO,CAAC,IAAI,CAAC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K,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAmBvD;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE"}
|
package/dist/tasks/owner.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { hash, randomUUID } from 'node:crypto';
|
|
2
|
-
import { z } from 'zod';
|
|
3
2
|
import { getRequestId, resolveMcpSessionOwnerKey, runWithRequestContext, } from '../lib/core.js';
|
|
4
3
|
import { isObject } from '../lib/utils.js';
|
|
5
4
|
import { sanitizeToolCallMeta, } from './call-contract.js';
|
|
@@ -143,27 +142,3 @@ export function withRequestContextIfMissing(handler) {
|
|
|
143
142
|
export function isServerResult(value) {
|
|
144
143
|
return isObject(value) && Array.isArray(value['content']);
|
|
145
144
|
}
|
|
146
|
-
const toolErrorContentSchema = z.strictObject({
|
|
147
|
-
error: z.string(),
|
|
148
|
-
});
|
|
149
|
-
const toolErrorBlockSchema = z.strictObject({
|
|
150
|
-
type: z.literal('text'),
|
|
151
|
-
text: z.string(),
|
|
152
|
-
});
|
|
153
|
-
export function tryReadToolStructuredError(value) {
|
|
154
|
-
if (!isObject(value))
|
|
155
|
-
return undefined;
|
|
156
|
-
const { content } = value;
|
|
157
|
-
if (!Array.isArray(content) || content.length === 0)
|
|
158
|
-
return undefined;
|
|
159
|
-
const parsedBlock = toolErrorBlockSchema.safeParse(content[0]);
|
|
160
|
-
if (!parsedBlock.success)
|
|
161
|
-
return undefined;
|
|
162
|
-
try {
|
|
163
|
-
const parsed = toolErrorContentSchema.safeParse(JSON.parse(parsedBlock.data.text));
|
|
164
|
-
return parsed.success ? parsed.data.error : undefined;
|
|
165
|
-
}
|
|
166
|
-
catch {
|
|
167
|
-
return undefined;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-url.d.ts","sourceRoot":"","sources":["../../src/tools/fetch-url.ts"],"names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