-
Notifications
You must be signed in to change notification settings - Fork 298
Get Context Bundle
Get a symbol's definition and its file's imports in one call — nothing more.
When an AI needs to modify a function, it typically has to load the entire file to understand its dependencies. For large files this wastes thousands of tokens on code the AI will never touch. get_context_bundle returns exactly two things: the symbol's full source and every import/require statement from the same file. That's the minimum viable context for understanding and editing any symbol.
The tool is intentionally scoped to definition + imports for v1. No call graph, no transitive dependencies — just the scaffolding a symbol needs to make sense.
If you ask an AI to fix a bug in one function, it no longer has to read the whole 800-line file first. You get faster, cheaper answers with less noise.
| Dimension | Detail |
|---|---|
| Tool name | get_context_bundle |
| Inputs |
repo (string), symbol_id (string) |
| Outputs |
symbol_id, name, kind, file, line, end_line, signature, docstring, source, imports[], _meta
|
| Import extraction | Language-aware regex; 16 languages supported |
| Go block imports |
import (...) blocks captured as a unit, including the open/close parens |
| Token savings | Reported in _meta.tokens_saved vs full-file baseline |
| Error handling | Returns {"error": "..."} on bad repo or unknown symbol ID |
Supported languages for import extraction: Python, JavaScript, TypeScript, TSX, Go, Rust, Java, Kotlin, C#, C, C++, Swift, Ruby, PHP, Elixir, Scala, Haskell, Lua, Dart.
{
"tool": "get_context_bundle",
"arguments": {
"repo": "local/my-project",
"symbol_id": "src/auth/token.py::verify_token#function"
}
}{
"symbol_id": "src/auth/token.py::verify_token#function",
"name": "verify_token",
"kind": "function",
"file": "src/auth/token.py",
"line": 24,
"end_line": 41,
"signature": "def verify_token(token: str, secret: str) -> dict",
"docstring": "Verify a JWT and return its payload.",
"source": "def verify_token(token: str, secret: str) -> dict:\n ...",
"imports": [
"import jwt",
"import time",
"from typing import Optional",
"from .exceptions import TokenExpiredError"
],
"_meta": {
"timing_ms": 4.1,
"tokens_saved": 812,
"total_tokens_saved": 7041823,
"cost_avoided": {
"claude_sonnet_4_6": 0.0024
}
}
}-
src/jcodemunch_mcp/tools/get_context_bundle.py— new tool: resolves repo, fetches symbol source via byte-offset read, extracts imports from cached file content using language-aware regex patterns -
src/jcodemunch_mcp/server.py— import added; tool registered inlist_tools(); handler added incall_tool() -
tests/test_get_context_bundle.py— 34 tests: unit tests for_extract_importsacross 9+ language classes, integration tests viaindex_folder+ real symbol lookup, error case coverage
get_context_bundle is the first implementation of the context bundle retrieval pattern described in the jMRI spec — a scoped, symbol-anchored bundle that returns only what's needed to act on a symbol. Future iterations may expand the bundle (e.g. direct callers, type definitions) while keeping the same interface.
jcodemunch-mcp on GitHub · 900+ stars