|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Zuplo |
| 3 | + * Copyright (c) 2024 Anthropic, PBC |
| 4 | + * |
| 5 | + * Licensed under the MIT License (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at: |
| 8 | + * |
| 9 | + * https://mit-license.org/ |
| 10 | + * |
| 11 | + * The following is a derivative work of github.com/modelcontextprotocol/typescript-sdk |
| 12 | + * and is attributed to the original authors under the License. |
| 13 | + */ |
| 14 | + |
| 15 | +import { z } from "zod/v4"; |
| 16 | + |
| 17 | +/** |
| 18 | + * Capabilities a client may support. Known capabilities are defined here, |
| 19 | + * in this schema, but this is not a closed set: any client can define its own, |
| 20 | + * additional capabilities. |
| 21 | + */ |
| 22 | +export const ClientCapabilitiesSchema = z |
| 23 | + .object({ |
| 24 | + /** |
| 25 | + * Experimental, non-standard capabilities that the client supports. |
| 26 | + */ |
| 27 | + experimental: z.optional(z.record(z.string(), z.object({}).loose())), |
| 28 | + |
| 29 | + /** |
| 30 | + * Present if the client supports listing roots. |
| 31 | + */ |
| 32 | + roots: z.optional( |
| 33 | + z |
| 34 | + .object({ |
| 35 | + /** |
| 36 | + * Whether the client supports notifications for changes to the roots list. |
| 37 | + */ |
| 38 | + listChanged: z.optional(z.boolean()), |
| 39 | + }) |
| 40 | + .loose() |
| 41 | + ), |
| 42 | + |
| 43 | + /** |
| 44 | + * Present if the client supports sampling from an LLM. |
| 45 | + */ |
| 46 | + sampling: z.optional( |
| 47 | + z |
| 48 | + .object({ |
| 49 | + /** |
| 50 | + * Whether the client supports context inclusion via includeContext parameter. |
| 51 | + */ |
| 52 | + context: z.optional(z.object({}).loose()), |
| 53 | + /** |
| 54 | + * Whether the client supports tool use via tools and toolChoice parameters. |
| 55 | + */ |
| 56 | + tools: z.optional(z.object({}).loose()), |
| 57 | + }) |
| 58 | + .loose() |
| 59 | + ), |
| 60 | + |
| 61 | + /** |
| 62 | + * Present if the client supports elicitation from the server. |
| 63 | + */ |
| 64 | + elicitation: z.optional( |
| 65 | + z |
| 66 | + .object({ |
| 67 | + form: z.optional(z.object({}).loose()), |
| 68 | + url: z.optional(z.object({}).loose()), |
| 69 | + }) |
| 70 | + .loose() |
| 71 | + ), |
| 72 | + |
| 73 | + /** |
| 74 | + * Present if the client supports task-augmented requests. |
| 75 | + */ |
| 76 | + tasks: z.optional( |
| 77 | + z |
| 78 | + .object({ |
| 79 | + /** |
| 80 | + * Whether this client supports tasks/list. |
| 81 | + */ |
| 82 | + list: z.optional(z.object({}).loose()), |
| 83 | + /** |
| 84 | + * Whether this client supports tasks/cancel. |
| 85 | + */ |
| 86 | + cancel: z.optional(z.object({}).loose()), |
| 87 | + /** |
| 88 | + * Specifies which request types can be augmented with tasks. |
| 89 | + */ |
| 90 | + requests: z.optional( |
| 91 | + z |
| 92 | + .object({ |
| 93 | + sampling: z.optional( |
| 94 | + z |
| 95 | + .object({ |
| 96 | + createMessage: z.optional(z.object({}).loose()), |
| 97 | + }) |
| 98 | + .loose() |
| 99 | + ), |
| 100 | + elicitation: z.optional( |
| 101 | + z |
| 102 | + .object({ |
| 103 | + create: z.optional(z.object({}).loose()), |
| 104 | + }) |
| 105 | + .loose() |
| 106 | + ), |
| 107 | + }) |
| 108 | + .loose() |
| 109 | + ), |
| 110 | + }) |
| 111 | + .loose() |
| 112 | + ), |
| 113 | + }) |
| 114 | + .loose(); |
| 115 | + |
| 116 | +/** |
| 117 | + * Capabilities that a server may support. Known capabilities are defined here, |
| 118 | + * in this schema, but this is not a closed set: any server can define its own, |
| 119 | + * additional capabilities. |
| 120 | + */ |
| 121 | +export const ServerCapabilitiesSchema = z |
| 122 | + .object({ |
| 123 | + /** |
| 124 | + * Experimental, non-standard capabilities that the server supports. |
| 125 | + */ |
| 126 | + experimental: z.optional(z.record(z.string(), z.object({}).loose())), |
| 127 | + |
| 128 | + /** |
| 129 | + * Present if the server supports sending log messages to the client. |
| 130 | + */ |
| 131 | + logging: z.optional(z.object({}).loose()), |
| 132 | + |
| 133 | + /** |
| 134 | + * Present if the server supports argument autocompletion suggestions. |
| 135 | + */ |
| 136 | + completions: z.optional(z.object({}).loose()), |
| 137 | + |
| 138 | + /** |
| 139 | + * Present if the server offers any prompt templates. |
| 140 | + */ |
| 141 | + prompts: z.optional( |
| 142 | + z |
| 143 | + .object({ |
| 144 | + /** |
| 145 | + * Whether this server supports notifications for changes to the prompt list. |
| 146 | + */ |
| 147 | + listChanged: z.optional(z.boolean()), |
| 148 | + }) |
| 149 | + .loose() |
| 150 | + ), |
| 151 | + |
| 152 | + /** |
| 153 | + * Present if the server offers any resources to read. |
| 154 | + */ |
| 155 | + resources: z.optional( |
| 156 | + z |
| 157 | + .object({ |
| 158 | + /** |
| 159 | + * Whether this server supports subscribing to resource updates. |
| 160 | + */ |
| 161 | + subscribe: z.optional(z.boolean()), |
| 162 | + /** |
| 163 | + * Whether this server supports notifications for changes to the resource list. |
| 164 | + */ |
| 165 | + listChanged: z.optional(z.boolean()), |
| 166 | + }) |
| 167 | + .loose() |
| 168 | + ), |
| 169 | + |
| 170 | + /** |
| 171 | + * Present if the server offers any tools to call. |
| 172 | + */ |
| 173 | + tools: z.optional( |
| 174 | + z |
| 175 | + .object({ |
| 176 | + /** |
| 177 | + * Whether this server supports notifications for changes to the tool list. |
| 178 | + */ |
| 179 | + listChanged: z.optional(z.boolean()), |
| 180 | + }) |
| 181 | + .loose() |
| 182 | + ), |
| 183 | + |
| 184 | + /** |
| 185 | + * Present if the server supports task-augmented requests. |
| 186 | + */ |
| 187 | + tasks: z.optional( |
| 188 | + z |
| 189 | + .object({ |
| 190 | + /** |
| 191 | + * Whether this server supports tasks/list. |
| 192 | + */ |
| 193 | + list: z.optional(z.object({}).loose()), |
| 194 | + /** |
| 195 | + * Whether this server supports tasks/cancel. |
| 196 | + */ |
| 197 | + cancel: z.optional(z.object({}).loose()), |
| 198 | + /** |
| 199 | + * Specifies which request types can be augmented with tasks. |
| 200 | + */ |
| 201 | + requests: z.optional( |
| 202 | + z |
| 203 | + .object({ |
| 204 | + tools: z.optional( |
| 205 | + z |
| 206 | + .object({ |
| 207 | + call: z.optional(z.object({}).loose()), |
| 208 | + }) |
| 209 | + .loose() |
| 210 | + ), |
| 211 | + }) |
| 212 | + .loose() |
| 213 | + ), |
| 214 | + }) |
| 215 | + .loose() |
| 216 | + ), |
| 217 | + }) |
| 218 | + .loose(); |
0 commit comments