@@ -22,15 +22,13 @@ import type {
2222 ListToolsRequest ,
2323 LoggingLevel ,
2424 MessageExtraInfo ,
25- Notification ,
2625 NotificationMethod ,
2726 ProtocolOptions ,
2827 ReadResourceRequest ,
29- Request ,
3028 RequestMethod ,
3129 RequestOptions ,
3230 RequestTypeMap ,
33- Result ,
31+ ResultTypeMap ,
3432 ServerCapabilities ,
3533 SubscribeRequest ,
3634 Tool ,
@@ -193,36 +191,8 @@ export type ClientOptions = ProtocolOptions & {
193191 *
194192 * The client will automatically begin the initialization flow with the server when connect() is called.
195193 *
196- * To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters:
197- *
198- * ```typescript
199- * // Custom schemas
200- * const CustomRequestSchema = RequestSchema.extend({...})
201- * const CustomNotificationSchema = NotificationSchema.extend({...})
202- * const CustomResultSchema = ResultSchema.extend({...})
203- *
204- * // Type aliases
205- * type CustomRequest = z.infer<typeof CustomRequestSchema>
206- * type CustomNotification = z.infer<typeof CustomNotificationSchema>
207- * type CustomResult = z.infer<typeof CustomResultSchema>
208- *
209- * // Create typed client
210- * const client = new Client<CustomRequest, CustomNotification, CustomResult>({
211- * name: "CustomClient",
212- * version: "1.0.0"
213- * })
214- * ```
215194 */
216- export class Client <
217- RequestT extends Request = Request ,
218- NotificationT extends Notification = Notification ,
219- ResultT extends Result = Result
220- > extends Protocol <
221- ClientRequest | RequestT ,
222- ClientNotification | NotificationT ,
223- ClientResult | ResultT ,
224- ClientContext < ClientRequest | RequestT , ClientNotification | NotificationT >
225- > {
195+ export class Client extends Protocol < ClientContext > {
226196 private _serverCapabilities ?: ServerCapabilities ;
227197 private _serverVersion ?: Implementation ;
228198 private _capabilities : ClientCapabilities ;
@@ -231,7 +201,7 @@ export class Client<
231201 private _cachedToolOutputValidators : Map < string , JsonSchemaValidator < unknown > > = new Map ( ) ;
232202 private _cachedKnownTaskTools : Set < string > = new Set ( ) ;
233203 private _cachedRequiredTaskTools : Set < string > = new Set ( ) ;
234- private _experimental ?: { tasks : ExperimentalClientTasks < RequestT , NotificationT , ResultT > } ;
204+ private _experimental ?: { tasks : ExperimentalClientTasks } ;
235205 private _listChangedDebounceTimers : Map < string , ReturnType < typeof setTimeout > > = new Map ( ) ;
236206 private _pendingListChangedConfig ?: ListChangedHandlers ;
237207 private _enforceStrictCapabilities : boolean ;
@@ -254,10 +224,7 @@ export class Client<
254224 }
255225 }
256226
257- protected override buildContext (
258- ctx : BaseContext < ClientRequest | RequestT , ClientNotification | NotificationT > ,
259- _transportInfo ?: MessageExtraInfo
260- ) : ClientContext < ClientRequest | RequestT , ClientNotification | NotificationT > {
227+ protected override buildContext ( ctx : BaseContext , _transportInfo ?: MessageExtraInfo ) : ClientContext {
261228 return ctx ;
262229 }
263230
@@ -297,7 +264,7 @@ export class Client<
297264 *
298265 * @experimental
299266 */
300- get experimental ( ) : { tasks : ExperimentalClientTasks < RequestT , NotificationT , ResultT > } {
267+ get experimental ( ) : { tasks : ExperimentalClientTasks } {
301268 if ( ! this . _experimental ) {
302269 this . _experimental = {
303270 tasks : new ExperimentalClientTasks ( this )
@@ -324,16 +291,10 @@ export class Client<
324291 */
325292 public override setRequestHandler < M extends RequestMethod > (
326293 method : M ,
327- handler : (
328- request : RequestTypeMap [ M ] ,
329- ctx : ClientContext < ClientRequest | RequestT , ClientNotification | NotificationT >
330- ) => ClientResult | ResultT | Promise < ClientResult | ResultT >
294+ handler : ( request : RequestTypeMap [ M ] , ctx : ClientContext ) => ResultTypeMap [ M ] | Promise < ResultTypeMap [ M ] >
331295 ) : void {
332296 if ( method === 'elicitation/create' ) {
333- const wrappedHandler = async (
334- request : RequestTypeMap [ M ] ,
335- ctx : ClientContext < ClientRequest | RequestT , ClientNotification | NotificationT >
336- ) : Promise < ClientResult | ResultT > => {
297+ const wrappedHandler = async ( request : RequestTypeMap [ M ] , ctx : ClientContext ) : Promise < ClientResult > => {
337298 const validatedRequest = parseSchema ( ElicitRequestSchema , request ) ;
338299 if ( ! validatedRequest . success ) {
339300 // Type guard: if success is false, error is guaranteed to exist
@@ -403,10 +364,7 @@ export class Client<
403364 }
404365
405366 if ( method === 'sampling/createMessage' ) {
406- const wrappedHandler = async (
407- request : RequestTypeMap [ M ] ,
408- ctx : ClientContext < ClientRequest | RequestT , ClientNotification | NotificationT >
409- ) : Promise < ClientResult | ResultT > => {
367+ const wrappedHandler = async ( request : RequestTypeMap [ M ] , ctx : ClientContext ) : Promise < ClientResult > => {
410368 const validatedRequest = parseSchema ( CreateMessageRequestSchema , request ) ;
411369 if ( ! validatedRequest . success ) {
412370 const errorMessage =
@@ -533,7 +491,7 @@ export class Client<
533491 return this . _instructions ;
534492 }
535493
536- protected assertCapabilityForMethod ( method : RequestT [ 'method' ] ) : void {
494+ protected assertCapabilityForMethod ( method : RequestMethod ) : void {
537495 switch ( method as ClientRequest [ 'method' ] ) {
538496 case 'logging/setLevel' : {
539497 if ( ! this . _serverCapabilities ?. logging ) {
@@ -596,7 +554,7 @@ export class Client<
596554 }
597555 }
598556
599- protected assertNotificationCapability ( method : NotificationT [ 'method' ] ) : void {
557+ protected assertNotificationCapability ( method : NotificationMethod ) : void {
600558 switch ( method as ClientNotification [ 'method' ] ) {
601559 case 'notifications/roots/list_changed' : {
602560 if ( ! this . _capabilities . roots ?. listChanged ) {
0 commit comments