Route tool calls to the appropriate handler.
(name: str, arguments: dict[str, Any])
| 358 | "type": "string", |
| 359 | "description": "Absolute path to the repository", |
| 360 | }, |
| 361 | "output_dir": { |
| 362 | "type": "string", |
| 363 | "description": "Directory containing generated docs (default: ./docs)", |
| 364 | "default": "docs", |
| 365 | }, |
| 366 | }, |
| 367 | "required": ["repo_path"], |
| 368 | }, |
| 369 | ), |
| 370 | ] |
| 371 | |
| 372 | |
| 373 | # =================================================================== |
| 374 | # Tool dispatch |
| 375 | # =================================================================== |
| 376 | |
| 377 | |
| 378 | @server.list_tools() |
| 379 | async def list_tools() -> list[Tool]: |
| 380 | """List all available CodeWiki MCP tools.""" |
| 381 | return _fine_grained_tools() + _legacy_tools() |
| 382 | |
| 383 | |
| 384 | _analyze_lock = asyncio.Lock() |
| 385 | |
| 386 | |
| 387 | @server.call_tool() |
| 388 | async def call_tool(name: str, arguments: dict[str, Any]) -> list[TextContent]: |
| 389 | """Route tool calls to the appropriate handler.""" |
| 390 | try: |
| 391 | # --- Fine-grained tools (no LLM config needed) --- |
| 392 | # Synchronous handlers run via asyncio.to_thread() so they never |
| 393 | # block the event loop (which would hang the MCP stdio server). |
| 394 | if name == "analyze_repo": |
| 395 | from codewiki.mcp.tools.analysis import handle_analyze_repo |
| 396 | |
| 397 | # Offloaded to a thread so the long-running analysis does not |
| 398 | # block the stdio pump. The lock serialises concurrent |
| 399 | # analyze_repo calls: each analyzer owns its own Tree-sitter |
| 400 | # Parser, but parsers are not safe to drive from several |
| 401 | # threads at once and the job is heavy anyway. |
| 402 | async with _analyze_lock: |
| 403 | return [_text(await asyncio.to_thread(handle_analyze_repo, arguments, _store))] |
| 404 | |
| 405 | elif name == "read_code_components": |
| 406 | from codewiki.mcp.tools.code_reader import handle_read_code_components |
| 407 | |
| 408 | return [_text(await asyncio.to_thread(handle_read_code_components, arguments, _store))] |
| 409 | |
| 410 | elif name == "write_doc_file": |
| 411 | from codewiki.mcp.tools.doc_writer import handle_write_doc_file |
| 412 | |
| 413 | result = await handle_write_doc_file(arguments, _store) |
| 414 | return [_text(result)] |
| 415 | |
| 416 | elif name == "edit_doc_file": |
| 417 | from codewiki.mcp.tools.doc_writer import handle_edit_doc_file |
nothing calls this directly
no test coverage detected