Просмотр исходного кода

Revert "fix(mcp): type tool error content"

This reverts commit 9258e8ca86136bb1f4f7d6831ccc6744051e3ee0.
adamelmore 2 месяцев назад
Родитель
Сommit
3a2ff11be8
1 измененных файлов с 7 добавлено и 17 удалено
  1. 7 17
      packages/opencode/src/mcp/catalog.ts

+ 7 - 17
packages/opencode/src/mcp/catalog.ts

@@ -65,7 +65,13 @@ export function convertTool(mcpTool: MCPToolDef, client: Client, timeout?: numbe
           onprogress: () => {},
         },
       )
-      if (result.isError) throw new Error(formatToolErrorContent(result.content))
+      if (result.isError)
+        throw new Error(
+          result.content
+            .flatMap((item) => (item.type === "text" ? [item.text] : []))
+            .filter((text) => text.trim())
+            .join("\n\n") || "MCP tool returned an error",
+        )
       if (result.structuredContent === undefined || result.structuredContent === null) return result
       return {
         ...result,
@@ -103,22 +109,6 @@ export function fetch<T extends { name: string }>(
 
 export const sanitize = (value: string) => value.replace(/[^a-zA-Z0-9_-]/g, "_")
 
-function formatToolErrorContent(content: unknown) {
-  if (!Array.isArray(content)) return "MCP tool returned an error"
-  return (
-    content
-      .flatMap((item) => (isTextContent(item) ? [item.text] : []))
-      .filter((text) => text.trim())
-      .join("\n\n") || "MCP tool returned an error"
-  )
-}
-
-function isTextContent(value: unknown): value is { type: "text"; text: string } {
-  if (typeof value !== "object" || value === null) return false
-  const item = value as Record<string, unknown>
-  return item.type === "text" && typeof item.text === "string"
-}
-
 export function prompts(client: Client, timeout?: number) {
   if (!client.getServerCapabilities()?.prompts) return Promise.resolve([])
   return paginate(