tmcp 1.12.2 → 1.14.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tmcp",
3
- "version": "1.12.2",
3
+ "version": "1.14.0",
4
4
  "description": "The main tmcp library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/index.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * @import SqidsType from "sqids";
5
5
  * @import { JSONRPCRequest, JSONRPCParams } from "json-rpc-2.0";
6
6
  * @import { ExtractURITemplateVariables } from "./internal/uri-template.js";
7
- * @import { CallToolResult, ReadResourceResult, GetPromptResult, ClientCapabilities as ClientCapabilitiesType, JSONRPCRequest as JSONRPCRequestType, JSONRPCResponse, CreateMessageRequestParams, CreateMessageResult, Resource, LoggingLevel, ToolAnnotations, ClientInfo } from "./validation/index.js";
7
+ * @import { CallToolResult, ReadResourceResult, GetPromptResult, ClientCapabilities as ClientCapabilitiesType, JSONRPCRequest as JSONRPCRequestType, JSONRPCResponse, CreateMessageRequestParams, CreateMessageResult, Resource, LoggingLevel, ToolAnnotations, ClientInfo, ElicitResult } from "./validation/index.js";
8
8
  * @import { Tool, Completion, Prompt, StoredResource, ServerOptions, ServerInfo, SubscriptionsKeys, ChangedArgs, McpEvents } from "./internal/internal.js";
9
9
  */
10
10
  import { JSONRPCClient, JSONRPCServer } from 'json-rpc-2.0';
@@ -23,6 +23,8 @@ import {
23
23
  JSONRPCResponseSchema,
24
24
  McpError,
25
25
  ReadResourceResultSchema,
26
+ ElicitResultSchema,
27
+ JSONRPCErrorSchema,
26
28
  } from './validation/index.js';
27
29
  import {
28
30
  get_supported_versions,
@@ -228,11 +230,6 @@ export class McpServer {
228
230
  }),
229
231
  );
230
232
 
231
- // Trigger initial roots request if client supports it
232
- if (validated_initialize.capabilities?.roots) {
233
- this.#refresh_roots();
234
- }
235
-
236
233
  // Return server response with negotiated version and capabilities
237
234
  return {
238
235
  protocolVersion: negotiated_version,
@@ -941,7 +938,10 @@ export class McpServer {
941
938
  );
942
939
  }
943
940
  // It's a response - handle with client
944
- const validated_response = v.parse(JSONRPCResponseSchema, message);
941
+ const validated_response = v.parse(
942
+ v.union([JSONRPCResponseSchema, JSONRPCErrorSchema]),
943
+ message,
944
+ );
945
945
  this.#lazyily_create_client();
946
946
  return this.#ctx_storage.run(ctx ?? {}, async () =>
947
947
  this.#client?.receive(validated_response),
@@ -1004,25 +1004,27 @@ export class McpServer {
1004
1004
  * @template {StandardSchema extends undefined ? never : StandardSchema} TSchema
1005
1005
  * @param {string} message
1006
1006
  * @param {TSchema} schema
1007
- * @returns {Promise<StandardSchemaV1.InferOutput<TSchema>>}
1007
+ * @returns {Promise<ElicitResult & { content?: StandardSchemaV1.InferOutput<TSchema> }>}
1008
1008
  */
1009
1009
  async elicitation(message, schema) {
1010
1010
  if (!this.#client_capabilities?.elicitation)
1011
1011
  throw new McpError(-32601, "Client doesn't support elicitation");
1012
1012
 
1013
1013
  this.#lazyily_create_client();
1014
+ const result = await this.#client?.request(
1015
+ 'elicitation/create',
1016
+ {
1017
+ message,
1018
+ requestedSchema:
1019
+ await this.#options.adapter.toJsonSchema(schema),
1020
+ },
1021
+ {
1022
+ sessions: [this.#session_id],
1023
+ },
1024
+ );
1025
+ const elicit_result = v.parse(ElicitResultSchema, result);
1014
1026
  let validated_result = schema['~standard'].validate(
1015
- await this.#client?.request(
1016
- 'elicitation/create',
1017
- {
1018
- message,
1019
- requestedSchema:
1020
- await this.#options.adapter.toJsonSchema(schema),
1021
- },
1022
- {
1023
- sessions: [this.#session_id],
1024
- },
1025
- ),
1027
+ elicit_result.content,
1026
1028
  );
1027
1029
  if (validated_result instanceof Promise)
1028
1030
  validated_result = await validated_result;
@@ -1032,7 +1034,7 @@ export class McpServer {
1032
1034
  `Invalid elicitation result: ${JSON.stringify(validated_result.issues)}`,
1033
1035
  );
1034
1036
  }
1035
- return validated_result.value;
1037
+ return { ...elicit_result, content: validated_result.value };
1036
1038
  }
1037
1039
 
1038
1040
  /**
@@ -120,7 +120,9 @@ declare module 'tmcp' {
120
120
  * If the client doesn't support elicitation, it will throw an error.
121
121
  *
122
122
  * */
123
- elicitation<TSchema extends StandardSchema extends undefined ? never : StandardSchema>(message: string, schema: TSchema): Promise<StandardSchemaV1.InferOutput<TSchema>>;
123
+ elicitation<TSchema extends StandardSchema extends undefined ? never : StandardSchema>(message: string, schema: TSchema): Promise<ElicitResult & {
124
+ content?: StandardSchemaV1.InferOutput<TSchema>;
125
+ }>;
124
126
  /**
125
127
  * Request language model sampling from the client
126
128
  * */
@@ -938,6 +940,24 @@ declare module 'tmcp' {
938
940
  */
939
941
  readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
940
942
  }, undefined>;
943
+ /**
944
+ * The client's response to an elicitation/create request from the server.
945
+ */
946
+ const ElicitResultSchema: v.ObjectSchema<{
947
+ /**
948
+ * The user's response action.
949
+ */
950
+ readonly action: v.PicklistSchema<["accept", "decline", "cancel"], undefined>;
951
+ /**
952
+ * The collected user input content (only present if action is "accept").
953
+ */
954
+ readonly content: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>, undefined>;
955
+ /**
956
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
957
+ * for notes on _meta usage.
958
+ */
959
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
960
+ }, undefined>;
941
961
  /**
942
962
  * The server's response to a completion/complete request
943
963
  */
@@ -984,6 +1004,7 @@ declare module 'tmcp' {
984
1004
  type JSONRPCResponse = v.InferInput<typeof JSONRPCResponseSchema>;
985
1005
  type LoggingLevel = v.InferInput<typeof LoggingLevelSchema>;
986
1006
  type ToolAnnotations = v.InferInput<typeof ToolAnnotationsSchema>;
1007
+ type ElicitResult = v.InferInput<typeof ElicitResultSchema>;
987
1008
  // Helper type to remove whitespace
988
1009
  type Trim<S extends string> = S extends ` ${infer R}`
989
1010
  ? Trim<R>
@@ -21,6 +21,7 @@
21
21
  "LoggingLevelSchema",
22
22
  "CreateMessageRequestParamsSchema",
23
23
  "CreateMessageResultSchema",
24
+ "ElicitResultSchema",
24
25
  "CompleteResultSchema",
25
26
  "ServerCapabilities",
26
27
  "InitializeRequestParams",
@@ -33,6 +34,7 @@
33
34
  "JSONRPCResponse",
34
35
  "LoggingLevel",
35
36
  "ToolAnnotations",
37
+ "ElicitResult",
36
38
  "Trim",
37
39
  "ExtractVarName",
38
40
  "SplitVariables",
@@ -55,6 +57,6 @@
55
57
  null,
56
58
  null
57
59
  ],
58
- "mappings": ";;;;;cAqGaA,SAASA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aCk2CsCC,kBAAkBA;MC56ClEC,UAAUA;;;;;MAyCVC,aAAaA;;;;;;;;;;;;;MAabC,UAAUA;;;;;;MAMVC,WAAWA;;;;;;;MAaXC,SAASA;;;;;;;;;;;;ODARC,qBAAqBA;;;;;;;;;;;;;;OAuGrBC,wBAAwBA;;;;;;;;;;;;;;;;;;;;;;;OA6BxBC,6BAA6BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuB7BC,wBAAwBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmMxBC,cAAcA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4GdC,wBAAwBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8PxBC,qBAAqBA;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8ChCC,yBAAyBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6GzBC,kBAAkBA;;;;;;;;;;;;;;;;;;OAkFlBC,oBAAoBA;;;;;;;;;;;;;;;;;;;;;;MA8H2BC,kBAAkBA;MASbC,uBAAuBA;;;;;;;;;;;MAO5BC,kBAAkBA;MAGrBC,eAAeA;MAGhBC,cAAcA;MAGFC,0BAA0BA;MAGjCC,mBAAmBA;MAY9BC,QAAQA;MAMDC,eAAeA;MAGlBC,YAAYA;MAGTC,eAAeA;MAGlBC,YAAYA;;MEhgD7DC,IAAIA;;;;;;;MAOJC,cAAcA;;;;;;;MAOdC,cAAcA;;;;;MAKdC,qBAAqBA;;;;;;;;;;;;;;;;;MAiBrBC,4BAA4BA;;;;;;MAMrBC,2BAA2BA;;;;;;;OCjC1BC,iBAAiBA;;;;;;;;;;;;;;;;cAAjBA,iBAAiBA",
59
61
  "ignoreList": []
60
62
  }
@@ -1534,3 +1534,6 @@ export const ServerResultSchema = v.union([
1534
1534
  /**
1535
1535
  * @typedef {v.InferInput<typeof ToolAnnotationsSchema>} ToolAnnotations
1536
1536
  */
1537
+ /**
1538
+ * @typedef {v.InferInput<typeof ElicitResultSchema>} ElicitResult
1539
+ */