contextful-mcp
by ceejaykelly
README.md
# contextful-mcp
Project-agnostic MCP server for persona loading, doc search, code search, and cached test execution. Gives coding agents **on-demand, ranked access** to project context — without front-loading the entire context window at session start.
## Token savings
<!-- benchmark-start -->
<!-- auto-updated by `bun benchmark.js --update-readme` — do not edit manually -->
| Metric | Baseline | Result |
|---|---|:---:|
| **Effectiveness vs grep** | Agent uses `grep -C 10` to find relevant lines | **58.8% saved** |
| **Effectiveness vs files** | Agent reads whole files after locating them | **75.7% saved** |
| **Quality (hit@5)** | Result set contains the expected file or section | **89%** |
<sub>Measured on 26 files, v0.4.0, 2026-04-06. Run `bun benchmark.js --update-readme` to regenerate.</sub>
<!-- benchmark-end -->
> See [docs/benchmarks.md](docs/benchmarks.md) for methodology.
---
## Recommended workflow
1. `get_status` — check which features are available and whether a persona is already active.
2. `list_personas` → `load_persona` — choose and load the right specialist for your task.
3. `search_docs` — pull targeted doc sections before opening full files.
4. `search_code` — find relevant code blocks before reading full files.
5. Use `get_doc` / `get_code_file` only when you need complete content.
---
## Configuration
Configured **exclusively** via environment variables — no config files or CLI args.
Set vars in the `env` block of your `.mcp.json` (or equivalent host config).
Omitting a variable **disables the corresponding feature** and removes its tools entirely.
### All environment variables
| Variable | Type | Default | Description |
|---|---|---|---|
| `CONTEXTSERVER_REPOROOT` | string | server dir | Base dir for test commands and relative path resolution. Set to `"."` to use the MCP host's working directory. |
| `CONTEXTSERVER_DOCSLOCATIONS` | JSON array | — | Directories containing `.md` documentation files. |
| `CONTEXTSERVER_PERSONASLOCATIONS` | JSON array | — | Directories containing `.md` agent persona files. |
| `CONTEXTSERVER_CODELOCATIONS` | JSON array | — | Directories to index for code search. Multiple entries are merged into one searchable index. |
| `CONTEXTSERVER_WATCHLOCATIONS` | JSON array | auto-derived | Directories to watch for hot-reload. Defaults to the union of all configured content locations. |
| `CONTEXTSERVER_BLOCK_SIZE` | integer (≥5) | `30` | Maximum lines per code block. Increase for larger functions; decrease for faster scanning. |
| `CONTEXTSERVER_CODE_EXTENSIONS` | JSON array | `[".js",".ts",".jsx",".tsx",".json",".md"]` | File extensions to index. E.g. `[".py",".go"]` for a Python/Go project. Leading dot is optional. |
| `CONTEXTSERVER_URLS` | JSON array | — | External URLs to fetch, strip, split into sections, and include in `search_docs` results. |
| `CONTEXTSERVER_URL_TTL` | integer (seconds) | `3600` | How long to cache fetched URL content before re-fetching. |
| `CONTEXTSERVER_TEST` | JSON object | — | Test runner config (see below). |
#### `CONTEXTSERVER_TEST` object fields
| Key | Type | Default | Description |
|---|---|---|---|
| `commands` | string[] | `[]` | Shell commands to run, e.g. `["bun test", "bun run typecheck"]`. Each is executed in sequence. |
| `hashLocations` | string[] | `[]` | Directories whose files are hashed to detect changes. If the hash matches the cache, tests are skipped. |
| `hashExtensions` | string[] | `[".js",".ts",".jsx",".tsx",".json",".md"]` | File extensions to include when computing the hash. |
| `cacheFile` | string | `.cache/test_cache.json` | Path to write the result cache (relative to `REPOROOT`). |
| `timeout` | integer (ms) | `30000` | Per-command timeout in milliseconds. Commands exceeding this are killed and marked failed. |
### Example `.mcp.json` — single repo
```jsonc
{
"mcpServers": {
"contextful-mcp": {
"type": "stdio",
"command": "/path/to/contextful-mcp.exe",
"env": {
"CONTEXTSERVER_REPOROOT": ".",
"CONTEXTSERVER_DOCSLOCATIONS": "[\"./docs\"]",
"CONTEXTSERVER_PERSONASLOCATIONS": "[\"./agent_personas\"]",
"CONTEXTSERVER_CODELOCATIONS": "[\"./src\"]",
"CONTEXTSERVER_TEST": "{\"hashLocations\":[\"./src\",\"./tests\"],\"commands\":[\"bun test\"],\"hashExtensions\":[\".js\",\".ts\"]}"
}
}
}
}
```
### Example — multiple doc and code directories
Supply multiple paths in the JSON array. All are merged into a single searchable index.
```jsonc
"CONTEXTSERVER_DOCSLOCATIONS": "[\"./docs\", \"./packages/core/docs\", \"./packages/api/docs\"]",
"CONTEXTSERVER_CODELOCATIONS": "[\"./src\", \"./packages/core/src\", \"./packages/api/src\"]"
```
### Example — multi-repo (indexing two separate projects)
Use absolute paths to index sources from multiple repositories simultaneously.
The `directory=` filter in `search_code` lets agents scope queries to a specific repo.
```jsonc
"CONTEXTSERVER_REPOROOT": "/home/user/projects/backend",
"CONTEXTSERVER_CODELOCATIONS": "[\"/home/user/projects/backend/src\", \"/home/user/projects/frontend/src\"]",
"CONTEXTSERVER_DOCSLOCATIONS": "[\"/home/user/projects/backend/docs\", \"/home/user/projects/frontend/docs\"]"
```
> **Tip:** Use `search_code(query, directory="backend/")` or `search_code(query, directory="frontend/")` to restrict results.
### Example — indexing external URLs (e.g. API reference docs)
Fetched pages are stripped of HTML, split into sections, and surfaced in `search_docs` results.
```jsonc
"CONTEXTSERVER_URLS": "[\"https://developers.cloudflare.com/workers/runtime-apis/\", \"https://bun.sh/docs/bundler\"]",
"CONTEXTSERVER_URL_TTL": "3600"
```
### Example — Python/Go project
```jsonc
"CONTEXTSERVER_CODE_EXTENSIONS": "[\".py\", \".pyi\"]",
"CONTEXTSERVER_BLOCK_SIZE": "50"
```
---
## Tools reference
Tools are registered conditionally — only those whose feature group is configured appear in the agent's tool list.
### Always available
| Tool | Parameters | Description |
|---|---|---|
| `get_status` | — | Index stats (file count, block count, section count), which features are enabled, and the currently active persona. Check this before loading a persona — it may already be active. |
| `get_usage` | — | Usage guide: all available tools, recommended workflow, and feature-specific tips. Call this first when new to the server. |
| `get_metrics` | — | Runtime performance metrics: per-tool call counts, average latency, index rebuild count, test cache hit rate. |
| `report_bad_result` | `tool`, `query`, `reason`, `expected?` | Report a search result that was unhelpful or wrong. Logs structured feedback to stderr to help identify ranking gaps over time. |
### Persona tools — requires `CONTEXTSERVER_PERSONASLOCATIONS`
| Tool | Parameters | Description |
|---|---|---|
| `list_personas` | — | Lists all persona names with their one-line purpose. Call this first to choose the right persona. |
| `load_persona` | `name`, `full?`, `field?` | Load a named persona. Returns a compact card by default. Pass `full=true` for the complete system prompt. Pass `field=` (e.g. `"tools"`, `"background"`, `"use_cases"`, or any `##` heading) to retrieve a single attribute without loading everything. |
| `create_persona` | `name`, `description`, `prompt_body`, `use_cases?`, `tools?`, `background?`, `overwrite?` | Write a new structured persona `.md` file and immediately index it. |
### Documentation tools — requires `CONTEXTSERVER_DOCSLOCATIONS` (or `CONTEXTSERVER_URLS`)
| Tool | Parameters | Description |
|---|---|---|
| `list_docs` | — | Lists all indexed documentation files with their titles. |
| `search_docs` | `query`, `limit?` (default 5, max 10) | Ranked section search across all doc files **and** any indexed URLs. Returns sections with source, heading, and score tier (strong/partial/weak). Sections are capped at ~600 chars; use `get_doc` if a result is truncated. |
| `get_doc` | `name`, `section?` | Full content of a doc file. Pass `section=` to return only a named `##` heading (case-insensitive substring match). Prefer `search_docs` for targeted queries. |
| `analyze_doc` | `name` | Audits a doc's section structure for search quality: flags sections that are too long, too short, or misstructured for ranked retrieval. |
### Code search tools — requires `CONTEXTSERVER_CODELOCATIONS`
| Tool | Parameters | Description |
|---|---|---|
| `search_code` | `query`, `is_regex?`, `language?`, `directory?`, `limit?` (default 5, max 20) | Ranked code block search across all indexed source files. `language` filters by extension (e.g. `"ts"`); `directory` filters by path substring (e.g. `"src/api/"`). Use `is_regex=true` for regex patterns. Returns scored blocks with file path and line number. |
| `get_code_file` | `path` | Full content of an indexed source file. Use paths from `search_code` results. |
### Test tools — requires `CONTEXTSERVER_TEST`
| Tool | Parameters | Description |
|---|---|---|
| `check_tests` | — | **Start here.** Runs tests (or returns the cached result if nothing changed) and returns a compact pass/fail. On failure, lists each failing test with the file path and line number so you can go directly to the problem. Updates the cache. |
| `get_test_results` | — | Returns the full test output (all stdout + stderr). Call only after `check_tests` reports failures and you need the complete error context. |
---
## Notes
- Lock files (e.g. `bun.lock`, `package-lock.json`) and minified files (`.min.js`) are automatically excluded from the code index.
- Duplicate persona or doc names across multiple directories produce a warning to stderr; the last-loaded file wins.
- Hot-reload watches configured locations for changes and rebuilds the index (debounced 2 s). `CONTEXTSERVER_WATCHLOCATIONS` defaults to the union of all content locations so it rarely needs to be set explicitly.
- All paths in array env vars may be absolute or relative to `CONTEXTSERVER_REPOROOT`.
- `CONTEXTSERVER_URLS` content is fetched at startup and on each hot-reload (within the TTL). On fetch failure the previous cached content is retained.
This server cannot be deployed
Maintenance
ActivityNo data
ResponsivenessNo recent community issues