Fix/MCP exposure v2 TODO's (#675)

* fix: OAuth tokens secure storage for Windows & Linux

* fix(mcp): MCP Tool Re-exposure & Strict Input Validation

Fixes the MCP re-exposure bug by correctly handling tool deduplication, input validation with Ajv, and structured output (including images). Also disables experimental API betas by default to prevent 500 errors on external accounts.

* fix(mcp): skip official registry prefetch in non-first-party mode

Prevents unnecessary calls to Anthropic's MCP registry when using other API providers.

* fix(cli): disable experimental API betas by default

This prevents 500 errors from Anthropic's API when tool-calling with non-Anthropic accounts or models that don't support certain beta features.

* fix: issues raised in the PR review for #675
This commit is contained in:
Yakout
2026-04-15 23:03:06 +02:00
committed by GitHub
parent b66633ea4d
commit 77083d769b
4 changed files with 190 additions and 21 deletions

View File

@@ -1,7 +1,8 @@
import { Ajv } from 'ajv'
import { z } from 'zod/v4'
import { buildTool, type ToolDef } from '../../Tool.js'
import { buildTool, type ToolDef, type ValidationResult } from '../../Tool.js'
import { lazySchema } from '../../utils/lazySchema.js'
import type { PermissionResult } from '../../utils/permissions/PermissionResult.js'
import type { PermissionResult } from '../../types/permissions.js'
import { isOutputLineTruncated } from '../../utils/terminal.js'
import { DESCRIPTION, PROMPT } from './prompt.js'
import {
@@ -37,6 +38,8 @@ export type Output = z.infer<OutputSchema>
// Re-export MCPProgress from centralized types to break import cycles
export type { MCPProgress } from '../../types/tools.js'
const ajv = new Ajv({ strict: false })
export const MCPTool = buildTool({
isMcp: true,
// Overridden in mcpClient.ts with the real MCP tool name + args
@@ -72,6 +75,27 @@ export const MCPTool = buildTool({
message: 'MCPTool requires permission.',
}
},
async validateInput(input, context): Promise<ValidationResult> {
if (this.inputJSONSchema) {
try {
const validate = ajv.compile(this.inputJSONSchema)
if (!validate(input)) {
return {
result: false,
message: ajv.errorsText(validate.errors),
errorCode: 400,
}
}
} catch (error) {
return {
result: false,
message: `Failed to compile JSON schema for validation: ${error}`,
errorCode: 500,
}
}
}
return { result: true }
},
renderToolUseMessage,
// Overridden in mcpClient.ts
userFacingName: () => 'mcp',
@@ -100,3 +124,4 @@ export const MCPTool = buildTool({
}
},
} satisfies ToolDef<InputSchema, Output>)