tmcp 1.18.1 → 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.
@@ -1,3 +1,7 @@
1
+ const created_tool: unique symbol;
2
+ const created_prompt: unique symbol;
3
+ const created_resource: unique symbol;
4
+ const created_template: unique symbol;
1
5
  declare module 'tmcp' {
2
6
  import type { StandardSchemaV1 } from '@standard-schema/spec';
3
7
  import type { JSONRPCServer, JSONRPCClient, JSONRPCParams, JSONRPCRequest } from 'json-rpc-2.0';
@@ -50,22 +54,38 @@ declare module 'tmcp' {
50
54
  } | undefined;
51
55
 
52
56
  on<TEvent extends keyof McpEvents>(event: TEvent, callback: McpEvents[TEvent], options?: AddEventListenerOptions): () => void;
57
+ /**
58
+ * Use the `defineTool` utility to create a reusable tool and pass it to this method to add it to the server.
59
+ * */
60
+ tools<T extends Array<CreatedTool<any, any>>, U extends T extends Array<CreatedTool<infer TSchema, infer TOutputSchema>> ? AllSame<TSchema, StandardSchema | undefined> extends true ? AllSame<TOutputSchema, StandardSchema | undefined> extends true ? T : never : never : never>(tools: T & NoInfer<U>): void;
61
+ /**
62
+ * Use the `definePrompt` utility to create a reusable tool and pass it to this method to add it to the server.
63
+ * */
64
+ prompts<T extends Array<CreatedPrompt<any>>, U extends T extends Array<CreatedPrompt<infer TSchema>> ? AllSame<TSchema, StandardSchema | undefined> extends true ? T : never : never>(prompts: T & NoInfer<U>): void;
65
+ /**
66
+ * Use the `defineResource` utility to create a reusable resource and pass it to this method to add it to the server.
67
+ *
68
+ * */
69
+ resources(resources: CreatedResource[]): void;
70
+ /**
71
+ * Use the `defineTemplate` utility to create a reusable template and pass it to this method to add it to the server.
72
+ *
73
+ * */
74
+ templates(templates: CreatedTemplate<any>[]): void;
53
75
  /**
54
76
  * 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,
55
77
  * 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.
56
78
  *
57
79
  * 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.
58
80
  * */
59
- tool<TSchema extends StandardSchema | undefined = undefined, TOutputSchema extends StandardSchema | undefined = undefined>({ name, description, title, schema, outputSchema, annotations, enabled, icons, _meta, }: {
60
- name: string;
61
- _meta?: Record<string, any>;
62
- description: string;
63
- title?: string;
64
- enabled?: () => boolean | Promise<boolean>;
65
- schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never;
66
- outputSchema?: StandardSchemaV1.InferOutput<TOutputSchema extends undefined ? never : TOutputSchema> extends Record<string, unknown> ? TOutputSchema : never;
67
- annotations?: ToolAnnotations;
68
- } & Icons, 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;
81
+ tool<TSchema extends StandardSchema | undefined = undefined, TOutputSchema extends StandardSchema | undefined = undefined>(tool_or_options: CreatedTool<TSchema, TOutputSchema>): void;
82
+ /**
83
+ * 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,
84
+ * 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.
85
+ *
86
+ * 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.
87
+ * */
88
+ 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;
69
89
  /**
70
90
  * Add a prompt to the server. Prompts are used to provide the user with pre-defined messages that adds context to the LLM.
71
91
  * Use the description and title to help the user to understand what the prompt does and when to use it.
@@ -73,25 +93,25 @@ declare module 'tmcp' {
73
93
  * 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
74
94
  * for each input that will be used to provide completions for the user.
75
95
  * */
76
- prompt<TSchema extends StandardSchema | undefined = undefined>({ name, description, title, schema, complete, enabled, icons }: {
77
- name: string;
78
- description: string;
79
- title?: string;
80
- enabled?: () => boolean | Promise<boolean>;
81
- schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never;
82
- complete?: NoInfer<TSchema extends undefined ? never : Partial<Record<keyof StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>, Completion>>>;
83
- } & Icons, execute: TSchema extends undefined ? (() => Promise<GetPromptResult> | GetPromptResult) : (input: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>) => Promise<GetPromptResult> | GetPromptResult): void;
96
+ prompt<TSchema extends StandardSchema | undefined = undefined>(prompt_or_options: CreatedPrompt<TSchema>): void;
97
+ /**
98
+ * Add a prompt to the server. Prompts are used to provide the user with pre-defined messages that adds context to the LLM.
99
+ * Use the description and title to help the user to understand what the prompt does and when to use it.
100
+ *
101
+ * 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
102
+ * for each input that will be used to provide completions for the user.
103
+ * */
104
+ prompt<TSchema extends StandardSchema | undefined = undefined>(prompt_or_options: PromptOptions<TSchema>, execute: TSchema extends undefined ? (() => Promise<GetPromptResult> | GetPromptResult) : (input: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>) => Promise<GetPromptResult> | GetPromptResult): void;
84
105
  /**
85
106
  * Add a resource to the server. Resources are added manually to the context by the user to provide the LLM with additional context.
86
107
  * Use the description and title to help the user to understand what the resource is.
87
108
  * */
88
- resource({ name, description, title, uri, enabled, icons }: {
89
- name: string;
90
- description: string;
91
- title?: string;
92
- uri: string;
93
- enabled?: () => boolean | Promise<boolean>;
94
- } & Icons, execute: (uri: string) => Promise<ReadResourceResult> | ReadResourceResult): void;
109
+ resource(resource_or_options: CreatedResource): void;
110
+ /**
111
+ * Add a resource to the server. Resources are added manually to the context by the user to provide the LLM with additional context.
112
+ * Use the description and title to help the user to understand what the resource is.
113
+ * */
114
+ resource(resource_or_options: ResourceOptions, execute: (uri: string) => Promise<ReadResourceResult> | ReadResourceResult): void;
95
115
  /**
96
116
  * Add a resource template to the server. Resources are added manually to the context by the user to provide the LLM with additional context.
97
117
  * 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.
@@ -99,15 +119,15 @@ declare module 'tmcp' {
99
119
  * be invoked to provide completions for the template variables to the user.
100
120
  * Use the description and title to help the user to understand what the resource is.
101
121
  * */
102
- template<TUri extends string, TVariables extends ExtractURITemplateVariables<TUri>>({ name, description, title, uri, complete, list: list_resources, enabled, icons, }: {
103
- name: string;
104
- description: string;
105
- title?: string;
106
- enabled?: () => boolean | Promise<boolean>;
107
- uri: TUri;
108
- complete?: NoInfer<TVariables extends never ? never : Partial<Record<TVariables, Completion>>>;
109
- list?: () => Promise<Array<Resource>> | Array<Resource>;
110
- } & Icons, execute: (uri: string, params: Record<TVariables, string | string[]>) => Promise<ReadResourceResult> | ReadResourceResult): void;
122
+ template<TUri extends string, TVariables extends ExtractURITemplateVariables<TUri>>(template_or_options: CreatedTemplate<TUri>): void;
123
+ /**
124
+ * Add a resource template to the server. Resources are added manually to the context by the user to provide the LLM with additional context.
125
+ * 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.
126
+ * 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
127
+ * be invoked to provide completions for the template variables to the user.
128
+ * Use the description and title to help the user to understand what the resource is.
129
+ * */
130
+ 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;
111
131
  /**
112
132
  * The main function that receive a JSONRpc message and either dispatch a `send` event or process the request.
113
133
  *
@@ -220,6 +240,52 @@ declare module 'tmcp' {
220
240
  export type ListResourceTemplatesResult = ListResourceTemplatesResult_1;
221
241
  export type ListResourcesResult = ListResourcesResult_1;
222
242
  export type CompleteResult = CompleteResult_1;
243
+
244
+ type AllSame<T, U> = [T] extends [U] ? true : false;
245
+
246
+ type PromptOptions<TSchema extends StandardSchemaV1 | undefined = undefined> = {
247
+ name: string;
248
+ description: string;
249
+ title?: string;
250
+ enabled?: ()=>boolean | Promise<boolean>;
251
+ schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never;
252
+ complete?: NoInfer<TSchema extends undefined ? never : Partial<Record<keyof (StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>), Completion>>>
253
+ } & Icons_1
254
+
255
+ type ToolOptions<TSchema extends StandardSchemaV1 | undefined = undefined, TOutputSchema extends StandardSchemaV1 | undefined = undefined> = {
256
+ name: string;
257
+ _meta?: Record<string, any>;
258
+ description: string;
259
+ title?: string;
260
+ enabled?: () => boolean | Promise<boolean>;
261
+ schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never;
262
+ outputSchema?: StandardSchemaV1.InferOutput<TOutputSchema extends undefined ? never : TOutputSchema> extends Record<string, unknown> ? TOutputSchema : never;
263
+ annotations?: ToolAnnotations;
264
+ } & Icons_1;
265
+
266
+ type ResourceOptions = {
267
+ name: string;
268
+ description: string;
269
+ title?: string;
270
+ uri: string,
271
+ enabled?: ()=>boolean | Promise<boolean>;
272
+ } & Icons_1
273
+
274
+ type TemplateOptions<TUri extends string = string, TVariables extends ExtractURITemplateVariables<TUri> = ExtractURITemplateVariables<TUri>> = {
275
+ name: string;
276
+ description: string;
277
+ title?: string;
278
+ enabled?: ()=>boolean | Promise<boolean>;
279
+ uri: TUri;
280
+ complete?: NoInfer<TVariables extends never ? never : Partial<Record<TVariables, Completion>>>;
281
+ list?: () => Promise<Array<Resource_1>> | Array<Resource_1>
282
+ } & Icons_1
283
+
284
+ type CreatedTool<TSchema extends StandardSchemaV1 | undefined = undefined, TOutputSchema extends StandardSchemaV1 | undefined = undefined> = ToolOptions<TSchema, TOutputSchema> & { [created_tool]: created_tool };
285
+ type CreatedPrompt<TSchema extends StandardSchemaV1 | undefined = undefined> = PromptOptions<TSchema> & { [created_prompt]: created_prompt };
286
+ type CreatedResource = ResourceOptions & { [created_resource]: created_resource };
287
+ type CreatedTemplate<TUri extends string = string> = TemplateOptions<TUri> & { [created_template]: created_template };
288
+
223
289
  type Completion = (
224
290
  query: string,
225
291
  context: { arguments: Record<string, string> },
@@ -263,6 +329,51 @@ declare module 'tmcp' {
263
329
  subscription: (subscriptions_request: { uri: string, action?: "add" | "remove" }) => void;
264
330
  loglevelchange: (change: { level: LoggingLevel_1 }) => void;
265
331
  };
332
+ // Helper type to remove whitespace
333
+ type Trim<S extends string> = S extends ` ${infer R}`
334
+ ? Trim<R>
335
+ : S extends `${infer L} `
336
+ ? Trim<L>
337
+ : S;
338
+
339
+ // Helper type to extract variable name, removing modifiers
340
+ type ExtractVarName<S extends string> = S extends `${infer Name}:${string}`
341
+ ? Trim<Name> // Remove prefix modifier
342
+ : S extends `${infer Name}*`
343
+ ? Trim<Name> // Remove explode modifier
344
+ : Trim<S>;
345
+
346
+ // Helper type to split comma-separated variables
347
+ type SplitVariables<S extends string> = S extends `${infer First},${infer Rest}`
348
+ ? ExtractVarName<First> | SplitVariables<Rest>
349
+ : ExtractVarName<S>;
350
+
351
+ // Helper type to extract content from braces and handle operators
352
+ type ExtractFromExpression<S extends string> = S extends `+${infer Vars}`
353
+ ? SplitVariables<Vars> // Reserved {+var}
354
+ : S extends `#${infer Vars}`
355
+ ? SplitVariables<Vars> // Fragment {#var}
356
+ : S extends `.${infer Vars}`
357
+ ? SplitVariables<Vars> // Label {.var}
358
+ : S extends `/${infer Vars}`
359
+ ? SplitVariables<Vars> // Path {/var}
360
+ : S extends `;${infer Vars}`
361
+ ? SplitVariables<Vars> // Path-style {;var}
362
+ : S extends `?${infer Vars}`
363
+ ? SplitVariables<Vars> // Query {?var}
364
+ : S extends `&${infer Vars}`
365
+ ? SplitVariables<Vars> // Query continuation {&var}
366
+ : SplitVariables<S>; // Simple {var}
367
+
368
+ // Main recursive type to extract all variables from URI template
369
+ type ExtractVariablesFromTemplate<S extends string> =
370
+ S extends `${string}{${infer Expression}}${infer Rest}`
371
+ ? ExtractFromExpression<Expression> | ExtractVariablesFromTemplate<Rest>
372
+ : never;
373
+
374
+ // Main exported type
375
+ type ExtractURITemplateVariables<T extends string> =
376
+ ExtractVariablesFromTemplate<T>;
266
377
  const JSONRPCMessageSchema: v.UnionSchema<[v.ObjectSchema<{
267
378
  readonly method: v.StringSchema<undefined>;
268
379
  readonly params: v.OptionalSchema<v.LooseObjectSchema<{
@@ -1747,51 +1858,6 @@ declare module 'tmcp' {
1747
1858
  type ListPromptsResult_1 = v.InferInput<typeof ListPromptsResultSchema>;
1748
1859
  type ListResourcesResult_1 = v.InferInput<typeof ListResourcesResultSchema>;
1749
1860
  type ListResourceTemplatesResult_1 = v.InferInput<typeof ListResourceTemplatesResultSchema>;
1750
- // Helper type to remove whitespace
1751
- type Trim<S extends string> = S extends ` ${infer R}`
1752
- ? Trim<R>
1753
- : S extends `${infer L} `
1754
- ? Trim<L>
1755
- : S;
1756
-
1757
- // Helper type to extract variable name, removing modifiers
1758
- type ExtractVarName<S extends string> = S extends `${infer Name}:${string}`
1759
- ? Trim<Name> // Remove prefix modifier
1760
- : S extends `${infer Name}*`
1761
- ? Trim<Name> // Remove explode modifier
1762
- : Trim<S>;
1763
-
1764
- // Helper type to split comma-separated variables
1765
- type SplitVariables<S extends string> = S extends `${infer First},${infer Rest}`
1766
- ? ExtractVarName<First> | SplitVariables<Rest>
1767
- : ExtractVarName<S>;
1768
-
1769
- // Helper type to extract content from braces and handle operators
1770
- type ExtractFromExpression<S extends string> = S extends `+${infer Vars}`
1771
- ? SplitVariables<Vars> // Reserved {+var}
1772
- : S extends `#${infer Vars}`
1773
- ? SplitVariables<Vars> // Fragment {#var}
1774
- : S extends `.${infer Vars}`
1775
- ? SplitVariables<Vars> // Label {.var}
1776
- : S extends `/${infer Vars}`
1777
- ? SplitVariables<Vars> // Path {/var}
1778
- : S extends `;${infer Vars}`
1779
- ? SplitVariables<Vars> // Path-style {;var}
1780
- : S extends `?${infer Vars}`
1781
- ? SplitVariables<Vars> // Query {?var}
1782
- : S extends `&${infer Vars}`
1783
- ? SplitVariables<Vars> // Query continuation {&var}
1784
- : SplitVariables<S>; // Simple {var}
1785
-
1786
- // Main recursive type to extract all variables from URI template
1787
- type ExtractVariablesFromTemplate<S extends string> =
1788
- S extends `${string}{${infer Expression}}${infer Rest}`
1789
- ? ExtractFromExpression<Expression> | ExtractVariablesFromTemplate<Rest>
1790
- : never;
1791
-
1792
- // Main exported type
1793
- type ExtractURITemplateVariables<T extends string> =
1794
- ExtractVariablesFromTemplate<T>;
1795
1861
  /**
1796
1862
  * @import { StandardSchemaV1 } from "@standard-schema/spec";
1797
1863
  * @import { JSONSchema7 } from "json-schema";
@@ -1805,6 +1871,917 @@ declare module 'tmcp' {
1805
1871
  export {};
1806
1872
  }
1807
1873
 
1874
+ declare module 'tmcp/tool' {
1875
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
1876
+ import * as v from 'valibot';
1877
+ /**
1878
+ * @import { StandardSchemaV1 } from "@standard-schema/spec";
1879
+ * @import { ToolOptions, CreatedTool } from "./internal/internal.js";
1880
+ */
1881
+ /**
1882
+ * 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,
1883
+ * 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.
1884
+ *
1885
+ * */
1886
+ 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>;
1887
+ type CallToolResult<TStructuredContent extends Record<string, unknown> | undefined> = CallToolResult_1<TStructuredContent>;
1888
+
1889
+ type ToolOptions<TSchema extends StandardSchemaV1 | undefined = undefined, TOutputSchema extends StandardSchemaV1 | undefined = undefined> = {
1890
+ name: string;
1891
+ _meta?: Record<string, any>;
1892
+ description: string;
1893
+ title?: string;
1894
+ enabled?: () => boolean | Promise<boolean>;
1895
+ schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never;
1896
+ outputSchema?: StandardSchemaV1.InferOutput<TOutputSchema extends undefined ? never : TOutputSchema> extends Record<string, unknown> ? TOutputSchema : never;
1897
+ annotations?: ToolAnnotations;
1898
+ } & Icons;
1899
+
1900
+ type CreatedTool<TSchema extends StandardSchemaV1 | undefined = undefined, TOutputSchema extends StandardSchemaV1 | undefined = undefined> = ToolOptions<TSchema, TOutputSchema> & { [created_tool]: created_tool };
1901
+ const IconsSchema: v.ObjectSchema<{
1902
+ /**
1903
+ * Optional set of sized icons that the client can display in a user interface.
1904
+ *
1905
+ * Clients that support rendering icons MUST support at least the following MIME types:
1906
+ * - `image/png` - PNG images (safe, universal compatibility)
1907
+ * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
1908
+ *
1909
+ * Clients that support rendering icons SHOULD also support:
1910
+ * - `image/svg+xml` - SVG images (scalable but requires security precautions)
1911
+ * - `image/webp` - WebP images (modern, efficient format)
1912
+ */
1913
+ readonly icons: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
1914
+ /**
1915
+ * URL or data URI for the icon.
1916
+ */
1917
+ readonly src: v.StringSchema<undefined>;
1918
+ /**
1919
+ * Optional MIME type for the icon.
1920
+ */
1921
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
1922
+ /**
1923
+ * Optional array of strings that specify sizes at which the icon can be used.
1924
+ * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
1925
+ *
1926
+ * If not provided, the client should assume that the icon can be used at any size.
1927
+ */
1928
+ readonly sizes: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
1929
+ }, undefined>, undefined>, undefined>;
1930
+ }, undefined>;
1931
+ /**
1932
+ * Additional properties describing a Tool to clients.
1933
+ *
1934
+ * NOTE: all properties in ToolAnnotations are **hints**.
1935
+ * They are not guaranteed to provide a faithful description of
1936
+ * tool behavior (including descriptive properties like `title`).
1937
+ *
1938
+ * Clients should never make tool use decisions based on ToolAnnotations
1939
+ * received from untrusted servers.
1940
+ */
1941
+ const ToolAnnotationsSchema: v.ObjectSchema<{
1942
+ /**
1943
+ * A human-readable title for the tool.
1944
+ */
1945
+ readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
1946
+ /**
1947
+ * If true, the tool does not modify its environment.
1948
+ *
1949
+ * Default: false
1950
+ */
1951
+ readonly readOnlyHint: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
1952
+ /**
1953
+ * If true, the tool may perform destructive updates to its environment.
1954
+ * If false, the tool performs only additive updates.
1955
+ *
1956
+ * (This property is meaningful only when `readOnlyHint == false`)
1957
+ *
1958
+ * Default: true
1959
+ */
1960
+ readonly destructiveHint: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
1961
+ /**
1962
+ * If true, calling the tool repeatedly with the same arguments
1963
+ * will have no additional effect on the its environment.
1964
+ *
1965
+ * (This property is meaningful only when `readOnlyHint == false`)
1966
+ *
1967
+ * Default: false
1968
+ */
1969
+ readonly idempotentHint: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
1970
+ /**
1971
+ * If true, this tool may interact with an "open world" of external
1972
+ * entities. If false, the tool's domain of interaction is closed.
1973
+ * For example, the world of a web search tool is open, whereas that
1974
+ * of a memory tool is not.
1975
+ *
1976
+ * Default: true
1977
+ */
1978
+ readonly openWorldHint: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
1979
+ }, undefined>;
1980
+ /**
1981
+ * The server's response to a tool call.
1982
+ */
1983
+ const CallToolResultSchema: v.ObjectSchema<{
1984
+ /**
1985
+ * A list of content objects that represent the result of the tool call.
1986
+ *
1987
+ * If the Tool does not define an outputSchema, this field MUST be present in the result.
1988
+ * For backwards compatibility, this field is always present, but it may be empty.
1989
+ */
1990
+ readonly content: v.OptionalSchema<v.ArraySchema<v.UnionSchema<[v.ObjectSchema<{
1991
+ readonly type: v.LiteralSchema<"text", undefined>;
1992
+ /**
1993
+ * The text content of the message.
1994
+ */
1995
+ readonly text: v.StringSchema<undefined>;
1996
+ /**
1997
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
1998
+ * for notes on _meta usage.
1999
+ */
2000
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2001
+ }, undefined>, v.ObjectSchema<{
2002
+ readonly type: v.LiteralSchema<"image", undefined>;
2003
+ /**
2004
+ * The base64-encoded image data.
2005
+ */
2006
+ readonly data: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
2007
+ /**
2008
+ * The MIME type of the image. Different providers may support different image types.
2009
+ */
2010
+ readonly mimeType: v.StringSchema<undefined>;
2011
+ /**
2012
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2013
+ * for notes on _meta usage.
2014
+ */
2015
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2016
+ }, undefined>, v.ObjectSchema<{
2017
+ readonly type: v.LiteralSchema<"audio", undefined>;
2018
+ /**
2019
+ * The base64-encoded audio data.
2020
+ */
2021
+ readonly data: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
2022
+ /**
2023
+ * The MIME type of the audio. Different providers may support different audio types.
2024
+ */
2025
+ readonly mimeType: v.StringSchema<undefined>;
2026
+ /**
2027
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2028
+ * for notes on _meta usage.
2029
+ */
2030
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2031
+ }, undefined>, v.ObjectSchema<{
2032
+ readonly type: v.LiteralSchema<"resource_link", undefined>;
2033
+ /**
2034
+ * Optional set of sized icons that the client can display in a user interface.
2035
+ *
2036
+ * Clients that support rendering icons MUST support at least the following MIME types:
2037
+ * - `image/png` - PNG images (safe, universal compatibility)
2038
+ * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
2039
+ *
2040
+ * Clients that support rendering icons SHOULD also support:
2041
+ * - `image/svg+xml` - SVG images (scalable but requires security precautions)
2042
+ * - `image/webp` - WebP images (modern, efficient format)
2043
+ */
2044
+ readonly icons: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
2045
+ /**
2046
+ * URL or data URI for the icon.
2047
+ */
2048
+ readonly src: v.StringSchema<undefined>;
2049
+ /**
2050
+ * Optional MIME type for the icon.
2051
+ */
2052
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2053
+ /**
2054
+ * Optional array of strings that specify sizes at which the icon can be used.
2055
+ * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
2056
+ *
2057
+ * If not provided, the client should assume that the icon can be used at any size.
2058
+ */
2059
+ readonly sizes: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
2060
+ }, undefined>, undefined>, undefined>;
2061
+ /**
2062
+ * The URI of this resource.
2063
+ */
2064
+ readonly uri: v.StringSchema<undefined>;
2065
+ /**
2066
+ * A description of what this resource represents.
2067
+ *
2068
+ * This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model.
2069
+ */
2070
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2071
+ /**
2072
+ * The MIME type of this resource, if known.
2073
+ */
2074
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2075
+ /**
2076
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2077
+ * for notes on _meta usage.
2078
+ */
2079
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2080
+ /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
2081
+ readonly name: v.StringSchema<undefined>;
2082
+ /**
2083
+ * Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
2084
+ * even by those unfamiliar with domain-specific terminology.
2085
+ *
2086
+ * If not provided, the name should be used for display (except for Tool,
2087
+ * where `annotations.title` should be given precedence over using `name`,
2088
+ * if present).
2089
+ */
2090
+ readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2091
+ }, undefined>, v.ObjectSchema<{
2092
+ readonly type: v.LiteralSchema<"resource", undefined>;
2093
+ readonly resource: v.UnionSchema<[v.ObjectSchema<{
2094
+ /**
2095
+ * The text of the item. This must only be set if the item can actually be represented as text (not binary data).
2096
+ */
2097
+ readonly text: v.StringSchema<undefined>;
2098
+ /**
2099
+ * The URI of this resource.
2100
+ */
2101
+ readonly uri: v.StringSchema<undefined>;
2102
+ /**
2103
+ * The MIME type of this resource, if known.
2104
+ */
2105
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2106
+ /**
2107
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2108
+ * for notes on _meta usage.
2109
+ */
2110
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2111
+ }, undefined>, v.ObjectSchema<{
2112
+ /**
2113
+ * A base64-encoded string representing the binary data of the item.
2114
+ */
2115
+ readonly blob: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
2116
+ /**
2117
+ * The URI of this resource.
2118
+ */
2119
+ readonly uri: v.StringSchema<undefined>;
2120
+ /**
2121
+ * The MIME type of this resource, if known.
2122
+ */
2123
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2124
+ /**
2125
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2126
+ * for notes on _meta usage.
2127
+ */
2128
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2129
+ }, undefined>], undefined>;
2130
+ /**
2131
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2132
+ * for notes on _meta usage.
2133
+ */
2134
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2135
+ }, undefined>], undefined>, undefined>, readonly []>;
2136
+ /**
2137
+ * An object containing structured tool output.
2138
+ *
2139
+ * If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema.
2140
+ */
2141
+ readonly structuredContent: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2142
+ /**
2143
+ * Whether the tool call ended in an error.
2144
+ *
2145
+ * If not set, this is assumed to be false (the call was successful).
2146
+ *
2147
+ * Any errors that originate from the tool SHOULD be reported inside the result
2148
+ * object, with `isError` set to true, _not_ as an MCP protocol-level error
2149
+ * response. Otherwise, the LLM would not be able to see that an error occurred
2150
+ * and self-correct.
2151
+ *
2152
+ * However, any errors in _finding_ the tool, an error indicating that the
2153
+ * server does not support tool calls, or any other exceptional conditions,
2154
+ * should be reported as an MCP error response.
2155
+ */
2156
+ readonly isError: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
2157
+ /**
2158
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2159
+ * for notes on _meta usage.
2160
+ */
2161
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2162
+ }, undefined>;
2163
+ type Icons = v.InferInput<typeof IconsSchema>;
2164
+ type CallToolResult_1<TStructuredContent extends Record<string, unknown> | undefined> = Omit<v.InferInput<typeof CallToolResultSchema>, "structuredContent" | "isError"> & (undefined extends TStructuredContent ? {
2165
+ structuredContent?: undefined;
2166
+ isError?: boolean;
2167
+ } : ({
2168
+ structuredContent: TStructuredContent;
2169
+ isError?: false;
2170
+ } | {
2171
+ isError: true;
2172
+ structuredContent?: TStructuredContent;
2173
+ }));
2174
+ type ToolAnnotations = v.InferInput<typeof ToolAnnotationsSchema>;
2175
+
2176
+ export {};
2177
+ }
2178
+
2179
+ declare module 'tmcp/prompt' {
2180
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
2181
+ import * as v from 'valibot';
2182
+ /**
2183
+ * @import { StandardSchemaV1 } from "@standard-schema/spec";
2184
+ * @import { PromptOptions, CreatedPrompt } from "./internal/internal.js";
2185
+ *
2186
+ */
2187
+ /**
2188
+ * 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,
2189
+ * 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.
2190
+ *
2191
+ * */
2192
+ 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>;
2193
+
2194
+ type PromptOptions<TSchema extends StandardSchemaV1 | undefined = undefined> = {
2195
+ name: string;
2196
+ description: string;
2197
+ title?: string;
2198
+ enabled?: ()=>boolean | Promise<boolean>;
2199
+ schema?: StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema> extends Record<string, unknown> ? TSchema : never;
2200
+ complete?: NoInfer<TSchema extends undefined ? never : Partial<Record<keyof (StandardSchemaV1.InferInput<TSchema extends undefined ? never : TSchema>), Completion>>>
2201
+ } & Icons
2202
+ type CreatedPrompt<TSchema extends StandardSchemaV1 | undefined = undefined> = PromptOptions<TSchema> & { [created_prompt]: created_prompt };
2203
+
2204
+ type Completion = (
2205
+ query: string,
2206
+ context: { arguments: Record<string, string> },
2207
+ ) => CompleteResult | Promise<CompleteResult>;
2208
+ const IconsSchema: v.ObjectSchema<{
2209
+ /**
2210
+ * Optional set of sized icons that the client can display in a user interface.
2211
+ *
2212
+ * Clients that support rendering icons MUST support at least the following MIME types:
2213
+ * - `image/png` - PNG images (safe, universal compatibility)
2214
+ * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
2215
+ *
2216
+ * Clients that support rendering icons SHOULD also support:
2217
+ * - `image/svg+xml` - SVG images (scalable but requires security precautions)
2218
+ * - `image/webp` - WebP images (modern, efficient format)
2219
+ */
2220
+ readonly icons: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
2221
+ /**
2222
+ * URL or data URI for the icon.
2223
+ */
2224
+ readonly src: v.StringSchema<undefined>;
2225
+ /**
2226
+ * Optional MIME type for the icon.
2227
+ */
2228
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2229
+ /**
2230
+ * Optional array of strings that specify sizes at which the icon can be used.
2231
+ * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
2232
+ *
2233
+ * If not provided, the client should assume that the icon can be used at any size.
2234
+ */
2235
+ readonly sizes: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
2236
+ }, undefined>, undefined>, undefined>;
2237
+ }, undefined>;
2238
+ /**
2239
+ * The server's response to a prompts/get request from the client.
2240
+ */
2241
+ const GetPromptResultSchema: v.ObjectSchema<{
2242
+ /**
2243
+ * An optional description for the prompt.
2244
+ */
2245
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2246
+ readonly messages: v.ArraySchema<v.ObjectSchema<{
2247
+ readonly role: v.PicklistSchema<["user", "assistant"], undefined>;
2248
+ readonly content: v.UnionSchema<[v.ObjectSchema<{
2249
+ readonly type: v.LiteralSchema<"text", undefined>;
2250
+ /**
2251
+ * The text content of the message.
2252
+ */
2253
+ readonly text: v.StringSchema<undefined>;
2254
+ /**
2255
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2256
+ * for notes on _meta usage.
2257
+ */
2258
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2259
+ }, undefined>, v.ObjectSchema<{
2260
+ readonly type: v.LiteralSchema<"image", undefined>;
2261
+ /**
2262
+ * The base64-encoded image data.
2263
+ */
2264
+ readonly data: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
2265
+ /**
2266
+ * The MIME type of the image. Different providers may support different image types.
2267
+ */
2268
+ readonly mimeType: v.StringSchema<undefined>;
2269
+ /**
2270
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2271
+ * for notes on _meta usage.
2272
+ */
2273
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2274
+ }, undefined>, v.ObjectSchema<{
2275
+ readonly type: v.LiteralSchema<"audio", undefined>;
2276
+ /**
2277
+ * The base64-encoded audio data.
2278
+ */
2279
+ readonly data: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
2280
+ /**
2281
+ * The MIME type of the audio. Different providers may support different audio types.
2282
+ */
2283
+ readonly mimeType: v.StringSchema<undefined>;
2284
+ /**
2285
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2286
+ * for notes on _meta usage.
2287
+ */
2288
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2289
+ }, undefined>, v.ObjectSchema<{
2290
+ readonly type: v.LiteralSchema<"resource_link", undefined>;
2291
+ /**
2292
+ * Optional set of sized icons that the client can display in a user interface.
2293
+ *
2294
+ * Clients that support rendering icons MUST support at least the following MIME types:
2295
+ * - `image/png` - PNG images (safe, universal compatibility)
2296
+ * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
2297
+ *
2298
+ * Clients that support rendering icons SHOULD also support:
2299
+ * - `image/svg+xml` - SVG images (scalable but requires security precautions)
2300
+ * - `image/webp` - WebP images (modern, efficient format)
2301
+ */
2302
+ readonly icons: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
2303
+ /**
2304
+ * URL or data URI for the icon.
2305
+ */
2306
+ readonly src: v.StringSchema<undefined>;
2307
+ /**
2308
+ * Optional MIME type for the icon.
2309
+ */
2310
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2311
+ /**
2312
+ * Optional array of strings that specify sizes at which the icon can be used.
2313
+ * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
2314
+ *
2315
+ * If not provided, the client should assume that the icon can be used at any size.
2316
+ */
2317
+ readonly sizes: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
2318
+ }, undefined>, undefined>, undefined>;
2319
+ /**
2320
+ * The URI of this resource.
2321
+ */
2322
+ readonly uri: v.StringSchema<undefined>;
2323
+ /**
2324
+ * A description of what this resource represents.
2325
+ *
2326
+ * This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model.
2327
+ */
2328
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2329
+ /**
2330
+ * The MIME type of this resource, if known.
2331
+ */
2332
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2333
+ /**
2334
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2335
+ * for notes on _meta usage.
2336
+ */
2337
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2338
+ /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
2339
+ readonly name: v.StringSchema<undefined>;
2340
+ /**
2341
+ * Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
2342
+ * even by those unfamiliar with domain-specific terminology.
2343
+ *
2344
+ * If not provided, the name should be used for display (except for Tool,
2345
+ * where `annotations.title` should be given precedence over using `name`,
2346
+ * if present).
2347
+ */
2348
+ readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2349
+ }, undefined>, v.ObjectSchema<{
2350
+ readonly type: v.LiteralSchema<"resource", undefined>;
2351
+ readonly resource: v.UnionSchema<[v.ObjectSchema<{
2352
+ /**
2353
+ * The text of the item. This must only be set if the item can actually be represented as text (not binary data).
2354
+ */
2355
+ readonly text: v.StringSchema<undefined>;
2356
+ /**
2357
+ * The URI of this resource.
2358
+ */
2359
+ readonly uri: v.StringSchema<undefined>;
2360
+ /**
2361
+ * The MIME type of this resource, if known.
2362
+ */
2363
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2364
+ /**
2365
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2366
+ * for notes on _meta usage.
2367
+ */
2368
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2369
+ }, undefined>, v.ObjectSchema<{
2370
+ /**
2371
+ * A base64-encoded string representing the binary data of the item.
2372
+ */
2373
+ readonly blob: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
2374
+ /**
2375
+ * The URI of this resource.
2376
+ */
2377
+ readonly uri: v.StringSchema<undefined>;
2378
+ /**
2379
+ * The MIME type of this resource, if known.
2380
+ */
2381
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2382
+ /**
2383
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2384
+ * for notes on _meta usage.
2385
+ */
2386
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2387
+ }, undefined>], undefined>;
2388
+ /**
2389
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2390
+ * for notes on _meta usage.
2391
+ */
2392
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2393
+ }, undefined>], undefined>;
2394
+ }, undefined>, undefined>;
2395
+ /**
2396
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2397
+ * for notes on _meta usage.
2398
+ */
2399
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2400
+ }, undefined>;
2401
+ /**
2402
+ * The server's response to a completion/complete request
2403
+ */
2404
+ const CompleteResultSchema: v.ObjectSchema<{
2405
+ readonly completion: v.ObjectSchema<{
2406
+ /**
2407
+ * An array of completion values. Must not exceed 100 items.
2408
+ */
2409
+ readonly values: v.SchemaWithPipe<readonly [v.ArraySchema<v.StringSchema<undefined>, undefined>, v.MaxLengthAction<string[], 100, undefined>]>;
2410
+ /**
2411
+ * The total number of completion options available. This can exceed the number of values actually sent in the response.
2412
+ */
2413
+ readonly total: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, undefined>;
2414
+ /**
2415
+ * Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
2416
+ */
2417
+ readonly hasMore: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
2418
+ }, undefined>;
2419
+ /**
2420
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2421
+ * for notes on _meta usage.
2422
+ */
2423
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2424
+ }, undefined>;
2425
+ type Icons = v.InferInput<typeof IconsSchema>;
2426
+ type GetPromptResult = v.InferInput<typeof GetPromptResultSchema>;
2427
+ type CompleteResult = v.InferInput<typeof CompleteResultSchema>;
2428
+
2429
+ export {};
2430
+ }
2431
+
2432
+ declare module 'tmcp/resource' {
2433
+ import * as v from 'valibot';
2434
+ /**
2435
+ * @import { ResourceOptions, CreatedResource } from "./internal/internal.js";
2436
+ * @import { ReadResourceResult } from "./validation/index.js";
2437
+ */
2438
+ /**
2439
+ * Add a resource to the server. Resources are added manually to the context by the user to provide the LLM with additional context.
2440
+ * Use the description and title to help the user to understand what the resource is.
2441
+ *
2442
+ * */
2443
+ export function defineResource(options: ResourceOptions, execute: (uri: string) => Promise<ReadResourceResult> | ReadResourceResult): CreatedResource;
2444
+
2445
+ type ResourceOptions = {
2446
+ name: string;
2447
+ description: string;
2448
+ title?: string;
2449
+ uri: string,
2450
+ enabled?: ()=>boolean | Promise<boolean>;
2451
+ } & Icons
2452
+ type CreatedResource = ResourceOptions & { [created_resource]: created_resource };
2453
+ const IconsSchema: v.ObjectSchema<{
2454
+ /**
2455
+ * Optional set of sized icons that the client can display in a user interface.
2456
+ *
2457
+ * Clients that support rendering icons MUST support at least the following MIME types:
2458
+ * - `image/png` - PNG images (safe, universal compatibility)
2459
+ * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
2460
+ *
2461
+ * Clients that support rendering icons SHOULD also support:
2462
+ * - `image/svg+xml` - SVG images (scalable but requires security precautions)
2463
+ * - `image/webp` - WebP images (modern, efficient format)
2464
+ */
2465
+ readonly icons: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
2466
+ /**
2467
+ * URL or data URI for the icon.
2468
+ */
2469
+ readonly src: v.StringSchema<undefined>;
2470
+ /**
2471
+ * Optional MIME type for the icon.
2472
+ */
2473
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2474
+ /**
2475
+ * Optional array of strings that specify sizes at which the icon can be used.
2476
+ * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
2477
+ *
2478
+ * If not provided, the client should assume that the icon can be used at any size.
2479
+ */
2480
+ readonly sizes: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
2481
+ }, undefined>, undefined>, undefined>;
2482
+ }, undefined>;
2483
+ /**
2484
+ * The server's response to a resources/read request from the client.
2485
+ */
2486
+ const ReadResourceResultSchema: v.ObjectSchema<{
2487
+ readonly contents: v.ArraySchema<v.UnionSchema<[v.ObjectSchema<{
2488
+ /**
2489
+ * The text of the item. This must only be set if the item can actually be represented as text (not binary data).
2490
+ */
2491
+ readonly text: v.StringSchema<undefined>;
2492
+ /**
2493
+ * The URI of this resource.
2494
+ */
2495
+ readonly uri: v.StringSchema<undefined>;
2496
+ /**
2497
+ * The MIME type of this resource, if known.
2498
+ */
2499
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2500
+ /**
2501
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2502
+ * for notes on _meta usage.
2503
+ */
2504
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2505
+ }, undefined>, v.ObjectSchema<{
2506
+ /**
2507
+ * A base64-encoded string representing the binary data of the item.
2508
+ */
2509
+ readonly blob: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
2510
+ /**
2511
+ * The URI of this resource.
2512
+ */
2513
+ readonly uri: v.StringSchema<undefined>;
2514
+ /**
2515
+ * The MIME type of this resource, if known.
2516
+ */
2517
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2518
+ /**
2519
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2520
+ * for notes on _meta usage.
2521
+ */
2522
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2523
+ }, undefined>], undefined>, undefined>;
2524
+ /**
2525
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2526
+ * for notes on _meta usage.
2527
+ */
2528
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2529
+ }, undefined>;
2530
+ type Icons = v.InferInput<typeof IconsSchema>;
2531
+ type ReadResourceResult = v.InferInput<typeof ReadResourceResultSchema>;
2532
+
2533
+ export {};
2534
+ }
2535
+
2536
+ declare module 'tmcp/template' {
2537
+ import * as v from 'valibot';
2538
+ /**
2539
+ * @import { ExtractURITemplateVariables } from "./internal/uri-template.js";
2540
+ * @import { TemplateOptions, CreatedTemplate } from "./internal/internal.js";
2541
+ * @import { ReadResourceResult } from "./validation/index.js";
2542
+ */
2543
+ /**
2544
+ * Add a resource template to the server. Resources are added manually to the context by the user to provide the LLM with additional context.
2545
+ * 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.
2546
+ * 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
2547
+ * be invoked to provide completions for the template variables to the user.
2548
+ * Use the description and title to help the user to understand what the resource is.
2549
+ *
2550
+ * */
2551
+ export function defineTemplate<TUri extends string, TVariables extends ExtractURITemplateVariables<TUri>>(options: TemplateOptions<TUri>, execute: (uri: string, params: Record<TVariables, string | string[]>) => Promise<ReadResourceResult> | ReadResourceResult): CreatedTemplate<TUri>;
2552
+ // Helper type to remove whitespace
2553
+ type Trim<S extends string> = S extends ` ${infer R}`
2554
+ ? Trim<R>
2555
+ : S extends `${infer L} `
2556
+ ? Trim<L>
2557
+ : S;
2558
+
2559
+ // Helper type to extract variable name, removing modifiers
2560
+ type ExtractVarName<S extends string> = S extends `${infer Name}:${string}`
2561
+ ? Trim<Name> // Remove prefix modifier
2562
+ : S extends `${infer Name}*`
2563
+ ? Trim<Name> // Remove explode modifier
2564
+ : Trim<S>;
2565
+
2566
+ // Helper type to split comma-separated variables
2567
+ type SplitVariables<S extends string> = S extends `${infer First},${infer Rest}`
2568
+ ? ExtractVarName<First> | SplitVariables<Rest>
2569
+ : ExtractVarName<S>;
2570
+
2571
+ // Helper type to extract content from braces and handle operators
2572
+ type ExtractFromExpression<S extends string> = S extends `+${infer Vars}`
2573
+ ? SplitVariables<Vars> // Reserved {+var}
2574
+ : S extends `#${infer Vars}`
2575
+ ? SplitVariables<Vars> // Fragment {#var}
2576
+ : S extends `.${infer Vars}`
2577
+ ? SplitVariables<Vars> // Label {.var}
2578
+ : S extends `/${infer Vars}`
2579
+ ? SplitVariables<Vars> // Path {/var}
2580
+ : S extends `;${infer Vars}`
2581
+ ? SplitVariables<Vars> // Path-style {;var}
2582
+ : S extends `?${infer Vars}`
2583
+ ? SplitVariables<Vars> // Query {?var}
2584
+ : S extends `&${infer Vars}`
2585
+ ? SplitVariables<Vars> // Query continuation {&var}
2586
+ : SplitVariables<S>; // Simple {var}
2587
+
2588
+ // Main recursive type to extract all variables from URI template
2589
+ type ExtractVariablesFromTemplate<S extends string> =
2590
+ S extends `${string}{${infer Expression}}${infer Rest}`
2591
+ ? ExtractFromExpression<Expression> | ExtractVariablesFromTemplate<Rest>
2592
+ : never;
2593
+
2594
+ // Main exported type
2595
+ type ExtractURITemplateVariables<T extends string> =
2596
+ ExtractVariablesFromTemplate<T>;
2597
+
2598
+ type TemplateOptions<TUri extends string = string, TVariables extends ExtractURITemplateVariables<TUri> = ExtractURITemplateVariables<TUri>> = {
2599
+ name: string;
2600
+ description: string;
2601
+ title?: string;
2602
+ enabled?: ()=>boolean | Promise<boolean>;
2603
+ uri: TUri;
2604
+ complete?: NoInfer<TVariables extends never ? never : Partial<Record<TVariables, Completion>>>;
2605
+ list?: () => Promise<Array<Resource>> | Array<Resource>
2606
+ } & Icons
2607
+ type CreatedTemplate<TUri extends string = string> = TemplateOptions<TUri> & { [created_template]: created_template };
2608
+
2609
+ type Completion = (
2610
+ query: string,
2611
+ context: { arguments: Record<string, string> },
2612
+ ) => CompleteResult | Promise<CompleteResult>;
2613
+ const IconsSchema: v.ObjectSchema<{
2614
+ /**
2615
+ * Optional set of sized icons that the client can display in a user interface.
2616
+ *
2617
+ * Clients that support rendering icons MUST support at least the following MIME types:
2618
+ * - `image/png` - PNG images (safe, universal compatibility)
2619
+ * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
2620
+ *
2621
+ * Clients that support rendering icons SHOULD also support:
2622
+ * - `image/svg+xml` - SVG images (scalable but requires security precautions)
2623
+ * - `image/webp` - WebP images (modern, efficient format)
2624
+ */
2625
+ readonly icons: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
2626
+ /**
2627
+ * URL or data URI for the icon.
2628
+ */
2629
+ readonly src: v.StringSchema<undefined>;
2630
+ /**
2631
+ * Optional MIME type for the icon.
2632
+ */
2633
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2634
+ /**
2635
+ * Optional array of strings that specify sizes at which the icon can be used.
2636
+ * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
2637
+ *
2638
+ * If not provided, the client should assume that the icon can be used at any size.
2639
+ */
2640
+ readonly sizes: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
2641
+ }, undefined>, undefined>, undefined>;
2642
+ }, undefined>;
2643
+ /**
2644
+ * A known resource that the server is capable of reading.
2645
+ */
2646
+ const ResourceSchema: v.ObjectSchema<{
2647
+ /**
2648
+ * Optional set of sized icons that the client can display in a user interface.
2649
+ *
2650
+ * Clients that support rendering icons MUST support at least the following MIME types:
2651
+ * - `image/png` - PNG images (safe, universal compatibility)
2652
+ * - `image/jpeg` (and `image/jpg`) - JPEG images (safe, universal compatibility)
2653
+ *
2654
+ * Clients that support rendering icons SHOULD also support:
2655
+ * - `image/svg+xml` - SVG images (scalable but requires security precautions)
2656
+ * - `image/webp` - WebP images (modern, efficient format)
2657
+ */
2658
+ readonly icons: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
2659
+ /**
2660
+ * URL or data URI for the icon.
2661
+ */
2662
+ readonly src: v.StringSchema<undefined>;
2663
+ /**
2664
+ * Optional MIME type for the icon.
2665
+ */
2666
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2667
+ /**
2668
+ * Optional array of strings that specify sizes at which the icon can be used.
2669
+ * Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
2670
+ *
2671
+ * If not provided, the client should assume that the icon can be used at any size.
2672
+ */
2673
+ readonly sizes: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
2674
+ }, undefined>, undefined>, undefined>;
2675
+ /**
2676
+ * The URI of this resource.
2677
+ */
2678
+ readonly uri: v.StringSchema<undefined>;
2679
+ /**
2680
+ * A description of what this resource represents.
2681
+ *
2682
+ * This can be used by clients to improve the LLM's understanding of available resources. It can be thought of like a "hint" to the model.
2683
+ */
2684
+ readonly description: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2685
+ /**
2686
+ * The MIME type of this resource, if known.
2687
+ */
2688
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2689
+ /**
2690
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2691
+ * for notes on _meta usage.
2692
+ */
2693
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2694
+ /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
2695
+ readonly name: v.StringSchema<undefined>;
2696
+ /**
2697
+ * Intended for UI and end-user contexts — optimized to be human-readable and easily understood,
2698
+ * even by those unfamiliar with domain-specific terminology.
2699
+ *
2700
+ * If not provided, the name should be used for display (except for Tool,
2701
+ * where `annotations.title` should be given precedence over using `name`,
2702
+ * if present).
2703
+ */
2704
+ readonly title: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2705
+ }, undefined>;
2706
+ /**
2707
+ * The server's response to a resources/read request from the client.
2708
+ */
2709
+ const ReadResourceResultSchema: v.ObjectSchema<{
2710
+ readonly contents: v.ArraySchema<v.UnionSchema<[v.ObjectSchema<{
2711
+ /**
2712
+ * The text of the item. This must only be set if the item can actually be represented as text (not binary data).
2713
+ */
2714
+ readonly text: v.StringSchema<undefined>;
2715
+ /**
2716
+ * The URI of this resource.
2717
+ */
2718
+ readonly uri: v.StringSchema<undefined>;
2719
+ /**
2720
+ * The MIME type of this resource, if known.
2721
+ */
2722
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2723
+ /**
2724
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2725
+ * for notes on _meta usage.
2726
+ */
2727
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2728
+ }, undefined>, v.ObjectSchema<{
2729
+ /**
2730
+ * A base64-encoded string representing the binary data of the item.
2731
+ */
2732
+ readonly blob: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.Base64Action<string, undefined>]>;
2733
+ /**
2734
+ * The URI of this resource.
2735
+ */
2736
+ readonly uri: v.StringSchema<undefined>;
2737
+ /**
2738
+ * The MIME type of this resource, if known.
2739
+ */
2740
+ readonly mimeType: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
2741
+ /**
2742
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2743
+ * for notes on _meta usage.
2744
+ */
2745
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2746
+ }, undefined>], undefined>, undefined>;
2747
+ /**
2748
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2749
+ * for notes on _meta usage.
2750
+ */
2751
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2752
+ }, undefined>;
2753
+ /**
2754
+ * The server's response to a completion/complete request
2755
+ */
2756
+ const CompleteResultSchema: v.ObjectSchema<{
2757
+ readonly completion: v.ObjectSchema<{
2758
+ /**
2759
+ * An array of completion values. Must not exceed 100 items.
2760
+ */
2761
+ readonly values: v.SchemaWithPipe<readonly [v.ArraySchema<v.StringSchema<undefined>, undefined>, v.MaxLengthAction<string[], 100, undefined>]>;
2762
+ /**
2763
+ * The total number of completion options available. This can exceed the number of values actually sent in the response.
2764
+ */
2765
+ readonly total: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>]>, undefined>;
2766
+ /**
2767
+ * Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
2768
+ */
2769
+ readonly hasMore: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
2770
+ }, undefined>;
2771
+ /**
2772
+ * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
2773
+ * for notes on _meta usage.
2774
+ */
2775
+ readonly _meta: v.OptionalSchema<v.LooseObjectSchema<{}, undefined>, undefined>;
2776
+ }, undefined>;
2777
+ type Icons = v.InferInput<typeof IconsSchema>;
2778
+ type ReadResourceResult = v.InferInput<typeof ReadResourceResultSchema>;
2779
+ type CompleteResult = v.InferInput<typeof CompleteResultSchema>;
2780
+ type Resource = v.InferInput<typeof ResourceSchema>;
2781
+
2782
+ export {};
2783
+ }
2784
+
1808
2785
  declare module 'tmcp/adapter' {
1809
2786
  import type { StandardSchemaV1 } from '@standard-schema/spec';
1810
2787
  import type { JSONSchema7 } from 'json-schema';