| 1 | /** |
| 2 | * Exact MCP v2025-06-18 wire schemas. |
| 3 | * |
| 4 | * This module is independent of the public compatibility-oriented McpSchema |
| 5 | * surface and is frozen as a dated delta from v2025-03-26. |
| 6 | * |
| 7 | * @internal |
| 8 | */ |
| 9 | import * as Rpc from "../../../rpc/Rpc.ts" |
| 10 | import * as RpcGroup from "../../../rpc/RpcGroup.ts" |
| 11 | import * as Schema from "../../../Schema.ts" |
| 12 | import * as Previous from "./v2025_03_26.ts" |
| 13 | |
| 14 | export * from "./v2025_03_26.ts" |
| 15 | |
| 16 | /** |
| 17 | * @internal |
| 18 | */ |
| 19 | export const protocolVersion = "2025-06-18" |
| 20 | |
| 21 | const optional = Previous.optional |
| 22 | const JsonObject = Schema.JsonObject |
| 23 | const Meta = optional(JsonObject) |
| 24 | |
| 25 | /** |
| 26 | * @internal |
| 27 | */ |
| 28 | export const Implementation = Schema.Struct({ |
| 29 | name: Schema.String, |
| 30 | title: optional(Schema.String), |
| 31 | version: Schema.String |
| 32 | }) |
| 33 | |
| 34 | /** |
| 35 | * @internal |
| 36 | */ |
| 37 | export const ClientCapabilities = Schema.Struct({ |
| 38 | ...Previous.ClientCapabilities.fields, |
| 39 | elicitation: optional(Schema.Struct({})) |
| 40 | }) |
| 41 | |
| 42 | /** |
| 43 | * @internal |
| 44 | */ |
| 45 | export const Annotations = Schema.Struct({ |
| 46 | audience: optional(Schema.Array(Previous.Role)), |
| 47 | priority: optional(Schema.Finite.check(Schema.isBetween({ minimum: 0, maximum: 1 }))) |
| 48 | }) |
| 49 | |
| 50 | /** |
| 51 | * @internal |
| 52 | */ |
| 53 | export const Resource = Schema.Struct({ |
| 54 | ...Previous.Resource.fields, |
| 55 | title: optional(Schema.String), |
| 56 | annotations: optional(Annotations), |
| 57 | _meta: Meta |
| 58 | }) |
| 59 | |
| 60 | /** |
| 61 | * @internal |
| 62 | */ |
| 63 | export const ResourceTemplate = Schema.Struct({ |
| 64 | ...Previous.ResourceTemplate.fields, |
| 65 | title: optional(Schema.String), |
| 66 | annotations: optional(Annotations), |
| 67 | _meta: Meta |
| 68 | }) |
| 69 | |
| 70 | /** |
| 71 | * @internal |
| 72 | */ |
| 73 | export const TextResourceContents = Schema.Struct({ |
| 74 | ...Previous.TextResourceContents.fields, |
| 75 | _meta: Meta |
| 76 | }) |
| 77 | |
| 78 | /** |
| 79 | * @internal |
| 80 | */ |
| 81 | export const BlobResourceContents = Schema.Struct({ |
| 82 | ...Previous.BlobResourceContents.fields, |
| 83 | _meta: Meta |
| 84 | }) |
| 85 | |
| 86 | /** |
| 87 | * @internal |
| 88 | */ |
| 89 | export const ResourceContents = Schema.Union([TextResourceContents, BlobResourceContents]) |
| 90 | |
| 91 | /** |
| 92 | * @internal |
| 93 | */ |
| 94 | export const PromptArgument = Schema.Struct({ |
| 95 | ...Previous.PromptArgument.fields, |
| 96 | title: optional(Schema.String) |
| 97 | }) |
| 98 | |
| 99 | /** |
| 100 | * @internal |
| 101 | */ |
| 102 | export const Prompt = Schema.Struct({ |
| 103 | ...Previous.Prompt.fields, |
| 104 | title: optional(Schema.String), |
| 105 | arguments: optional(Schema.Array(PromptArgument)), |
| 106 | _meta: Meta |
| 107 | }) |
| 108 | |
| 109 | /** |
| 110 | * @internal |
| 111 | */ |
| 112 | export const EmbeddedResource = Schema.Struct({ |
| 113 | type: Schema.Literal("resource"), |
| 114 | resource: ResourceContents, |
| 115 | annotations: optional(Annotations), |
| 116 | _meta: Meta |
| 117 | }) |
| 118 | |
| 119 | /** |
| 120 | * @internal |
| 121 | */ |
| 122 | export const ResourceLink = Schema.Struct({ |
| 123 | ...Resource.fields, |
| 124 | type: Schema.Literal("resource_link") |
| 125 | }) |
| 126 | |
| 127 | /** |
| 128 | * @internal |
| 129 | */ |
| 130 | export const TextContent = Schema.Struct({ |
| 131 | ...Previous.TextContent.fields, |
| 132 | annotations: optional(Annotations), |
| 133 | _meta: Meta |
| 134 | }) |
| 135 | |
| 136 | /** |
| 137 | * @internal |
| 138 | */ |
| 139 | export const ImageContent = Schema.Struct({ |
| 140 | ...Previous.ImageContent.fields, |
| 141 | annotations: optional(Annotations), |
| 142 | _meta: Meta |
| 143 | }) |
| 144 | |
| 145 | /** |
| 146 | * @internal |
| 147 | */ |
| 148 | export const AudioContent = Schema.Struct({ |
| 149 | ...Previous.AudioContent.fields, |
| 150 | annotations: optional(Annotations), |
| 151 | _meta: Meta |
| 152 | }) |
| 153 | |
| 154 | /** |
| 155 | * @internal |
| 156 | */ |
| 157 | export const ContentBlock = Schema.Union([ |
| 158 | TextContent, |
| 159 | ImageContent, |
| 160 | AudioContent, |
| 161 | EmbeddedResource, |
| 162 | ResourceLink |
| 163 | ]) |
| 164 | |
| 165 | /** |
| 166 | * @internal |
| 167 | */ |
| 168 | export const SamplingContent = Schema.Union([TextContent, ImageContent, AudioContent]) |
| 169 | |
| 170 | /** |
| 171 | * @internal |
| 172 | */ |
| 173 | export const PromptMessage = Schema.Struct({ |
| 174 | role: Previous.Role, |
| 175 | content: ContentBlock |
| 176 | }) |
| 177 | |
| 178 | /** |
| 179 | * @internal |
| 180 | */ |
| 181 | export const SamplingMessage = Schema.Struct({ |
| 182 | role: Previous.Role, |
| 183 | content: SamplingContent |
| 184 | }) |
| 185 | |
| 186 | /** |
| 187 | * @internal |
| 188 | */ |
| 189 | export const ServerCapabilities = Schema.Struct({ |
| 190 | ...Previous.ServerCapabilities.fields |
| 191 | }) |
| 192 | |
| 193 | /** |
| 194 | * @internal |
| 195 | */ |
| 196 | export const InitializeResult = Schema.Struct({ |
| 197 | ...Previous.ResultMeta.fields, |
| 198 | protocolVersion: Schema.String, |
| 199 | capabilities: ServerCapabilities, |
| 200 | serverInfo: Implementation, |
| 201 | instructions: optional(Schema.String) |
| 202 | }) |
| 203 | |
| 204 | /** |
| 205 | * @internal |
| 206 | */ |
| 207 | export class Initialize extends Rpc.make("initialize", { |
| 208 | success: InitializeResult, |
| 209 | error: Previous.McpError, |
| 210 | payload: { |
| 211 | ...Previous.RequestMeta.fields, |
| 212 | protocolVersion: Schema.String, |
| 213 | capabilities: ClientCapabilities, |
| 214 | clientInfo: Implementation |
| 215 | } |
| 216 | }) {} |
| 217 | |
| 218 | const ToolJsonSchema = Schema.StructWithRest( |
| 219 | Schema.Struct({ |
| 220 | type: Schema.Literal("object"), |
| 221 | properties: optional(Schema.Record(Schema.String, JsonObject)), |
| 222 | required: optional(Schema.Array(Schema.String)) |
| 223 | }), |
| 224 | [Schema.JsonObject] |
| 225 | ) |
| 226 | |
| 227 | /** |
| 228 | * @internal |
| 229 | */ |
| 230 | export const Tool = Schema.Struct({ |
| 231 | name: Schema.String, |
| 232 | title: optional(Schema.String), |
| 233 | description: optional(Schema.String), |
| 234 | inputSchema: ToolJsonSchema, |
| 235 | outputSchema: optional(ToolJsonSchema), |
| 236 | annotations: optional(Previous.ToolAnnotations), |
| 237 | _meta: Meta |
| 238 | }) |
| 239 | |
| 240 | /** |
| 241 | * @internal |
| 242 | */ |
| 243 | export const CallToolResult = Schema.Struct({ |
| 244 | ...Previous.ResultMeta.fields, |
| 245 | content: Schema.Array(ContentBlock), |
| 246 | structuredContent: optional(JsonObject), |
| 247 | isError: optional(Schema.Boolean) |
| 248 | }) |
| 249 | |
| 250 | /** |
| 251 | * @internal |
| 252 | */ |
| 253 | export const CreateMessageResult = Schema.Struct({ |
| 254 | ...Previous.ResultMeta.fields, |
| 255 | role: Previous.Role, |
| 256 | content: SamplingContent, |
| 257 | model: Schema.String, |
| 258 | stopReason: optional(Schema.String) |
| 259 | }) |
| 260 | |
| 261 | /** |
| 262 | * @internal |
| 263 | */ |
| 264 | export class CreateMessage extends Rpc.make("sampling/createMessage", { |
| 265 | success: CreateMessageResult, |
| 266 | error: Previous.McpError, |
| 267 | payload: { |
| 268 | ...Previous.RequestMeta.fields, |
| 269 | messages: Schema.Array(SamplingMessage), |
| 270 | modelPreferences: optional(Previous.ModelPreferences), |
| 271 | systemPrompt: optional(Schema.String), |
| 272 | includeContext: optional(Schema.Literals(["none", "thisServer", "allServers"])), |
| 273 | temperature: optional(Schema.Finite), |
| 274 | maxTokens: Schema.Finite, |
| 275 | stopSequences: optional(Schema.Array(Schema.String)), |
| 276 | metadata: optional(JsonObject) |
| 277 | } |
| 278 | }) {} |
| 279 | |
| 280 | /** |
| 281 | * @internal |
| 282 | */ |
| 283 | export const PromptReference = Schema.Struct({ |
| 284 | ...Previous.PromptReference.fields, |
| 285 | title: optional(Schema.String) |
| 286 | }) |
| 287 | |
| 288 | /** |
| 289 | * @internal |
| 290 | */ |
| 291 | export const ResourceTemplateReference = Schema.Struct({ |
| 292 | type: Schema.Literal("ref/resource"), |
| 293 | uri: Schema.String |
| 294 | }) |
| 295 | |
| 296 | /** |
| 297 | * @internal |
| 298 | */ |
| 299 | export const CompleteResult = Previous.CompleteResult |
| 300 | |
| 301 | /** |
| 302 | * @internal |
| 303 | */ |
| 304 | export class Complete extends Rpc.make("completion/complete", { |
| 305 | success: CompleteResult, |
| 306 | error: Previous.McpError, |
| 307 | payload: { |
| 308 | ...Previous.RequestMeta.fields, |
| 309 | ref: Schema.Union([PromptReference, ResourceTemplateReference]), |
| 310 | argument: Schema.Struct({ |
| 311 | name: Schema.String, |
| 312 | value: Schema.String |
| 313 | }), |
| 314 | context: optional(Schema.Struct({ |
| 315 | arguments: optional(Schema.Record(Schema.String, Schema.String)) |
| 316 | })) |
| 317 | } |
| 318 | }) {} |
| 319 | |
| 320 | /** |
| 321 | * @internal |
| 322 | */ |
| 323 | export const ListResourcesResult = Schema.Struct({ |
| 324 | ...Previous.PaginatedResult.fields, |
| 325 | resources: Schema.Array(Resource) |
| 326 | }) |
| 327 | |
| 328 | /** |
| 329 | * @internal |
| 330 | */ |
| 331 | export const ListResourceTemplatesResult = Schema.Struct({ |
| 332 | ...Previous.PaginatedResult.fields, |
| 333 | resourceTemplates: Schema.Array(ResourceTemplate) |
| 334 | }) |
| 335 | |
| 336 | /** |
| 337 | * @internal |
| 338 | */ |
| 339 | export const ReadResourceResult = Schema.Struct({ |
| 340 | ...Previous.ResultMeta.fields, |
| 341 | contents: Schema.Array(ResourceContents) |
| 342 | }) |
| 343 | |
| 344 | /** |
| 345 | * @internal |
| 346 | */ |
| 347 | export const ListPromptsResult = Schema.Struct({ |
| 348 | ...Previous.PaginatedResult.fields, |
| 349 | prompts: Schema.Array(Prompt) |
| 350 | }) |
| 351 | |
| 352 | /** |
| 353 | * @internal |
| 354 | */ |
| 355 | export const GetPromptResult = Schema.Struct({ |
| 356 | ...Previous.ResultMeta.fields, |
| 357 | description: optional(Schema.String), |
| 358 | messages: Schema.Array(PromptMessage) |
| 359 | }) |
| 360 | |
| 361 | /** |
| 362 | * @internal |
| 363 | */ |
| 364 | export const ListToolsResult = Schema.Struct({ |
| 365 | ...Previous.PaginatedResult.fields, |
| 366 | tools: Schema.Array(Tool) |
| 367 | }) |
| 368 | |
| 369 | /** |
| 370 | * @internal |
| 371 | */ |
| 372 | export class ListResources extends Rpc.make("resources/list", { |
| 373 | success: ListResourcesResult, |
| 374 | error: Previous.McpError, |
| 375 | payload: Schema.UndefinedOr(Previous.PaginatedRequest) |
| 376 | }) {} |
| 377 | |
| 378 | /** |
| 379 | * @internal |
| 380 | */ |
| 381 | export class ListResourceTemplates extends Rpc.make("resources/templates/list", { |
| 382 | success: ListResourceTemplatesResult, |
| 383 | error: Previous.McpError, |
| 384 | payload: Schema.UndefinedOr(Previous.PaginatedRequest) |
| 385 | }) {} |
| 386 | |
| 387 | /** |
| 388 | * @internal |
| 389 | */ |
| 390 | export class ReadResource extends Rpc.make("resources/read", { |
| 391 | success: ReadResourceResult, |
| 392 | error: Previous.McpError, |
| 393 | payload: { ...Previous.RequestMeta.fields, uri: Schema.String } |
| 394 | }) {} |
| 395 | |
| 396 | /** |
| 397 | * @internal |
| 398 | */ |
| 399 | export class ListPrompts extends Rpc.make("prompts/list", { |
| 400 | success: ListPromptsResult, |
| 401 | error: Previous.McpError, |
| 402 | payload: Schema.UndefinedOr(Previous.PaginatedRequest) |
| 403 | }) {} |
| 404 | |
| 405 | /** |
| 406 | * @internal |
| 407 | */ |
| 408 | export class GetPrompt extends Rpc.make("prompts/get", { |
| 409 | success: GetPromptResult, |
| 410 | error: Previous.McpError, |
| 411 | payload: { |
| 412 | ...Previous.RequestMeta.fields, |
| 413 | name: Schema.String, |
| 414 | arguments: optional(Schema.Record(Schema.String, Schema.String)) |
| 415 | } |
| 416 | }) {} |
| 417 | |
| 418 | /** |
| 419 | * @internal |
| 420 | */ |
| 421 | export class ListTools extends Rpc.make("tools/list", { |
| 422 | success: ListToolsResult, |
| 423 | error: Previous.McpError, |
| 424 | payload: Schema.UndefinedOr(Previous.PaginatedRequest) |
| 425 | }) {} |
| 426 | |
| 427 | /** |
| 428 | * @internal |
| 429 | */ |
| 430 | export class CallTool extends Rpc.make("tools/call", { |
| 431 | success: CallToolResult, |
| 432 | error: Previous.McpError, |
| 433 | payload: { |
| 434 | ...Previous.RequestMeta.fields, |
| 435 | name: Schema.String, |
| 436 | arguments: optional(JsonObject) |
| 437 | } |
| 438 | }) {} |
| 439 | |
| 440 | /** |
| 441 | * @internal |
| 442 | */ |
| 443 | export const ElicitResult = Schema.Struct({ |
| 444 | ...Previous.ResultMeta.fields, |
| 445 | action: Schema.Literals(["accept", "decline", "cancel"]), |
| 446 | content: optional(Schema.Record( |
| 447 | Schema.String, |
| 448 | Schema.Union([Schema.String, Schema.Finite, Schema.Boolean]) |
| 449 | )) |
| 450 | }) |
| 451 | |
| 452 | const StringSchema = Schema.Struct({ |
| 453 | type: Schema.Literal("string"), |
| 454 | title: optional(Schema.String), |
| 455 | description: optional(Schema.String), |
| 456 | minLength: optional(Schema.Int), |
| 457 | maxLength: optional(Schema.Int), |
| 458 | format: optional(Schema.Literals(["email", "uri", "date", "date-time"])) |
| 459 | }) |
| 460 | const NumberSchema = Schema.Struct({ |
| 461 | type: Schema.Literals(["number", "integer"]), |
| 462 | title: optional(Schema.String), |
| 463 | description: optional(Schema.String), |
| 464 | minimum: optional(Schema.Finite), |
| 465 | maximum: optional(Schema.Finite) |
| 466 | }) |
| 467 | const BooleanSchema = Schema.Struct({ |
| 468 | type: Schema.Literal("boolean"), |
| 469 | title: optional(Schema.String), |
| 470 | description: optional(Schema.String), |
| 471 | default: optional(Schema.Boolean) |
| 472 | }) |
| 473 | const EnumSchema = Schema.Struct({ |
| 474 | type: Schema.Literal("string"), |
| 475 | title: optional(Schema.String), |
| 476 | description: optional(Schema.String), |
| 477 | enum: Schema.Array(Schema.String), |
| 478 | enumNames: optional(Schema.Array(Schema.String)) |
| 479 | }) |
| 480 | const RequestedSchema = Schema.Struct({ |
| 481 | type: Schema.Literal("object"), |
| 482 | properties: Schema.Record( |
| 483 | Schema.String, |
| 484 | Schema.Union([StringSchema, NumberSchema, BooleanSchema, EnumSchema]) |
| 485 | ), |
| 486 | required: optional(Schema.Array(Schema.String)) |
| 487 | }) |
| 488 | |
| 489 | /** |
| 490 | * @internal |
| 491 | */ |
| 492 | export class Elicit extends Rpc.make("elicitation/create", { |
| 493 | success: ElicitResult, |
| 494 | error: Previous.McpError, |
| 495 | payload: { |
| 496 | ...Previous.RequestMeta.fields, |
| 497 | message: Schema.String, |
| 498 | requestedSchema: RequestedSchema |
| 499 | } |
| 500 | }) {} |
| 501 | |
| 502 | /** |
| 503 | * @internal |
| 504 | */ |
| 505 | export class ClientRequestRpcs extends RpcGroup.make( |
| 506 | Previous.Ping, |
| 507 | Initialize, |
| 508 | Complete, |
| 509 | Previous.SetLevel, |
| 510 | GetPrompt, |
| 511 | ListPrompts, |
| 512 | ListResources, |
| 513 | ListResourceTemplates, |
| 514 | ReadResource, |
| 515 | Previous.Subscribe, |
| 516 | Previous.Unsubscribe, |
| 517 | CallTool, |
| 518 | ListTools |
| 519 | ) {} |
| 520 | |
| 521 | /** |
| 522 | * @internal |
| 523 | */ |
| 524 | export class ClientNotificationRpcs extends RpcGroup.make( |
| 525 | Previous.CancelledNotification, |
| 526 | Previous.ProgressNotification, |
| 527 | Previous.InitializedNotification, |
| 528 | Previous.RootsListChangedNotification |
| 529 | ) {} |
| 530 | |
| 531 | /** |
| 532 | * @internal |
| 533 | */ |
| 534 | export class ServerRequestRpcs extends RpcGroup.make( |
| 535 | Previous.Ping, |
| 536 | CreateMessage, |
| 537 | Previous.ListRoots, |
| 538 | Elicit |
| 539 | ) {} |
| 540 | |
| 541 | /** |
| 542 | * @internal |
| 543 | */ |
| 544 | export class ServerNotificationRpcs extends RpcGroup.make( |
| 545 | Previous.CancelledNotification, |
| 546 | Previous.ProgressNotification, |
| 547 | Previous.LoggingMessageNotification, |
| 548 | Previous.ResourceUpdatedNotification, |
| 549 | Previous.ResourceListChangedNotification, |
| 550 | Previous.ToolListChangedNotification, |
| 551 | Previous.PromptListChangedNotification |
| 552 | ) {} |