narrow-mcp
An MCP server that narrows large, low-density non-source files (logs, test output, CSV, JSON, HTML) down to the verbatim spans relevant to a stated intent -- verified against the original file, never a summary.
Why
Coding agents burn context reading large low-density files. A 40k-token log might hold a few hundred tokens of signal. This tool:
- Runs deterministic narrowing first (grep-style search, structural parsing per file type, sampling) -- free, fast, zero LLM cost.
- If that alone resolves the query with confidence (e.g. an exact CSV "null column" query), returns it directly. No LLM call at all.
- Otherwise passes only the narrowed candidates (never the raw file) to a cheap, fast selector model that returns line ranges and a one-line reason -- never prose.
- Re-reads the chosen line ranges from the original file on disk and returns that verbatim text. The selector's own words are never trusted or returned -- only its line-number coordinates, which get verified.
- If the selector fails, times out, or returns something invalid, falls back to the deterministic candidate set rather than failing outright.
Non-goals: source code retrieval (use LSP/tree-sitter/ast-grep), prose summarization, local/self-hosted models.
Status
v1, single file per call. Four file types: log/build-output, CSV, JSON (single document or JSONL), HTML.
Development
pip install -e ".[dev]"
pytest
python eval/run_eval.py # mocked selector, free
python eval/run_eval.py --live # real selector call, needs an API key (see Configuration)
Configuration
You only need to set one API key. The provider is auto-detected from whichever key is present -- no separate provider/model config required:
| If you set... | Provider used | Default model |
|---|---|---|
ANTHROPIC_API_KEY |
anthropic |
claude-haiku-4-5 |
OPENAI_API_KEY |
openai |
gpt-5-nano |
OPENROUTER_API_KEY |
openrouter |
openrouter/free (see below) |
| (none) | anthropic |
claude-haiku-4-5 (calls just always fall back to the deterministic path) |
If more than one key is set, priority is Anthropic > OpenAI > OpenRouter. Override anything explicitly with the env vars below.
Using OpenRouter's free models
OpenRouter still requires its own API key even for $0-cost models -- set
OPENROUTER_API_KEY and you're done, no other config needed. It defaults to
openrouter/free, a meta-router that auto-picks among whichever
tool-calling-capable models are currently free, so it never goes stale the
way hardcoding one specific :free model name would.
To see the current free-model roster live (it rotates) and pick a specific one instead of the meta-router:
narrow-mcp-list-free-models
Then set NARROW_MCP_SELECTOR_MODEL=<id> to whichever one you want.
OpenRouter's free tier is rate-limited (20 req/min; 50 req/day, or 1000/day once the account has $10+ lifetime spend) -- fine for interactive use, worth knowing about for batch runs.
All environment variables
NARROW_MCP_SELECTOR_PROVIDER--anthropic|openai|openrouter. Overrides auto-detection.NARROW_MCP_SELECTOR_MODEL-- overrides the provider's default model.NARROW_MCP_SELECTOR_API_KEY_ENV-- overrides which env var holds the key.NARROW_MCP_SELECTOR_TIMEOUT_S(default3.0)NARROW_MCP_MAX_CANDIDATE_CHARS,NARROW_MCP_MAX_CANDIDATES,NARROW_MCP_CONTEXT_LINES,NARROW_MCP_RIPGREP_PATH,NARROW_MCP_MAX_JSON_BYTES
Registering with Claude Code
claude mcp add narrow-mcp -- uvx narrow-mcp
Verify current claude mcp add flag syntax against claude mcp add --help
before relying on the above -- CLI flags change across releases.
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 narrow_mcp-0.1.0.tar.gz.
File metadata
- Download URL: narrow_mcp-0.1.0.tar.gz
- Upload date:
- Size: 26.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65b2a287810425af912394dda4dfe59c8a7e140937d7059797f32b990394b589
|
|
| MD5 |
b1a55080150604169bae8eac4185d2f3
|
|
| BLAKE2b-256 |
a8a27e1bb7afb05cdde0785eccb0b1402e02c37e0802d601697571f423dace93
|
Provenance
The following attestation bundles were made for narrow_mcp-0.1.0.tar.gz:
Publisher:
publish-to-pypi.yml on manik-prakash/narrow-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
narrow_mcp-0.1.0.tar.gz -
Subject digest:
65b2a287810425af912394dda4dfe59c8a7e140937d7059797f32b990394b589 - Sigstore transparency entry: 2756367596
- Sigstore integration time:
-
Permalink:
manik-prakash/narrow-mcp@a0c004b3514e1ee20251817d90f0bb70056e77a6 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/manik-prakash
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@a0c004b3514e1ee20251817d90f0bb70056e77a6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file narrow_mcp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: narrow_mcp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 31.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed7c2d7e0cd47694a9fa073f4e5e73d3388e2e21614e947e3a412f6fe31315e5
|
|
| MD5 |
8a1ad11e31f89408c678adf7499302d4
|
|
| BLAKE2b-256 |
9db789ca8de452dc2cb52b888a8e4f8e2a67f195aae7b1f6ac3a77d58f547709
|
Provenance
The following attestation bundles were made for narrow_mcp-0.1.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on manik-prakash/narrow-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
narrow_mcp-0.1.0-py3-none-any.whl -
Subject digest:
ed7c2d7e0cd47694a9fa073f4e5e73d3388e2e21614e947e3a412f6fe31315e5 - Sigstore transparency entry: 2756367635
- Sigstore integration time:
-
Permalink:
manik-prakash/narrow-mcp@a0c004b3514e1ee20251817d90f0bb70056e77a6 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/manik-prakash
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@a0c004b3514e1ee20251817d90f0bb70056e77a6 -
Trigger Event:
release
-
Statement type: