Skip to main content

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:

  1. Runs deterministic narrowing first (grep-style search, structural parsing per file type, sampling) -- free, fast, zero LLM cost.
  2. If that alone resolves the query with confidence (e.g. an exact CSV "null column" query), returns it directly. No LLM call at all.
  3. 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.
  4. 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.
  5. 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 (default 3.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

narrow_mcp-0.1.0.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

narrow_mcp-0.1.0-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

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

Hashes for narrow_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 65b2a287810425af912394dda4dfe59c8a7e140937d7059797f32b990394b589
MD5 b1a55080150604169bae8eac4185d2f3
BLAKE2b-256 a8a27e1bb7afb05cdde0785eccb0b1402e02c37e0802d601697571f423dace93

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for narrow_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed7c2d7e0cd47694a9fa073f4e5e73d3388e2e21614e947e3a412f6fe31315e5
MD5 8a1ad11e31f89408c678adf7499302d4
BLAKE2b-256 9db789ca8de452dc2cb52b888a8e4f8e2a67f195aae7b1f6ac3a77d58f547709

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page