PyEye 👁️¶
PyEye Server¶
An extensible MCP (Model Context Protocol) server that provides intelligent Python code analysis, navigation, and understanding capabilities for AI assistants like Claude.
Features¶
- 🔍 Semantic Code Navigation: Resolve any identifier to a stable canonical handle, then inspect or outline it
- 📊 Structural Traversal: Walk relationship edges (listed below) one hop with
expand, or many withtrace - 🤝 Honest by Construction: Unsupported questions (notably "who calls this") are refused, not guessed; absent counts mean "not measured", never "zero"
- 🏗️ Multi-Project Support: Analyze multiple projects and dependencies simultaneously
- 📦 Namespace Packages: Handle packages distributed across multiple repositories
- 📝 Standalone Scripts: Analyze standalone
.pyfiles (for example inscripts/orexamples/directories) alongside formal packages - 🔄 Auto-Update: Watches the project's files and drops cached results when they change
- ⚙️ Configuration System: Configure packages and namespaces in config files, or let pyeye auto-discover them; tune performance with environment variables
- 🔌 Plugin System: Built-in framework analyzers (Pydantic, Django, Flask)
- 🎯 Type-Aware: Uses Jedi's type inference, including type hints and annotations
- 📈 Performance Metrics: Optional per-tool latency metrics (
get_performance_metrics)
Installation¶
| You use | Recommended | Alternatives |
|---|---|---|
| Claude Code | The plugin | claude mcp add |
| Another MCP client (Claude Desktop, VS Code, …) | uvx pyeye-mcp |
An installed pyeye-mcp |
| One project, pinned to a version | Install into the project's environment | |
| You're working on pyeye itself | CONTRIBUTING |
pyeye needs Python >=3.11.
The plugin and uvx need uv.
pyeye analyses the directory its server starts in, and every analysis tool also
takes a project_path. The entry points list the
commands that start the server.
Your project's environment. pyeye reads the project's installed
third-party packages (requests, django, …) from the project's own Python
environment, whichever way pyeye itself runs. It uses the first of:
- the
environmentsetting in the project's pyeye config: the path to a virtualenv, orfalsefor none; - a virtualenv in the project:
.venv,venvorenv(for a project that is itself a package, in its parent directory too, unless that directory is shared: group- or world-writable, or owned by another user); - the activated environment (
VIRTUAL_ENV, orCONDA_PREFIXfor conda), as Poetry, Pipenv and Hatch set it for an environment outside the project, unless it is pyeye's own environment, which is skipped. One activated environment serves every project that has none of its own.
It reads the environment's packages from disk and never runs its Python. It
skips an environment, or a path one adds, that is in or contains a system
directory or a credential store, with a warning. When it finds none, a
third-party import doesn't resolve, and resolve and inspect say that no
environment was found (#993).
Claude Code plugin (recommended)¶
In Claude Code:
/plugin marketplace add okeefeco/pyeye-mcp
/plugin install pyeye@pyeye-marketplace
From a shell, the same is claude plugin marketplace add okeefeco/pyeye-mcp
followed by claude plugin install pyeye@pyeye-marketplace. Claude Code's
plugin documentation covers
updating and removing plugins.
The plugin brings:
- the pyeye MCP server;
- the skills
python-explore,architecture-review,duplication-reviewanddecision-log; - a session-start hook that installs pyeye's dependencies with
uvinto a per-user environment, the first time and again whenever its lockfile changes. The server does the same before it starts, so the first session connects.
Install pyeye either as the plugin or with claude mcp add, not both:
with both, every tool appears twice (mcp__plugin_pyeye_pyeye__… and
mcp__pyeye__…). If you added it with claude mcp add before, run
claude mcp remove pyeye.
Claude Code without the plugin¶
claude mcp add pyeye -s user -- uvx pyeye-mcp
claude mcp list # check that pyeye is connected
uvx runs the latest release from PyPI in an environment of its own. To use an
installed command instead, see Installing the command
and register -- pyeye-mcp. Claude Code's
MCP documentation covers scopes and options.
Other MCP clients¶
pyeye is a standard stdio MCP server. Give your client the command uvx with
the argument pyeye-mcp, or an installed pyeye-mcp. Where that goes depends
on the client, so follow its own documentation:
- Claude Desktop: Connect to local MCP servers.
Claude Desktop doesn't start the server in your project, so ask for the
project explicitly: every analysis tool takes a
project_pathargument. - VS Code (GitHub Copilot): Add and manage MCP servers in VS Code.
Run MCP: List Servers from the Command Palette to check that
pyeyestarted. - JetBrains IDEs, Visual Studio, Eclipse and Xcode (GitHub Copilot): Extending Copilot Chat with MCP.
For example, in a client that takes an mcpServers map:
{
"mcpServers": {
"pyeye": {
"command": "uvx",
"args": ["pyeye-mcp"]
}
}
}
Installing the command¶
To install pyeye-mcp once instead of running it through uvx, use
uv tool install pyeye-mcp or
pipx install pyeye-mcp. The server command is then
pyeye-mcp.
Install into a project's environment¶
Install pyeye into the project's virtual environment (pip install pyeye-mcp,
or uv pip install pyeye-mcp, with that environment active), then point your
client at that environment's Python. For Claude Code, a .mcp.json in the
project root:
{
"mcpServers": {
"pyeye": {
"type": "stdio",
"command": "/path/to/your/project/.venv/bin/python",
"args": ["-m", "pyeye.mcp"]
}
}
}
On Windows the path is .venv\Scripts\python.exe. A bare "command": "python"
works only if your MCP client was started from a shell with that environment
active; otherwise it runs whichever Python is first on the client's PATH.
Configuration¶
The server can be configured to analyze packages in other locations. Create a .pyeye.json file in your project:
{
"packages": [
"../my-shared-library",
"~/repos/company-utils",
"/absolute/path/to/package"
],
"namespaces": {
"mycompany": [
"~/repos/mycompany-auth",
"~/repos/mycompany-api"
]
}
}
Configuration Methods¶
Configuration is loaded in the following order (later sources override earlier ones):
- Global Config: the first of
~/.config/pyeye/config.json,~/.pyeye.jsonthat exists - User defaults - Project Config: the first of
.pyeye.json,.pyeye.yaml,.pyeye.yml,pyproject.toml,.claude/pyeye.jsonin the project root (inpyproject.toml, the[tool.pyeye]section) - Override File:
.pyeye.override.json- Local development overrides (keep it out of git) - Auto-Discovery: a
src/layout, only if nopackagesare configured yet, and the path dependencies the project'spyproject.tomldeclares, always (below). (The project's virtualenv isn't a package: pyeye reads it as the project's environment, above.)configure_packageslists what was discovered underdiscovered, and a save never writes it to.pyeye.json. - This session's unsaved additions: packages, namespaces and standalone directories added with
configure_packages(save=false). They're applied last and don't stop auto-discovery
Packages beside your project. pyeye doesn't guess at neighbouring directories (#1035). A package that lives beside your project is analysed when one of these says so:
- A path dependency in
pyproject.toml, read statically: [tool.uv.sources]entries with apath;[tool.uv.workspace]members(a glob member stays inside the workspace; a literal path can point anywhere);- Poetry
pathdependencies, in the main table and in groups; name @ file:...references in[project]dependencies, optional dependencies and[dependency-groups]. PDM's${PROJECT_ROOT}and Hatch's{root:uri}are expanded.- An editable install in the project's environment. Most installs write their path to a
.pthfile. A few use an import hook instead: setuptools with a flat layout, hatchling'sdev-mode-exact, and pdm-backend'seditablesmode. For those, pyeye reads the hook's module as text for its target directories. It never runs it. - Your pyeye config:
packages,namespaces, orconfigure_packages.
A declared directory with a src/ layout is read from its src/. When a top-level import doesn't resolve, resolve and inspect suggest declaring the package or adding it with configure_packages.
The top-level keys pyeye reads are packages, namespaces, standalone, scope_defaults, scope_aliases, environment.
Using Override Files¶
Override files are perfect for local development configurations that shouldn't be committed.
.pyeye.override.json takes precedence over the other sources; add it to your
project's .gitignore:
{
"packages": [
"../my-local-dev-package",
"~/dev/experimental"
],
"namespaces": {
"company.feature": ["/home/user/feature-branch"]
}
}
Performance Settings¶
Performance settings are configured through environment variables. The
generated reference lists every PYEYE_* variable
pyeye reads, with its default, range and status (live or deprecated). Deprecated
variables have no effect.
These are read when the server starts, from the server's own environment.
The MCP client starts the server, so set them on its server entry and restart
the client. In Claude Code, remove the server and add it again with -e flags,
using the command you registered it with (here uvx pyeye-mcp):
claude mcp remove pyeye && claude mcp add pyeye -s user -e PYEYE_MAX_PROJECTS=20 -- uvx pyeye-mcp.
Other clients take an env map in their config. An export in your shell only
reaches the server if the client was launched from that shell.
Packages and namespaces are not configured through environment variables. Use
.pyeye.json, pyproject.toml, the global config file, or the
configure_packages tool (see Configuration).
Sizing the parsed-file cache¶
pyeye walks every .py file in a project to build its name index and its
subclass and import graphs, and rebuilds them after every file change.
PYEYE_ARTIFACT_CACHE_MAX_ENTRIES decides how many of those parsed files stay
in memory between walks. Answers are the same at any value; only speed and
memory change.
- Set it at or above your project's
.pyfile count (the default is
2000). Each rebuild after an edit then re-parses only what changed. - Don't set it just below that count. The cache then evicts files during each walk and parses them again in the same walk, so it is both slower and uses more memory than the default. - To save memory, go well below it and accept slower rebuilds.
This advice comes from measurements on one large project in #768.
Performance Tuning Examples¶
Set the variables on the server entry, so they reach the server however the client was started. For example, with Claude Code (remove the server first, and use the command you registered it with):
claude mcp remove pyeye
# Keep more projects in memory, cache longer and batch file changes more
claude mcp add pyeye -s user \
-e PYEYE_MAX_PROJECTS=50 -e PYEYE_CACHE_TTL=1800 -e PYEYE_WATCHER_DEBOUNCE=2.0 \
-- uvx pyeye-mcp
# Or use less memory: fewer projects and fewer parsed files kept
claude mcp add pyeye -s user \
-e PYEYE_MAX_PROJECTS=3 -e PYEYE_ARTIFACT_CACHE_MAX_ENTRIES=250 \
-- uvx pyeye-mcp
Other clients take the same names in the server entry's env map.
Auto-Detection of Source Layouts¶
PyEye automatically detects source layouts from pyproject.toml build backend metadata, supporting projects that use the src/ directory pattern. This works with multiple build backends:
Setuptools:
[tool.setuptools.packages.find]
where = ["src"]
Poetry:
[[tool.poetry.packages]]
include = "mypackage"
from = "src"
Hatch:
[tool.hatch.build.targets.wheel]
sources = ["src"]
PDM:
[tool.pdm.build]
package-dir = "src"
Two conditions apply. pyproject.toml is read only when it is the project's config
file, the first of the project config files above that exists, so a
.pyeye.json or .pyeye.yaml in the root means it is never read. And detection
only runs when no packages are set yet, including by your global config.
If no configuration is found in pyproject.toml, PyEye also treats src/ as a source root when it holds a regular package (a directory with __init__.py), or when it holds the project's own package under its declared name ([project].name or [tool.poetry].name, lowercased, with - and . as _), even a namespace package with no __init__.py. That is where Poetry, Hatch, uv, PDM and setuptools look by default, so a project like Poetry, whose src/poetry is a namespace, is named poetry.…, not src.poetry.…. No other directory under src/ is taken as a root.
Note: Explicit [tool.pyeye] configuration always takes precedence over auto-detected layouts.
Core Tools¶
PyEye exposes a small set of progressive-disclosure primitives that work on canonical handles (a re-exported path collapses to its definition site). They are cheap by default: they return structural facts and pointers, never source content.
The core tools are configure_packages, expand, inspect, outline, resolve, resolve_at, trace. The usual
flow is to resolve a name to a handle, inspect or outline it, then follow
relationship edges with expand (one hop) or trace (many hops);
configure_packages registers extra package locations. The
tool reference gives every tool's parameters and
defaults, and the edge reference lists the supported
edges. For worked examples, see the python-explore skill
(.claude/skills/python-explore/SKILL.md).
Known limitation: no reverse references¶
The interface does not answer "who calls / references this". Reverse-reference
support is deferred to a planned Pyright backend
(#333). When you ask for a
callers or references edge, pyeye reports it as unsupported rather than
guessing, and inspect's edge_counts omits those keys entirely instead of
reporting 0. Delegate caller questions to a language server; pyeye's resolve
gives you the definition-site position an LSP reference query needs.
Forward and structural questions are answered, through the implemented edges:
members, callees, imported_by, subclasses, superclasses, imports, enclosing_scope, submodules, re_exports.
Static-surface ceiling: each edge measures a stated scope, and its answer is
complete only over that scope. The
edge reference gives each edge's ceiling.
Removed in v2.0.
find_references,get_call_hierarchy, andanalyze_dependencieswere removed in #505 — not deprecated — because they returned confidently wrong answers rather than merely incomplete ones. See the CHANGELOG's migration map for replacements.
Framework-Specific Tools (Auto-Activated)¶
A plugin's tools are registered when its framework is detected in the project. See the tool reference for each tool's parameters.
- Django:
find_django_migrations,find_django_models,find_django_templates,find_django_urls,find_django_views - Pydantic:
find_computed_fields,find_field_validators,find_model_config,find_pydantic_models,find_validators,get_model_schema,trace_model_inheritance - Flask:
find_cli_commands,find_error_handlers,find_flask_blueprints,find_flask_config,find_flask_extensions,find_flask_routes,find_flask_templates,find_flask_views
Advanced Features¶
Multi-Project Support¶
Analyze your main project along with local dependencies. Put them in
.pyeye.json (see Configuration), or ask your assistant to
call the configure_packages tool
with arguments like these:
{
"packages": ["../my-lib", "~/repos/shared-utils"],
"namespaces": {"company": ["~/repos/company-auth", "~/repos/company-api"]}
}
Namespace Packages¶
Handle packages distributed across multiple repositories, for example
company.auth in one repo and company.api in another:
{
"namespaces": {"company": ["~/repos/company-auth", "~/repos/company-api"]}
}
Auto-Update on File Changes¶
The server watches the project's files and drops cached results for the files that change, so answers follow your edits without a restart. See Caching for how invalidation works.
Architecture¶
The architecture pages describe how pyeye works inside:
- Resolution: how a name becomes a canonical handle
- Caching: what is cached and when it is invalidated
- Plugin system: how framework plugins are detected and register their tools
Plugin Development¶
Plugins are built into pyeye; there is no dynamic loading. To add a framework plugin, follow Adding a plugin.
Performance Monitoring¶
Set PYEYE_ENABLE_PERFORMANCE_METRICS to true to register the admin tools:
get_performance_metrics, which reports per-tool latencies, and
get_connection_diagnostics, which reports the server's
connection state and recent errors. Their parameters are in the
tool reference.
Development¶
# Install pyeye with its development dependencies, exactly as locked
uv sync --frozen
# Run tests
uv run pytest
# Format and lint
uv run black src/
uv run ruff check src/
See CONTRIBUTING.md for the full setup and workflow.
Documentation¶
The full documentation is published at okeefeco.github.io/pyeye-mcp, built from the Markdown in this repository.
- Installation Guide
- Configuration Guide
- Troubleshooting Guide - Common issues and solutions
- API Reference - every tool and its parameters
Security¶
Please report vulnerabilities privately through GitHub's private vulnerability reporting, not in public issues. SECURITY.md covers supported versions, what to expect after reporting, and pyeye's security model (static analysis only; it reads whatever paths the MCP client points it at).
Contributing¶
Contributions are welcome! See CONTRIBUTING.md before opening a pull request.
License¶
MIT License - see LICENSE for details
Acknowledgments¶
Built on top of:
- Jedi - Python static analysis and type inference
- MCP Python SDK - MCP server framework (
MCPServer) - Watchdog - File system monitoring