@j0hanz/fetch-url-mcp 1.11.5 → 1.11.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/health.js +1 -1
- package/dist/http/native.d.ts.map +1 -1
- package/dist/http/native.js +2 -6
- package/dist/lib/cache.d.ts +48 -0
- package/dist/lib/cache.d.ts.map +1 -0
- package/dist/lib/cache.js +273 -0
- package/dist/lib/core.d.ts +1 -40
- package/dist/lib/core.d.ts.map +1 -1
- package/dist/lib/core.js +2 -233
- package/dist/lib/fetch-pipeline.d.ts.map +1 -1
- package/dist/lib/fetch-pipeline.js +5 -2
- package/dist/lib/mcp-interop.d.ts +2 -2
- package/dist/lib/mcp-interop.js +2 -2
- package/dist/resources/index.d.ts +21 -0
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/resources/index.js +47 -72
- package/dist/tasks/execution.d.ts.map +1 -1
- package/dist/tasks/execution.js +18 -3
- package/dist/tasks/handlers.d.ts.map +1 -1
- package/dist/tasks/handlers.js +3 -4
- package/dist/tasks/manager.js +3 -3
- package/dist/tasks/waiters.js +1 -1
- package/dist/tools/fetch-url.d.ts.map +1 -1
- package/dist/tools/fetch-url.js +3 -6
- package/dist/transform/transform.js +1 -2
- package/package.json +1 -1
- package/dist/lib/task-handlers.d.ts +0 -11
- package/dist/lib/task-handlers.d.ts.map +0 -1
- package/dist/lib/task-handlers.js +0 -151
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-pipeline.d.ts","sourceRoot":"","sources":["../../src/lib/fetch-pipeline.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"fetch-pipeline.d.ts","sourceRoot":"","sources":["../../src/lib/fetch-pipeline.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AASrE,OAAO,EAA6B,U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sB,CAAC,CAAC;IAC9D,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,MAAM,CAAC;IAChE,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,sBAAsB,GAAG,SAAS,CAAC;CAC/E;AACD,UAAU,eAAe;IACvB,QAAQ,CAAC,oBAAoB,CAAC,EAAE,OAAO,oBAAoB,CAAC;CAC7D;AASD,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,oBAAoB,EAC7B,IAAI,GAAE,eAAoB,GACzB,OAAO,CAAC;IACT,QAAQ,EAAE,cAAc,CAAC,sBAAsB,CAAC,CAAC;IACjD,YAAY,EAAE,mBAAmB,CAAC;CACnC,CAAC,CAaD"}
|
|
@@ -2,7 +2,9 @@ import { z } from 'zod';
|
|
|
2
2
|
import { cachedPayloadValueSchema, extractedMetadataSchema, normalizeExtractedMetadata, normalizePageTitle, parseCachedPayload, stringifyCachedPayload, } from '../schemas.js';
|
|
3
3
|
import { transformBufferToMarkdown } from '../transform/transform.js';
|
|
4
4
|
import {} from '../transform/types.js';
|
|
5
|
-
import {
|
|
5
|
+
import { createCacheKey, get, isEnabled, set } from './cache.js';
|
|
6
|
+
import { toCacheScopeId } from './cache.js';
|
|
7
|
+
import { config, getSessionId, logDebug, logError, logWarn } from './core.js';
|
|
6
8
|
import { fetchNormalizedUrlBuffer, normalizeUrl, transformToRawUrl, } from './http.js';
|
|
7
9
|
import { getErrorMessage, isObject, withSignal } from './utils.js';
|
|
8
10
|
export { withSignal };
|
|
@@ -129,7 +131,7 @@ function logCacheMiss(reason, cacheNamespace, normalizedUrl, error) {
|
|
|
129
131
|
function attemptCacheRetrieval(cacheKey, deserialize, cacheNamespace, normalizedUrl) {
|
|
130
132
|
if (!cacheKey)
|
|
131
133
|
return null;
|
|
132
|
-
const cached = get(cacheKey);
|
|
134
|
+
const cached = get(cacheKey, { scopeId: toCacheScopeId(getSessionId()) });
|
|
133
135
|
if (!cached)
|
|
134
136
|
return null;
|
|
135
137
|
if (!deserialize) {
|
|
@@ -178,6 +180,7 @@ function persistCacheEntry(cacheKey, data, serialize, normalizedUrl, cacheNamesp
|
|
|
178
180
|
const title = typeof dataRecord?.title === 'string' ? dataRecord.title : undefined;
|
|
179
181
|
const metadata = {
|
|
180
182
|
url: normalizedUrl,
|
|
183
|
+
scopeIds: [toCacheScopeId(getSessionId())],
|
|
181
184
|
...(title === undefined ? {} : { title }),
|
|
182
185
|
};
|
|
183
186
|
try {
|
|
@@ -67,14 +67,14 @@ export declare function registerServerLifecycleCleanup(server: McpServer, callba
|
|
|
67
67
|
/**
|
|
68
68
|
* Retrieves the SDK's internal request-handler map.
|
|
69
69
|
*
|
|
70
|
-
* Depends on SDK private API `_requestHandlers` (verified against ^1.
|
|
70
|
+
* Depends on SDK private API `_requestHandlers` (verified against ^1.28).
|
|
71
71
|
* If the SDK changes this internal, the sdk-compat-guard.test.ts tests will fail.
|
|
72
72
|
*/
|
|
73
73
|
export declare function getSdkCallToolHandler(server: McpServer): RequestHandlerFn | null;
|
|
74
74
|
/**
|
|
75
75
|
* Patches the SDK's internal capabilities to enable/disable task-mode tool calls.
|
|
76
76
|
*
|
|
77
|
-
* Depends on SDK private API `_capabilities.tasks.requests` (verified against ^1.
|
|
77
|
+
* Depends on SDK private API `_capabilities.tasks.requests` (verified against ^1.28).
|
|
78
78
|
* If the SDK changes this internal, the sdk-compat-guard.test.ts tests will fail.
|
|
79
79
|
*/
|
|
80
80
|
export declare function setTaskToolCallCapability(server: McpServer, enabled: boolean): void;
|
package/dist/lib/mcp-interop.js
CHANGED
|
@@ -176,7 +176,7 @@ export function registerServerLifecycleCleanup(server, callback) {
|
|
|
176
176
|
/**
|
|
177
177
|
* Retrieves the SDK's internal request-handler map.
|
|
178
178
|
*
|
|
179
|
-
* Depends on SDK private API `_requestHandlers` (verified against ^1.
|
|
179
|
+
* Depends on SDK private API `_requestHandlers` (verified against ^1.28).
|
|
180
180
|
* If the SDK changes this internal, the sdk-compat-guard.test.ts tests will fail.
|
|
181
181
|
*/
|
|
182
182
|
export function getSdkCallToolHandler(server) {
|
|
@@ -189,7 +189,7 @@ export function getSdkCallToolHandler(server) {
|
|
|
189
189
|
/**
|
|
190
190
|
* Patches the SDK's internal capabilities to enable/disable task-mode tool calls.
|
|
191
191
|
*
|
|
192
|
-
* Depends on SDK private API `_capabilities.tasks.requests` (verified against ^1.
|
|
192
|
+
* Depends on SDK private API `_capabilities.tasks.requests` (verified against ^1.28).
|
|
193
193
|
* If the SDK changes this internal, the sdk-compat-guard.test.ts tests will fail.
|
|
194
194
|
*/
|
|
195
195
|
export function setTaskToolCallCapability(server, enabled) {
|
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
import { type McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import type { ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
3
|
import { type IconInfo } from '../lib/utils.js';
|
|
4
|
+
type TemplateVariableValue = string | string[] | undefined;
|
|
5
|
+
interface CacheEntryMetaView {
|
|
6
|
+
scopeIds: string[];
|
|
7
|
+
}
|
|
8
|
+
export declare function isCacheEntryVisibleToScope(scopeId: string, meta: CacheEntryMetaView): boolean;
|
|
9
|
+
export declare function listCacheResourcesForScope(scopeId: string): {
|
|
10
|
+
resources: {
|
|
11
|
+
uri: string;
|
|
12
|
+
name: string;
|
|
13
|
+
title: string;
|
|
14
|
+
description: string;
|
|
15
|
+
mimeType: string;
|
|
16
|
+
annotations: {
|
|
17
|
+
audience: ['assistant'];
|
|
18
|
+
priority: number;
|
|
19
|
+
};
|
|
20
|
+
}[];
|
|
21
|
+
};
|
|
22
|
+
export declare function readCacheResourceForScope(uri: URL, variables: Record<string, TemplateVariableValue>, scopeId: string): ReadResourceResult;
|
|
3
23
|
export declare function registerInstructionResource(server: McpServer, instructions: string, iconInfo?: IconInfo): void;
|
|
4
24
|
export declare function registerCacheResourceTemplate(server: McpServer, iconInfo?: IconInfo): void;
|
|
5
25
|
export declare function buildServerInstructions(): string;
|
|
6
26
|
export declare function registerGetHelpPrompt(server: McpServer, instructions: string, iconInfo?: IconInfo): void;
|
|
27
|
+
export {};
|
|
7
28
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resources/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EAEf,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resources/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EAEf,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EAEV,kBAAkB,EACnB,MAAM,oCAAoC,CAAC;AAkB5C,OAAO,EAAsB,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAiBpE,KAAK,qBAAqB,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;AAQ3D,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAyFD,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAET;AAuCD,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG;IAC3D,SAAS,EAAE;QACT,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE;YAAE,QAAQ,EAAE,CAAC,WAAW,CAAC,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAC;KAC5D,EAAE,CAAC;CACL,CA0BA;AA2HD,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,EAChD,OAAO,EAAE,MAAM,GACd,kBAAkB,CA8BpB;AAED,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,SAAS,EACjB,YAAY,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,QAAQ,GAClB,IAAI,CAwBN;AAED,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,SAAS,EACjB,QAAQ,CAAC,EAAE,QAAQ,GAClB,IAAI,CAkCN;AAED,wBAAgB,uBAAuB,IAAI,MAAM,CAoChD;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,SAAS,EACjB,YAAY,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,QAAQ,GAClB,IAAI,CAwBN"}
|
package/dist/resources/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { ResourceTemplate, } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import { ErrorCode, McpError, SubscribeRequestSchema, UnsubscribeRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
-
import { get as getCacheEntry, getEntryMeta, keys as listCacheKeys, onCacheUpdate, parseCacheKey, } from '../lib/
|
|
4
|
-
import { logWarn } from '../lib/core.js';
|
|
5
|
-
import { config } from '../lib/core.js';
|
|
3
|
+
import { get as getCacheEntry, getEntryMeta, keys as listCacheKeys, onCacheUpdate, parseCacheKey, toCacheScopeId, } from '../lib/cache.js';
|
|
4
|
+
import { config, logWarn, resolveMcpSessionIdByServer } from '../lib/core.js';
|
|
6
5
|
import { registerServerLifecycleCleanup } from '../lib/mcp-interop.js';
|
|
7
6
|
import { buildOptionalIcons } from '../lib/utils.js';
|
|
8
7
|
import { isObject } from '../lib/utils.js';
|
|
@@ -84,85 +83,52 @@ function toCacheResourceUri(parts) {
|
|
|
84
83
|
const hash = encodeURIComponent(parts.hash);
|
|
85
84
|
return `${CACHE_RESOURCE_PREFIX}${namespace}/${hash}`;
|
|
86
85
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
hashIndex = null;
|
|
90
|
-
invalidate() {
|
|
91
|
-
this.namespaces = null;
|
|
92
|
-
this.hashIndex = null;
|
|
93
|
-
}
|
|
94
|
-
getNamespaces() {
|
|
95
|
-
if (!this.namespaces) {
|
|
96
|
-
const seen = new Set();
|
|
97
|
-
for (const key of listCacheKeys()) {
|
|
98
|
-
const parsed = parseCacheKey(key);
|
|
99
|
-
if (parsed)
|
|
100
|
-
seen.add(parsed.namespace);
|
|
101
|
-
}
|
|
102
|
-
this.namespaces = [...seen].sort((a, b) => a.localeCompare(b));
|
|
103
|
-
}
|
|
104
|
-
return this.namespaces;
|
|
105
|
-
}
|
|
106
|
-
getHashes(namespace) {
|
|
107
|
-
if (!this.hashIndex) {
|
|
108
|
-
const index = new Map();
|
|
109
|
-
for (const key of listCacheKeys()) {
|
|
110
|
-
const parsed = parseCacheKey(key);
|
|
111
|
-
if (!parsed)
|
|
112
|
-
continue;
|
|
113
|
-
let set = index.get(parsed.namespace);
|
|
114
|
-
if (!set) {
|
|
115
|
-
set = new Set();
|
|
116
|
-
index.set(parsed.namespace, set);
|
|
117
|
-
}
|
|
118
|
-
set.add(parsed.urlHash);
|
|
119
|
-
}
|
|
120
|
-
this.hashIndex = new Map();
|
|
121
|
-
for (const [ns, set] of index) {
|
|
122
|
-
this.hashIndex.set(ns, [...set].sort((a, b) => a.localeCompare(b)));
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
if (namespace)
|
|
126
|
-
return this.hashIndex.get(namespace) ?? [];
|
|
127
|
-
const all = [];
|
|
128
|
-
for (const hashes of this.hashIndex.values()) {
|
|
129
|
-
all.push(...hashes);
|
|
130
|
-
}
|
|
131
|
-
return all.sort((a, b) => a.localeCompare(b));
|
|
132
|
-
}
|
|
86
|
+
export function isCacheEntryVisibleToScope(scopeId, meta) {
|
|
87
|
+
return meta.scopeIds.includes(scopeId);
|
|
133
88
|
}
|
|
134
|
-
|
|
135
|
-
|
|
89
|
+
function getVisibleCacheEntries(scopeId) {
|
|
90
|
+
return listCacheKeys()
|
|
91
|
+
.map((key) => parseCacheKey(key))
|
|
92
|
+
.filter((parts) => parts !== null)
|
|
93
|
+
.map((parts) => ({ namespace: parts.namespace, hash: parts.urlHash }))
|
|
94
|
+
.filter((parts) => {
|
|
95
|
+
const meta = getEntryMeta(`${parts.namespace}:${parts.hash}`);
|
|
96
|
+
return meta ? isCacheEntryVisibleToScope(scopeId, meta) : false;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function completeCacheNamespaces(value, scopeId) {
|
|
136
100
|
const normalized = normalizeCompletionPrefix(value);
|
|
137
|
-
const namespaces =
|
|
138
|
-
.
|
|
139
|
-
|
|
101
|
+
const namespaces = [
|
|
102
|
+
...new Set(getVisibleCacheEntries(scopeId).map((entry) => entry.namespace)),
|
|
103
|
+
].filter((ns) => ns.toLowerCase().startsWith(normalized));
|
|
140
104
|
return sortAndLimitValues(namespaces);
|
|
141
105
|
}
|
|
142
|
-
function completeCacheHashes(value, context) {
|
|
106
|
+
function completeCacheHashes(value, scopeId, context) {
|
|
143
107
|
const normalized = normalizeCompletionPrefix(value);
|
|
144
108
|
const namespace = context?.arguments?.['namespace']?.trim();
|
|
145
|
-
const hashes =
|
|
146
|
-
.
|
|
109
|
+
const hashes = getVisibleCacheEntries(scopeId)
|
|
110
|
+
.filter((entry) => namespace === undefined || entry.namespace === namespace)
|
|
111
|
+
.map((entry) => entry.hash)
|
|
147
112
|
.filter((h) => h.toLowerCase().startsWith(normalized));
|
|
148
113
|
return sortAndLimitValues(hashes);
|
|
149
114
|
}
|
|
150
|
-
function
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
115
|
+
function getServerCacheScopeId(server) {
|
|
116
|
+
return toCacheScopeId(resolveMcpSessionIdByServer(server));
|
|
117
|
+
}
|
|
118
|
+
export function listCacheResourcesForScope(scopeId) {
|
|
119
|
+
const resources = getVisibleCacheEntries(scopeId)
|
|
154
120
|
.map((parts) => {
|
|
155
121
|
const cacheParts = {
|
|
156
122
|
namespace: parts.namespace,
|
|
157
|
-
hash: parts.
|
|
123
|
+
hash: parts.hash,
|
|
158
124
|
};
|
|
159
|
-
const cacheKey = `${parts.namespace}:${parts.
|
|
125
|
+
const cacheKey = `${parts.namespace}:${parts.hash}`;
|
|
160
126
|
const meta = getEntryMeta(cacheKey);
|
|
161
127
|
if (!meta)
|
|
162
128
|
return null; // expired between keys() and meta read — skip
|
|
163
129
|
return {
|
|
164
130
|
uri: toCacheResourceUri(cacheParts),
|
|
165
|
-
name: `${parts.namespace}:${parts.
|
|
131
|
+
name: `${parts.namespace}:${parts.hash}`,
|
|
166
132
|
title: meta.title ?? 'Cached Markdown',
|
|
167
133
|
description: 'Cached markdown output generated by fetch-url',
|
|
168
134
|
mimeType: 'text/markdown',
|
|
@@ -210,12 +176,15 @@ function registerCacheResourceNotifications(server) {
|
|
|
210
176
|
return Promise.resolve({});
|
|
211
177
|
});
|
|
212
178
|
const unsubscribe = onCacheUpdate((event) => {
|
|
213
|
-
|
|
179
|
+
const scopeId = getServerCacheScopeId(server);
|
|
214
180
|
const changedUri = toCacheResourceUri({
|
|
215
181
|
namespace: event.namespace,
|
|
216
182
|
hash: event.urlHash,
|
|
217
183
|
});
|
|
218
|
-
|
|
184
|
+
const isVisibleToServer = event.scopeIds.includes(scopeId);
|
|
185
|
+
if (isVisibleToServer &&
|
|
186
|
+
server.isConnected() &&
|
|
187
|
+
subscribedResourceUris.has(changedUri)) {
|
|
219
188
|
void server.server
|
|
220
189
|
.sendResourceUpdated({ uri: changedUri })
|
|
221
190
|
.catch((error) => {
|
|
@@ -227,7 +196,7 @@ function registerCacheResourceNotifications(server) {
|
|
|
227
196
|
}
|
|
228
197
|
if (!event.listChanged)
|
|
229
198
|
return;
|
|
230
|
-
if (!server.isConnected())
|
|
199
|
+
if (!server.isConnected() || !isVisibleToServer)
|
|
231
200
|
return;
|
|
232
201
|
try {
|
|
233
202
|
server.sendResourceListChanged();
|
|
@@ -269,9 +238,15 @@ function resolveCacheResourceParts(uri, variables) {
|
|
|
269
238
|
return fromUri;
|
|
270
239
|
throw new McpError(ErrorCode.InvalidParams, 'Invalid cache resource URI or template arguments');
|
|
271
240
|
}
|
|
272
|
-
function
|
|
241
|
+
export function readCacheResourceForScope(uri, variables, scopeId) {
|
|
273
242
|
const parts = resolveCacheResourceParts(uri, variables);
|
|
274
243
|
const cacheKey = `${parts.namespace}:${parts.hash}`;
|
|
244
|
+
const meta = getEntryMeta(cacheKey);
|
|
245
|
+
if (!meta || !isCacheEntryVisibleToScope(scopeId, meta)) {
|
|
246
|
+
throw new McpError(RESOURCE_NOT_FOUND_ERROR_CODE, 'Resource not found', {
|
|
247
|
+
uri: uri.href,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
275
250
|
const entry = getCacheEntry(cacheKey);
|
|
276
251
|
if (!entry) {
|
|
277
252
|
throw new McpError(RESOURCE_NOT_FOUND_ERROR_CODE, 'Resource not found', {
|
|
@@ -313,10 +288,10 @@ export function registerInstructionResource(server, instructions, iconInfo) {
|
|
|
313
288
|
}
|
|
314
289
|
export function registerCacheResourceTemplate(server, iconInfo) {
|
|
315
290
|
const template = new ResourceTemplate(CACHE_RESOURCE_TEMPLATE_URI, {
|
|
316
|
-
list: () =>
|
|
291
|
+
list: () => listCacheResourcesForScope(getServerCacheScopeId(server)),
|
|
317
292
|
complete: {
|
|
318
|
-
namespace: (value) => completeCacheNamespaces(value),
|
|
319
|
-
hash: (value, context) => completeCacheHashes(value, context),
|
|
293
|
+
namespace: (value) => completeCacheNamespaces(value, getServerCacheScopeId(server)),
|
|
294
|
+
hash: (value, context) => completeCacheHashes(value, getServerCacheScopeId(server), context),
|
|
320
295
|
},
|
|
321
296
|
});
|
|
322
297
|
server.registerResource('fetch-url-mcp-cache-entry', template, {
|
|
@@ -328,7 +303,7 @@ export function registerCacheResourceTemplate(server, iconInfo) {
|
|
|
328
303
|
priority: 0.6,
|
|
329
304
|
},
|
|
330
305
|
...buildOptionalIcons(iconInfo),
|
|
331
|
-
}, (uri, variables) =>
|
|
306
|
+
}, (uri, variables) => readCacheResourceForScope(uri, normalizeTemplateVariables(variables), getServerCacheScopeId(server)));
|
|
332
307
|
registerCacheResourceNotifications(server);
|
|
333
308
|
}
|
|
334
309
|
export function buildServerInstructions() {
|
|
@@ -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;AAQ5C,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,EAErB,MAAM,YAAY,CAAC;AAgCpB,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,WAAW,GACX,eAAe,GACf,KAAK,GACL,cAAc,CACjB,CAAC;AAEF,wBAAgB,aAAa,CAAC,IAAI,EAAE,uBAAuB,GAAG,WAAW,CAUxE;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,SAAS,GACd,IAAI,CAeN;AAED,wBAAgB,iBAAiB,IAAI,KAAK,CAEzC;
|
|
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;AAQ5C,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,EAErB,MAAM,YAAY,CAAC;AAgCpB,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,WAAW,GACX,eAAe,GACf,KAAK,GACL,cAAc,CACjB,CAAC;AAEF,wBAAgB,aAAa,CAAC,IAAI,EAAE,uBAAuB,GAAG,WAAW,CAUxE;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,SAAS,GACd,IAAI,CAeN;AAED,wBAAgB,iBAAiB,IAAI,KAAK,CAEzC;AAmID,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,YAAY,CAAC,CA4CvB"}
|
package/dist/tasks/execution.js
CHANGED
|
@@ -83,18 +83,33 @@ function updateTaskAndEmitStatus(server, taskId, update) {
|
|
|
83
83
|
emitTaskStatusNotification(server, task);
|
|
84
84
|
}
|
|
85
85
|
function buildTaskFailureState(error) {
|
|
86
|
-
const
|
|
86
|
+
const mcpErrorMessage = error instanceof McpError
|
|
87
|
+
? (/^MCP error -?\d+:\s*(.*)$/s.exec(error.message)?.[1] ?? error.message)
|
|
88
|
+
: undefined;
|
|
89
|
+
const statusMessage = mcpErrorMessage ?? getErrorMessage(error);
|
|
90
|
+
const payload = { error: statusMessage };
|
|
87
91
|
if (error instanceof McpError) {
|
|
92
|
+
payload['code'] = error.code;
|
|
93
|
+
if (error.data !== undefined) {
|
|
94
|
+
payload['data'] = error.data;
|
|
95
|
+
}
|
|
88
96
|
return {
|
|
89
97
|
status: 'failed',
|
|
90
98
|
statusMessage,
|
|
91
|
-
|
|
99
|
+
result: {
|
|
100
|
+
content: [{ type: 'text', text: JSON.stringify(payload) }],
|
|
101
|
+
isError: true,
|
|
102
|
+
},
|
|
92
103
|
};
|
|
93
104
|
}
|
|
105
|
+
payload['code'] = ErrorCode.InternalError;
|
|
94
106
|
return {
|
|
95
107
|
status: 'failed',
|
|
96
108
|
statusMessage,
|
|
97
|
-
|
|
109
|
+
result: {
|
|
110
|
+
content: [{ type: 'text', text: JSON.stringify(payload) }],
|
|
111
|
+
isError: true,
|
|
112
|
+
},
|
|
98
113
|
};
|
|
99
114
|
}
|
|
100
115
|
function buildTaskCompletionUpdate(result, tool) {
|
|
@@ -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;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;AACD,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,EACjB,OAAO,CAAC,EAAE,8BAA8B,GACvC,6BAA6B,
|
|
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;AACD,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,EACjB,OAAO,CAAC,EAAE,8BAA8B,GACvC,6BAA6B,CAyJ/B"}
|
package/dist/tasks/handlers.js
CHANGED
|
@@ -91,15 +91,14 @@ export function registerTaskHandlers(server, options) {
|
|
|
91
91
|
throwTaskNotFound();
|
|
92
92
|
try {
|
|
93
93
|
if (task.status === 'failed') {
|
|
94
|
-
if (task.error) {
|
|
95
|
-
throw new McpError(task.error.code, task.error.message, task.error.data);
|
|
96
|
-
}
|
|
97
94
|
const failedResult = (task.result ?? null);
|
|
98
95
|
const fallback = failedResult ?? {
|
|
99
96
|
content: [
|
|
100
97
|
{
|
|
101
98
|
type: 'text',
|
|
102
|
-
text:
|
|
99
|
+
text: JSON.stringify({
|
|
100
|
+
error: task.statusMessage ?? 'Task execution failed',
|
|
101
|
+
}),
|
|
103
102
|
},
|
|
104
103
|
],
|
|
105
104
|
isError: true,
|
package/dist/tasks/manager.js
CHANGED
|
@@ -35,9 +35,9 @@ function resolveNextTaskStatus(task, updates) {
|
|
|
35
35
|
return nextStatus;
|
|
36
36
|
}
|
|
37
37
|
function normalizeTaskTtl(ttl) {
|
|
38
|
-
if (!Number.isFinite(ttl))
|
|
38
|
+
if (ttl === undefined || !Number.isFinite(ttl))
|
|
39
39
|
return DEFAULT_TTL_MS;
|
|
40
|
-
return Math.max(MIN_TTL_MS, Math.min(Math.trunc(
|
|
40
|
+
return Math.max(MIN_TTL_MS, Math.min(Math.trunc(ttl), MAX_TTL_MS));
|
|
41
41
|
}
|
|
42
42
|
class TaskManager {
|
|
43
43
|
tasks = new Map();
|
|
@@ -218,7 +218,7 @@ class TaskManager {
|
|
|
218
218
|
}
|
|
219
219
|
const anchorIndex = validTasks.findIndex((t) => t.taskId === anchorTaskId);
|
|
220
220
|
if (anchorIndex === -1) {
|
|
221
|
-
|
|
221
|
+
throw new McpError(ErrorCode.InvalidParams, 'Invalid cursor');
|
|
222
222
|
}
|
|
223
223
|
return validTasks.slice(anchorIndex + 1, anchorIndex + 1 + pageSize + 1);
|
|
224
224
|
}
|
package/dist/tasks/waiters.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-url.d.ts","sourceRoot":"","sources":["../../src/tools/fetch-url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EACV,YAAY,EAEb,MAAM,oCAAoC,CAAC;AAE5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAc7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"fetch-url.d.ts","sourceRoot":"","sources":["../../src/tools/fetch-url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EACV,YAAY,EAEb,MAAM,oCAAoC,CAAC;AAE5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAc7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B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BAAsB,KAAK,IAAI,CAAC;CAC3D;AAqBD,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,wBAAwB,CAoCzE"}
|
package/dist/tools/fetch-url.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
2
2
|
import { config, logDebug, logError, logWarn } from '../lib/core.js';
|
|
3
3
|
import { finalizeInlineMarkdown, markdownTransform, parseCachedMarkdownResult, performSharedFetch, serializeMarkdownResult, withSignal, } from '../lib/fetch-pipeline.js';
|
|
4
|
-
import { handleToolError } from '../lib/mcp-interop.js';
|
|
5
|
-
import {
|
|
6
|
-
import { composeAbortSignal, isAbortError, parseUrlOrNull, toError, } from '../lib/utils.js';
|
|
7
|
-
import { isObject } from '../lib/utils.js';
|
|
4
|
+
import { createProgressReporter, handleToolError, } from '../lib/mcp-interop.js';
|
|
5
|
+
import { composeAbortSignal, isAbortError, isObject, parseUrlOrNull, toError, } from '../lib/utils.js';
|
|
8
6
|
import { formatZodError } from '../lib/zod.js';
|
|
9
7
|
import { fetchUrlInputSchema, fetchUrlOutputSchema, normalizeExtractedMetadata, normalizePageTitle, } from '../schemas.js';
|
|
10
8
|
import { withRequestContextIfMissing } from '../tasks/owner.js';
|
|
@@ -287,10 +285,9 @@ export function registerTools(server) {
|
|
|
287
285
|
execution: { taskSupport: 'optional' },
|
|
288
286
|
icons: [TOOL_ICON],
|
|
289
287
|
}, withRequestContextIfMissing(TOOL_DEFINITION.handler));
|
|
290
|
-
const registeredToolRecord = registeredTool;
|
|
291
288
|
const updateTaskSupport = (support) => {
|
|
292
289
|
setTaskCapableToolSupport(FETCH_URL_TOOL_NAME, support);
|
|
293
|
-
|
|
290
|
+
registeredTool.execution = { taskSupport: support };
|
|
294
291
|
};
|
|
295
292
|
updateTaskSupport('optional');
|
|
296
293
|
return { setTaskSupport: updateTaskSupport };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import diagnosticsChannel from 'node:diagnostics_channel';
|
|
2
2
|
import { isProbablyReaderable, Readability } from '@mozilla/readability';
|
|
3
3
|
import { parseHTML } from 'linkedom';
|
|
4
|
-
import { config } from '../lib/core.js';
|
|
5
|
-
import { getOperationId, getRequestId, logDebug, logError, logInfo, logWarn, redactUrl, } from '../lib/core.js';
|
|
4
|
+
import { config, getOperationId, getRequestId, logDebug, logError, logInfo, logWarn, redactUrl, } from '../lib/core.js';
|
|
6
5
|
import { isRawTextContentUrl } from '../lib/http.js';
|
|
7
6
|
import { composeAbortSignal, FetchError, getErrorMessage, getUtf8ByteLength, isAsciiOnly, isObject, throwIfAborted, toError, trimDanglingTagFragment, truncateToUtf8Boundary, } from '../lib/utils.js';
|
|
8
7
|
import { evaluateArticleContent, extractNoscriptImages, getVisibleTextLength, normalizeTabContent, prepareDocumentForMarkdown, removeNoiseFromHtml, serializeDocumentForMarkdown, stripDocsControls, stripScreenReaderText, surfaceCodeEditorContent, } from './dom-prep.js';
|
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
-
export { cancelTasksForOwner, abortAllTaskExecutions, } from '../tasks/execution.js';
|
|
3
|
-
interface TaskHandlerRegistrationOptions {
|
|
4
|
-
requireInterception?: boolean;
|
|
5
|
-
}
|
|
6
|
-
interface TaskHandlerRegistrationResult {
|
|
7
|
-
interceptedToolsCall: boolean;
|
|
8
|
-
taskCapableToolsRegistered: boolean;
|
|
9
|
-
}
|
|
10
|
-
export declare function registerTaskHandlers(server: McpServer, options?: TaskHandlerRegistrationOptions): TaskHandlerRegistrationResult;
|
|
11
|
-
//# sourceMappingURL=task-handlers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"task-handlers.d.ts","sourceRoot":"","sources":["../../src/lib/task-handlers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAkCzE,OAAO,EACL,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AA4D/B,UAAU,8BAA8B;IACtC,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,UAAU,6BAA6B;IACrC,oBAAoB,EAAE,OAAO,CAAC;IAC9B,0BAA0B,EAAE,OAAO,CAAC;CACrC;AACD,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,EACjB,OAAO,CAAC,EAAE,8BAA8B,GACvC,6BAA6B,CA+J/B"}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import {} from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
|
-
import { CallToolRequestSchema, ErrorCode, McpError, } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
import { parseExtendedCallToolRequest, withRelatedTaskMeta, } from '../tasks/call-contract.js';
|
|
6
|
-
import { abortTaskExecution, emitTaskStatusNotification, handleToolCallRequest, throwTaskNotFound, toTaskSummary, } from '../tasks/execution.js';
|
|
7
|
-
import { taskManager } from '../tasks/manager.js';
|
|
8
|
-
import { isServerResult, parseHandlerExtra, resolveTaskOwnerKey, resolveToolCallContext, } from '../tasks/owner.js';
|
|
9
|
-
import { hasRegisteredTaskCapableTools, hasTaskCapableTool, } from '../tasks/registry.js';
|
|
10
|
-
import { logWarn, runWithRequestContext } from './core.js';
|
|
11
|
-
import { getSdkCallToolHandler } from './mcp-interop.js';
|
|
12
|
-
export { cancelTasksForOwner, abortAllTaskExecutions, } from '../tasks/execution.js';
|
|
13
|
-
/* -------------------------------------------------------------------------------------------------
|
|
14
|
-
* Task handler schemas and registration
|
|
15
|
-
* ------------------------------------------------------------------------------------------------- */
|
|
16
|
-
const TaskGetSchema = z.looseObject({
|
|
17
|
-
method: z.literal('tasks/get', 'Expected "tasks/get"'),
|
|
18
|
-
params: z.looseObject({ taskId: z.string('Expected string') }, 'Expected object'),
|
|
19
|
-
}, 'Invalid request');
|
|
20
|
-
const TaskListSchema = z.looseObject({
|
|
21
|
-
method: z.literal('tasks/list', 'Expected "tasks/list"'),
|
|
22
|
-
params: z
|
|
23
|
-
.looseObject({
|
|
24
|
-
cursor: z.string('Expected string').optional(),
|
|
25
|
-
}, 'Expected object')
|
|
26
|
-
.optional(),
|
|
27
|
-
}, 'Invalid request');
|
|
28
|
-
const TaskCancelSchema = z.looseObject({
|
|
29
|
-
method: z.literal('tasks/cancel', 'Expected "tasks/cancel"'),
|
|
30
|
-
params: z.looseObject({ taskId: z.string('Expected string') }, 'Expected object'),
|
|
31
|
-
}, 'Invalid request');
|
|
32
|
-
const TaskResultSchema = z.looseObject({
|
|
33
|
-
method: z.literal('tasks/result', 'Expected "tasks/result"'),
|
|
34
|
-
params: z.looseObject({ taskId: z.string('Expected string') }, 'Expected object'),
|
|
35
|
-
}, 'Invalid request');
|
|
36
|
-
function resolveOwnerScopedExtra(extra) {
|
|
37
|
-
const parsedExtra = parseHandlerExtra(extra);
|
|
38
|
-
return {
|
|
39
|
-
parsedExtra,
|
|
40
|
-
ownerKey: resolveTaskOwnerKey(parsedExtra),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
export function registerTaskHandlers(server, options) {
|
|
44
|
-
const sdkCallToolHandler = getSdkCallToolHandler(server);
|
|
45
|
-
const taskCapableToolsRegistered = hasRegisteredTaskCapableTools();
|
|
46
|
-
const requireInterception = options?.requireInterception ?? true;
|
|
47
|
-
if (!sdkCallToolHandler) {
|
|
48
|
-
if (taskCapableToolsRegistered && requireInterception) {
|
|
49
|
-
throw new Error('Task-capable tools are registered but SDK tools/call interception is unavailable. Upgrade compatibility or disable strict interception with TASKS_REQUIRE_INTERCEPTION=false.');
|
|
50
|
-
}
|
|
51
|
-
logWarn('Task call interception disabled: SDK tools/call handler unavailable; task-capable tools require MCP SDK compatibility update', { sdkVersion: 'unknown' });
|
|
52
|
-
}
|
|
53
|
-
if (sdkCallToolHandler) {
|
|
54
|
-
server.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
55
|
-
const parsedExtra = parseHandlerExtra(extra);
|
|
56
|
-
const requestId = parsedExtra?.requestId !== undefined
|
|
57
|
-
? String(parsedExtra.requestId)
|
|
58
|
-
: randomUUID();
|
|
59
|
-
return runWithRequestContext({
|
|
60
|
-
requestId,
|
|
61
|
-
operationId: requestId,
|
|
62
|
-
...(parsedExtra?.sessionId
|
|
63
|
-
? { sessionId: parsedExtra.sessionId }
|
|
64
|
-
: {}),
|
|
65
|
-
}, () => {
|
|
66
|
-
const toolName = request.params.name;
|
|
67
|
-
// Only intercept task-capable tools managed by the local task registry.
|
|
68
|
-
// Delegate all other tools to the SDK handler to avoid shadowing future tools.
|
|
69
|
-
if (!hasTaskCapableTool(toolName)) {
|
|
70
|
-
return sdkCallToolHandler(request, extra);
|
|
71
|
-
}
|
|
72
|
-
const parsed = parseExtendedCallToolRequest(request);
|
|
73
|
-
const context = resolveToolCallContext(parsedExtra, parsed.params._meta);
|
|
74
|
-
return handleToolCallRequest(server, parsed, context);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
server.server.setRequestHandler(TaskGetSchema, (request, extra) => {
|
|
79
|
-
const { taskId } = request.params;
|
|
80
|
-
const { ownerKey } = resolveOwnerScopedExtra(extra);
|
|
81
|
-
const task = taskManager.getTask(taskId, ownerKey);
|
|
82
|
-
if (!task)
|
|
83
|
-
throwTaskNotFound();
|
|
84
|
-
return toTaskSummary(task);
|
|
85
|
-
});
|
|
86
|
-
server.server.setRequestHandler(TaskResultSchema, async (request, extra) => {
|
|
87
|
-
const { taskId } = request.params;
|
|
88
|
-
const { parsedExtra, ownerKey } = resolveOwnerScopedExtra(extra);
|
|
89
|
-
const task = await taskManager.waitForTerminalTask(taskId, ownerKey, parsedExtra?.signal);
|
|
90
|
-
if (!task)
|
|
91
|
-
throwTaskNotFound();
|
|
92
|
-
try {
|
|
93
|
-
if (task.status === 'failed') {
|
|
94
|
-
if (task.error) {
|
|
95
|
-
throw new McpError(task.error.code, task.error.message, task.error.data);
|
|
96
|
-
}
|
|
97
|
-
const failedResult = (task.result ?? null);
|
|
98
|
-
const fallback = failedResult ?? {
|
|
99
|
-
content: [
|
|
100
|
-
{
|
|
101
|
-
type: 'text',
|
|
102
|
-
text: task.statusMessage ?? 'Task execution failed',
|
|
103
|
-
},
|
|
104
|
-
],
|
|
105
|
-
isError: true,
|
|
106
|
-
};
|
|
107
|
-
return withRelatedTaskMeta(fallback, task.taskId);
|
|
108
|
-
}
|
|
109
|
-
if (task.status === 'cancelled') {
|
|
110
|
-
throw new McpError(ErrorCode.InvalidRequest, 'Task was cancelled', {
|
|
111
|
-
taskId: task.taskId,
|
|
112
|
-
status: 'cancelled',
|
|
113
|
-
...(task.statusMessage ? { statusMessage: task.statusMessage } : {}),
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
const result = isServerResult(task.result)
|
|
117
|
-
? task.result
|
|
118
|
-
: { content: [] };
|
|
119
|
-
return withRelatedTaskMeta(result, task.taskId);
|
|
120
|
-
}
|
|
121
|
-
finally {
|
|
122
|
-
// Shrink TTL only after the result has been fully constructed and
|
|
123
|
-
// is about to be delivered — avoids premature expiry if result
|
|
124
|
-
// construction throws.
|
|
125
|
-
taskManager.shrinkTtlAfterDelivery(taskId);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
server.server.setRequestHandler(TaskListSchema, (request, extra) => {
|
|
129
|
-
const { ownerKey } = resolveOwnerScopedExtra(extra);
|
|
130
|
-
const cursor = request.params?.cursor;
|
|
131
|
-
const { tasks, nextCursor } = taskManager.listTasks(cursor === undefined ? { ownerKey } : { ownerKey, cursor });
|
|
132
|
-
return {
|
|
133
|
-
tasks: tasks.map((task) => toTaskSummary(task)),
|
|
134
|
-
nextCursor,
|
|
135
|
-
};
|
|
136
|
-
});
|
|
137
|
-
server.server.setRequestHandler(TaskCancelSchema, (request, extra) => {
|
|
138
|
-
const { taskId } = request.params;
|
|
139
|
-
const { ownerKey } = resolveOwnerScopedExtra(extra);
|
|
140
|
-
const task = taskManager.cancelTask(taskId, ownerKey);
|
|
141
|
-
if (!task)
|
|
142
|
-
throwTaskNotFound();
|
|
143
|
-
abortTaskExecution(taskId);
|
|
144
|
-
emitTaskStatusNotification(server, task);
|
|
145
|
-
return toTaskSummary(task);
|
|
146
|
-
});
|
|
147
|
-
return {
|
|
148
|
-
interceptedToolsCall: sdkCallToolHandler !== null,
|
|
149
|
-
taskCapableToolsRegistered,
|
|
150
|
-
};
|
|
151
|
-
}
|