CO

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.

Quick Install
npx -y @AB498/code-context-provider-mcp

Overview

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:

git clone https://github.com/AB498/code-context-provider-mcp.git
cd code-context-provider-mcp

# Install dependencies and build
npm ci
npm run build

# Run (example)
REPO_ROOT=/path/to/repo PORT=8080 node dist/server.js

Run via Docker:

# Build image
docker build -t code-context-mcp .

# Run container with mounted repository
docker run --rm -p 8080:8080 \
  -e REPO_ROOT=/repo \
  -v /local/path/to/repo:/repo:ro \
  code-context-mcp

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):

{
  "repoRoot": "/workspace",
  "port": 8080,
  "includeGlobs": ["**/*.js", "**/*.ts", "**/*.py"],
  "excludeGlobs": ["**/node_modules/**", "**/.git/**"],
  "parserCacheDir": "/tmp/tree-sitter-wasm"
}

Start with:

node dist/server.js --config ./config.json

Available Tools / Resources

The server exposes a small set of MCP-style tools for AI assistants. Typical tools include:

Tool namePurposeKey inputs
directory_treeReturn full or partial repository treepath, depth, include/exclude globs
file_previewReturn file contents or line rangespath, start_line, end_line, max_chars
code_symbolsReturn parsed symbols for a file or treepath, language_hint, symbol_kinds
search_symbolsSearch symbols across repositoryquery, symbol_kind, max_results

Example tool manifest (simplified MCP-style):

{
  "name": "code_symbols",
  "description": "Extract language symbols (functions, classes, imports) using WASM Tree-sitter.",
  "inputs": {
    "path": "string",
    "language": "string (optional)",
    "kinds": "array of symbol kinds (optional)"
  }
}

Example HTTP usage (tool discovery):

# Get available tools
curl http://localhost:8080/mcp/tools

Invoke a tool (example: code_symbols):

curl -X POST http://localhost:8080/mcp/tools/code_symbols \
  -H "Content-Type: application/json" \
  -d '{"path":"src/index.js","language":"javascript"}'

Example response (truncated):

{
  "path": "src/index.js",
  "language": "javascript",
  "symbols": [
    {"kind":"function","name":"render","start_line":45,"end_line":68},
    {"kind":"class","name":"App","start_line":10,"end_line":44}
  ]
}

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.