| 1255 | cb: ToolHandler<InputArgs>, |
| 1256 | ): this; |
| 1257 | registerTool(...args: unknown[]): unknown { |
| 1258 | const baseFn = McpServerBase.prototype.registerTool as ( |
| 1259 | ...args: unknown[] |
| 1260 | ) => unknown; |
| 1261 | |
| 1262 | if (typeof args[0] === "string") { |
| 1263 | baseFn.call(this, args[0], args[1], args[2]); |
| 1264 | return this; |
| 1265 | } |
| 1266 | |
| 1267 | const config = args[0] as ToolConfig<ZodRawShapeCompat>; |
| 1268 | const cb = args[1] as ToolHandler<ZodRawShapeCompat>; |
| 1269 | |
| 1270 | const { |
| 1271 | name, |
| 1272 | view, |
| 1273 | securitySchemes, |
| 1274 | _meta: userToolMeta, |
| 1275 | ...toolFields |
| 1276 | } = config; |
| 1277 | |
| 1278 | const toolMeta: InternalToolMeta = { ...userToolMeta }; |
| 1279 | |
| 1280 | if (securitySchemes) { |
| 1281 | // SEP-1488 puts `securitySchemes` at the top level of the tool |
| 1282 | // descriptor, but the SDK's `registerTool` drops unknown top-level |
| 1283 | // fields, so the canonical spot isn't reachable without intercepting |
| 1284 | // `tools/list`. Use the `_meta` back-compat mirror documented in the |
| 1285 | // Apps SDK reference until SEP-1488 lands in the spec. |
| 1286 | toolMeta.securitySchemes = securitySchemes; |
| 1287 | } |
| 1288 | |
| 1289 | if (view) { |
| 1290 | this.enforceOneToolPerView(view.component, name); |
| 1291 | this.registerViewResources(name, view, toolMeta); |
| 1292 | } |
| 1293 | |
| 1294 | const wrappedCb = this.wrapHandler(cb, { attachViewUUID: Boolean(view) }); |
| 1295 | |
| 1296 | baseFn.call(this, name, { ...toolFields, _meta: toolMeta }, wrappedCb); |
| 1297 | |
| 1298 | return this; |
| 1299 | } |
| 1300 | } |