agentleFS
wralewrale/mcp-server-tree-sitter/AGENTS.md

mcp-server-tree-sitter

AGENTS.md309 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 code style.

    Of the AGENTS.md files we read, the 35,337 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
  1. Distinctive:

    All of these must pass — CI enforces them:

    line 18
  2. Very specific:

    Create language/templates/<lang>.py with a TEMPLATES dict (follow existing patterns like go.py)

    line 45
  3. Very specific:

    Import and register in language/templates/__init__.py

    line 47
  4. Very specific:

    Add default symbol types in tools/analysis.py extract_symbols()

    line 48
  5. Very specific:

    Verify the language identifier works: from tree_sitter_language_pack import get_language.

    line 49
  6. Very specific:

    Root logger: Do NOT call configure_root_logger() at module import time.

    line 54
  7. Very specific:

    TypeScript grammar: Import statements require the import_clause node between import_statement and named_imports/namespace_import.

    line 56
  8. Distinctive:

    All PRs must pass CI (ruff check, ruff format, mypy, pytest)

    line 61
  9. Distinctive:

    Update README if features/languages changed

    line 69
  10. Very specific:

    Create GitHub release with tag vX.Y.Z — this triggers the release workflow which publishes to PyPI

    line 71

≈ “Common” is an estimate: at least 1 in 5 of the 45,344 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

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 pass

Or 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 — ConfigurationManager auto-loads YAML from MCP_TS_CONFIG_PATH or ~/.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 — includes query_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

  1. Create language/templates/<lang>.py with a TEMPLATES dict (follow existing patterns like go.py)
  2. Register the file extension in language/registry.py _language_map
  3. Import and register in language/templates/__init__.py
  4. Add default symbol types in tools/analysis.py extract_symbols()
  5. 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 import get_container from __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_languages list: Uses tree-sitter-language-pack identifiers (e.g., csharp not c_sharp). Verify with get_language() before adding.
  • TypeScript grammar: Import statements require the import_clause node between import_statement and named_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

  1. Bump version in pyproject.toml
  2. Update README if features/languages changed
  3. Merge to main, confirm CI green
  4. Create GitHub release with tag vX.Y.Z — this triggers the release workflow which publishes to PyPI

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.