| import { z } from 'zod/v4' |
| import { buildTool, type ToolDef } from '../../Tool.js' |
| import { lazySchema } from '../../utils/lazySchema.js' |
| import type { PermissionResult } from '../../utils/permissions/PermissionResult.js' |
| import { isOutputLineTruncated } from '../../utils/terminal.js' |
| import { DESCRIPTION, PROMPT } from './prompt.js' |
| import { |
| renderToolResultMessage, |
| renderToolUseMessage, |
| renderToolUseProgressMessage, |
| } from './UI.js' |
|
|
| |
| export const inputSchema = lazySchema(() => z.object({}).passthrough()) |
| type InputSchema = ReturnType<typeof inputSchema> |
|
|
| export const outputSchema = lazySchema(() => |
| z.string().describe('MCP tool execution result'), |
| ) |
| type OutputSchema = ReturnType<typeof outputSchema> |
|
|
| export type Output = z.infer<OutputSchema> |
|
|
| |
| export type { MCPProgress } from '../../types/tools.js' |
|
|
| export const MCPTool = buildTool({ |
| isMcp: true, |
| |
| isOpenWorld() { |
| return false |
| }, |
| |
| name: 'mcp', |
| maxResultSizeChars: 100_000, |
| |
| async description() { |
| return DESCRIPTION |
| }, |
| |
| async prompt() { |
| return PROMPT |
| }, |
| get inputSchema(): InputSchema { |
| return inputSchema() |
| }, |
| get outputSchema(): OutputSchema { |
| return outputSchema() |
| }, |
| |
| async call() { |
| return { |
| data: '', |
| } |
| }, |
| async checkPermissions(): Promise<PermissionResult> { |
| return { |
| behavior: 'passthrough', |
| message: 'MCPTool requires permission.', |
| } |
| }, |
| renderToolUseMessage, |
| |
| userFacingName: () => 'mcp', |
| renderToolUseProgressMessage, |
| renderToolResultMessage, |
| isResultTruncated(output: Output): boolean { |
| return isOutputLineTruncated(output) |
| }, |
| mapToolResultToToolResultBlockParam(content, toolUseID) { |
| return { |
| tool_use_id: toolUseID, |
| type: 'tool_result', |
| content, |
| } |
| }, |
| } satisfies ToolDef<InputSchema, Output>) |
|
|