The open source coding agent.
TypeScript
fix: ensure mcp tools are sanitized (#11984)
Aiden Clineb7b734f51f83
diff --git a/packages/opencode/src/provider/transform.ts b/packages/opencode/src/provider/transform.tsindex 2879f7edafc..6833cd0c0c8 100644--- a/packages/opencode/src/provider/transform.ts+++ b/packages/opencode/src/provider/transform.ts@@ -1,5 +1,6 @@import type { APICallError, ModelMessage } from "ai"import { mergeDeep, unique } from "remeda"+import type { JSONSchema7 } from "@ai-sdk/provider"import type { JSONSchema } from "zod/v4/core"import type { Provider } from "./provider"import type { ModelsDev } from "./models"@@ -719,7 +720,7 @@ export namespace ProviderTransform {return standardLimit}- export function schema(model: Provider.Model, schema: JSONSchema.BaseSchema) {+ export function schema(model: Provider.Model, schema: JSONSchema.BaseSchema | JSONSchema7): JSONSchema7 {/*if (["openai", "azure"].includes(providerID)) {if (schema.type === "object" && schema.properties) {@@ -793,7 +794,7 @@ export namespace ProviderTransform {schema = sanitizeGemini(schema)}- return schema+ return schema as JSONSchema7}export function error(providerID: string, error: APICallError) {diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.tsindex e0861c4df52..b85a7c336e9 100644--- a/packages/opencode/src/session/prompt.ts+++ b/packages/opencode/src/session/prompt.ts@@ -9,7 +9,7 @@ import { SessionRevert } from "./revert"import { Session } from "."import { Agent } from "../agent/agent"import { Provider } from "../provider/provider"-import { type Tool as AITool, tool, jsonSchema, type ToolCallOptions } from "ai"+import { type Tool as AITool, tool, jsonSchema, type ToolCallOptions, asSchema } from "ai"import { SessionCompaction } from "./compaction"import { Instance } from "../project/instance"import { Bus } from "../bus"@@ -738,6 +738,8 @@ export namespace SessionPrompt {const execute = item.executeif (!execute) continue+ const transformed = ProviderTransform.schema(input.model, asSchema(item.inputSchema).jsonSchema)+ item.inputSchema = jsonSchema(transformed)// Wrap execute to add plugin hooks and format outputitem.execute = async (args, opts) => {const ctx = context(args, opts)