tmcp 1.18.0 → 1.19.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/src/index.js CHANGED
@@ -5,7 +5,8 @@
5
5
  * @import { JSONRPCRequest, JSONRPCParams } from "json-rpc-2.0";
6
6
  * @import { ExtractURITemplateVariables } from "./internal/uri-template.js";
7
7
  * @import { CallToolResult as CallToolResultType, ReadResourceResult as ReadResourceResultType, GetPromptResult as GetPromptResultType, ServerInfo as ServerInfoType, ClientCapabilities as ClientCapabilitiesType, JSONRPCRequest as JSONRPCRequestType, JSONRPCResponse, CreateMessageRequestParams as CreateMessageRequestParamsType, CreateMessageResult as CreateMessageResultType, Resource as ResourceType, LoggingLevel as LoggingLevelType, ToolAnnotations, ClientInfo as ClientInfoType, ElicitResult as ElicitResultType, Icons as IconsType, JSONRPCMessage, InitializeResult as InitializeResultType, ListToolsResult as ListToolsResultType, ListPromptsResult as ListPromptsResultType, ListResourceTemplatesResult as ListResourceTemplatesResultType, ListResourcesResult as ListResourcesResultType, CompleteResult as CompleteResultType } from "./validation/index.js";
8
- * @import { Tool, Completion, Prompt, StoredResource, ServerOptions, SubscriptionsKeys, ChangedArgs, McpEvents } from "./internal/internal.js";
8
+ * @import { Tool, Completion, Prompt, StoredResource, ServerOptions, SubscriptionsKeys, ChangedArgs, McpEvents, AllSame, TemplateOptions } from "./internal/internal.js";
9
+ * @import { CreatedTool, ToolOptions, CreatedPrompt, PromptOptions, CreatedResource, CreatedTemplate, ResourceOptions } from "./internal/internal.js";
9
10
  */
10
11
  import { JSONRPCClient, JSONRPCServer } from 'json-rpc-2.0';
11
12
  import { AsyncLocalStorage } from 'node:async_hooks';
@@ -860,6 +861,117 @@ export class McpServer {
860
861
  }
861
862
  }
862
863
 
864
+ /**
865
+ * Use the `defineTool` utility to create a reusable tool and pass it to this method to add it to the server.
866
+ * @template {Array<CreatedTool<any, any>>} T
867
+ * @template {T extends Array<CreatedTool<infer TSchema, infer TOutputSchema>> ? AllSame<TSchema, StandardSchema | undefined> extends true ? AllSame<TOutputSchema, StandardSchema | undefined> extends true ? T : never : never : never} U
868
+ * @param {T & NoInfer<U>} tools
869
+ */
870
+ tools(tools) {
871
+ for (const tool of tools) {
872
+ this.tool(
873
+ {
874
+ name: tool.name,
875
+ description: tool.description,
876
+ title: tool.title,
877
+ schema: tool.schema,
878
+ outputSchema: tool.outputSchema,
879
+ annotations: tool.annotations,
880
+ enabled: tool.enabled,
881
+ icons: tool.icons,
882
+ _meta: tool._meta,
883
+ },
884
+ // @ts-expect-error typescript doesn't know about execute because of an egregious hack to prevent it
885
+ // from showing in intellisense when declaring a tool inline
886
+ tool.execute,
887
+ );
888
+ }
889
+ }
890
+
891
+ /**
892
+ * Use the `definePrompt` utility to create a reusable tool and pass it to this method to add it to the server.
893
+ * @template {Array<CreatedPrompt<any>>} T
894
+ * @template {T extends Array<CreatedPrompt<infer TSchema>> ? AllSame<TSchema, StandardSchema | undefined> extends true ? T : never : never} U
895
+ * @param {T & NoInfer<U>} prompts
896
+ */
897
+ prompts(prompts) {
898
+ for (const prompt of prompts) {
899
+ this.prompt(
900
+ {
901
+ name: prompt.name,
902
+ description: prompt.description,
903
+ title: prompt.title,
904
+ schema: prompt.schema,
905
+ complete: prompt.complete,
906
+ enabled: prompt.enabled,
907
+ icons: prompt.icons,
908
+ },
909
+ // @ts-expect-error typescript doesn't know about execute because of an egregious hack to prevent it
910
+ // from showing in intellisense when declaring a tool inline
911
+ prompt.execute,
912
+ );
913
+ }
914
+ }
915
+
916
+ /**
917
+ * Use the `defineResource` utility to create a reusable resource and pass it to this method to add it to the server.
918
+ *
919
+ * @param {CreatedResource[]} resources
920
+ */
921
+ resources(resources) {
922
+ for (const resource of resources) {
923
+ this.resource(
924
+ {
925
+ name: resource.name,
926
+ description: resource.description,
927
+ title: resource.title,
928
+ uri: resource.uri,
929
+ enabled: resource.enabled,
930
+ icons: resource.icons,
931
+ },
932
+ // @ts-expect-error typescript doesn't know about execute because of an egregious hack to prevent it
933
+ // from showing in intellisense when declaring a tool inline
934
+ resource.execute,
935
+ );
936
+ }
937
+ }
938
+
939
+ /**
940
+ * Use the `defineTemplate` utility to create a reusable template and pass it to this method to add it to the server.
941
+ *
942
+ * @param {CreatedTemplate<any>[]} templates
943
+ */
944
+ templates(templates) {
945
+ for (const template of templates) {
946
+ this.template(
947
+ {
948
+ name: template.name,
949
+ description: template.description,
950
+ title: template.title,
951
+ uri: template.uri,
952
+ complete: template.complete,
953
+ list: template.list,
954
+ enabled: template.enabled,
955
+ icons: template.icons,
956
+ },
957
+ // @ts-expect-error typescript doesn't know about execute because of an egregious hack to prevent it
958
+ // from showing in intellisense when declaring a tool inline
959
+ template.execute,
960
+ );
961
+ }
962
+ }
963
+
964
+ /**
965
+ * Add a tool to the server. If you want to receive any input you need to provide a schema. The schema needs to be a valid Standard Schema V1 schema and needs to be an Object with the properties you need,
966
+ * Use the description and title to help the LLM to understand what the tool does and when to use it. If you provide an outputSchema, you need to return a structuredContent that matches the schema.
967
+ *
968
+ * 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.
969
+ * @template {StandardSchema | undefined} [TSchema=undefined]
970
+ * @template {StandardSchema | undefined} [TOutputSchema=undefined]
971
+ * @overload
972
+ * @param {CreatedTool<TSchema, TOutputSchema>} tool_or_options
973
+ * @returns {void}
974
+ */
863
975
  /**
864
976
  * Add a tool to the server. If you want to receive any input you need to provide a schema. The schema needs to be a valid Standard Schema V1 schema and needs to be an Object with the properties you need,
865
977
  * Use the description and title to help the LLM to understand what the tool does and when to use it. If you provide an outputSchema, you need to return a structuredContent that matches the schema.
@@ -867,8 +979,20 @@ export class McpServer {
867
979
  * 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.
868
980
  * @template {StandardSchema | undefined} [TSchema=undefined]
869
981
  * @template {StandardSchema | undefined} [TOutputSchema=undefined]
870
- * @param {{ name: string; _meta?: Record<string, any>; description: string; title?: string; enabled?: ()=>boolean | Promise<boolean>; schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never; outputSchema?: StandardSchemaV1.InferOutput<TOutputSchema extends undefined ? never : TOutputSchema> extends Record<string, unknown> ? TOutputSchema : never; annotations?: ToolAnnotations } & Icons} options
982
+ * @overload
983
+ * @param {ToolOptions<TSchema, TOutputSchema>} tool_or_options
871
984
  * @param {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>>)} execute
985
+ * @returns {void}
986
+ * */
987
+ /**
988
+ * Add a tool to the server. If you want to receive any input you need to provide a schema. The schema needs to be a valid Standard Schema V1 schema and needs to be an Object with the properties you need,
989
+ * Use the description and title to help the LLM to understand what the tool does and when to use it. If you provide an outputSchema, you need to return a structuredContent that matches the schema.
990
+ *
991
+ * 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.
992
+ * @template {StandardSchema | undefined} [TSchema=undefined]
993
+ * @template {StandardSchema | undefined} [TOutputSchema=undefined]
994
+ * @param {CreatedTool<TSchema, TOutputSchema> | ToolOptions<TSchema, TOutputSchema>} tool_or_options
995
+ * @param {undefined | 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>>)} [execute]
872
996
  */
873
997
  tool(
874
998
  {
@@ -881,9 +1005,15 @@ export class McpServer {
881
1005
  enabled,
882
1006
  icons,
883
1007
  _meta,
1008
+ ...tool_or_options
884
1009
  },
885
1010
  execute,
886
1011
  ) {
1012
+ if ('execute' in tool_or_options) {
1013
+ // @ts-expect-error typescript doesn't know about execute because of an egregious hack to prevent it
1014
+ // from showing in intellisense when declaring a tool inline
1015
+ execute = tool_or_options.execute;
1016
+ }
887
1017
  this.#notify_tools_list_changed();
888
1018
  this.#tools.set(name, {
889
1019
  description,
@@ -891,12 +1021,24 @@ export class McpServer {
891
1021
  enabled,
892
1022
  schema,
893
1023
  outputSchema,
894
- execute,
1024
+ execute: /** @type {NonNullable<typeof execute>} */ (execute),
895
1025
  annotations,
896
1026
  icons,
897
1027
  _meta,
898
1028
  });
899
1029
  }
1030
+
1031
+ /**
1032
+ * Add a prompt to the server. Prompts are used to provide the user with pre-defined messages that adds context to the LLM.
1033
+ * Use the description and title to help the user to understand what the prompt does and when to use it.
1034
+ *
1035
+ * A prompt can also have a schema that defines the input it expects, the user will be prompted to enter the inputs you request. It can also have a complete function
1036
+ * for each input that will be used to provide completions for the user.
1037
+ * @template {StandardSchema | undefined} [TSchema=undefined]
1038
+ * @overload
1039
+ * @param {CreatedPrompt<TSchema>} prompt_or_options
1040
+ * @returns {void}
1041
+ */
900
1042
  /**
901
1043
  * Add a prompt to the server. Prompts are used to provide the user with pre-defined messages that adds context to the LLM.
902
1044
  * Use the description and title to help the user to understand what the prompt does and when to use it.
@@ -904,13 +1046,39 @@ export class McpServer {
904
1046
  * A prompt can also have a schema that defines the input it expects, the user will be prompted to enter the inputs you request. It can also have a complete function
905
1047
  * for each input that will be used to provide completions for the user.
906
1048
  * @template {StandardSchema | undefined} [TSchema=undefined]
907
- * @param {{ name: string; description: string; title?: string; enabled?: ()=>boolean | Promise<boolean>; schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never; complete?: NoInfer<TSchema extends undefined ? never : Partial<Record<keyof (StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>), Completion>>> } & Icons} options
1049
+ * @overload
1050
+ * @param {PromptOptions<TSchema>} prompt_or_options
908
1051
  * @param {TSchema extends undefined ? (()=>Promise<GetPromptResult> | GetPromptResult) : (input: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>) => Promise<GetPromptResult> | GetPromptResult} execute
1052
+ * @returns {void}
1053
+ * */
1054
+ /**
1055
+ * Add a prompt to the server. Prompts are used to provide the user with pre-defined messages that adds context to the LLM.
1056
+ * Use the description and title to help the user to understand what the prompt does and when to use it.
1057
+ *
1058
+ * A prompt can also have a schema that defines the input it expects, the user will be prompted to enter the inputs you request. It can also have a complete function
1059
+ * for each input that will be used to provide completions for the user.
1060
+ * @template {StandardSchema | undefined} [TSchema=undefined]
1061
+ * @param {CreatedPrompt<TSchema> | PromptOptions<TSchema>} options
1062
+ * @param {TSchema extends undefined ? (()=>Promise<GetPromptResult> | GetPromptResult) : (input: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>) => Promise<GetPromptResult> | GetPromptResult} [execute]
909
1063
  */
910
1064
  prompt(
911
- { name, description, title, schema, complete, enabled, icons },
1065
+ {
1066
+ name,
1067
+ description,
1068
+ title,
1069
+ schema,
1070
+ complete,
1071
+ enabled,
1072
+ icons,
1073
+ ...prompt_or_options
1074
+ },
912
1075
  execute,
913
1076
  ) {
1077
+ if ('execute' in prompt_or_options) {
1078
+ // @ts-expect-error typescript doesn't know about execute because of an egregious hack to prevent it
1079
+ // from showing in intellisense when declaring a tool inline
1080
+ execute = prompt_or_options.execute;
1081
+ }
914
1082
  if (complete) {
915
1083
  this.#completions['ref/prompt'].set(name, complete);
916
1084
  }
@@ -919,7 +1087,7 @@ export class McpServer {
919
1087
  description,
920
1088
  title,
921
1089
  schema,
922
- execute,
1090
+ execute: /** @type {NonNullable<typeof execute>} */ (execute),
923
1091
  enabled,
924
1092
  icons,
925
1093
  });
@@ -941,16 +1109,47 @@ export class McpServer {
941
1109
  /**
942
1110
  * Add a resource to the server. Resources are added manually to the context by the user to provide the LLM with additional context.
943
1111
  * Use the description and title to help the user to understand what the resource is.
944
- * @param {{ name: string; description: string; title?: string; uri: string, enabled?: ()=>boolean | Promise<boolean>; } & Icons} options
1112
+ * @overload
1113
+ * @param {CreatedResource} resource_or_options
1114
+ * @returns {void}
1115
+ */
1116
+ /**
1117
+ * Add a resource to the server. Resources are added manually to the context by the user to provide the LLM with additional context.
1118
+ * Use the description and title to help the user to understand what the resource is.
1119
+ * @overload
1120
+ * @param {ResourceOptions} resource_or_options
945
1121
  * @param {(uri: string) => Promise<ReadResourceResult> | ReadResourceResult} execute
1122
+ * @returns {void}
946
1123
  */
947
- resource({ name, description, title, uri, enabled, icons }, execute) {
1124
+ /**
1125
+ * Add a resource to the server. Resources are added manually to the context by the user to provide the LLM with additional context.
1126
+ * Use the description and title to help the user to understand what the resource is.
1127
+ * @param {CreatedResource | ResourceOptions} resource_or_options
1128
+ * @param {(uri: string) => Promise<ReadResourceResult> | ReadResourceResult} [execute]
1129
+ */
1130
+ resource(
1131
+ {
1132
+ name,
1133
+ description,
1134
+ title,
1135
+ uri,
1136
+ enabled,
1137
+ icons,
1138
+ ...resource_or_options
1139
+ },
1140
+ execute,
1141
+ ) {
1142
+ if ('execute' in resource_or_options) {
1143
+ // @ts-expect-error typescript doesn't know about execute because of an egregious hack to prevent it
1144
+ // from showing in intellisense when declaring a tool inline
1145
+ execute = resource_or_options.execute;
1146
+ }
948
1147
  this.#resource({
949
1148
  name,
950
1149
  description,
951
1150
  title,
952
1151
  uri,
953
- execute,
1152
+ execute: /** @type {NonNullable<typeof execute>} */ (execute),
954
1153
  enabled,
955
1154
  icons,
956
1155
  template: false,
@@ -964,8 +1163,33 @@ export class McpServer {
964
1163
  * Use the description and title to help the user to understand what the resource is.
965
1164
  * @template {string} TUri
966
1165
  * @template {ExtractURITemplateVariables<TUri>} TVariables
967
- * @param {{ name: string; description: string; title?: string; enabled?: ()=>boolean | Promise<boolean>; uri: TUri; complete?: NoInfer<TVariables extends never ? never : Partial<Record<TVariables, Completion>>>; list?: () => Promise<Array<Resource>> | Array<Resource> } & Icons} options
1166
+ * @overload
1167
+ * @param {CreatedTemplate<TUri>} template_or_options
1168
+ * @returns {void}
1169
+ */
1170
+ /**
1171
+ * Add a resource template to the server. Resources are added manually to the context by the user to provide the LLM with additional context.
1172
+ * Resource templates are used to create resources dynamically based on a URI template. The URI template should be a valid URI template as defined in RFC 6570.
1173
+ * Resource templates can have a list method that returns a list of resources that match the template and a complete method that returns a list of resources given one of the template variables, this method will
1174
+ * be invoked to provide completions for the template variables to the user.
1175
+ * Use the description and title to help the user to understand what the resource is.
1176
+ * @template {string} TUri
1177
+ * @template {ExtractURITemplateVariables<TUri>} TVariables
1178
+ * @overload
1179
+ * @param {TemplateOptions<TUri>} template_or_options
968
1180
  * @param {(uri: string, params: Record<TVariables, string | string[]>) => Promise<ReadResourceResult> | ReadResourceResult} execute
1181
+ * @returns {void}
1182
+ */
1183
+ /**
1184
+ * Add a resource template to the server. Resources are added manually to the context by the user to provide the LLM with additional context.
1185
+ * Resource templates are used to create resources dynamically based on a URI template. The URI template should be a valid URI template as defined in RFC 6570.
1186
+ * Resource templates can have a list method that returns a list of resources that match the template and a complete method that returns a list of resources given one of the template variables, this method will
1187
+ * be invoked to provide completions for the template variables to the user.
1188
+ * Use the description and title to help the user to understand what the resource is.
1189
+ * @template {string} TUri
1190
+ * @template {ExtractURITemplateVariables<TUri>} TVariables
1191
+ * @param {CreatedTemplate<TUri> | TemplateOptions<TUri>} template_or_options
1192
+ * @param {(uri: string, params: Record<TVariables, string | string[]>) => Promise<ReadResourceResult> | ReadResourceResult} [execute]
969
1193
  */
970
1194
  template(
971
1195
  {
@@ -977,16 +1201,22 @@ export class McpServer {
977
1201
  list: list_resources,
978
1202
  enabled,
979
1203
  icons,
1204
+ ...template_or_options
980
1205
  },
981
1206
  execute,
982
1207
  ) {
1208
+ if ('execute' in template_or_options) {
1209
+ // @ts-expect-error typescript doesn't know about execute because of an egregious hack to prevent it
1210
+ // from showing in intellisense when declaring a tool inline
1211
+ execute = template_or_options.execute;
1212
+ }
983
1213
  this.#resource({
984
1214
  name,
985
1215
  enabled,
986
1216
  description,
987
1217
  title,
988
1218
  uri,
989
- execute,
1219
+ execute: /** @type {NonNullable<typeof execute>} */ (execute),
990
1220
  complete,
991
1221
  icons,
992
1222
  list_resources,
@@ -13,6 +13,57 @@ import {
13
13
  ToolAnnotations,
14
14
  Icons
15
15
  } from '../validation/index.js';
16
+ import { ExtractURITemplateVariables } from './uri-template.js';
17
+
18
+ declare const created_tool: unique symbol;
19
+ declare const created_prompt: unique symbol;
20
+ declare const created_resource: unique symbol;
21
+ declare const created_template: unique symbol;
22
+
23
+ export type AllSame<T, U> = [T] extends [U] ? true : false;
24
+
25
+ export type PromptOptions<TSchema extends StandardSchemaV1 | undefined = undefined> = {
26
+ name: string;
27
+ description: string;
28
+ title?: string;
29
+ enabled?: ()=>boolean | Promise<boolean>;
30
+ schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never;
31
+ complete?: NoInfer<TSchema extends undefined ? never : Partial<Record<keyof (StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>), Completion>>>
32
+ } & Icons
33
+
34
+ export type ToolOptions<TSchema extends StandardSchemaV1 | undefined = undefined, TOutputSchema extends StandardSchemaV1 | undefined = undefined> = {
35
+ name: string;
36
+ _meta?: Record<string, any>;
37
+ description: string;
38
+ title?: string;
39
+ enabled?: () => boolean | Promise<boolean>;
40
+ schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never;
41
+ outputSchema?: StandardSchemaV1.InferOutput<TOutputSchema extends undefined ? never : TOutputSchema> extends Record<string, unknown> ? TOutputSchema : never;
42
+ annotations?: ToolAnnotations;
43
+ } & Icons;
44
+
45
+ export type ResourceOptions = {
46
+ name: string;
47
+ description: string;
48
+ title?: string;
49
+ uri: string,
50
+ enabled?: ()=>boolean | Promise<boolean>;
51
+ } & Icons
52
+
53
+ export type TemplateOptions<TUri extends string = string, TVariables extends ExtractURITemplateVariables<TUri> = ExtractURITemplateVariables<TUri>> = {
54
+ name: string;
55
+ description: string;
56
+ title?: string;
57
+ enabled?: ()=>boolean | Promise<boolean>;
58
+ uri: TUri;
59
+ complete?: NoInfer<TVariables extends never ? never : Partial<Record<TVariables, Completion>>>;
60
+ list?: () => Promise<Array<Resource>> | Array<Resource>
61
+ } & Icons
62
+
63
+ export type CreatedTool<TSchema extends StandardSchemaV1 | undefined = undefined, TOutputSchema extends StandardSchemaV1 | undefined = undefined> = ToolOptions<TSchema, TOutputSchema> & { [created_tool]: created_tool };
64
+ export type CreatedPrompt<TSchema extends StandardSchemaV1 | undefined = undefined> = PromptOptions<TSchema> & { [created_prompt]: created_prompt };
65
+ export type CreatedResource = ResourceOptions & { [created_resource]: created_resource };
66
+ export type CreatedTemplate<TUri extends string = string> = TemplateOptions<TUri> & { [created_template]: created_template };
16
67
 
17
68
  export type Tool<TSchema extends StandardSchemaV1 = StandardSchemaV1<any>, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1<any>> = {
18
69
  description: string;
package/src/prompt.js ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @import { StandardSchemaV1 } from "@standard-schema/spec";
3
+ * @import { PromptOptions, CreatedPrompt } from "./internal/internal.js";
4
+ * @import { GetPromptResult } from "./validation/index.js"
5
+ */
6
+
7
+ /**
8
+ * Add a tool to the server. If you want to receive any input you need to provide a schema. The schema needs to be a valid Standard Schema V1 schema and needs to be an Object with the properties you need,
9
+ * Use the description and title to help the LLM to understand what the tool does and when to use it. If you provide an outputSchema, you need to return a structuredContent that matches the schema.
10
+ *
11
+ * @template {StandardSchemaV1 | undefined} [TSchema=undefined]
12
+ * @param {PromptOptions<TSchema>} options
13
+ * @param {TSchema extends undefined ? (()=>Promise<GetPromptResult> | GetPromptResult) : (input: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>) => Promise<GetPromptResult> | GetPromptResult} execute
14
+ */
15
+ export function definePrompt(options, execute) {
16
+ // eslint-disable-next-line jsdoc/no-undefined-types
17
+ return /** @type {CreatedPrompt<TSchema>} */ (
18
+ /** @type {unknown} */ ({
19
+ ...options,
20
+ execute,
21
+ })
22
+ );
23
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @import { ResourceOptions, CreatedResource } from "./internal/internal.js";
3
+ * @import { ReadResourceResult } from "./validation/index.js";
4
+ */
5
+
6
+ /**
7
+ * Add a resource to the server. Resources are added manually to the context by the user to provide the LLM with additional context.
8
+ * Use the description and title to help the user to understand what the resource is.
9
+ *
10
+ * @param {ResourceOptions} options
11
+ * @param {(uri: string) => Promise<ReadResourceResult> | ReadResourceResult} execute
12
+ */
13
+ export function defineResource(options, execute) {
14
+ return /** @type {CreatedResource} */ (
15
+ /** @type {unknown} */ ({
16
+ ...options,
17
+ execute,
18
+ })
19
+ );
20
+ }
@@ -0,0 +1,27 @@
1
+ /* eslint-disable jsdoc/no-undefined-types */
2
+ /**
3
+ * @import { ExtractURITemplateVariables } from "./internal/uri-template.js";
4
+ * @import { TemplateOptions, CreatedTemplate } from "./internal/internal.js";
5
+ * @import { ReadResourceResult } from "./validation/index.js";
6
+ */
7
+
8
+ /**
9
+ * Add a resource template to the server. Resources are added manually to the context by the user to provide the LLM with additional context.
10
+ * Resource templates are used to create resources dynamically based on a URI template. The URI template should be a valid URI template as defined in RFC 6570.
11
+ * Resource templates can have a list method that returns a list of resources that match the template and a complete method that returns a list of resources given one of the template variables, this method will
12
+ * be invoked to provide completions for the template variables to the user.
13
+ * Use the description and title to help the user to understand what the resource is.
14
+ *
15
+ * @template {string} TUri
16
+ * @template {ExtractURITemplateVariables<TUri>} TVariables
17
+ * @param {TemplateOptions<TUri>} options
18
+ * @param {(uri: string, params: Record<TVariables, string | string[]>) => Promise<ReadResourceResult> | ReadResourceResult} execute
19
+ */
20
+ export function defineTemplate(options, execute) {
21
+ return /** @type {CreatedTemplate<TUri>} */ (
22
+ /** @type {unknown} */ ({
23
+ ...options,
24
+ execute,
25
+ })
26
+ );
27
+ }
package/src/tool.js ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @import { StandardSchemaV1 } from "@standard-schema/spec";
3
+ * @import { ToolOptions, CreatedTool } from "./internal/internal.js";
4
+ */
5
+
6
+ /**
7
+ * Add a tool to the server. If you want to receive any input you need to provide a schema. The schema needs to be a valid Standard Schema V1 schema and needs to be an Object with the properties you need,
8
+ * Use the description and title to help the LLM to understand what the tool does and when to use it. If you provide an outputSchema, you need to return a structuredContent that matches the schema.
9
+ *
10
+ * @template {StandardSchemaV1 | undefined} [TSchema=undefined]
11
+ * @template {StandardSchemaV1 | undefined} [TOutputSchema=undefined]
12
+ * @param {ToolOptions<TSchema, TOutputSchema>} options
13
+ * @param {TSchema extends undefined ? (()=>Promise<import("./index.js").CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>> | import("./index.js").CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>) : ((input: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>) => Promise<import("./index.js").CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>> | import("./index.js").CallToolResult<TOutputSchema extends undefined ? undefined : StandardSchemaV1.InferInput<TOutputSchema extends undefined ? never : TOutputSchema>>)} execute
14
+ */
15
+ export function defineTool(options, execute) {
16
+ // eslint-disable-next-line jsdoc/no-undefined-types
17
+ return /** @type {CreatedTool<TSchema, TOutputSchema>} */ (
18
+ /** @type {unknown} */ ({
19
+ ...options,
20
+ execute,
21
+ })
22
+ );
23
+ }