MCP server that analyzes codebases and generates AGENTS.md files
Project description
agents-md-generator
MCP server that analyzes codebases with tree-sitter and generates AGENTS.md files.
Compatible with any MCP-capable client: Claude Code, Gemini CLI, Cursor, Windsurf, and others.
How it works: The server exposes three tools with a clear separation of concerns. generate_agents_md is the main entry point — it runs the analysis pipeline internally, embeds writing rules into the payload, and returns chunked read instructions to your client. scan_codebase is a standalone context tool for when you want deep codebase understanding without generating any file. read_payload_chunk streams the payload back in chunks regardless of which tool produced it. No large data travels over the MCP wire.
Supported Languages
Python · C# · TypeScript · JavaScript · Go
Installation
See INSTALLATION.md for the full guide including prerequisites and troubleshooting.
Requirements: Python 3.11+, uv, Git, and any MCP-compatible client.
Claude Code
claude mcp add agents-md uvx agents-md-generator
Or add it manually to ~/.claude.json (Linux/macOS) or %USERPROFILE%\.claude.json (Windows):
{
"mcpServers": {
"agents-md": {
"command": "uvx",
"args": ["agents-md-generator"]
}
}
}
Gemini CLI
Add it to ~/.gemini/settings.json:
{
"mcpServers": {
"agents-md": {
"command": "uvx",
"args": ["agents-md-generator"]
}
}
}
Other MCP clients (Cursor, Windsurf, etc.)
The server uses stdio transport. Add this entry to your client's MCP config under mcpServers:
"agents-md": {
"command": "uvx",
"args": ["agents-md-generator"]
}
Restart your client — uvx downloads the package automatically on first run.
Usage
Once registered, ask your AI client:
"Generate the AGENTS.md for this project"
The client will call generate_agents_md automatically. To scan a different directory:
"Generate the AGENTS.md for the project at /path/to/project"
Tools
| Tool | Purpose |
|---|---|
generate_agents_md |
Main entry point. Runs the pipeline internally, embeds writing rules into the payload, and returns chunked read instructions. Use this to create or update AGENTS.md. |
scan_codebase |
Standalone context tool. Analyzes the codebase and returns a pure data payload with no AGENTS.md mandate. Use this when you need architectural context for any other task. |
read_payload_chunk |
Streams the payload written by either tool in chunks until has_more is false. |
Tool Parameters
generate_agents_md
| Parameter | Type | Default | Description |
|---|---|---|---|
project_path |
string | "." |
Path to the project root |
scan_codebase
| Parameter | Type | Default | Description |
|---|---|---|---|
project_path |
string | "." |
Path to the project root |
force_full_scan |
boolean | true |
Ignore cache and rescan everything. Defaults to true — direct calls always perform a full scan. |
read_payload_chunk
| Parameter | Type | Default | Description |
|---|---|---|---|
project_path |
string | "." |
Must match the path used in the preceding tool call |
chunk_index |
integer | — | Zero-based chunk index. Increment until has_more is false |
What Gets Generated
The generated AGENTS.md follows the agents.md open standard. It is written as a README for AI agents, not as documentation for humans. Sections include:
- Project Overview — tech stack and top-level architecture shape
- Architecture & Data Flow — detected layers or domains with data flow direction
- Conventions & Patterns — naming rules, export contracts, import rules, and how to add new entities end-to-end
- Environment Variables — variables detected in source files and
.env.example - Setup Commands — exact install and run commands from
package.json,Makefile, etc. - Development Workflow — build, watch, and dev server commands
- Testing Instructions — test commands and framework info (if detected)
- Code Style — lint/format commands (if config files detected)
- Build and Deployment — CI pipeline info (if detected)
Sections with no detected data are omitted entirely.
How Incremental Scanning Works
- First run (cold start): All git-tracked source files are parsed with tree-sitter and cached
- Subsequent runs: Only files whose SHA-256 hash changed since the last scan are re-parsed
- Semantic diff: For modified files, only changed public symbols are included in the payload
- No source changes? The tool stops and asks whether you want to improve the existing
AGENTS.mdcontent anyway - Private symbols and test file internals are excluded from both cache and payload — only the public API surface matters for
AGENTS.md
How Large Payloads Are Streamed
For large codebases the analysis payload can be too big to return inline over the MCP wire. The server handles this transparently through read_payload_chunk.
generate_agents_md flow:
generate_agents_mdruns the pipeline internally, writes the payload to disk (includingAGENTS.mdwriting rules), and returnstotal_chunkswith read instructions- The client calls
read_payload_chunk(project_path, chunk_index=0), then incrementschunk_indexuntilhas_moreis false - The client concatenates all
datafields — the payload contains the rules and analysis data needed to writeAGENTS.md - The payload file is automatically deleted after the last chunk is read
scan_codebase flow (pure context, no AGENTS.md mandate):
scan_codebaseruns the analysis and writes a pure data payload to disk- Same chunked read via
read_payload_chunk - The client uses the payload for any purpose — code review, planning, Q&A
This flow is pure MCP — no filesystem access required from the client side. Any MCP-compatible client can follow it.
Cache and Payload Location
All runtime artifacts are stored outside your project, in the user cache directory:
~/.cache/agents-md-generator/<project-hash>/cache.json ← incremental scan cache
The <project-hash> is a SHA-256 of the project's absolute path — unique per project. Nothing is written to your repository.
Note: The server also writes a temporary
payload.jsonto this directory during analysis, but it is managed entirely by theread_payload_chunktool and deleted automatically after the last chunk is read. You never need to access it directly.
Project Configuration
Create .agents-config.json at your project root to customize behavior. This file is optional — all fields have defaults.
{
"project_size": "medium",
"exclude": [
"**/node_modules/**",
"**/bin/**",
"**/obj/**",
"**/.git/**",
"**/dist/**",
"**/build/**",
"**/__pycache__/**",
"**/*.min.js",
"**/*.min.css",
"**/*.bundle.js",
"**/vendor/**",
"**/packages/**",
"**/.venv/**",
"**/venv/**",
"**/bower_components/**",
"**/app/lib/**",
"**/wwwroot/lib/**",
"**/wwwroot/libs/**",
"**/static/vendor/**",
"**/public/vendor/**",
"**/assets/vendor/**",
"**/site-packages/**"
],
"include": [],
"languages": "auto",
"agents_md_path": "./AGENTS.md",
"max_file_size_bytes": 1048576
}
Options
| Key | Default | Description |
|---|---|---|
project_size |
"medium" |
Project scale — tunes all internal caps and thresholds (see Project Size Profiles) |
exclude |
(see above) | Glob patterns to exclude from analysis |
include |
[] |
If non-empty, only analyze files matching these patterns |
languages |
"auto" |
"auto" detects all supported languages, or pass a list like ["typescript", "python"] |
agents_md_path |
"./AGENTS.md" |
Output path for the generated file |
max_file_size_bytes |
1048576 |
Files larger than this are skipped (default: 1 MB) |
You can commit .agents-config.json to share settings with your team.
Environment Variables
| Variable | Default | Description |
|---|---|---|
AGENTS_MD_LOG_LEVEL |
INFO |
Server log verbosity. Set to DEBUG to see per-file analysis details. Valid values: DEBUG, INFO, WARNING, ERROR |
Project Size Profiles
The project_size setting controls how aggressively the payload is compressed. A single knob tunes all internal caps — methods per class, symbols per file, directory aggregation, route caps, tree depth, and impact filtering.
| Profile | Lines (guidance) | Impact filter | Description |
|---|---|---|---|
"small" |
0–15k | medium | Generous caps — nearly everything is included. Best for small projects where full visibility matters. |
"medium" (default) |
15k–50k | medium | Balanced caps suitable for most projects. |
"large" |
50k+ | high | Aggressive compression — only structural/breaking changes in diffs, more directory collapsing, tighter symbol caps. |
Detailed profile values:
| Constant | Small | Medium | Large |
|---|---|---|---|
| Methods per class | 30 | 12 | 8 |
| Symbols per file | 40 | 20 | 10 |
| Dir aggregation threshold | 20 | 10 | 5 |
| Files per layer (before overflow) | 15 | 8 | 5 |
| Aggregation sample size | 5 | 4 | 3 |
| Route controllers cap | 30 | 15 | 10 |
| Routes per controller | 15 | 8 | 5 |
| Go handlers cap | 15 | 8 | 5 |
| Directory tree depth | 4 | 3 | 2 |
| Impact filter | medium | medium | high |
What the Analysis Detects
Environment Variables
The server scans all source files for environment variable references using language-specific patterns:
| Language | Pattern detected |
|---|---|
| JavaScript / TypeScript | process.env.VAR_NAME |
| Python | os.environ['VAR'], os.getenv('VAR') |
| Go | os.Getenv("VAR") |
| Ruby | ENV['VAR'] |
| Rust | env!("VAR"), var("VAR") |
It also parses .env.example, .env.template, and .env.sample files at the project root.
Entry Points
Files named index, main, app, server, program, bootstrap, or startup (with any supported extension) are detected as entry points and annotated with their inferred role (e.g., "HTTP server bootstrap", "Electron main process").
Public API Surface
Tree-sitter parses each source file and extracts public symbols — classes, functions, methods, interfaces — filtering out private/protected members and underscore-prefixed symbols. For classes and structs, constructors (when they have parameters) and public properties are also included, revealing dependency injection patterns and data shapes. Interface methods are always included as they define the public contract. These are used to detect naming conventions, DI patterns, and export contracts across layers.
Architectural Distillation
For large codebases, the tool applies several heuristics to ensure the payload remains high-signal:
- Boilerplate Suppression: Common directories like
Migrations,bin,obj, andPropertiesare automatically flagged and collapsed in the project structure, preventing them from bloating the directory listing. - Low-Entropy Summarization: Files that primarily contain data structures (DTOs, Entities) with no logic methods are "minified". Instead of listing every property, the tool provides a high-level summary (e.g., "Contains 25 DTO classes").
- Semantic Clustering: The aggregator groups these minified summaries at the directory level, allowing the consuming AI to understand entire data layers through a single line of signal.
- Instruction Embedding: When called via
generate_agents_md, writing rules are embedded directly in the payload so the AI agent reads the "Rules of Engagement" before processing the code architecture. Directscan_codebasecalls return pure data with no mandate.
Credits
AGENTS.md format based on the open agents.md standard.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agents_md_generator-0.5.1.tar.gz.
File metadata
- Download URL: agents_md_generator-0.5.1.tar.gz
- Upload date:
- Size: 95.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22.2","id":"zara","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
201cacdc21572a46ed53d47701898877d6c372e7cde05f81e12984b71416d5d6
|
|
| MD5 |
8153eeb2d580e4b7be547729b05e5958
|
|
| BLAKE2b-256 |
55ee9054450bf730c4267e4b1fb4410921687a9402a31266f74a70a2a21cef30
|
File details
Details for the file agents_md_generator-0.5.1-py3-none-any.whl.
File metadata
- Download URL: agents_md_generator-0.5.1-py3-none-any.whl
- Upload date:
- Size: 57.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22.2","id":"zara","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ff750fc983ff17ebf8c5b4e7fd99723f2bc6e8c327753c2d6f463bae417e7d8
|
|
| MD5 |
fd7b674cbe0404d93a24afea65d61f37
|
|
| BLAKE2b-256 |
58f0ac72ec1ede836a0de2e0508f9477a3d96282843335fcc94ae95b11360d2e
|