Code Context MCP Server with WebAssembly Tree-sitter
Enable AI assistants with an MCP server that extracts directory structure and code symbols using WebAssembly Tree-sitter parsers with zero native dependencies.
npx -y @AB498/code-context-provider-mcpOverview
This MCP (Model Context Protocol) server makes repository structure and code-symbol information available to AI assistants and other tools. It walks a project directory, parses source files with WebAssembly builds of Tree-sitter grammars, and exposes those results as lightweight MCP tools so an LLM can request the context it needs (file tree, symbol lists, file previews, etc.) without shelling out to native parsers.
Because it uses WebAssembly Tree-sitter parsers, the server has zero native dependencies. That makes it simple to run in containers, serverless runtimes, or CI environments where installing platform-specific libraries is undesirable. The server is intended for developers who want deterministic, fast, language-aware context for code-related prompts and automations.
Features
- Directory traversal and project tree extraction (file paths, sizes, types)
- Language-aware symbol extraction using WebAssembly Tree-sitter parsers (functions, classes, imports, etc.)
- File preview and range-based extraction (N lines, line ranges)
- Zero native dependencies — runs anywhere Node.js and WASM are supported
- Simple HTTP/MCP-compatible endpoints for tool discovery and invocation
- Configurable includes/excludes and parser cache for performance
Installation / Configuration
Prerequisites: Node.js (14+ / 16+ recommended) or Docker.
Clone and run locally:
# Install dependencies and build
# Run (example)
REPO_ROOT=/path/to/repo PORT=8080
Run via Docker:
# Build image
# Run container with mounted repository
Configuration options (environment variables and config file supported):
- REPO_ROOT — path to the root of the repository to index (required)
- PORT — HTTP port (default: 8080)
- LOG_LEVEL — debug|info|warn|error
- INCLUDE_GLOBS / EXCLUDE_GLOBS — glob strings to filter files
- PARSER_CACHE_DIR — path to cache downloaded/compiled WASM parsers
Example JSON config (config.json):
Start with:
Available Tools / Resources
The server exposes a small set of MCP-style tools for AI assistants. Typical tools include:
| Tool name | Purpose | Key inputs |
|---|---|---|
| directory_tree | Return full or partial repository tree | path, depth, include/exclude globs |
| file_preview | Return file contents or line ranges | path, start_line, end_line, max_chars |
| code_symbols | Return parsed symbols for a file or tree | path, language_hint, symbol_kinds |
| search_symbols | Search symbols across repository | query, symbol_kind, max_results |
Example tool manifest (simplified MCP-style):
Example HTTP usage (tool discovery):
# Get available tools
Invoke a tool (example: code_symbols):
Example response (truncated):
Use Cases
- Code-aware chat assistants: Allow an assistant to list project files, fetch a source file portion, and extract symbols to answer questions like “Where is the render function defined?”
- Pull request summarization: Index changed files and extract top-level symbols to generate concise summaries of what changed and what modules were affected.
- Automated code navigation: Provide jump-to-definition or symbol-search features inside a multi-language codebase without requiring native Tree-sitter installs.
- Security and static analysis helpers: Quickly find imports/usages of sensitive APIs or libraries across a repository by querying parsed symbols.
- Lightweight integration in CI: Run inside ephemeral CI containers to provide context for bots that generate comments, suggestions, or test scaffolding.
Notes and Tips
- Add or tune include/exclude globs to avoid indexing large directories like node_modules or build artifacts.
- The project relies on WASM Tree-sitter grammars; ensure network access for initial downloads or pre-populate a parser cache directory.
- For production, run behind a reverse proxy and mount only the repository paths you intend to index.
Repository and source code: https://github.com/AB498/code-context-provider-mcp — consult the README and examples in that repo for full API docs and advanced configuration.