# Track Specification: Tree-Sitter C/C++ MCP Tools

## Overview

Add tree-sitter-based C and C++ parsing support to the MCP client, providing skeleton and outline tools for C/C++ codebases. Tools will be prefixed `ts_c_` and `ts_cpp_` to distinguish from existing Python tools and leave namespace open for future gencpp integration.

## Current State Audit (as of 08e003a)

### Already Implemented
- `src/file_cache.py`: ASTParser class with tree-sitter-python support
- `src/mcp_client.py`: 26 MCP tools (all Python-prefixed: `py_get_skeleton`, `py_get_definition`, etc.)
- `pyproject.toml`: tree-sitter>=0.25.2 and tree-sitter-python>=0.25.0 already listed
- Existing pattern: `get_skeleton()`, `get_code_outline()` methods extract functions, classes, docstrings

### Gaps to Fill (This Track's Scope)
- No C/C++ tree-sitter grammars installed
- No C/C++ parsing logic in ASTParser
- No MCP tools for C/C++ code extraction
- No MCP tools for C/C++ code modification (Parity with Python `py_update_definition`)

## Goals

1. Add tree-sitter-c and tree-sitter-cpp dependencies
2. Extend ASTParser to support C and C++ languages
3. Implement skeleton and outline generation for C/C++ (functions, structs, enums, classes)
4. Add MCP tools: `ts_c_get_skeleton`, `ts_cpp_get_skeleton`, `ts_c_get_code_outline`, `ts_cpp_get_code_outline`
5. Implement definition, signature, and update tools for C/C++ parity
6. Register tools in mcp_client dispatch
7. Validate tools against real-world C++ components from `gencpp` repository

## Functional Requirements

### Dependencies
- Add `tree-sitter-c` to pyproject.toml
- Add `tree-sitter-cpp` to pyproject.toml

### ASTParser Extensions
- Modify `ASTParser.__init__` to accept "c", "cpp", "python" as valid languages
- Load appropriate tree-sitter language grammar based on parameter
- Reuse existing caching mechanism (`get_cached_tree`)
- Implement C-specific node types: `function_definition`, `struct_specifier`, `enum_specifier`, `typedef`
- Implement C++-specific node types: all C types plus `class_specifier`, `access_specifier`, `template_declaration`

### MCP Tools
| Tool Name | Description |
|-----------|-------------|
| `ts_c_get_skeleton` | Returns C file skeleton (function signatures, struct/union/enum definitions) |
| `ts_cpp_get_skeleton` | Returns C++ file skeleton (above + class methods, templates, namespaces) |
| `ts_c_get_code_outline` | Returns hierarchical C outline (functions, structs, enums, globals with line ranges) |
| `ts_cpp_get_code_outline` | Returns hierarchical C++ outline (above + classes, templates, namespaces) |
| `ts_c_get_definition` | Get full source code of a specific C function or struct |
| `ts_cpp_get_definition` | Get full source code of a specific C++ class, function, or method |
| `ts_c_get_signature` | Get only the signature part of a C function |
| `ts_cpp_get_signature` | Get only the signature part of a C++ function or method |
| `ts_c_update_definition` | Surgically replace the definition of a C function or struct |
| `ts_cpp_update_definition` | Surgically replace the definition of a C++ class, function, or method |

### Tool Output Format
Match existing Python tool formats for consistency:
- Skeleton: signatures + docstrings, bodies replaced with `...`
- Outline: hierarchical list with `[Class] name (Lines X-Y)` format
- Definition: raw source code of the identified range
- Signature: code from start of definition until start of block/semicolon

## Non-Functional Requirements

- Follow existing 1-space indentation code style
- Use exact same patterns as existing Python tree-sitter implementation
- Maintain AST cache with mtime invalidation (reuse existing logic)
- Tools must pass allowlist check in mcp_client

## Architecture Reference

- **ASTParser pattern**: `src/file_cache.py:16-333` - existing tree-sitter integration
- **MCP tool dispatch**: `src/mcp_client.py:920-987` - tool registration and dispatch
- **Tool schema format**: `src/mcp_client.py:998-1000` - `get_tool_schemas()`

## Out of Scope
- Cross-file symbol resolution (AI uses search tools for this)
- Template instantiation analysis
- Macro expansion
- gencpp integration (orchestrating gencpp logic itself is a separate track)
