tmcp 1.12.1 → 1.13.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.1",
3
+ "version": "1.13.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,7 @@ import {
23
23
  JSONRPCResponseSchema,
24
24
  McpError,
25
25
  ReadResourceResultSchema,
26
+ ElicitResultSchema,
26
27
  } from './validation/index.js';
27
28
  import {
28
29
  get_supported_versions,
@@ -1004,25 +1005,27 @@ export class McpServer {
1004
1005
  * @template {StandardSchema extends undefined ? never : StandardSchema} TSchema
1005
1006
  * @param {string} message
1006
1007
  * @param {TSchema} schema
1007
- * @returns {Promise<StandardSchemaV1.InferOutput<TSchema>>}
1008
+ * @returns {Promise<ElicitResult & { content?: StandardSchemaV1.InferOutput<TSchema> }>}
1008
1009
  */
1009
1010
  async elicitation(message, schema) {
1010
1011
  if (!this.#client_capabilities?.elicitation)
1011
1012
  throw new McpError(-32601, "Client doesn't support elicitation");
1012
1013
 
1013
1014
  this.#lazyily_create_client();
1015
+ const result = 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
+ );
1026
+ const elicit_result = v.parse(ElicitResultSchema, result);
1014
1027
  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
- ),
1028
+ elicit_result.content,
1026
1029
  );
1027
1030
  if (validated_result instanceof Promise)
1028
1031
  validated_result = await validated_result;
@@ -1032,7 +1035,7 @@ export class McpServer {
1032
1035
  `Invalid elicitation result: ${JSON.stringify(validated_result.issues)}`,
1033
1036
  );
1034
1037
  }
1035
- return validated_result.value;
1038
+ return { ...elicit_result, content: validated_result.value };
1036
1039
  }
1037
1040
 
1038
1041
  /**
@@ -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
  */
@@ -965,11 +985,16 @@ declare module 'tmcp' {
965
985
  type ClientCapabilities_1 = v.InferInput<typeof ClientCapabilitiesSchema>;
966
986
  type ServerCapabilities = v.InferInput<typeof ServerCapabilitiesSchema>;
967
987
  type InitializeRequestParams = v.InferInput<typeof InitializeRequestParamsSchema>;
968
- type CallToolResult<TStructuredContent extends Record<string, unknown> | undefined> = Omit<v.InferInput<typeof CallToolResultSchema>, "structuredContent"> & (undefined extends TStructuredContent ? {
988
+ type CallToolResult<TStructuredContent extends Record<string, unknown> | undefined> = Omit<v.InferInput<typeof CallToolResultSchema>, "structuredContent" | "isError"> & (undefined extends TStructuredContent ? {
969
989
  structuredContent?: undefined;
970
- } : {
990
+ isError?: boolean;
991
+ } : ({
971
992
  structuredContent: TStructuredContent;
972
- });
993
+ isError?: false;
994
+ } | {
995
+ isError: true;
996
+ structuredContent?: TStructuredContent;
997
+ }));
973
998
  type ReadResourceResult = v.InferInput<typeof ReadResourceResultSchema>;
974
999
  type GetPromptResult = v.InferInput<typeof GetPromptResultSchema>;
975
1000
  type CompleteResult = v.InferInput<typeof CompleteResultSchema>;
@@ -979,6 +1004,7 @@ declare module 'tmcp' {
979
1004
  type JSONRPCResponse = v.InferInput<typeof JSONRPCResponseSchema>;
980
1005
  type LoggingLevel = v.InferInput<typeof LoggingLevelSchema>;
981
1006
  type ToolAnnotations = v.InferInput<typeof ToolAnnotationsSchema>;
1007
+ type ElicitResult = v.InferInput<typeof ElicitResultSchema>;
982
1008
  // Helper type to remove whitespace
983
1009
  type Trim<S extends string> = S extends ` ${infer R}`
984
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,wBAAwB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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoEpBC,kBAAkBA;OAuGlBC,gCAAgCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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
  }
@@ -1493,7 +1493,7 @@ export const ServerResultSchema = v.union([
1493
1493
  */
1494
1494
  /**
1495
1495
  * @template {Record<string, unknown> | undefined} TStructuredContent
1496
- * @typedef {Omit<v.InferInput<typeof CallToolResultSchema>, "structuredContent"> & (undefined extends TStructuredContent ? { structuredContent?: undefined } : { structuredContent: TStructuredContent })} CallToolResult
1496
+ * @typedef {Omit<v.InferInput<typeof CallToolResultSchema>, "structuredContent" | "isError"> & (undefined extends TStructuredContent ? { structuredContent?: undefined, isError?: boolean } : ({ structuredContent: TStructuredContent, isError?: false } | { isError: true, structuredContent?: TStructuredContent }))} CallToolResult
1497
1497
  */
1498
1498
  /**
1499
1499
  * @typedef {v.InferInput<typeof ReadResourceResultSchema>} ReadResourceResult
@@ -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
+ */