tmcp 1.2.0 → 1.4.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.
@@ -0,0 +1,271 @@
1
+ /* eslint-disable jsdoc/no-undefined-types */
2
+ import * as v from 'valibot';
3
+
4
+ /**
5
+ * Text provided to or from an LLM.
6
+ */
7
+ export const TextContentSchema = v.looseObject({
8
+ type: v.literal('text'),
9
+ /**
10
+ * The text content of the message.
11
+ */
12
+ text: v.string(),
13
+ /**
14
+ * See [MCP specification] for notes on _meta usage.
15
+ */
16
+ _meta: v.optional(v.looseObject({})),
17
+ });
18
+
19
+ /**
20
+ * An image provided to or from an LLM.
21
+ */
22
+ export const ImageContentSchema = v.looseObject({
23
+ type: v.literal('image'),
24
+ /**
25
+ * The base64-encoded image data.
26
+ */
27
+ data: v.pipe(v.string(), v.base64()),
28
+ /**
29
+ * The MIME type of the image. Different providers may support different image types.
30
+ */
31
+ mimeType: v.string(),
32
+ /**
33
+ * See [MCP specification] for notes on _meta usage.
34
+ */
35
+ _meta: v.optional(v.looseObject({})),
36
+ });
37
+
38
+ /**
39
+ * An Audio provided to or from an LLM.
40
+ */
41
+ export const AudioContentSchema = v.looseObject({
42
+ type: v.literal('audio'),
43
+ /**
44
+ * The base64-encoded audio data.
45
+ */
46
+ data: v.pipe(v.string(), v.base64()),
47
+ /**
48
+ * The MIME type of the audio. Different providers may support different audio types.
49
+ */
50
+ mimeType: v.string(),
51
+ /**
52
+ * See [MCP specification] for notes on _meta usage.
53
+ */
54
+ _meta: v.optional(v.looseObject({})),
55
+ });
56
+
57
+ /**
58
+ * The contents of a specific resource or sub-resource.
59
+ */
60
+ export const ResourceContentsSchema = v.looseObject({
61
+ /**
62
+ * The URI of this resource.
63
+ */
64
+ uri: v.string(),
65
+ /**
66
+ * The MIME type of this resource, if known.
67
+ */
68
+ mimeType: v.optional(v.string()),
69
+ /**
70
+ * See [MCP specification] for notes on _meta usage.
71
+ */
72
+ _meta: v.optional(v.looseObject({})),
73
+ });
74
+
75
+ export const TextResourceContentsSchema = v.looseObject({
76
+ /**
77
+ * The URI of this resource.
78
+ */
79
+ uri: v.string(),
80
+ /**
81
+ * The MIME type of this resource, if known.
82
+ */
83
+ mimeType: v.optional(v.string()),
84
+ /**
85
+ * The text of the item. This must only be set if the item can actually be represented as text (not binary data).
86
+ */
87
+ text: v.string(),
88
+ /**
89
+ * See [MCP specification] for notes on _meta usage.
90
+ */
91
+ _meta: v.optional(v.looseObject({})),
92
+ });
93
+
94
+ export const BlobResourceContentsSchema = v.looseObject({
95
+ /**
96
+ * The URI of this resource.
97
+ */
98
+ uri: v.string(),
99
+ /**
100
+ * The MIME type of this resource, if known.
101
+ */
102
+ mimeType: v.optional(v.string()),
103
+ /**
104
+ * A base64-encoded string representing the binary data of the item.
105
+ */
106
+ blob: v.pipe(v.string(), v.base64()),
107
+ /**
108
+ * See [MCP specification] for notes on _meta usage.
109
+ */
110
+ _meta: v.optional(v.looseObject({})),
111
+ });
112
+
113
+ /**
114
+ * The contents of a resource, embedded into a prompt or tool call result.
115
+ */
116
+ export const EmbeddedResourceSchema = v.looseObject({
117
+ type: v.literal('resource'),
118
+ resource: v.union([TextResourceContentsSchema, BlobResourceContentsSchema]),
119
+ /**
120
+ * See [MCP specification] for notes on _meta usage.
121
+ */
122
+ _meta: v.optional(v.looseObject({})),
123
+ });
124
+
125
+ /**
126
+ * A resource that the server is capable of reading, included in a prompt or tool call result.
127
+ */
128
+ export const ResourceLinkSchema = v.looseObject({
129
+ /** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
130
+ name: v.string(),
131
+ title: v.optional(v.string()),
132
+ /**
133
+ * The URI of this resource.
134
+ */
135
+ uri: v.string(),
136
+ /**
137
+ * A description of what this resource represents.
138
+ */
139
+ description: v.optional(v.string()),
140
+ /**
141
+ * The MIME type of this resource, if known.
142
+ */
143
+ mimeType: v.optional(v.string()),
144
+ type: v.literal('resource_link'),
145
+ /**
146
+ * See [MCP specification] for notes on _meta usage.
147
+ */
148
+ _meta: v.optional(v.looseObject({})),
149
+ });
150
+
151
+ /**
152
+ * A content block that can be used in prompts and tool results.
153
+ */
154
+ export const ContentBlockSchema = v.union([
155
+ TextContentSchema,
156
+ ImageContentSchema,
157
+ AudioContentSchema,
158
+ ResourceLinkSchema,
159
+ EmbeddedResourceSchema,
160
+ ]);
161
+
162
+ /**
163
+ * Describes a message returned as part of a prompt.
164
+ */
165
+ export const PromptMessageSchema = v.looseObject({
166
+ role: v.picklist(['user', 'assistant']),
167
+ content: ContentBlockSchema,
168
+ });
169
+
170
+ /**
171
+ * The server's response to a tool call.
172
+ */
173
+ export const CallToolResultSchema = v.looseObject({
174
+ /**
175
+ * A list of content objects that represent the result of the tool call.
176
+ */
177
+ content: v.optional(v.array(ContentBlockSchema), []),
178
+
179
+ /**
180
+ * An object containing structured tool output.
181
+ */
182
+ structuredContent: v.optional(v.looseObject({})),
183
+
184
+ /**
185
+ * Whether the tool call ended in an error.
186
+ */
187
+ isError: v.optional(v.boolean()),
188
+ _meta: v.optional(v.looseObject({})),
189
+ });
190
+
191
+ /**
192
+ * The server's response to a resources/read request from the client.
193
+ */
194
+ export const ReadResourceResultSchema = v.looseObject({
195
+ contents: v.array(
196
+ v.union([TextResourceContentsSchema, BlobResourceContentsSchema]),
197
+ ),
198
+ _meta: v.optional(v.looseObject({})),
199
+ });
200
+
201
+ /**
202
+ * The server's response to a prompts/get request from the client.
203
+ */
204
+ export const GetPromptResultSchema = v.looseObject({
205
+ /**
206
+ * An optional description for the prompt.
207
+ */
208
+ description: v.optional(v.string()),
209
+ messages: v.array(PromptMessageSchema),
210
+ _meta: v.optional(v.looseObject({})),
211
+ });
212
+
213
+ /**
214
+ * The server's response to a completion/complete request
215
+ */
216
+ export const CompleteResultSchema = v.looseObject({
217
+ completion: v.looseObject({
218
+ /**
219
+ * An array of completion values. Must not exceed 100 items.
220
+ */
221
+ values: v.pipe(v.array(v.string()), v.maxLength(100)),
222
+ /**
223
+ * The total number of completion options available. This can exceed the number of values actually sent in the response.
224
+ */
225
+ total: v.optional(v.pipe(v.number(), v.integer())),
226
+ /**
227
+ * Indicates whether there are additional completion options beyond those provided in the current response, even if the exact total is unknown.
228
+ */
229
+ hasMore: v.optional(v.boolean()),
230
+ }),
231
+ _meta: v.optional(v.looseObject({})),
232
+ });
233
+
234
+ export const ClientCapabilitiesSchema = v.looseObject({
235
+ roots: v.optional(
236
+ v.looseObject({
237
+ listChanged: v.optional(v.boolean()),
238
+ }),
239
+ ),
240
+ sampling: v.optional(v.looseObject({})),
241
+ elicitation: v.optional(v.looseObject({})),
242
+ });
243
+
244
+ export const InitializeRequestSchema = v.looseObject({
245
+ protocolVersion: v.string(),
246
+ capabilities: ClientCapabilitiesSchema,
247
+ });
248
+
249
+ /**
250
+ * @typedef {v.InferInput<typeof ClientCapabilitiesSchema>} ClientCapabilities
251
+ */
252
+
253
+ /**
254
+ * @typedef {v.InferInput<typeof InitializeRequestSchema>} InitializeRequest
255
+ */
256
+
257
+ /**
258
+ * @typedef {v.InferInput<typeof CallToolResultSchema>} CallToolResult
259
+ */
260
+
261
+ /**
262
+ * @typedef {v.InferInput<typeof ReadResourceResultSchema>} ReadResourceResult
263
+ */
264
+
265
+ /**
266
+ * @typedef {v.InferInput<typeof GetPromptResultSchema>} GetPromptResult
267
+ */
268
+
269
+ /**
270
+ * @typedef {v.InferInput<typeof CompleteResultSchema>} CompleteResult
271
+ */