mcp-server-tree-sitter
AGENTS.md310 starsChanged 6 months agoMITArchived repositoryView on GitHub
Instructions for AI coding agents working in this repository. MCP Tree-sitter Server — a Model Context Protocol server providing code analysis via tree-sitter. Python 3.10+, packaged with hatchling, managed with uv. All of these must pass — CI enforces them: Or use the Makefile: make prepare tree-sitter >= 0.24 removed Query.captures(). Always use the query_captures(query, node) wrapper from utils/tree_sitter_helpers.py instead of calling query.captures() directly. This applies to both source and test code.
- Installs packages
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,736 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
The file
We split this AGENTS.md into the rules it gives an agent
10 rules. About 0 are common, 3 are distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 18
All of these must pass — CI enforces them:
- Very specific: line 45
Create language/templates/<lang>.py with a TEMPLATES dict (follow existing patterns like go.py)
- Very specific: line 47
Import and register in language/templates/__init__.py
- Very specific: line 48
Add default symbol types in tools/analysis.py extract_symbols()
- Very specific: line 49
Verify the language identifier works: from tree_sitter_language_pack import get_language.
- Very specific: line 54
Root logger: Do NOT call configure_root_logger() at module import time.
- Very specific: line 56
TypeScript grammar: Import statements require the import_clause node between import_statement and named_imports/namespace_import.
- Distinctive: line 61
All PRs must pass CI (ruff check, ruff format, mypy, pytest)
- Distinctive: line 69
Update README if features/languages changed
- Very specific: line 71
Create GitHub release with tag vX.Y.Z — this triggers the release workflow which publishes to PyPI
≈ “Common” is an estimate: at least 1 in 5 of the 16,597 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md
Instructions for AI coding agents working in this repository.
Project Overview
MCP Tree-sitter Server — a Model Context Protocol server providing code analysis via tree-sitter. Python 3.10+, packaged with hatchling, managed with uv.
Setup
uv venv --python 3.12
uv pip install -e ".[dev]"Before Committing
All of these must pass — CI enforces them:
ruff check src/ # Lint (E, F, I, W, B rules)
ruff format --check src/ # Format check
mypy src/mcp_server_tree_sitter # Type check
pytest tests/ # 217+ tests, must all passOr use the Makefile: make prepare
Key Architecture
- Source:
src/mcp_server_tree_sitter/ - DI container:
di.py— constructs all dependencies; avoid circular imports with it - Config:
config.py—ConfigurationManagerauto-loads YAML fromMCP_TS_CONFIG_PATHor~/.config/tree-sitter/config.yaml. Precedence: env vars > YAML > defaults - Language registry:
language/registry.py— maps file extensions to tree-sitter-language-pack identifiers - Templates:
language/templates/— per-language query templates (one file per language) - Tools:
tools/— MCP tool implementations (analysis, search, ast_operations, file_operations) - Helpers:
utils/tree_sitter_helpers.py— includesquery_captures()compat wrapper for tree-sitter >= 0.24
tree-sitter API Compatibility
tree-sitter >= 0.24 removed Query.captures(). Always use the query_captures(query, node) wrapper from utils/tree_sitter_helpers.py instead of calling query.captures() directly. This applies to both source and test code.
Adding a New Language
- Create
language/templates/<lang>.pywith aTEMPLATESdict (follow existing patterns likego.py) - Register the file extension in
language/registry.py_language_map - Import and register in
language/templates/__init__.py - Add default symbol types in
tools/analysis.pyextract_symbols() - Verify the language identifier works:
from tree_sitter_language_pack import get_language; get_language("<id>")
Common Pitfalls
- Circular imports with
di.py: The DI container constructs registries. Don't importget_containerfrom__init__methods of objects the container creates. Use method injection instead. - Root logger: Do NOT call
configure_root_logger()at module import time. Libraries must not reconfigure the root logger. common_languageslist: Uses tree-sitter-language-pack identifiers (e.g.,csharpnotc_sharp). Verify withget_language()before adding.- TypeScript grammar: Import statements require the
import_clausenode betweenimport_statementandnamed_imports/namespace_import. - Test isolation: Some tests are order-dependent due to shared singleton state. If a test passes alone but fails in suite, check for state leakage.
PR Process
- All PRs must pass CI (ruff check, ruff format, mypy, pytest)
- Squash merge to main
- Credit community contributors in commit messages and PR descriptions
- For dependency bumps, pin transitive deps with security floors in
pyproject.toml
Release Process
- Bump version in
pyproject.toml - Update README if features/languages changed
- Merge to main, confirm CI green
- Create GitHub release with tag
vX.Y.Z— this triggers the release workflow which publishes to PyPI
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

