Skip to content

Commit 2912f34

Browse files
fix: resolve CI lint failures
- Remove duplicate exports (taskManager.ts exported from both protocol.ts and index.ts). Keep only index.ts export, use type-only import in protocol.ts - Remove unused imports (RelatedTaskMetadata in taskManager.ts, RequestTaskStore in interfaces.ts) - Fix import sorting and formatting (auto-fixed by eslint/prettier) - Remove isTaskAugmentedRequestParams unused import from protocol.ts
1 parent 584adf7 commit 2912f34

File tree

7 files changed

+72
-73
lines changed

7 files changed

+72
-73
lines changed

packages/client/src/experimental/tasks/client.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
import type {
9+
AnyObjectSchema,
910
CallToolRequest,
1011
CancelTaskResult,
1112
ClientRequest,
@@ -20,7 +21,6 @@ import type {
2021
SchemaOutput
2122
} from '@modelcontextprotocol/core';
2223
import { CallToolResultSchema, ErrorCode, McpError } from '@modelcontextprotocol/core';
23-
import type { AnyObjectSchema } from '@modelcontextprotocol/core';
2424

2525
import type { Client } from '../../client/client.js';
2626

@@ -75,11 +75,7 @@ export class ExperimentalClientTasks<
7575
task: options?.task ?? (clientInternal.isToolTask(params.name) ? {} : undefined)
7676
};
7777

78-
const stream = tasks.requestStream(
79-
{ method: 'tools/call', params } as ClientRequest | RequestT,
80-
resultSchema,
81-
optionsWithTask
82-
);
78+
const stream = tasks.requestStream({ method: 'tools/call', params } as ClientRequest | RequestT, resultSchema, optionsWithTask);
8379

8480
// Get the validator for this tool (if it has an output schema)
8581
const validator = clientInternal.getToolOutputValidator(params.name);

packages/core/src/experimental/tasks/interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import type { RequestHandlerExtra } from '../../shared/protocol.js';
7-
import type { RequestTaskStore, TaskContext } from '../../shared/taskManager.js';
7+
import type { TaskContext } from '../../shared/taskManager.js';
88
import type {
99
JSONRPCErrorResponse,
1010
JSONRPCNotification,

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export * from './shared/authUtils.js';
44
export * from './shared/metadataUtils.js';
55
export * from './shared/protocol.js';
66
export * from './shared/responseMessage.js';
7-
export * from './shared/taskManager.js';
87
export * from './shared/stdio.js';
8+
export * from './shared/taskManager.js';
99
export * from './shared/toolNameValidation.js';
1010
export * from './shared/transport.js';
1111
export * from './shared/uriTemplate.js';

packages/core/src/shared/protocol.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
isJSONRPCNotification,
3131
isJSONRPCRequest,
3232
isJSONRPCResultResponse,
33-
isTaskAugmentedRequestParams,
3433
ListTasksRequestSchema,
3534
McpError,
3635
PingRequestSchema,
@@ -40,14 +39,9 @@ import {
4039
import type { AnyObjectSchema, AnySchema, SchemaOutput } from '../util/zodCompat.js';
4140
import { safeParse } from '../util/zodCompat.js';
4241
import { getMethodLiteral, parseWithCompat } from '../util/zodJsonSchemaCompat.js';
43-
import type { TaskContext } from './taskManager.js';
44-
import { TaskManager } from './taskManager.js';
42+
import type { TaskContext, TaskManager } from './taskManager.js';
4543
import type { Transport, TransportSendOptions } from './transport.js';
4644

47-
// Re-export TaskManager types for backwards compatibility
48-
export type { RequestTaskStore, TaskContext, TaskManagerHost, TaskManagerOptions, TaskRequestOptions } from './taskManager.js';
49-
export { TaskManager } from './taskManager.js';
50-
5145
/**
5246
* Callback for progress notifications.
5347
*/
@@ -194,7 +188,11 @@ export type RequestHandlerExtra<SendRequestT extends Request, SendNotificationT
194188
*
195189
* This is used by certain transports to correctly associate related messages.
196190
*/
197-
sendRequest: <U extends AnySchema>(request: SendRequestT, resultSchema: U, options?: Omit<RequestOptions, 'relatedTask'>) => Promise<SchemaOutput<U>>;
191+
sendRequest: <U extends AnySchema>(
192+
request: SendRequestT,
193+
resultSchema: U,
194+
options?: Omit<RequestOptions, 'relatedTask'>
195+
) => Promise<SchemaOutput<U>>;
198196

199197
/**
200198
* Closes the SSE stream for this request, triggering client reconnection.
@@ -267,7 +265,10 @@ export abstract class Protocol<SendRequestT extends Request, SendNotificationT e
267265
*/
268266
fallbackNotificationHandler?: (notification: Notification) => Promise<void>;
269267

270-
constructor(private _options?: ProtocolOptions, taskManager?: TaskManager) {
268+
constructor(
269+
private _options?: ProtocolOptions,
270+
taskManager?: TaskManager
271+
) {
271272
this.setNotificationHandler(CancelledNotificationSchema, notification => {
272273
this._oncancel(notification);
273274
});
@@ -288,8 +289,8 @@ export abstract class Protocol<SendRequestT extends Request, SendNotificationT e
288289
taskManager.bind({
289290
request: (request, resultSchema, options) => this.request(request as SendRequestT, resultSchema, options),
290291
notification: (notification, options) => this.notification(notification as SendNotificationT, options),
291-
reportError: (error) => this._onerror(error),
292-
removeProgressHandler: (token) => this._progressHandlers.delete(token)
292+
reportError: error => this._onerror(error),
293+
removeProgressHandler: token => this._progressHandlers.delete(token)
293294
});
294295
// Only register task handlers if a task store is configured
295296
if (taskManager.taskStore) {
@@ -484,7 +485,8 @@ export abstract class Protocol<SendRequestT extends Request, SendNotificationT e
484485

485486
// Route error response: queue if task-related, otherwise send directly
486487
if (relatedTaskId && this._taskManager) {
487-
this._taskManager.routeResponse(relatedTaskId, errorResponse, capturedTransport?.sessionId)
488+
this._taskManager
489+
.routeResponse(relatedTaskId, errorResponse, capturedTransport?.sessionId)
488490
.catch(error => this._onerror(new Error(`Failed to enqueue error response: ${error}`)));
489491
} else {
490492
capturedTransport
@@ -502,9 +504,8 @@ export abstract class Protocol<SendRequestT extends Request, SendNotificationT e
502504
await this.notification(notification, { relatedRequestId: request.id });
503505
};
504506
if (relatedTaskId && this._taskManager) {
505-
sendNotification = this._taskManager.wrapSendNotification(
506-
relatedTaskId,
507-
(n, opts) => this.notification(n as SendNotificationT, { ...opts, relatedRequestId: request.id })
507+
sendNotification = this._taskManager.wrapSendNotification(relatedTaskId, (n, opts) =>
508+
this.notification(n as SendNotificationT, { ...opts, relatedRequestId: request.id })
508509
) as (notification: SendNotificationT) => Promise<void>;
509510
}
510511

@@ -792,7 +793,7 @@ export abstract class Protocol<SendRequestT extends Request, SendNotificationT e
792793
// Delegate to TaskManager for task param augmentation and queue routing
793794
if (this._taskManager) {
794795
const responseHandler = this._responseHandlers.get(messageId)!;
795-
const queued = this._taskManager.prepareOutboundRequest(jsonrpcRequest, options, messageId, responseHandler, (error) => {
796+
const queued = this._taskManager.prepareOutboundRequest(jsonrpcRequest, options, messageId, responseHandler, error => {
796797
this._cleanupTimeout(messageId);
797798
reject(error);
798799
});

packages/core/src/shared/taskManager.ts

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type {
1010
JSONRPCResponse,
1111
JSONRPCResultResponse,
1212
Notification,
13-
RelatedTaskMetadata,
1413
Request,
1514
RequestId,
1615
Result,
@@ -33,8 +32,8 @@ import {
3332
TaskStatusNotificationSchema
3433
} from '../types/types.js';
3534
import type { AnySchema, SchemaOutput } from '../util/zodCompat.js';
36-
import type { ResponseMessage } from './responseMessage.js';
3735
import type { NotificationOptions, RequestOptions } from './protocol.js';
36+
import type { ResponseMessage } from './responseMessage.js';
3837

3938
// ============================================================================
4039
// Types
@@ -217,12 +216,14 @@ export class TaskManager {
217216
yield { type: 'result', result };
218217
break;
219218
}
220-
case 'failed':
219+
case 'failed': {
221220
yield { type: 'error', error: new McpError(ErrorCode.InternalError, `Task ${taskId} failed`) };
222221
break;
223-
case 'cancelled':
222+
}
223+
case 'cancelled': {
224224
yield { type: 'error', error: new McpError(ErrorCode.InternalError, `Task ${taskId} was cancelled`) };
225225
break;
226+
}
226227
}
227228
return;
228229
}
@@ -299,11 +300,7 @@ export class TaskManager {
299300
resolver(message as JSONRPCResultResponse);
300301
} else {
301302
const errorMessage = message as JSONRPCErrorResponse;
302-
resolver(new McpError(
303-
errorMessage.error.code,
304-
errorMessage.error.message,
305-
errorMessage.error.data
306-
));
303+
resolver(new McpError(errorMessage.error.code, errorMessage.error.message, errorMessage.error.data));
307304
}
308305
} else {
309306
const messageType = queuedMessage.type === 'response' ? 'Response' : 'Error';
@@ -345,15 +342,15 @@ export class TaskManager {
345342
return await handleTaskResult();
346343
}
347344

348-
async handleListTasks(cursor: string | undefined, sessionId?: string): Promise<{ tasks: Task[]; nextCursor?: string; _meta: Record<string, unknown> }> {
345+
async handleListTasks(
346+
cursor: string | undefined,
347+
sessionId?: string
348+
): Promise<{ tasks: Task[]; nextCursor?: string; _meta: Record<string, unknown> }> {
349349
try {
350350
const { tasks, nextCursor } = await this._requireTaskStore.listTasks(cursor, sessionId);
351351
return { tasks, nextCursor, _meta: {} };
352352
} catch (error) {
353-
throw new McpError(
354-
ErrorCode.InvalidParams,
355-
`Failed to list tasks: ${error instanceof Error ? error.message : String(error)}`
356-
);
353+
throw new McpError(ErrorCode.InvalidParams, `Failed to list tasks: ${error instanceof Error ? error.message : String(error)}`);
357354
}
358355
}
359356

@@ -445,7 +442,10 @@ export class TaskManager {
445442
/**
446443
* Extracts task-related context from an inbound request.
447444
*/
448-
extractInboundTaskContext(request: JSONRPCRequest, sessionId?: string): {
445+
extractInboundTaskContext(
446+
request: JSONRPCRequest,
447+
sessionId?: string
448+
): {
449449
relatedTaskId?: string;
450450
taskCreationParams?: TaskCreationParams;
451451
taskContext?: TaskContext;
@@ -484,8 +484,7 @@ export class TaskManager {
484484
originalSendNotification: (notification: Notification, options?: NotificationOptions) => Promise<void>
485485
): (notification: Notification) => Promise<void> {
486486
return async (notification: Notification) => {
487-
const notificationOptions: NotificationOptions = {};
488-
notificationOptions.relatedTask = { taskId: relatedTaskId };
487+
const notificationOptions: NotificationOptions = { relatedTask: { taskId: relatedTaskId } };
489488
await originalSendNotification(notification, notificationOptions);
490489
};
491490
}
@@ -590,19 +589,13 @@ export class TaskManager {
590589
): Promise<boolean> {
591590
if (!relatedTaskId || !this._taskMessageQueue) return false;
592591

593-
if (isJSONRPCErrorResponse(message)) {
594-
await this._enqueueTaskMessage(
595-
relatedTaskId,
596-
{ type: 'error', message, timestamp: Date.now() },
597-
sessionId
598-
);
599-
} else {
600-
await this._enqueueTaskMessage(
601-
relatedTaskId,
602-
{ type: 'response', message: message as JSONRPCResultResponse, timestamp: Date.now() },
603-
sessionId
604-
);
605-
}
592+
await (isJSONRPCErrorResponse(message)
593+
? this._enqueueTaskMessage(relatedTaskId, { type: 'error', message, timestamp: Date.now() }, sessionId)
594+
: this._enqueueTaskMessage(
595+
relatedTaskId,
596+
{ type: 'response', message: message as JSONRPCResultResponse, timestamp: Date.now() },
597+
sessionId
598+
));
606599
return true;
607600
}
608601

@@ -616,9 +609,7 @@ export class TaskManager {
616609
return {
617610
createTask: async taskParams => {
618611
if (!request) throw new Error('No request provided');
619-
return await taskStore.createTask(
620-
taskParams, request.id, { method: request.method, params: request.params }, sessionId
621-
);
612+
return await taskStore.createTask(taskParams, request.id, { method: request.method, params: request.params }, sessionId);
622613
},
623614
getTask: async taskId => {
624615
const task = await taskStore.getTask(taskId, sessionId);
@@ -630,7 +621,8 @@ export class TaskManager {
630621
const task = await taskStore.getTask(taskId, sessionId);
631622
if (task) {
632623
const notification: TaskStatusNotification = TaskStatusNotificationSchema.parse({
633-
method: 'notifications/tasks/status', params: task
624+
method: 'notifications/tasks/status',
625+
params: task
634626
});
635627
await host?.notification(notification as Notification);
636628
if (isTerminal(task.status)) {
@@ -654,7 +646,8 @@ export class TaskManager {
654646
const updatedTask = await taskStore.getTask(taskId, sessionId);
655647
if (updatedTask) {
656648
const notification: TaskStatusNotification = TaskStatusNotificationSchema.parse({
657-
method: 'notifications/tasks/status', params: updatedTask
649+
method: 'notifications/tasks/status',
650+
params: updatedTask
658651
});
659652
await host?.notification(notification as Notification);
660653
if (isTerminal(updatedTask.status)) {
@@ -714,10 +707,14 @@ export class TaskManager {
714707
return;
715708
}
716709
const timeoutId = setTimeout(resolve, interval);
717-
signal.addEventListener('abort', () => {
718-
clearTimeout(timeoutId);
719-
reject(new McpError(ErrorCode.InvalidRequest, 'Request cancelled'));
720-
}, { once: true });
710+
signal.addEventListener(
711+
'abort',
712+
() => {
713+
clearTimeout(timeoutId);
714+
reject(new McpError(ErrorCode.InvalidRequest, 'Request cancelled'));
715+
},
716+
{ once: true }
717+
);
721718
});
722719
}
723720

packages/core/test/shared/protocol.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4795,11 +4795,14 @@ describe('Error handling for missing resolvers', () => {
47954795
protected assertCapabilityForMethod(_method: string): void {}
47964796
protected assertNotificationCapability(_method: string): void {}
47974797
protected assertRequestHandlerCapability(_method: string): void {}
4798-
})({}, new TaskManager({
4799-
taskStore,
4800-
taskMessageQueue,
4801-
defaultTaskPollInterval: 100
4802-
}));
4798+
})(
4799+
{},
4800+
new TaskManager({
4801+
taskStore,
4802+
taskMessageQueue,
4803+
defaultTaskPollInterval: 100
4804+
})
4805+
);
48034806

48044807
// @ts-expect-error deliberately overriding error handler with mock
48054808
protocol.onerror = errorHandler;

packages/server/src/server/mcp.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import type {
99
CompleteResult,
1010
CreateTaskRequestHandlerExtra,
1111
CreateTaskResult,
12-
JSONRPCRequest,
1312
GetPromptResult,
1413
Implementation,
14+
JSONRPCRequest,
1515
ListPromptsResult,
1616
ListResourcesResult,
1717
ListToolsResult,
@@ -369,10 +369,12 @@ export class McpServer {
369369
): Promise<CallToolResult> {
370370
// For automatic polling, we need a task store. Use the one from extra.task if available,
371371
// otherwise create one from the server's TaskManager (auto-poll creates tasks internally).
372-
const taskStore = extra.task?.taskStore ?? this.server.tasks?.createRequestTaskStore(
373-
{ jsonrpc: '2.0', id: extra.requestId, method: request.method, params: request.params } as JSONRPCRequest,
374-
extra.sessionId
375-
);
372+
const taskStore =
373+
extra.task?.taskStore ??
374+
this.server.tasks?.createRequestTaskStore(
375+
{ jsonrpc: '2.0', id: extra.requestId, method: request.method, params: request.params } as JSONRPCRequest,
376+
extra.sessionId
377+
);
376378
if (!taskStore) {
377379
throw new Error('No task store provided for task-capable tool.');
378380
}

0 commit comments

Comments
 (0)