Skip to main content

A static analysis MCP server that traces Python function and class dependencies across files for AI assistants.

Project description

Queequeg

Queequeg logo

A static analysis MCP server for Python codebases. Queequeg gives AI assistants structured code context by tracing function and class dependencies across files — so instead of opening ten files to understand one function, the assistant calls one tool and gets everything it needs.

Why

When an AI assistant needs to understand a function, it typically reads the file, finds imports, reads those files, finds more imports, and so on. It loses context, misses things, and wastes tokens.

Harpoon does that traversal statically using AST analysis and returns a single structured result — the full dependency graph, assembled and ready to use.

Installation

pip install queequeg
# or
uv add queequeg

Setup with Claude Code

claude mcp add queequeg --scope user -- uvx --from queequeg queequeg-mcp

Then add a CLAUDE.md to your project (see CLAUDE.md example below) to tell Claude when and how to use it.

Tools

trace_code

Returns the full source of a symbol and all its transitive dependencies assembled into a single virtual file. Use this when you need to understand what a function actually does end-to-end.

Example — tracing uses_imported_function which calls shared_helper from another file:

# file: myproject/utils.py
def shared_helper():
    return "i am from another file"


# file: myproject/main.py
def uses_imported_function():
    return shared_helper()

No manual import chasing. Everything needed to understand the function is in one place.


trace_graph

Returns a JSON dependency graph of a symbol — what it calls and what those call, recursively. Use this for a structural overview without reading all the code.

Example:

{
  "myproject/main.py::uses_imported_function": {
    "type": "function",
    "file_path": "myproject/main.py",
    "dependencies": [
      "myproject/utils.py::shared_helper"
    ]
  },
  "myproject/utils.py::shared_helper": {
    "type": "function",
    "file_path": "myproject/utils.py",
    "dependencies": []
  }
}

trace_callers

Returns a JSON graph of every function that directly or transitively calls a given symbol. The target is the root — each node lists its callers. Use this for impact analysis before modifying a function.

Example — finding everything that calls process_user:

{
  "myproject/users.py::process_user": {
    "type": "function",
    "file_path": "myproject/users.py",
    "callers": [
      "myproject/api.py::create_user"
    ]
  },
  "myproject/api.py::create_user": {
    "type": "function",
    "file_path": "myproject/api.py",
    "callers": [
      "myproject/handlers.py::handle_request"
    ]
  },
  "myproject/handlers.py::handle_request": {
    "type": "function",
    "file_path": "myproject/handlers.py",
    "callers": []
  }
}

trace_callers accepts an optional search_path parameter. It defaults to the directory of the target file — pass the project root to scan the whole codebase.


Limitations

  • Only resolves static dependencies — dynamic dispatch, getattr(obj, name)(), callbacks stored in dicts or lists, and __call__ are not traced
  • Does not cross package boundaries — third-party library internals are not traced
  • String annotations (e.g. def foo(x: "MyModel")) are not resolved
  • importlib.import_module() with a dynamic string argument cannot be traced

CLAUDE.md example

Add this to your project's CLAUDE.md to instruct Claude when to use queequeg:

# Tools

## Harpoon MCP Tools

Use queequeg for understanding code structure, but only in specific cases:
- `mcp__queequeg__trace_code` — get the full code of a symbol and all its dependencies
- `mcp__queequeg__trace_graph` — get a structural overview of a symbol's dependency graph
- `mcp__queequeg__trace_callers` — find all functions that call a given symbol (impact analysis)

### When queequeg is useful:
- Function has dependencies scattered across **multiple different files**
- You want to pull a small relevant portion of a large file without guessing offset/limit ranges
- Understanding a deep dependency chain (e.g., function A calls B calls C calls D across different modules)
- Before modifying a function — use trace_callers to find everything that will be affected

### When queequeg is NOT useful:
- All related functions are in the **same file and nearby** (just read the file)
- Small files where reading the whole thing is faster than using a tool
- You need file context, comments, or surrounding code for understanding

### Limitations (apply to all queequeg tools):
- Only resolves **static** dependencies — dynamic dispatch, `getattr(obj, name)()`, callbacks stored in dicts or lists, and `__call__` usage will be missed
- Does not cross package boundaries — third-party library internals are not traced
- String annotations (e.g. `def foo(x: "MyModel")`) are not resolved
- `importlib.import_module()` with a dynamic string argument cannot be traced

### Special case:
If anything requires tree-sitter analysis, use queequeg — it has tree-sitter built in and can be extended for custom analysis needs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

queequeg-0.1.0.tar.gz (39.0 kB view details)

Uploaded Source

Built Distribution

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

queequeg-0.1.0-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

Details for the file queequeg-0.1.0.tar.gz.

File metadata

  • Download URL: queequeg-0.1.0.tar.gz
  • Upload date:
  • Size: 39.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for queequeg-0.1.0.tar.gz
Algorithm Hash digest
SHA256 11dc03f3cd1c36d1f287c8a79ab2c4e84c4d82f9293ad2cafb9d226063531649
MD5 6b1fb7ebdd9e58f050e665c2a5257909
BLAKE2b-256 c00db4a18c2bd6e068c450171fa6baab61fc3a792e98099576a6fb8fda9dfb18

See more details on using hashes here.

File details

Details for the file queequeg-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: queequeg-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for queequeg-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f0ac4c38a26297034215d9758f42c4850612febc1dd430bbcf55b68fcb109a50
MD5 a823e41c24a3897e85ce6211e1ca4638
BLAKE2b-256 e2407df595bbed5949f956ccfb85c01fd4eac7afc74435d91880b5980eba38dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page