( cwd: string, debug: boolean, verbose: boolean, )
| 33 | const MCP_COMMANDS: Command[] = [review] |
| 34 | |
| 35 | export async function startMCPServer( |
| 36 | cwd: string, |
| 37 | debug: boolean, |
| 38 | verbose: boolean, |
| 39 | ): Promise<void> { |
| 40 | // Use size-limited LRU cache for readFileState to prevent unbounded memory growth |
| 41 | // 100 files and 25MB limit should be sufficient for MCP server operations |
| 42 | const READ_FILE_STATE_CACHE_SIZE = 100 |
| 43 | const readFileStateCache = createFileStateCacheWithSizeLimit( |
| 44 | READ_FILE_STATE_CACHE_SIZE, |
| 45 | ) |
| 46 | setCwd(cwd) |
| 47 | const server = new Server( |
| 48 | { |
| 49 | name: 'claude/tengu', |
| 50 | version: MACRO.VERSION, |
| 51 | }, |
| 52 | { |
| 53 | capabilities: { |
| 54 | tools: {}, |
| 55 | }, |
| 56 | }, |
| 57 | ) |
| 58 | |
| 59 | server.setRequestHandler( |
| 60 | ListToolsRequestSchema, |
| 61 | async (): Promise<ListToolsResult> => { |
| 62 | // TODO: Also re-expose any MCP tools |
| 63 | const toolPermissionContext = getEmptyToolPermissionContext() |
| 64 | const tools = getTools(toolPermissionContext) |
| 65 | return { |
| 66 | tools: await Promise.all( |
| 67 | tools.map(async tool => { |
| 68 | let outputSchema: ToolOutput | undefined |
| 69 | if (tool.outputSchema) { |
| 70 | const convertedSchema = zodToJsonSchema(tool.outputSchema) |
| 71 | // MCP SDK requires outputSchema to have type: "object" at root level |
| 72 | // Skip schemas with anyOf/oneOf at root (from z.union, z.discriminatedUnion, etc.) |
| 73 | // See: https://github.com/anthropics/claude-code/issues/8014 |
| 74 | if ( |
| 75 | typeof convertedSchema === 'object' && |
| 76 | convertedSchema !== null && |
| 77 | 'type' in convertedSchema && |
| 78 | convertedSchema.type === 'object' |
| 79 | ) { |
| 80 | outputSchema = convertedSchema as ToolOutput |
| 81 | } |
| 82 | } |
| 83 | return { |
| 84 | ...tool, |
| 85 | description: await tool.prompt({ |
| 86 | getToolPermissionContext: async () => toolPermissionContext, |
| 87 | tools, |
| 88 | agents: [], |
| 89 | }), |
| 90 | inputSchema: zodToJsonSchema(tool.inputSchema) as ToolInput, |
| 91 | outputSchema, |
| 92 | } |
no test coverage detected