tmcp 1.19.3 → 1.20.0-next.0

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.
@@ -4,9 +4,33 @@ const created_resource: unique symbol;
4
4
  const created_template: unique symbol;
5
5
  declare module 'tmcp' {
6
6
  import type { StandardSchemaV1 } from '@standard-schema/spec';
7
- import type { JSONRPCServer, JSONRPCClient, JSONRPCParams, JSONRPCRequest } from 'json-rpc-2.0';
7
+ import type { JSONRPCServer, JSONRPCClient, JSONRPCParams, JSONRPCRequest, JSONRPCErrorException } from 'json-rpc-2.0';
8
8
  import type { JSONSchema7 } from 'json-schema';
9
9
  import * as v from 'valibot';
10
+ /**
11
+ * Check whether an error means that tmcp is waiting for client input.
12
+ *
13
+ * When there is no open connection to the client, `elicitation()` and
14
+ * `message()` ask the client to retry the original request with the answer.
15
+ * They stop the current handler by throwing a private error. A broad `catch`
16
+ * in the handler must rethrow that error, or tmcp cannot ask for the retry.
17
+ * Use this helper to distinguish it from errors your handler should process:
18
+ *
19
+ * ```js
20
+ * try {
21
+ * const answer = await server.elicitation(msg, schema);
22
+ * } catch (error) {
23
+ * if (isInputRequired(error)) throw error;
24
+ * // handle the real error
25
+ * }
26
+ * ```
27
+ * */
28
+ export function isInputRequired(error: unknown): boolean;
29
+ /**
30
+ * Return the per-request protocol versions supported by tmcp.
31
+ * */
32
+ export function getPerRequestProtocolVersions(): string[];
33
+
10
34
  export class McpServer<StandardSchema extends StandardSchemaV1 | undefined = undefined, CustomContext extends Record<string, unknown> | undefined = undefined> {
11
35
 
12
36
  constructor(server_info: ServerInfo, options: ServerOptions<StandardSchema>);
@@ -45,12 +69,32 @@ declare module 'tmcp' {
45
69
  * @deprecated Use `server.ctx.sessionInfo.clientCapabilities` instead.
46
70
  */
47
71
  currentClientCapabilities(): ({
48
- experimental?: {} | undefined;
49
- sampling?: {} | undefined;
50
- elicitation?: {} | undefined;
51
- roots?: {
52
- listChanged?: boolean | undefined;
72
+ experimental?: ({} & {
73
+ [key: string]: unknown;
74
+ }) | undefined;
75
+ sampling?: ({} & {
76
+ [key: string]: unknown;
77
+ }) | undefined;
78
+ elicitation?: ({
79
+ form?: ({} & {
80
+ [key: string]: unknown;
81
+ }) | undefined;
82
+ url?: ({} & {
83
+ [key: string]: unknown;
84
+ }) | undefined;
85
+ } & {
86
+ [key: string]: unknown;
87
+ }) | undefined;
88
+ extensions?: {
89
+ [x: string]: {} & {
90
+ [key: string]: unknown;
91
+ };
53
92
  } | undefined;
93
+ roots?: ({
94
+ listChanged?: boolean | undefined;
95
+ } & {
96
+ [key: string]: unknown;
97
+ }) | undefined;
54
98
  } & {
55
99
  [key: string]: unknown;
56
100
  }) | undefined;
@@ -88,6 +132,11 @@ declare module 'tmcp' {
88
132
  * Tools will be invoked by the LLM when it thinks it needs to use them, you can use the annotations to provide additional information about the tool, like what it does, how to use it, etc.
89
133
  * */
90
134
  tool<TSchema extends StandardSchema | undefined = undefined, TOutputSchema extends StandardSchema | undefined = undefined>(tool_or_options: ToolOptions<TSchema, TOutputSchema>, execute: TSchema extends undefined ? (() => Promise<CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>> | CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>) : ((input: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>) => Promise<CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>> | CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>)): void;
135
+ /**
136
+ * Run transport-specific validation against a registered tool's JSON
137
+ * Schema without enabling, validating, or executing the tool.
138
+ * */
139
+ validateToolCall(name: string, args: Record<string, unknown>, validator: (input_schema: Record<string, unknown>, args: Record<string, unknown>) => void | Promise<void>): Promise<boolean>;
91
140
  /**
92
141
  * Add a prompt to the server. Prompts are used to provide the user with pre-defined messages that adds context to the LLM.
93
142
  * Use the description and title to help the user to understand what the prompt does and when to use it.
@@ -130,11 +179,15 @@ declare module 'tmcp' {
130
179
  * Use the description and title to help the user to understand what the resource is.
131
180
  * */
132
181
  template<TUri extends string, TVariables extends ExtractURITemplateVariables<TUri>>(template_or_options: TemplateOptions<TUri>, execute: (uri: string, params: Record<TVariables, string | string[]>) => Promise<ReadResourceResult> | ReadResourceResult): void;
182
+ /**
183
+ * Check whether a JSON-RPC method is registered without invoking it.
184
+ * */
185
+ hasMethod(method: string): boolean;
133
186
  /**
134
187
  * The main function that receive a JSONRpc message and either dispatch a `send` event or process the request.
135
188
  *
136
189
  * */
137
- receive(message: JSONRPCMessage, ctx?: Context<CustomContext>): ReturnType<JSONRPCServer["receive"]> | ReturnType<JSONRPCClient["receive"] | undefined>;
190
+ receive(message: JSONRPCMessage, ctx?: ReceiveContext<CustomContext>): ReturnType<JSONRPCServer["receive"]> | ReturnType<JSONRPCClient["receive"] | undefined>;
138
191
  /**
139
192
  * Lower level api to send a request to the client, mostly useful to call client methods that not yet supported by the server or
140
193
  * if you want to send requests with json schema that is not expressible with your validation library.
@@ -148,9 +201,34 @@ declare module 'tmcp' {
148
201
  * */
149
202
  changed<TWhat extends keyof ChangedArgs>(what: TWhat, ...args: ChangedArgs[TWhat]): void;
150
203
  /**
151
- * Refresh roots list from client
204
+ * Refresh the roots list when the server has an open client session.
205
+ *
206
+ * This throws when handling a standalone request because roots are no
207
+ * longer supported by protocol version `2026-07-28`.
152
208
  */
153
209
  refreshRoots(): Promise<void>;
210
+ /**
211
+ * Save data that the handler will need when the client retries this
212
+ * request. tmcp turns it into text, sends it to the client, and restores it
213
+ * as `server.ctx.requestState` on the retry.
214
+ * Passing `undefined` clears previously set state.
215
+ *
216
+ * This does nothing when the server has an open client session or when the
217
+ * request finishes without asking for input.
218
+ *
219
+ * SECURITY: the default JSON converter lets the client read and change this
220
+ * data. Do not put secrets in it or use it for authorization. Configure a
221
+ * protected `requestStateCodec` if the server must detect changes.
222
+ * */
223
+ setRequestState(state: unknown): void;
224
+ /**
225
+ * Ask the user to complete an interaction at a URL. The client will open
226
+ * the URL out of band and return the user's action without form content.
227
+ *
228
+ * */
229
+ elicitation(message: string, url: string, options?: {
230
+ key?: string;
231
+ } | undefined): Promise<Omit<ElicitResult, "content">>;
154
232
  /**
155
233
  * Emit an elicitation request to the client. Elicitations are used to ask the user for input in a structured way, the client will show a UI to the user to fill the input.
156
234
  * The schema should be a valid Standard Schema V1 schema and should be an Object with the properties you need.
@@ -158,14 +236,31 @@ declare module 'tmcp' {
158
236
  *
159
237
  * If the client doesn't support elicitation, it will throw an error.
160
238
  *
239
+ * When there is no open client session, tmcp returns the question to the
240
+ * client and asks it to retry the original request with the answer. The
241
+ * handler then starts again from the beginning, so its definition must set
242
+ * `replayable: true`. Always await this call. If a surrounding `catch`
243
+ * handles errors, use `isInputRequired()` and rethrow tmcp's private error.
244
+ *
161
245
  * */
162
- elicitation<TSchema extends StandardSchema extends undefined ? never : StandardSchema>(message: string, schema: TSchema): Promise<ElicitResult & {
246
+ elicitation<TSchema extends StandardSchema extends undefined ? never : StandardSchema>(message: string, schema: TSchema, options?: {
247
+ key?: string;
248
+ } | undefined): Promise<ElicitResult & {
163
249
  content?: StandardSchemaV1.InferOutput<TSchema>;
164
250
  }>;
165
251
  /**
166
- * Request language model sampling from the client
252
+ * Request language model sampling from the client.
253
+ *
254
+ * When there is no open client session, tmcp returns the sampling request
255
+ * to the client and asks it to retry the original request with the answer.
256
+ * The handler then starts again from the beginning, so its definition must
257
+ * set `replayable: true`. Always await this call. If a surrounding `catch`
258
+ * handles errors, use `isInputRequired()` and rethrow tmcp's private error.
259
+ * @param options `key` names this request so tmcp can match its answer on a retry. By default tmcp uses `"1"`, `"2"`, and so on. Set a name when the handler may make different requests on different runs. When mixing named and numbered requests, use non-numeric names.
167
260
  * */
168
- message(request: CreateMessageRequestParams): Promise<CreateMessageResult>;
261
+ message(request: CreateMessageRequestParams, options?: {
262
+ key?: string;
263
+ }): Promise<CreateMessageResult>;
169
264
  /**
170
265
  * Send a progress notification to the client. This is useful for long-running operations where you want to inform the user about the progress.
171
266
  *
@@ -220,12 +315,40 @@ declare module 'tmcp' {
220
315
  clientInfo?: ClientInfo_1;
221
316
  logLevel?: LoggingLevel;
222
317
  } | undefined;
318
+ /**
319
+ * The exact per-request protocol version when the current request carries per-request protocol metadata; `undefined` for session-negotiated requests.
320
+ */
321
+ protocolVersion?: string | undefined;
322
+ /**
323
+ * Data saved by the handler before asking the client for input, then returned by the client on the retry. It is `undefined` when no data was saved or when the request uses an open session. The default JSON converter lets the client read and change this value. Do not store secrets in it or use it to make authorization decisions. Configure `requestStateCodec` if the server must detect changes.
324
+ */
325
+ requestState?: unknown;
326
+ /**
327
+ * Aborted when the transport observes that the current request was cancelled.
328
+ */
329
+ signal?: AbortSignal | undefined;
223
330
  auth?: AuthInfo | undefined;
224
331
  custom?: TCustom | undefined;
225
332
  };
333
+ /**
334
+ * Context accepted by `receive()`. Subscription routing fields are
335
+ * transport-only and are deliberately omitted from `server.ctx`.
336
+ */
337
+ export type ReceiveContext<TCustom extends Record<string, unknown> | undefined = undefined> = Context<TCustom> & {
338
+ subscriptionOrigin?: SubscriptionOrigin_1;
339
+ subscriptionManager?: SubscriptionManager_1;
340
+ };
341
+ export type SubscriptionFilter = SubscriptionFilter_1;
342
+ export type SubscriptionOrigin = SubscriptionOrigin_1;
343
+ export type Subscription = Subscription_1;
344
+ export type SubscriptionCallbacks = SubscriptionCallbacks_1;
345
+ export type SubscriptionManager = SubscriptionManager_1;
346
+ export type SubscriptionsListenRequest = SubscriptionsListenRequest_1;
347
+ export type SubscriptionsListenResult = SubscriptionsListenResult_1;
348
+ export type SubscriptionsAcknowledgedNotification = SubscriptionsAcknowledgedNotification_1;
226
349
  export type Icons = Icons_1;
227
350
  export type Subscriptions = Record<SubscriptionsKeys, string[]>;
228
- export type CallToolResult<TStructuredContent extends Record<string, unknown> | undefined> = CallToolResult_1<TStructuredContent>;
351
+ export type CallToolResult<TStructuredContent> = CallToolResult_1<TStructuredContent>;
229
352
  export type ReadResourceResult = ReadResourceResult_1;
230
353
  export type GetPromptResult = GetPromptResult_1;
231
354
  export type ClientCapabilities = ClientCapabilities_1;
@@ -245,56 +368,167 @@ declare module 'tmcp' {
245
368
 
246
369
  type AllSame<T, U> = [T] extends [U] ? true : false;
247
370
 
248
- type PromptOptions<TSchema extends StandardSchemaV1 | undefined = undefined> = {
249
- name: string;
250
- description: string;
251
- title?: string;
252
- enabled?: ()=>boolean | Promise<boolean>;
253
- schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never;
254
- complete?: NoInfer<TSchema extends undefined ? never : Partial<Record<keyof (StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>), Completion>>>
255
- } & Icons_1
371
+ type SubscriptionOrigin_1 = string;
372
+
373
+ type Subscription_1 = {
374
+ id: RequestId;
375
+ origin: SubscriptionOrigin_1;
376
+ filters: SubscriptionFilter_1;
377
+ };
378
+
379
+ type SubscriptionCallbacks_1 = {
380
+ acknowledge: () => void | Promise<void>;
381
+ send: (notification: JSONRPCRequest) => void | Promise<void>;
382
+ close: (reason: 'closed' | 'cancelled') => void | Promise<void>;
383
+ };
384
+
385
+ type SubscriptionManager_1 = {
386
+ create(
387
+ subscription: Subscription_1,
388
+ callbacks: SubscriptionCallbacks_1,
389
+ ): boolean | Promise<boolean>;
390
+ send(notification: JSONRPCRequest): void | Promise<void>;
391
+ close(
392
+ id: RequestId,
393
+ origin: SubscriptionOrigin_1,
394
+ reason: 'closed' | 'cancelled',
395
+ ): boolean | Promise<boolean>;
396
+ closeAll(
397
+ origin?: SubscriptionOrigin_1,
398
+ reason?: 'closed' | 'cancelled',
399
+ ): void | Promise<void>;
400
+ };
401
+
402
+ type Replayable = {
403
+ /**
404
+ * Allow tmcp to run this handler again after asking the client for input.
405
+ *
406
+ * For standalone requests, the server cannot pause and wait for the client.
407
+ * It returns the questions to the client, which then retries the original
408
+ * request with the answers. The handler starts again FROM THE TOP on every
409
+ * retry. This means work done before an input call, such as database writes,
410
+ * emails, or payments, may happen more than once. Set `replayable: true`
411
+ * only when that work is safe to repeat or is delayed until all answers are
412
+ * available.
413
+ *
414
+ * Without this flag, tmcp returns an error rather than risk repeating work.
415
+ * This is a tmcp safety check, not an MCP requirement. Requests using an
416
+ * open client session are unaffected because their handlers do not restart.
417
+ */
418
+ replayable?: boolean;
419
+ };
420
+
421
+ type PromptOptions<
422
+ TSchema extends StandardSchemaV1 | undefined = undefined,
423
+ > = {
424
+ name: string;
425
+ description: string;
426
+ title?: string;
427
+ enabled?: () => boolean | Promise<boolean>;
428
+ schema?: StandardSchemaV1.InferInput<
429
+ TSchema extends undefined ? never : TSchema
430
+ > extends Record<string, unknown>
431
+ ? TSchema
432
+ : never;
433
+ complete?: NoInfer<
434
+ TSchema extends undefined
435
+ ? never
436
+ : Partial<
437
+ Record<
438
+ keyof StandardSchemaV1.InferInput<
439
+ TSchema extends undefined ? never : TSchema
440
+ >,
441
+ Completion
442
+ >
443
+ >
444
+ >;
445
+ } & Icons_1 &
446
+ Replayable;
256
447
 
257
- type ToolOptions<TSchema extends StandardSchemaV1 | undefined = undefined, TOutputSchema extends StandardSchemaV1 | undefined = undefined> = {
448
+ type ToolOptions<
449
+ TSchema extends StandardSchemaV1 | undefined = undefined,
450
+ TOutputSchema extends StandardSchemaV1 | undefined = undefined,
451
+ > = {
258
452
  name: string;
259
453
  _meta?: Record<string, any>;
260
454
  description: string;
261
455
  title?: string;
262
456
  enabled?: () => boolean | Promise<boolean>;
263
- schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never;
264
- outputSchema?: StandardSchemaV1.InferOutput<TOutputSchema extends undefined ? never : TOutputSchema> extends Record<string, unknown> ? TOutputSchema : never;
457
+ schema?: StandardSchemaV1.InferInput<
458
+ TSchema extends undefined ? never : TSchema
459
+ > extends Record<string, unknown>
460
+ ? TSchema
461
+ : never;
462
+ outputSchema?: StandardSchemaV1.InferOutput<
463
+ TOutputSchema extends undefined ? never : TOutputSchema
464
+ > extends Record<string, unknown>
465
+ ? TOutputSchema
466
+ : never;
265
467
  annotations?: ToolAnnotations;
266
- } & Icons_1;
468
+ } & Icons_1 &
469
+ Replayable;
267
470
 
268
- type ResourceOptions = {
471
+ type ResourceOptions = {
269
472
  name: string;
270
- description: string;
271
- title?: string;
473
+ description: string;
474
+ title?: string;
272
475
  uri: string;
273
476
  mimeType?: string;
274
- enabled?: ()=>boolean | Promise<boolean>;
275
- } & Icons_1
477
+ enabled?: () => boolean | Promise<boolean>;
478
+ } & Icons_1 &
479
+ Replayable;
276
480
 
277
- type TemplateOptions<TUri extends string = string, TVariables extends ExtractURITemplateVariables<TUri> = ExtractURITemplateVariables<TUri>> = {
481
+ type TemplateOptions<
482
+ TUri extends string = string,
483
+ TVariables extends ExtractURITemplateVariables<TUri> =
484
+ ExtractURITemplateVariables<TUri>,
485
+ > = {
278
486
  name: string;
279
487
  description: string;
280
488
  title?: string;
281
489
  mimeType?: string;
282
- enabled?: ()=>boolean | Promise<boolean>;
490
+ enabled?: () => boolean | Promise<boolean>;
283
491
  uri: TUri;
284
- complete?: NoInfer<TVariables extends never ? never : Partial<Record<TVariables, Completion>>>;
285
- list?: () => Promise<Array<Resource_1>> | Array<Resource_1>
286
- } & Icons_1
492
+ complete?: NoInfer<
493
+ TVariables extends never
494
+ ? never
495
+ : Partial<Record<TVariables, Completion>>
496
+ >;
497
+ list?: () => Promise<Array<Resource_1>> | Array<Resource_1>;
498
+ } & Icons_1 &
499
+ Replayable;
287
500
 
288
- type CreatedTool<TSchema extends StandardSchemaV1 | undefined = undefined, TOutputSchema extends StandardSchemaV1 | undefined = undefined> = ToolOptions<TSchema, TOutputSchema> & { [created_tool]: created_tool };
289
- type CreatedPrompt<TSchema extends StandardSchemaV1 | undefined = undefined> = PromptOptions<TSchema> & { [created_prompt]: created_prompt };
290
- type CreatedResource = ResourceOptions & { [created_resource]: created_resource };
291
- type CreatedTemplate<TUri extends string = string> = TemplateOptions<TUri> & { [created_template]: created_template };
501
+ type CreatedTool<
502
+ TSchema extends StandardSchemaV1 | undefined = undefined,
503
+ TOutputSchema extends StandardSchemaV1 | undefined = undefined,
504
+ > = ToolOptions<TSchema, TOutputSchema> & { [created_tool]: created_tool };
505
+ type CreatedPrompt<
506
+ TSchema extends StandardSchemaV1 | undefined = undefined,
507
+ > = PromptOptions<TSchema> & { [created_prompt]: created_prompt };
508
+ type CreatedResource = ResourceOptions & {
509
+ [created_resource]: created_resource;
510
+ };
511
+ type CreatedTemplate<TUri extends string = string> =
512
+ TemplateOptions<TUri> & { [created_template]: created_template };
292
513
 
293
514
  type Completion = (
294
515
  query: string,
295
516
  context: { arguments: Record<string, string> },
296
517
  ) => CompleteResult_1 | Promise<CompleteResult_1>;
297
518
 
519
+ type CachePolicy = {
520
+ /**
521
+ * Time-to-live in milliseconds for cacheable results (>= 0). Defaults to 0 (no caching).
522
+ */
523
+ ttlMs?: number;
524
+ /**
525
+ * Cache scope for cacheable results. Defaults to 'private'. `public` must be
526
+ * explicitly opted into: `enabled` callbacks, auth context, and dynamic
527
+ * resource/template listings can make otherwise identical lists user-specific.
528
+ */
529
+ cacheScope?: 'public' | 'private';
530
+ };
531
+
298
532
  type ServerOptions<TSchema extends StandardSchemaV1 | undefined> = {
299
533
  capabilities?: ServerCapabilities;
300
534
  instructions?: string;
@@ -306,31 +540,70 @@ declare module 'tmcp' {
306
540
  };
307
541
  logging?: {
308
542
  default: LoggingLevel_1;
309
- }
543
+ };
544
+ /**
545
+ * Cache policy for per-request protocol cacheable results
546
+ * (`server/discover`, `tools/list`, `prompts/list`, `resources/list`,
547
+ * `resources/read`, `resources/templates/list`). Defaults to
548
+ * `{ ttlMs: 0, cacheScope: 'private' }`. Per-method overrides win over
549
+ * the top-level defaults.
550
+ */
551
+ cache?: CachePolicy & {
552
+ methods?: Record<string, CachePolicy>;
553
+ };
554
+ /**
555
+ * Convert tmcp's retry data to text before sending it to the client, and
556
+ * restore that data when the client retries the request. The value includes
557
+ * data saved by the handler and validated answers needed to restart it from
558
+ * the beginning. Treat the value passed to `encode` as tmcp-owned data; its
559
+ * internal shape may grow in future protocol versions.
560
+ *
561
+ * SECURITY: the default uses plain JSON, so the client can read, change, or
562
+ * replace the saved data. Do not store secrets in it or use it to make
563
+ * authorization decisions. Use a protected converter if the server must
564
+ * detect changes. That converter should also tie the data to the current
565
+ * user, the original request, and a short expiry time.
566
+ *
567
+ * tmcp limits the text length before calling `decode`. `decode` may be
568
+ * asynchronous. Custom converters should also limit the restored value if
569
+ * needed, because tmcp cannot measure every application-specific value.
570
+ */
571
+ requestStateCodec?: {
572
+ encode: (state: unknown) => string | Promise<string>;
573
+ decode: (encoded: string) => unknown | Promise<unknown>;
574
+ };
310
575
  };
311
576
 
312
577
  type ChangedArgs = {
313
- 'resource': [id: string];
314
- 'tools': [];
315
- 'prompts': [];
316
- 'resources': [];
317
- }
578
+ resource: [id: string];
579
+ tools: [];
580
+ prompts: [];
581
+ resources: [];
582
+ };
318
583
 
319
584
  type SubscriptionsKeysObj = {
320
- [K in keyof ChangedArgs as ChangedArgs[K]["length"] extends 0 ? "without_args" : "with_args"]: K
585
+ [K in keyof ChangedArgs as ChangedArgs[K]['length'] extends 0
586
+ ? 'without_args'
587
+ : 'with_args']: K;
321
588
  };
322
589
 
323
- type SubscriptionsKeys = SubscriptionsKeysObj["with_args"];
590
+ type SubscriptionsKeys = SubscriptionsKeysObj['with_args'];
324
591
 
325
592
  type McpEvents = {
326
593
  send: (message: {
327
594
  request: JSONRPCRequest;
595
+ subscriptionId?: RequestId;
596
+ subscriptionOrigin?: SubscriptionOrigin_1;
328
597
  }) => void;
329
598
  broadcast: (message: {
330
599
  request: JSONRPCRequest;
600
+ subscriptionOnly?: boolean;
331
601
  }) => void;
332
602
  initialize: (initialize_request: InitializeRequestParams) => void;
333
- subscription: (subscriptions_request: { uri: string, action?: "add" | "remove" }) => void;
603
+ subscription: (subscriptions_request: {
604
+ uri: string;
605
+ action?: 'add' | 'remove';
606
+ }) => void;
334
607
  loglevelchange: (change: { level: LoggingLevel_1 }) => void;
335
608
  };
336
609
  // Helper type to remove whitespace
@@ -378,6 +651,62 @@ declare module 'tmcp' {
378
651
  // Main exported type
379
652
  type ExtractURITemplateVariables<T extends string> =
380
653
  ExtractVariablesFromTemplate<T>;
654
+ /**
655
+ * A required header was missing, malformed, or mismatched the request body.
656
+ */
657
+ export const HEADER_MISMATCH: -32020;
658
+ /**
659
+ * The request requires a client capability that was not declared.
660
+ * `error.data` contains `{ requiredCapabilities }`.
661
+ */
662
+ export const MISSING_REQUIRED_CLIENT_CAPABILITY: -32021;
663
+ /**
664
+ * The requested per-request protocol version is not supported.
665
+ * `error.data` contains `{ supported, requested }`.
666
+ */
667
+ export const UNSUPPORTED_PROTOCOL_VERSION: -32022;
668
+ export class McpError extends JSONRPCErrorException {
669
+
670
+ constructor(code: number, message: string, data?: unknown);
671
+ }
672
+ /**
673
+ * A uniquely identifying ID for a request in JSON-RPC.
674
+ */
675
+ const RequestIdSchema: v.UnionSchema<[v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>], undefined>;
676
+ /**
677
+ * The severity of a log message.
678
+ */
679
+ const LoggingLevelSchema: v.PicklistSchema<["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"], undefined>;
680
+ /**
681
+ * A request that expects a response.
682
+ */
683
+ const JSONRPCRequestSchema: v.ObjectSchema<{
684
+ readonly method: v.StringSchema<undefined>;
685
+ readonly params: v.OptionalSchema<v.LooseObjectSchema<{
686
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{
687
+ /**
688
+ * If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
689
+ */
690
+ readonly progressToken: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>], undefined>, undefined>;
691
+ }, undefined>, undefined>;
692
+ }, undefined>, undefined>;
693
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
694
+ readonly id: v.UnionSchema<[v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>], undefined>;
695
+ }, undefined>;
696
+ /**
697
+ * A notification which does not expect a response.
698
+ */
699
+ const JSONRPCNotificationSchema: v.ObjectSchema<{
700
+ readonly method: v.StringSchema<undefined>;
701
+ readonly params: v.OptionalSchema<v.LooseObjectSchema<{
702
+ /**
703
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
704
+ * for notes on _meta usage.
705
+ */
706
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
707
+ }, undefined>, undefined>;
708
+ readonly jsonrpc: v.LiteralSchema<"2.0", undefined>;
709
+ }, undefined>;
381
710
  const JSONRPCMessageSchema: v.UnionSchema<[v.ObjectSchema<{
382
711
  readonly method: v.StringSchema<undefined>;
383
712
  readonly params: v.OptionalSchema<v.LooseObjectSchema<{
@@ -511,19 +840,29 @@ declare module 'tmcp' {
511
840
  /**
512
841
  * Experimental, non-standard capabilities that the client supports.
513
842
  */
514
- readonly experimental: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>;
843
+ readonly experimental: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
515
844
  /**
516
845
  * Present if the client supports sampling from an LLM.
846
+ * @deprecated in the per-request (2026-07-28) protocol; still fully supported for session-negotiated clients.
517
847
  */
518
- readonly sampling: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>;
848
+ readonly sampling: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
519
849
  /**
520
850
  * Present if the client supports eliciting user input.
851
+ * Accepts both the legacy bare `{}` shape and the modern `{ form?, url? }` sub-shapes.
852
+ */
853
+ readonly elicitation: v.OptionalSchema<v.LooseObjectSchema<{
854
+ readonly form: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
855
+ readonly url: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
856
+ }, undefined>, undefined>;
857
+ /**
858
+ * Extensions supported by the client, keyed by prefixed extension identifier.
521
859
  */
522
- readonly elicitation: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>;
860
+ readonly extensions: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.LooseObjectSchema<{}, undefined>, undefined>, undefined>;
523
861
  /**
524
862
  * Present if the client supports listing roots.
863
+ * @deprecated in the per-request (2026-07-28) protocol; still fully supported for session-negotiated clients.
525
864
  */
526
- readonly roots: v.OptionalSchema<v.ObjectSchema<{
865
+ readonly roots: v.OptionalSchema<v.LooseObjectSchema<{
527
866
  /**
528
867
  * Whether the client supports issuing notifications for changes to the roots list.
529
868
  */
@@ -539,19 +878,29 @@ declare module 'tmcp' {
539
878
  /**
540
879
  * Experimental, non-standard capabilities that the client supports.
541
880
  */
542
- readonly experimental: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>;
881
+ readonly experimental: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
543
882
  /**
544
883
  * Present if the client supports sampling from an LLM.
884
+ * @deprecated in the per-request (2026-07-28) protocol; still fully supported for session-negotiated clients.
545
885
  */
546
- readonly sampling: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>;
886
+ readonly sampling: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
547
887
  /**
548
888
  * Present if the client supports eliciting user input.
889
+ * Accepts both the legacy bare `{}` shape and the modern `{ form?, url? }` sub-shapes.
549
890
  */
550
- readonly elicitation: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>;
891
+ readonly elicitation: v.OptionalSchema<v.LooseObjectSchema<{
892
+ readonly form: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
893
+ readonly url: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
894
+ }, undefined>, undefined>;
895
+ /**
896
+ * Extensions supported by the client, keyed by prefixed extension identifier.
897
+ */
898
+ readonly extensions: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.LooseObjectSchema<{}, undefined>, undefined>, undefined>;
551
899
  /**
552
900
  * Present if the client supports listing roots.
901
+ * @deprecated in the per-request (2026-07-28) protocol; still fully supported for session-negotiated clients.
553
902
  */
554
- readonly roots: v.OptionalSchema<v.ObjectSchema<{
903
+ readonly roots: v.OptionalSchema<v.LooseObjectSchema<{
555
904
  /**
556
905
  * Whether the client supports issuing notifications for changes to the roots list.
557
906
  */
@@ -618,8 +967,13 @@ declare module 'tmcp' {
618
967
  readonly experimental: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>;
619
968
  /**
620
969
  * Present if the server supports sending log messages to the client.
970
+ * @deprecated in the per-request (2026-07-28) protocol; still fully supported for session-negotiated clients.
621
971
  */
622
972
  readonly logging: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>;
973
+ /**
974
+ * Extensions supported by the server, keyed by prefixed extension identifier.
975
+ */
976
+ readonly extensions: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.LooseObjectSchema<{}, undefined>, undefined>, undefined>;
623
977
  /**
624
978
  * Present if the server supports sending completions to the client.
625
979
  */
@@ -671,8 +1025,13 @@ declare module 'tmcp' {
671
1025
  readonly experimental: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>;
672
1026
  /**
673
1027
  * Present if the server supports sending log messages to the client.
1028
+ * @deprecated in the per-request (2026-07-28) protocol; still fully supported for session-negotiated clients.
674
1029
  */
675
1030
  readonly logging: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>;
1031
+ /**
1032
+ * Extensions supported by the server, keyed by prefixed extension identifier.
1033
+ */
1034
+ readonly extensions: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.LooseObjectSchema<{}, undefined>, undefined>, undefined>;
676
1035
  /**
677
1036
  * Present if the server supports sending completions to the client.
678
1037
  */
@@ -980,7 +1339,7 @@ declare module 'tmcp' {
980
1339
  /**
981
1340
  * The server's response to a resources/read request from the client.
982
1341
  */
983
- const ReadResourceResultSchema: v.ObjectSchema<{
1342
+ const ReadResourceResultSchema: v.LooseObjectSchema<{
984
1343
  readonly contents: v.ArraySchema<v.UnionSchema<[v.ObjectSchema<{
985
1344
  /**
986
1345
  * The text of the item. This must only be set if the item can actually be represented as text (not binary data).
@@ -1024,6 +1383,137 @@ declare module 'tmcp' {
1024
1383
  */
1025
1384
  readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
1026
1385
  }, undefined>;
1386
+ /**
1387
+ * Notification types requested on a per-request subscription stream. Every field
1388
+ * is opt-in.
1389
+ */
1390
+ const SubscriptionFilterSchema: v.ObjectSchema<{
1391
+ readonly toolsListChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
1392
+ readonly promptsListChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
1393
+ readonly resourcesListChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
1394
+ readonly resourceSubscriptions: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
1395
+ }, undefined>;
1396
+ const SubscriptionsListenRequestSchema: v.ObjectSchema<{
1397
+ readonly method: v.LiteralSchema<"subscriptions/listen", undefined>;
1398
+ readonly params: v.ObjectSchema<{
1399
+ readonly _meta: v.LooseObjectSchema<{
1400
+ readonly 'io.modelcontextprotocol/protocolVersion': v.StringSchema<undefined>;
1401
+ readonly 'io.modelcontextprotocol/clientCapabilities': v.LooseObjectSchema<{
1402
+ /**
1403
+ * Experimental, non-standard capabilities that the client supports.
1404
+ */
1405
+ readonly experimental: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
1406
+ /**
1407
+ * Present if the client supports sampling from an LLM.
1408
+ * @deprecated in the per-request (2026-07-28) protocol; still fully supported for session-negotiated clients.
1409
+ */
1410
+ readonly sampling: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
1411
+ /**
1412
+ * Present if the client supports eliciting user input.
1413
+ * Accepts both the legacy bare `{}` shape and the modern `{ form?, url? }` sub-shapes.
1414
+ */
1415
+ readonly elicitation: v.OptionalSchema<v.LooseObjectSchema<{
1416
+ readonly form: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
1417
+ readonly url: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
1418
+ }, undefined>, undefined>;
1419
+ /**
1420
+ * Extensions supported by the client, keyed by prefixed extension identifier.
1421
+ */
1422
+ readonly extensions: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.LooseObjectSchema<{}, undefined>, undefined>, undefined>;
1423
+ /**
1424
+ * Present if the client supports listing roots.
1425
+ * @deprecated in the per-request (2026-07-28) protocol; still fully supported for session-negotiated clients.
1426
+ */
1427
+ readonly roots: v.OptionalSchema<v.LooseObjectSchema<{
1428
+ /**
1429
+ * Whether the client supports issuing notifications for changes to the roots list.
1430
+ */
1431
+ readonly listChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
1432
+ }, undefined>, undefined>;
1433
+ }, undefined>;
1434
+ readonly 'io.modelcontextprotocol/clientInfo': v.OptionalSchema<v.ObjectSchema<{
1435
+ /**
1436
+ * Optional set of sized icons that the client can display in a user interface.
1437
+ *
1438
+ * Clients that support rendering icons MUST support at least the following MIME types:
1439
+ * - `image/png` - PNG images (safe, universal compatibility)
1440
+ * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
1441
+ *
1442
+ * Clients that support rendering icons SHOULD also support:
1443
+ * - `image/svg+xml` - SVG images (scalable but requires security precautions)
1444
+ * - `image/webp` - WebP images (modern, efficient format)
1445
+ */
1446
+ readonly icons: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
1447
+ /**
1448
+ * URL or data URI for the icon.
1449
+ */
1450
+ readonly src: v.StringSchema<undefined>;
1451
+ /**
1452
+ * Optional MIME type for the icon.
1453
+ */
1454
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
1455
+ /**
1456
+ * Optional array of strings that specify sizes at which the icon can be used.
1457
+ * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
1458
+ *
1459
+ * If not provided, the client should assume that the icon can be used at any size.
1460
+ */
1461
+ readonly sizes: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
1462
+ }, undefined>, undefined>, undefined>;
1463
+ readonly version: v.StringSchema<undefined>;
1464
+ readonly websiteUrl: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
1465
+ /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
1466
+ readonly name: v.StringSchema<undefined>;
1467
+ /**
1468
+ * Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
1469
+ * even by those unfamiliar with domain-specific terminology.
1470
+ *
1471
+ * If not provided, the name should be used for display (except for Tool,
1472
+ * where `annotations.title` should be given precedence over using `name`,
1473
+ * if present).
1474
+ */
1475
+ readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
1476
+ }, undefined>, undefined>;
1477
+ readonly 'io.modelcontextprotocol/logLevel': v.OptionalSchema<v.PicklistSchema<["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"], undefined>, undefined>;
1478
+ /**
1479
+ * If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
1480
+ */
1481
+ readonly progressToken: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>], undefined>, undefined>;
1482
+ }, undefined>;
1483
+ readonly notifications: v.ObjectSchema<{
1484
+ readonly toolsListChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
1485
+ readonly promptsListChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
1486
+ readonly resourcesListChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
1487
+ readonly resourceSubscriptions: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
1488
+ }, undefined>;
1489
+ }, undefined>;
1490
+ }, undefined>;
1491
+ /**
1492
+ * Returned when the server gracefully closes a subscription stream.
1493
+ */
1494
+ const SubscriptionsListenResultSchema: v.LooseObjectSchema<{
1495
+ readonly resultType: v.LiteralSchema<"complete", undefined>;
1496
+ readonly _meta: v.LooseObjectSchema<{
1497
+ readonly "io.modelcontextprotocol/subscriptionId": v.UnionSchema<[v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>], undefined>;
1498
+ }, undefined>;
1499
+ }, undefined>;
1500
+ /**
1501
+ * The first notification emitted for a per-request subscription stream.
1502
+ */
1503
+ const SubscriptionsAcknowledgedNotificationSchema: v.ObjectSchema<{
1504
+ readonly method: v.LiteralSchema<"notifications/subscriptions/acknowledged", undefined>;
1505
+ readonly params: v.ObjectSchema<{
1506
+ readonly _meta: v.LooseObjectSchema<{
1507
+ readonly "io.modelcontextprotocol/subscriptionId": v.UnionSchema<[v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>], undefined>;
1508
+ }, undefined>;
1509
+ readonly notifications: v.ObjectSchema<{
1510
+ readonly toolsListChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
1511
+ readonly promptsListChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
1512
+ readonly resourcesListChanged: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
1513
+ readonly resourceSubscriptions: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
1514
+ }, undefined>;
1515
+ }, undefined>;
1516
+ }, undefined>;
1027
1517
  /**
1028
1518
  * The server's response to a prompts/list request from the client.
1029
1519
  */
@@ -1109,7 +1599,7 @@ declare module 'tmcp' {
1109
1599
  /**
1110
1600
  * The server's response to a prompts/get request from the client.
1111
1601
  */
1112
- const GetPromptResultSchema: v.ObjectSchema<{
1602
+ const GetPromptResultSchema: v.LooseObjectSchema<{
1113
1603
  /**
1114
1604
  * An optional description for the prompt.
1115
1605
  */
@@ -1357,20 +1847,18 @@ declare module 'tmcp' {
1357
1847
  readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
1358
1848
  /**
1359
1849
  * A JSON Schema object defining the expected parameters for the tool.
1850
+ * Any JSON Schema 2020-12 keywords are allowed alongside the required `type: "object"` root.
1360
1851
  */
1361
- readonly inputSchema: v.ObjectSchema<{
1852
+ readonly inputSchema: v.LooseObjectSchema<{
1853
+ readonly $schema: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
1362
1854
  readonly type: v.LiteralSchema<"object", undefined>;
1363
- readonly properties: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>;
1364
- readonly required: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
1365
1855
  }, undefined>;
1366
1856
  /**
1367
1857
  * An optional JSON Schema object defining the structure of the tool's output returned in
1368
- * the structuredContent field of a CallToolResult.
1858
+ * the structuredContent field of a CallToolResult. Any JSON Schema 2020-12 keywords are allowed.
1369
1859
  */
1370
- readonly outputSchema: v.OptionalSchema<v.ObjectSchema<{
1371
- readonly type: v.LiteralSchema<"object", undefined>;
1372
- readonly properties: v.OptionalSchema<v.ObjectSchema<{}, undefined>, undefined>;
1373
- readonly required: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
1860
+ readonly outputSchema: v.OptionalSchema<v.LooseObjectSchema<{
1861
+ readonly $schema: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
1374
1862
  }, undefined>, undefined>;
1375
1863
  /**
1376
1864
  * Optional additional tool information.
@@ -1445,7 +1933,7 @@ declare module 'tmcp' {
1445
1933
  /**
1446
1934
  * The server's response to a tool call.
1447
1935
  */
1448
- const CallToolResultSchema: v.ObjectSchema<{
1936
+ const CallToolResultSchema: v.LooseObjectSchema<{
1449
1937
  /**
1450
1938
  * A list of content objects that represent the result of the tool call.
1451
1939
  *
@@ -1599,11 +2087,11 @@ declare module 'tmcp' {
1599
2087
  readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
1600
2088
  }, undefined>], undefined>, undefined>, readonly []>;
1601
2089
  /**
1602
- * An object containing structured tool output.
2090
+ * Structured tool output. May be ANY JSON value, not only objects.
1603
2091
  *
1604
- * If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema.
2092
+ * If the Tool defines an outputSchema, this field MUST be present in the result and match the schema.
1605
2093
  */
1606
- readonly structuredContent: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2094
+ readonly structuredContent: v.OptionalSchema<v.UnknownSchema, undefined>;
1607
2095
  /**
1608
2096
  * Whether the tool call ended in an error.
1609
2097
  *
@@ -1625,10 +2113,6 @@ declare module 'tmcp' {
1625
2113
  */
1626
2114
  readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
1627
2115
  }, undefined>;
1628
- /**
1629
- * The severity of a log message.
1630
- */
1631
- const LoggingLevelSchema: v.PicklistSchema<["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"], undefined>;
1632
2116
  const CreateMessageRequestParamsSchema: v.ObjectSchema<{
1633
2117
  readonly messages: v.ArraySchema<v.ObjectSchema<{
1634
2118
  readonly role: v.PicklistSchema<["user", "assistant"], undefined>;
@@ -1808,7 +2292,7 @@ declare module 'tmcp' {
1808
2292
  /**
1809
2293
  * The server's response to a completion/complete request
1810
2294
  */
1811
- const CompleteResultSchema: v.ObjectSchema<{
2295
+ const CompleteResultSchema: v.LooseObjectSchema<{
1812
2296
  readonly completion: v.ObjectSchema<{
1813
2297
  /**
1814
2298
  * An array of completion values. Must not exceed 100 items.
@@ -1837,7 +2321,7 @@ declare module 'tmcp' {
1837
2321
  description?: string;
1838
2322
  };
1839
2323
  type InitializeRequestParams = v.InferInput<typeof InitializeRequestParamsSchema>;
1840
- type CallToolResult_1<TStructuredContent extends Record<string, unknown> | undefined> = Omit<v.InferInput<typeof CallToolResultSchema>, "structuredContent" | "isError"> & (undefined extends TStructuredContent ? {
2324
+ type CallToolResult_1<TStructuredContent> = Omit<v.InferInput<typeof CallToolResultSchema>, "structuredContent" | "isError"> & (undefined extends TStructuredContent ? {
1841
2325
  structuredContent?: undefined;
1842
2326
  isError?: boolean;
1843
2327
  } : ({
@@ -1862,6 +2346,11 @@ declare module 'tmcp' {
1862
2346
  type ListPromptsResult_1 = v.InferInput<typeof ListPromptsResultSchema>;
1863
2347
  type ListResourcesResult_1 = v.InferInput<typeof ListResourcesResultSchema>;
1864
2348
  type ListResourceTemplatesResult_1 = v.InferInput<typeof ListResourceTemplatesResultSchema>;
2349
+ type RequestId = v.InferInput<typeof RequestIdSchema>;
2350
+ type SubscriptionFilter_1 = v.InferInput<typeof SubscriptionFilterSchema>;
2351
+ type SubscriptionsListenResult_1 = v.InferInput<typeof SubscriptionsListenResultSchema>;
2352
+ type SubscriptionsListenRequest_1 = v.InferInput<typeof JSONRPCRequestSchema> & v.InferInput<typeof SubscriptionsListenRequestSchema>;
2353
+ type SubscriptionsAcknowledgedNotification_1 = v.InferInput<typeof JSONRPCNotificationSchema> & v.InferInput<typeof SubscriptionsAcknowledgedNotificationSchema>;
1865
2354
  /**
1866
2355
  * @import { StandardSchemaV1 } from "@standard-schema/spec";
1867
2356
  * @import { JSONSchema7 } from "json-schema";
@@ -1888,20 +2377,54 @@ declare module 'tmcp/tool' {
1888
2377
  *
1889
2378
  * */
1890
2379
  export function defineTool<TSchema extends StandardSchemaV1 | undefined = undefined, TOutputSchema extends StandardSchemaV1 | undefined = undefined>(options: ToolOptions<TSchema, TOutputSchema>, execute: TSchema extends undefined ? (() => Promise<CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>> | CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>) : ((input: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>) => Promise<CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>> | CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>)): CreatedTool<TSchema, TOutputSchema>;
1891
- type CallToolResult<TStructuredContent extends Record<string, unknown> | undefined> = CallToolResult_1<TStructuredContent>;
2380
+ type CallToolResult<TStructuredContent> = CallToolResult_1<TStructuredContent>;
1892
2381
 
1893
- type ToolOptions<TSchema extends StandardSchemaV1 | undefined = undefined, TOutputSchema extends StandardSchemaV1 | undefined = undefined> = {
2382
+ type Replayable = {
2383
+ /**
2384
+ * Allow tmcp to run this handler again after asking the client for input.
2385
+ *
2386
+ * For standalone requests, the server cannot pause and wait for the client.
2387
+ * It returns the questions to the client, which then retries the original
2388
+ * request with the answers. The handler starts again FROM THE TOP on every
2389
+ * retry. This means work done before an input call, such as database writes,
2390
+ * emails, or payments, may happen more than once. Set `replayable: true`
2391
+ * only when that work is safe to repeat or is delayed until all answers are
2392
+ * available.
2393
+ *
2394
+ * Without this flag, tmcp returns an error rather than risk repeating work.
2395
+ * This is a tmcp safety check, not an MCP requirement. Requests using an
2396
+ * open client session are unaffected because their handlers do not restart.
2397
+ */
2398
+ replayable?: boolean;
2399
+ };
2400
+
2401
+ type ToolOptions<
2402
+ TSchema extends StandardSchemaV1 | undefined = undefined,
2403
+ TOutputSchema extends StandardSchemaV1 | undefined = undefined,
2404
+ > = {
1894
2405
  name: string;
1895
2406
  _meta?: Record<string, any>;
1896
2407
  description: string;
1897
2408
  title?: string;
1898
2409
  enabled?: () => boolean | Promise<boolean>;
1899
- schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never;
1900
- outputSchema?: StandardSchemaV1.InferOutput<TOutputSchema extends undefined ? never : TOutputSchema> extends Record<string, unknown> ? TOutputSchema : never;
2410
+ schema?: StandardSchemaV1.InferInput<
2411
+ TSchema extends undefined ? never : TSchema
2412
+ > extends Record<string, unknown>
2413
+ ? TSchema
2414
+ : never;
2415
+ outputSchema?: StandardSchemaV1.InferOutput<
2416
+ TOutputSchema extends undefined ? never : TOutputSchema
2417
+ > extends Record<string, unknown>
2418
+ ? TOutputSchema
2419
+ : never;
1901
2420
  annotations?: ToolAnnotations;
1902
- } & Icons;
2421
+ } & Icons &
2422
+ Replayable;
1903
2423
 
1904
- type CreatedTool<TSchema extends StandardSchemaV1 | undefined = undefined, TOutputSchema extends StandardSchemaV1 | undefined = undefined> = ToolOptions<TSchema, TOutputSchema> & { [created_tool]: created_tool };
2424
+ type CreatedTool<
2425
+ TSchema extends StandardSchemaV1 | undefined = undefined,
2426
+ TOutputSchema extends StandardSchemaV1 | undefined = undefined,
2427
+ > = ToolOptions<TSchema, TOutputSchema> & { [created_tool]: created_tool };
1905
2428
  const IconsSchema: v.ObjectSchema<{
1906
2429
  /**
1907
2430
  * Optional set of sized icons that the client can display in a user interface.
@@ -1984,7 +2507,7 @@ declare module 'tmcp/tool' {
1984
2507
  /**
1985
2508
  * The server's response to a tool call.
1986
2509
  */
1987
- const CallToolResultSchema: v.ObjectSchema<{
2510
+ const CallToolResultSchema: v.LooseObjectSchema<{
1988
2511
  /**
1989
2512
  * A list of content objects that represent the result of the tool call.
1990
2513
  *
@@ -2138,11 +2661,11 @@ declare module 'tmcp/tool' {
2138
2661
  readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2139
2662
  }, undefined>], undefined>, undefined>, readonly []>;
2140
2663
  /**
2141
- * An object containing structured tool output.
2664
+ * Structured tool output. May be ANY JSON value, not only objects.
2142
2665
  *
2143
- * If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema.
2666
+ * If the Tool defines an outputSchema, this field MUST be present in the result and match the schema.
2144
2667
  */
2145
- readonly structuredContent: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2668
+ readonly structuredContent: v.OptionalSchema<v.UnknownSchema, undefined>;
2146
2669
  /**
2147
2670
  * Whether the tool call ended in an error.
2148
2671
  *
@@ -2165,7 +2688,7 @@ declare module 'tmcp/tool' {
2165
2688
  readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2166
2689
  }, undefined>;
2167
2690
  type Icons = v.InferInput<typeof IconsSchema>;
2168
- type CallToolResult_1<TStructuredContent extends Record<string, unknown> | undefined> = Omit<v.InferInput<typeof CallToolResultSchema>, "structuredContent" | "isError"> & (undefined extends TStructuredContent ? {
2691
+ type CallToolResult_1<TStructuredContent> = Omit<v.InferInput<typeof CallToolResultSchema>, "structuredContent" | "isError"> & (undefined extends TStructuredContent ? {
2169
2692
  structuredContent?: undefined;
2170
2693
  isError?: boolean;
2171
2694
  } : ({
@@ -2195,15 +2718,54 @@ declare module 'tmcp/prompt' {
2195
2718
  * */
2196
2719
  export function definePrompt<TSchema extends StandardSchemaV1 | undefined = undefined>(options: PromptOptions<TSchema>, execute: TSchema extends undefined ? (() => Promise<GetPromptResult> | GetPromptResult) : (input: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>) => Promise<GetPromptResult> | GetPromptResult): CreatedPrompt<TSchema>;
2197
2720
 
2198
- type PromptOptions<TSchema extends StandardSchemaV1 | undefined = undefined> = {
2199
- name: string;
2200
- description: string;
2201
- title?: string;
2202
- enabled?: ()=>boolean | Promise<boolean>;
2203
- schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never;
2204
- complete?: NoInfer<TSchema extends undefined ? never : Partial<Record<keyof (StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>), Completion>>>
2205
- } & Icons
2206
- type CreatedPrompt<TSchema extends StandardSchemaV1 | undefined = undefined> = PromptOptions<TSchema> & { [created_prompt]: created_prompt };
2721
+ type Replayable = {
2722
+ /**
2723
+ * Allow tmcp to run this handler again after asking the client for input.
2724
+ *
2725
+ * For standalone requests, the server cannot pause and wait for the client.
2726
+ * It returns the questions to the client, which then retries the original
2727
+ * request with the answers. The handler starts again FROM THE TOP on every
2728
+ * retry. This means work done before an input call, such as database writes,
2729
+ * emails, or payments, may happen more than once. Set `replayable: true`
2730
+ * only when that work is safe to repeat or is delayed until all answers are
2731
+ * available.
2732
+ *
2733
+ * Without this flag, tmcp returns an error rather than risk repeating work.
2734
+ * This is a tmcp safety check, not an MCP requirement. Requests using an
2735
+ * open client session are unaffected because their handlers do not restart.
2736
+ */
2737
+ replayable?: boolean;
2738
+ };
2739
+
2740
+ type PromptOptions<
2741
+ TSchema extends StandardSchemaV1 | undefined = undefined,
2742
+ > = {
2743
+ name: string;
2744
+ description: string;
2745
+ title?: string;
2746
+ enabled?: () => boolean | Promise<boolean>;
2747
+ schema?: StandardSchemaV1.InferInput<
2748
+ TSchema extends undefined ? never : TSchema
2749
+ > extends Record<string, unknown>
2750
+ ? TSchema
2751
+ : never;
2752
+ complete?: NoInfer<
2753
+ TSchema extends undefined
2754
+ ? never
2755
+ : Partial<
2756
+ Record<
2757
+ keyof StandardSchemaV1.InferInput<
2758
+ TSchema extends undefined ? never : TSchema
2759
+ >,
2760
+ Completion
2761
+ >
2762
+ >
2763
+ >;
2764
+ } & Icons &
2765
+ Replayable;
2766
+ type CreatedPrompt<
2767
+ TSchema extends StandardSchemaV1 | undefined = undefined,
2768
+ > = PromptOptions<TSchema> & { [created_prompt]: created_prompt };
2207
2769
 
2208
2770
  type Completion = (
2209
2771
  query: string,
@@ -2242,7 +2804,7 @@ declare module 'tmcp/prompt' {
2242
2804
  /**
2243
2805
  * The server's response to a prompts/get request from the client.
2244
2806
  */
2245
- const GetPromptResultSchema: v.ObjectSchema<{
2807
+ const GetPromptResultSchema: v.LooseObjectSchema<{
2246
2808
  /**
2247
2809
  * An optional description for the prompt.
2248
2810
  */
@@ -2405,7 +2967,7 @@ declare module 'tmcp/prompt' {
2405
2967
  /**
2406
2968
  * The server's response to a completion/complete request
2407
2969
  */
2408
- const CompleteResultSchema: v.ObjectSchema<{
2970
+ const CompleteResultSchema: v.LooseObjectSchema<{
2409
2971
  readonly completion: v.ObjectSchema<{
2410
2972
  /**
2411
2973
  * An array of completion values. Must not exceed 100 items.
@@ -2446,15 +3008,37 @@ declare module 'tmcp/resource' {
2446
3008
  * */
2447
3009
  export function defineResource(options: ResourceOptions, execute: (uri: string) => Promise<ReadResourceResult> | ReadResourceResult): CreatedResource;
2448
3010
 
2449
- type ResourceOptions = {
3011
+ type Replayable = {
3012
+ /**
3013
+ * Allow tmcp to run this handler again after asking the client for input.
3014
+ *
3015
+ * For standalone requests, the server cannot pause and wait for the client.
3016
+ * It returns the questions to the client, which then retries the original
3017
+ * request with the answers. The handler starts again FROM THE TOP on every
3018
+ * retry. This means work done before an input call, such as database writes,
3019
+ * emails, or payments, may happen more than once. Set `replayable: true`
3020
+ * only when that work is safe to repeat or is delayed until all answers are
3021
+ * available.
3022
+ *
3023
+ * Without this flag, tmcp returns an error rather than risk repeating work.
3024
+ * This is a tmcp safety check, not an MCP requirement. Requests using an
3025
+ * open client session are unaffected because their handlers do not restart.
3026
+ */
3027
+ replayable?: boolean;
3028
+ };
3029
+
3030
+ type ResourceOptions = {
2450
3031
  name: string;
2451
- description: string;
2452
- title?: string;
3032
+ description: string;
3033
+ title?: string;
2453
3034
  uri: string;
2454
3035
  mimeType?: string;
2455
- enabled?: ()=>boolean | Promise<boolean>;
2456
- } & Icons
2457
- type CreatedResource = ResourceOptions & { [created_resource]: created_resource };
3036
+ enabled?: () => boolean | Promise<boolean>;
3037
+ } & Icons &
3038
+ Replayable;
3039
+ type CreatedResource = ResourceOptions & {
3040
+ [created_resource]: created_resource;
3041
+ };
2458
3042
  const IconsSchema: v.ObjectSchema<{
2459
3043
  /**
2460
3044
  * Optional set of sized icons that the client can display in a user interface.
@@ -2488,7 +3072,7 @@ declare module 'tmcp/resource' {
2488
3072
  /**
2489
3073
  * The server's response to a resources/read request from the client.
2490
3074
  */
2491
- const ReadResourceResultSchema: v.ObjectSchema<{
3075
+ const ReadResourceResultSchema: v.LooseObjectSchema<{
2492
3076
  readonly contents: v.ArraySchema<v.UnionSchema<[v.ObjectSchema<{
2493
3077
  /**
2494
3078
  * The text of the item. This must only be set if the item can actually be represented as text (not binary data).
@@ -2600,17 +3184,46 @@ declare module 'tmcp/template' {
2600
3184
  type ExtractURITemplateVariables<T extends string> =
2601
3185
  ExtractVariablesFromTemplate<T>;
2602
3186
 
2603
- type TemplateOptions<TUri extends string = string, TVariables extends ExtractURITemplateVariables<TUri> = ExtractURITemplateVariables<TUri>> = {
3187
+ type Replayable = {
3188
+ /**
3189
+ * Allow tmcp to run this handler again after asking the client for input.
3190
+ *
3191
+ * For standalone requests, the server cannot pause and wait for the client.
3192
+ * It returns the questions to the client, which then retries the original
3193
+ * request with the answers. The handler starts again FROM THE TOP on every
3194
+ * retry. This means work done before an input call, such as database writes,
3195
+ * emails, or payments, may happen more than once. Set `replayable: true`
3196
+ * only when that work is safe to repeat or is delayed until all answers are
3197
+ * available.
3198
+ *
3199
+ * Without this flag, tmcp returns an error rather than risk repeating work.
3200
+ * This is a tmcp safety check, not an MCP requirement. Requests using an
3201
+ * open client session are unaffected because their handlers do not restart.
3202
+ */
3203
+ replayable?: boolean;
3204
+ };
3205
+
3206
+ type TemplateOptions<
3207
+ TUri extends string = string,
3208
+ TVariables extends ExtractURITemplateVariables<TUri> =
3209
+ ExtractURITemplateVariables<TUri>,
3210
+ > = {
2604
3211
  name: string;
2605
3212
  description: string;
2606
3213
  title?: string;
2607
3214
  mimeType?: string;
2608
- enabled?: ()=>boolean | Promise<boolean>;
3215
+ enabled?: () => boolean | Promise<boolean>;
2609
3216
  uri: TUri;
2610
- complete?: NoInfer<TVariables extends never ? never : Partial<Record<TVariables, Completion>>>;
2611
- list?: () => Promise<Array<Resource>> | Array<Resource>
2612
- } & Icons
2613
- type CreatedTemplate<TUri extends string = string> = TemplateOptions<TUri> & { [created_template]: created_template };
3217
+ complete?: NoInfer<
3218
+ TVariables extends never
3219
+ ? never
3220
+ : Partial<Record<TVariables, Completion>>
3221
+ >;
3222
+ list?: () => Promise<Array<Resource>> | Array<Resource>;
3223
+ } & Icons &
3224
+ Replayable;
3225
+ type CreatedTemplate<TUri extends string = string> =
3226
+ TemplateOptions<TUri> & { [created_template]: created_template };
2614
3227
 
2615
3228
  type Completion = (
2616
3229
  query: string,
@@ -2712,7 +3325,7 @@ declare module 'tmcp/template' {
2712
3325
  /**
2713
3326
  * The server's response to a resources/read request from the client.
2714
3327
  */
2715
- const ReadResourceResultSchema: v.ObjectSchema<{
3328
+ const ReadResourceResultSchema: v.LooseObjectSchema<{
2716
3329
  readonly contents: v.ArraySchema<v.UnionSchema<[v.ObjectSchema<{
2717
3330
  /**
2718
3331
  * The text of the item. This must only be set if the item can actually be represented as text (not binary data).
@@ -2759,7 +3372,7 @@ declare module 'tmcp/template' {
2759
3372
  /**
2760
3373
  * The server's response to a completion/complete request
2761
3374
  */
2762
- const CompleteResultSchema: v.ObjectSchema<{
3375
+ const CompleteResultSchema: v.LooseObjectSchema<{
2763
3376
  readonly completion: v.ObjectSchema<{
2764
3377
  /**
2765
3378
  * An array of completion values. Must not exceed 100 items.
@@ -2804,6 +3417,15 @@ declare module 'tmcp/adapter' {
2804
3417
  export {};
2805
3418
  }
2806
3419
 
3420
+ declare module 'tmcp/method-policy' {
3421
+ /**
3422
+ * Check whether a method may be called with per-request protocol metadata.
3423
+ * */
3424
+ export function isPerRequestMethodAllowed(method: string): boolean;
3425
+
3426
+ export {};
3427
+ }
3428
+
2807
3429
  declare module 'tmcp/utils' {
2808
3430
  import * as v from 'valibot';
2809
3431
  export namespace tool {
@@ -2872,7 +3494,7 @@ declare module 'tmcp/utils' {
2872
3494
  };
2873
3495
 
2874
3496
  function structured<T extends Record<string, unknown>>(obj: T): {
2875
- readonly content: [{
3497
+ readonly content: readonly [{
2876
3498
  readonly type: "text";
2877
3499
  readonly text: string;
2878
3500
  }];
@@ -3148,7 +3770,7 @@ declare module 'tmcp/utils' {
3148
3770
  /**
3149
3771
  * The server's response to a resources/read request from the client.
3150
3772
  */
3151
- const ReadResourceResultSchema: v.ObjectSchema<{
3773
+ const ReadResourceResultSchema: v.LooseObjectSchema<{
3152
3774
  readonly contents: v.ArraySchema<v.UnionSchema<[v.ObjectSchema<{
3153
3775
  /**
3154
3776
  * The text of the item. This must only be set if the item can actually be represented as text (not binary data).
@@ -3309,7 +3931,7 @@ declare module 'tmcp/utils' {
3309
3931
  /**
3310
3932
  * The server's response to a prompts/get request from the client.
3311
3933
  */
3312
- const GetPromptResultSchema: v.ObjectSchema<{
3934
+ const GetPromptResultSchema: v.LooseObjectSchema<{
3313
3935
  /**
3314
3936
  * An optional description for the prompt.
3315
3937
  */
@@ -3472,7 +4094,7 @@ declare module 'tmcp/utils' {
3472
4094
  /**
3473
4095
  * The server's response to a tool call.
3474
4096
  */
3475
- const CallToolResultSchema: v.ObjectSchema<{
4097
+ const CallToolResultSchema: v.LooseObjectSchema<{
3476
4098
  /**
3477
4099
  * A list of content objects that represent the result of the tool call.
3478
4100
  *
@@ -3626,11 +4248,11 @@ declare module 'tmcp/utils' {
3626
4248
  readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
3627
4249
  }, undefined>], undefined>, undefined>, readonly []>;
3628
4250
  /**
3629
- * An object containing structured tool output.
4251
+ * Structured tool output. May be ANY JSON value, not only objects.
3630
4252
  *
3631
- * If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema.
4253
+ * If the Tool defines an outputSchema, this field MUST be present in the result and match the schema.
3632
4254
  */
3633
- readonly structuredContent: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
4255
+ readonly structuredContent: v.OptionalSchema<v.UnknownSchema, undefined>;
3634
4256
  /**
3635
4257
  * Whether the tool call ended in an error.
3636
4258
  *
@@ -3652,7 +4274,7 @@ declare module 'tmcp/utils' {
3652
4274
  */
3653
4275
  readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
3654
4276
  }, undefined>;
3655
- type CallToolResult<TStructuredContent extends Record<string, unknown> | undefined> = Omit<v.InferInput<typeof CallToolResultSchema>, "structuredContent" | "isError"> & (undefined extends TStructuredContent ? {
4277
+ type CallToolResult<TStructuredContent> = Omit<v.InferInput<typeof CallToolResultSchema>, "structuredContent" | "isError"> & (undefined extends TStructuredContent ? {
3656
4278
  structuredContent?: undefined;
3657
4279
  isError?: boolean;
3658
4280
  } : ({