Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ import {
ListToolsResultSchema,
type LoggingLevel,
McpError,
type Notification,
type ReadResourceRequest,
ReadResourceResultSchema,
type Request,
type Result,
type ServerCapabilities,
SUPPORTED_PROTOCOL_VERSIONS,
type SubscribeRequest,
Expand All @@ -48,7 +45,10 @@ import {
ResourceListChangedNotificationSchema,
ListChangedOptions,
ListChangedOptionsBaseSchema,
type ListChangedHandlers
type ListChangedHandlers,
type RequestGeneric,
type NotificationGeneric,
type Result
} from '../types.js';
import { AjvJsonSchemaValidator } from '../validation/ajv-provider.js';
import type { JsonSchemaType, JsonSchemaValidator, jsonSchemaValidator } from '../validation/types.js';
Expand Down Expand Up @@ -231,8 +231,8 @@ export type ClientOptions = ProtocolOptions & {
* ```
*/
export class Client<
RequestT extends Request = Request,
NotificationT extends Notification = Notification,
RequestT extends RequestGeneric = RequestGeneric,
NotificationT extends NotificationGeneric = NotificationGeneric,
ResultT extends Result = Result
> extends Protocol<ClientRequest | RequestT, ClientNotification | NotificationT, ClientResult | ResultT> {
private _serverCapabilities?: ServerCapabilities;
Expand Down Expand Up @@ -368,14 +368,14 @@ export class Client<
}

const { params } = validatedRequest.data;
const mode = params.mode ?? 'form';
params.mode = params.mode ?? 'form';
const { supportsFormMode, supportsUrlMode } = getSupportedElicitationModes(this._capabilities.elicitation);

if (mode === 'form' && !supportsFormMode) {
if (params.mode === 'form' && !supportsFormMode) {
throw new McpError(ErrorCode.InvalidParams, 'Client does not support form-mode elicitation requests');
}

if (mode === 'url' && !supportsUrlMode) {
if (params.mode === 'url' && !supportsUrlMode) {
throw new McpError(ErrorCode.InvalidParams, 'Client does not support URL-mode elicitation requests');
}

Expand Down Expand Up @@ -404,9 +404,9 @@ export class Client<
}

const validatedResult = validationResult.data;
const requestedSchema = mode === 'form' ? (params.requestedSchema as JsonSchemaType) : undefined;
const requestedSchema = params.mode === 'form' ? (params.requestedSchema as JsonSchemaType) : undefined;

if (mode === 'form' && validatedResult.action === 'accept' && validatedResult.content && requestedSchema) {
if (params.mode === 'form' && validatedResult.action === 'accept' && validatedResult.content && requestedSchema) {
if (this._capabilities.elicitation?.form?.applyDefaults) {
try {
applyElicitationDefaults(requestedSchema, validatedResult.content);
Expand Down
6 changes: 3 additions & 3 deletions src/experimental/tasks/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import {
Task,
Request,
RequestId,
Result,
JSONRPCRequest,
Expand All @@ -16,7 +15,8 @@ import {
ServerNotification,
CallToolResult,
GetTaskResult,
ToolExecution
ToolExecution,
RequestGeneric
} from '../../types.js';
import { CreateTaskResult } from './types.js';
import type { RequestHandlerExtra, RequestTaskStore } from '../../shared/protocol.js';
Expand Down Expand Up @@ -226,7 +226,7 @@ export interface TaskStore {
* @param sessionId - Optional session ID for binding the task to a specific session
* @returns The created task object
*/
createTask(taskParams: CreateTaskOptions, requestId: RequestId, request: Request, sessionId?: string): Promise<Task>;
createTask(taskParams: CreateTaskOptions, requestId: RequestId, request: RequestGeneric, sessionId?: string): Promise<Task>;

/**
* Gets the current status of a task.
Expand Down
6 changes: 3 additions & 3 deletions src/experimental/tasks/stores/in-memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* @experimental
*/

import { Task, Request, RequestId, Result } from '../../../types.js';
import { Task, RequestId, Result, RequestGeneric } from '../../../types.js';
import { TaskStore, isTerminal, TaskMessageQueue, QueuedMessage, CreateTaskOptions } from '../interfaces.js';
import { randomBytes } from 'node:crypto';

interface StoredTask {
task: Task;
request: Request;
request: RequestGeneric;
requestId: RequestId;
result?: Result;
}
Expand Down Expand Up @@ -39,7 +39,7 @@ export class InMemoryTaskStore implements TaskStore {
return randomBytes(16).toString('hex');
}

async createTask(taskParams: CreateTaskOptions, requestId: RequestId, request: Request, _sessionId?: string): Promise<Task> {
async createTask(taskParams: CreateTaskOptions, requestId: RequestId, request: RequestGeneric, _sessionId?: string): Promise<Task> {
// Generate a unique task ID
const taskId = this.generateTaskId();

Expand Down
12 changes: 6 additions & 6 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ import {
LoggingLevelSchema,
type LoggingMessageNotification,
McpError,
type Notification,
type Request,
type ResourceUpdatedNotification,
type Result,
type ServerCapabilities,
type ServerNotification,
type ServerRequest,
Expand All @@ -40,7 +37,10 @@ import {
type ToolUseContent,
CallToolRequestSchema,
CallToolResultSchema,
CreateTaskResultSchema
CreateTaskResultSchema,
type RequestGeneric,
type NotificationGeneric,
type Result
} from '../types.js';
import { AjvJsonSchemaValidator } from '../validation/ajv-provider.js';
import type { JsonSchemaType, jsonSchemaValidator } from '../validation/types.js';
Expand Down Expand Up @@ -127,8 +127,8 @@ export type ServerOptions = ProtocolOptions & {
* @deprecated Use `McpServer` instead for the high-level API. Only use `Server` for advanced use cases.
*/
export class Server<
RequestT extends Request = Request,
NotificationT extends Notification = Notification,
RequestT extends RequestGeneric = RequestGeneric,
NotificationT extends NotificationGeneric = NotificationGeneric,
ResultT extends Result = Result
> extends Protocol<ServerRequest | RequestT, ServerNotification | NotificationT, ServerResult | ResultT> {
private _clientCapabilities?: ClientCapabilities;
Expand Down
16 changes: 10 additions & 6 deletions src/shared/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ import {
JSONRPCRequest,
JSONRPCResponse,
McpError,
Notification,
PingRequestSchema,
Progress,
ProgressNotification,
ProgressNotificationSchema,
RELATED_TASK_META_KEY,
Request,
RequestId,
Result,
ServerCapabilities,
Expand All @@ -41,7 +39,9 @@ import {
CancelledNotification,
Task,
TaskStatusNotification,
TaskStatusNotificationSchema
TaskStatusNotificationSchema,
RequestGeneric,
NotificationGeneric
} from '../types.js';
import { Transport, TransportSendOptions } from './transport.js';
import { AuthInfo } from '../server/auth/types.js';
Expand Down Expand Up @@ -232,7 +232,7 @@ export interface RequestTaskStore {
/**
* Extra data given to request handlers.
*/
export type RequestHandlerExtra<SendRequestT extends Request, SendNotificationT extends Notification> = {
export type RequestHandlerExtra<SendRequestT extends RequestGeneric, SendNotificationT extends NotificationGeneric> = {
/**
* An abort signal used to communicate if the request was cancelled from the sender's side.
*/
Expand Down Expand Up @@ -315,7 +315,11 @@ type TimeoutInfo = {
* Implements MCP protocol framing on top of a pluggable transport, including
* features like request/response linking, notifications, and progress.
*/
export abstract class Protocol<SendRequestT extends Request, SendNotificationT extends Notification, SendResultT extends Result> {
export abstract class Protocol<
SendRequestT extends RequestGeneric,
SendNotificationT extends NotificationGeneric,
SendResultT extends Result
> {
private _transport?: Transport;
private _requestMessageId = 0;
private _requestHandlers: Map<
Expand Down Expand Up @@ -359,7 +363,7 @@ export abstract class Protocol<SendRequestT extends Request, SendNotificationT e
/**
* A handler to invoke for any notification types that do not have their own handler installed.
*/
fallbackNotificationHandler?: (notification: Notification) => Promise<void>;
fallbackNotificationHandler?: (notification: NotificationGeneric) => Promise<void>;

constructor(private _options?: ProtocolOptions) {
this.setNotificationHandler(CancelledNotificationSchema, notification => {
Expand Down
Loading
Loading