Skip to content

Commit 43c08a8

Browse files
committed
fix: add ui schema prop to prevent validation errors on non-UI responses
1 parent 254bc8a commit 43c08a8

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/tools/mongodb/metadata/listDatabases.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class ListDatabasesTool extends MongoDBToolBase {
1111
public name = "list-databases";
1212
protected description = "List all databases for a MongoDB connection";
1313
protected argsShape = {};
14-
protected override outputSchema = ListDatabasesOutputSchema;
14+
protected override uiOutputSchema = ListDatabasesOutputSchema;
1515
static operationType: OperationType = "metadata";
1616

1717
protected async execute(): Promise<CallToolResult> {

src/tools/tool.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ export abstract class ToolBase {
282282
/**
283283
* Optional Zod schema defining the tool's structured output.
284284
*
285+
* This schema is registered with the MCP server and used to validate
286+
* `structuredContent` in the tool's response.
287+
*
285288
* @example
286289
* ```typescript
287290
* protected outputSchema = {
@@ -300,6 +303,12 @@ export abstract class ToolBase {
300303
*/
301304
protected outputSchema?: ZodRawShape;
302305

306+
/**
307+
* Optional Zod schema for structured output when mcpUI feature is enabled.
308+
* Takes precedence over `outputSchema` when defined and mcpUI is active.
309+
*/
310+
protected uiOutputSchema?: ZodRawShape;
311+
303312
private registeredTool: RegisteredTool | undefined;
304313

305314
protected get annotations(): ToolAnnotations {
@@ -525,7 +534,9 @@ export abstract class ToolBase {
525534
{
526535
description: this.description,
527536
inputSchema: this.argsShape,
528-
outputSchema: this.outputSchema,
537+
outputSchema: this.isFeatureEnabled("mcpUI")
538+
? (this.uiOutputSchema ?? this.outputSchema)
539+
: this.outputSchema,
529540
annotations: this.annotations,
530541
},
531542
callback

0 commit comments

Comments
 (0)