Skip to main content

importlens-mcp

Stop feeding your coding agent the whole repo. Feed it the files that actually matter.

importlens-mcp is a tiny MCP server that reads your Python project's import graph and hands your agent only the slice of code relevant to what it's working on — the file that defines a symbol, the files that use it, and the files it depends on. No embeddings, no vector DB, no re-reading the tree on every question.

npx-style one-liner for python:  uvx importlens-mcp

Why: on a big repo, agents burn tokens (and get confused) re-reading files that have nothing to do with the task. importlens-mcp answers "which files matter for UserService?" in one call, using nothing but Python's own ast.

demo


Install

# with uv (recommended)
uvx importlens-mcp            # run straight from PyPI, no install

# or pip
pip install importlens-mcp

Add it to your agent. For(what I use) Claude Code:

claude mcp add importlens-mcp -- uvx importlens-mcp

For any MCP client, point it at the importlens-mcp command (stdio transport). It indexes the current working directory by default, or set IMPORTLENS_ROOT.

What your agent gets

Four tools, all returning plain readable text:

tool what it does
project_map one-glance summary: files, modules, symbols, line count
relevant_files(symbol) the files that define a symbol + its dependents + its dependencies
file_context(path) one file's source plus the paths of its local imports
reindex rebuild after you change files on disk

Example

Ask your agent "how does CodeIndex fit together?" and under the hood it calls:

relevant_files("CodeIndex")
# Relevant files for `CodeIndex`

## Defined in
- src/importlens_mcp/graph.py

## Used by (dependents)
- src/importlens_mcp/__main__.py
- src/importlens_mcp/server.py

## Depends on (local imports)
- (none)

Three files instead of thirty. That's the whole idea.

Quick look without an agent

importlens-mcp map .
importlens-mcp: 4 files, 4 modules, 10 symbols, 371 lines
  importlens_mcp           src/importlens_mcp/__init__.py
  importlens_mcp.graph     src/importlens_mcp/graph.py
  importlens_mcp.server    src/importlens_mcp/server.py
  ...

How it works

  1. Walk the repo, skipping the usual noise (.venv, node_modules, __pycache__, …).
  2. Parse each .py file with the standard-library ast module — top-level functions/classes become symbols, import statements become edges.
  3. Build two maps: symbol -> files that define it and module -> files that import it.
  4. Answer queries by walking those maps. No network, no model calls, runs in milliseconds.

Import resolution is best-effort and handles src/ layouts and relative imports. It won't catch dynamic imports or runtime magic — and that's a fine tradeoff for a v0.

Roadmap

  • call-graph edges (who calls this function), not just imports
  • respect .gitignore
  • method-level symbols, not just top-level
  • tree-sitter backend for speed on huge repos

Contributing

It's ~370 lines of plain Python. Read it, break it, send a PR. Good first issues are labeled.

License

MIT

Metadata

Release files for importlens-mcp 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for importlens-mcp 0.1.0
File Size Uploaded Provenance Actions
importlens_mcp-0.1.0.tar.gz 132.4 kB Without provenance Details for importlens_mcp-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for importlens-mcp 0.1.0
File Interpreter ABI Platform Actions
importlens_mcp-0.1.0-py3-none-any.whl Python 3 none any Details for importlens_mcp-0.1.0-py3-none-any.whl

Total release size: 141.7 kB

Release files / importlens_mcp-0.1.0.tar.gz

Download URL importlens_mcp-0.1.0.tar.gz
Size 132.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9cc47b7bc7d74cd2be466afa4ad7cb4e1fef0169c604c8057457c0fcbf7112f0
BLAKE2b-256 checksum
How to use checksums
c90dc9aab117f4034bbdab10f0b9faff92ce6cb590005b8064e8ee29fb71e59a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release files / importlens_mcp-0.1.0-py3-none-any.whl

Download URL importlens_mcp-0.1.0-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
99590f9d835ca017a1cc68e6be96b2ecb06c439c08977ff7809066d777bf1dcd
BLAKE2b-256 checksum
How to use checksums
475f5f10edce173ec2dd2b99a6d9cadae7e9753587df730f1943193d2fa24af9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Security for importlens-mcp 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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