Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
15 changes: 7 additions & 8 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
type ClientNotification,
type ClientRequest,
type ClientResult,
type CompatibilityCallToolResultSchema,
type CompleteRequest,
CompleteResultSchema,
EmptyResultSchema,
Expand All @@ -27,18 +26,18 @@ import {
ListToolsResultSchema,
type LoggingLevel,
McpError,
type Notification,
type ReadResourceRequest,
ReadResourceResultSchema,
type Request,
type Result,
type ServerCapabilities,
SUPPORTED_PROTOCOL_VERSIONS,
type SubscribeRequest,
type Tool,
type UnsubscribeRequest,
ElicitResultSchema,
ElicitRequestSchema
ElicitRequestSchema,
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 @@ -149,8 +148,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 @@ -461,7 +460,7 @@ export class Client<

async callTool(
params: CallToolRequest['params'],
resultSchema: typeof CallToolResultSchema | typeof CompatibilityCallToolResultSchema = CallToolResultSchema,
resultSchema: typeof CallToolResultSchema = CallToolResultSchema,
options?: RequestOptions
) {
const result = await this.request({ method: 'tools/call', params }, resultSchema, options);
Expand Down
12 changes: 6 additions & 6 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ import {
LoggingLevelSchema,
type LoggingMessageNotification,
McpError,
type Notification,
type Request,
type ResourceUpdatedNotification,
type Result,
type ServerCapabilities,
type ServerNotification,
type ServerRequest,
type ServerResult,
SetLevelRequestSchema,
SUPPORTED_PROTOCOL_VERSIONS
SUPPORTED_PROTOCOL_VERSIONS,
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 @@ -104,8 +104,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
1 change: 1 addition & 0 deletions src/server/mcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4273,6 +4273,7 @@ describe('elicitInput()', () => {

expect(checkAvailability).toHaveBeenCalledWith('ABC Restaurant', '2024-12-25', 2);
expect(findAlternatives).not.toHaveBeenCalled();

expect(result.content).toEqual([
{
type: 'text',
Expand Down
20 changes: 10 additions & 10 deletions src/shared/protocol.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ZodType, z } from 'zod';
import { ClientCapabilities, ErrorCode, McpError, Notification, Request, Result, ServerCapabilities } from '../types.js';
import { ClientCapabilities, ErrorCode, McpError, NotificationGeneric, RequestGeneric, Result, ServerCapabilities } from '../types.js';
import { Protocol, mergeCapabilities } from './protocol.js';
import { Transport } from './transport.js';
import { MockInstance } from 'vitest';
Expand All @@ -18,14 +18,14 @@ class MockTransport implements Transport {
}

describe('protocol tests', () => {
let protocol: Protocol<Request, Notification, Result>;
let protocol: Protocol<RequestGeneric, NotificationGeneric, Result>;
let transport: MockTransport;
let sendSpy: MockInstance;

beforeEach(() => {
transport = new MockTransport();
sendSpy = vi.spyOn(transport, 'send');
protocol = new (class extends Protocol<Request, Notification, Result> {
protocol = new (class extends Protocol<RequestGeneric, NotificationGeneric, Result> {
protected assertCapabilityForMethod(): void {}
protected assertNotificationCapability(): void {}
protected assertRequestHandlerCapability(): void {}
Expand Down Expand Up @@ -479,7 +479,7 @@ describe('protocol tests', () => {

it('should NOT debounce a notification that has parameters', async () => {
// ARRANGE
protocol = new (class extends Protocol<Request, Notification, Result> {
protocol = new (class extends Protocol<RequestGeneric, NotificationGeneric, Result> {
protected assertCapabilityForMethod(): void {}
protected assertNotificationCapability(): void {}
protected assertRequestHandlerCapability(): void {}
Expand All @@ -500,7 +500,7 @@ describe('protocol tests', () => {

it('should NOT debounce a notification that has a relatedRequestId', async () => {
// ARRANGE
protocol = new (class extends Protocol<Request, Notification, Result> {
protocol = new (class extends Protocol<RequestGeneric, NotificationGeneric, Result> {
protected assertCapabilityForMethod(): void {}
protected assertNotificationCapability(): void {}
protected assertRequestHandlerCapability(): void {}
Expand All @@ -519,7 +519,7 @@ describe('protocol tests', () => {

it('should clear pending debounced notifications on connection close', async () => {
// ARRANGE
protocol = new (class extends Protocol<Request, Notification, Result> {
protocol = new (class extends Protocol<RequestGeneric, NotificationGeneric, Result> {
protected assertCapabilityForMethod(): void {}
protected assertNotificationCapability(): void {}
protected assertRequestHandlerCapability(): void {}
Expand All @@ -543,7 +543,7 @@ describe('protocol tests', () => {

it('should debounce multiple synchronous calls when params property is omitted', async () => {
// ARRANGE
protocol = new (class extends Protocol<Request, Notification, Result> {
protocol = new (class extends Protocol<RequestGeneric, NotificationGeneric, Result> {
protected assertCapabilityForMethod(): void {}
protected assertNotificationCapability(): void {}
protected assertRequestHandlerCapability(): void {}
Expand All @@ -570,7 +570,7 @@ describe('protocol tests', () => {

it('should debounce calls when params is explicitly undefined', async () => {
// ARRANGE
protocol = new (class extends Protocol<Request, Notification, Result> {
protocol = new (class extends Protocol<RequestGeneric, NotificationGeneric, Result> {
protected assertCapabilityForMethod(): void {}
protected assertNotificationCapability(): void {}
protected assertRequestHandlerCapability(): void {}
Expand All @@ -595,7 +595,7 @@ describe('protocol tests', () => {

it('should send non-debounced notifications immediately and multiple times', async () => {
// ARRANGE
protocol = new (class extends Protocol<Request, Notification, Result> {
protocol = new (class extends Protocol<RequestGeneric, NotificationGeneric, Result> {
protected assertCapabilityForMethod(): void {}
protected assertNotificationCapability(): void {}
protected assertRequestHandlerCapability(): void {}
Expand Down Expand Up @@ -628,7 +628,7 @@ describe('protocol tests', () => {

it('should handle sequential batches of debounced notifications correctly', async () => {
// ARRANGE
protocol = new (class extends Protocol<Request, Notification, Result> {
protocol = new (class extends Protocol<RequestGeneric, NotificationGeneric, Result> {
protected assertCapabilityForMethod(): void {}
protected assertNotificationCapability(): void {}
protected assertRequestHandlerCapability(): void {}
Expand Down
12 changes: 9 additions & 3 deletions src/shared/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import {
ProgressNotificationSchema,
Request,
RequestId,
Result,
ServerCapabilities,
RequestMeta,
MessageExtraInfo,
RequestInfo
RequestInfo,
type RequestGeneric,
type NotificationGeneric,
type Result
} from '../types.js';
import { Transport, TransportSendOptions } from './transport.js';
import { AuthInfo } from '../server/auth/types.js';
Expand Down Expand Up @@ -171,7 +173,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
Loading
Loading