
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
mcp-code-context
Advanced tools
Powerful MCP server with Tree-sitter WASM parsers for 100% AST accuracy. Zero native dependencies. Production-ready with persistent caching, structured logging, file watching, fuzzy search, rate limiting, file locking, and ReDoS protection. Supports TypeS
MCP server with Tree-sitter WASM parsers for 100% AST accuracy. Zero native dependencies. Production-ready with persistent caching, structured logging, fuzzy search, multi-process safety, and session-scoped state.
npm install -g mcp-code-contextclaude_desktop_config.json:{
"mcpServers": {
"code-context": {
"command": "npx",
"args": ["-y", "mcp-code-context"]
}
}
}
@code-context to map repos or edit code surgically.No build tools required - Works on Windows/Mac/Linux without Visual Studio, Python, or node-gyp.
Works with Claude Desktop, Cursor, Windsurf, GitHub Copilot, Amazon Q, and any Model Context Protocol compatible client.
📖 For AI Agents: See INSTRUCTIONS.md for essential usage patterns and best practices.
This tool was born out of necessity in Caracas, Venezuela 🇻🇪, where economic limitations made every API token count. When you're choosing between groceries and Claude API credits, you learn to optimize fast.
What started as a personal script to compress context windows became a full MCP server when I realized others faced the same problem: LLM APIs are expensive, and most tools waste tokens on boilerplate.
If this tool saves you money or time, consider supporting its development. Every contribution helps keep this project maintained and free for everyone.
LLMs working with code face two bottlenecks:
mcp-code-context provides 25 tools — covering reading, writing, AST transformation, search, and session management — all operating at the symbol level (functions, classes, methods). Tools support a className scope to correctly isolate identical symbol names in the same file (e.g. Flutter build() methods). Read tools extract structural skeletons. Write tools splice changes into the exact AST location.
| File | Original | Compressed | Reduction |
|---|---|---|---|
| PHP class (426 lines) | 426 | 60 | 85.9% |
| Dart repository (230 lines) | 230 | 30 | 87.0% |
| PHP config (68 lines) | 68 | 15 | 77.9% |
Real-world results:
Built to be robust and precise. Both read and write engines are tested against real-world, complex codebases (including nested generic types in Dart, complex interfaces in PHP, and multi-file rename operations) with a 100% test pass rate across all languages and operations.
| Feature | v3.6.x | v3.7.1 | Benefit |
|---|---|---|---|
| Multi-process safety | ✅ | ✅ | No file corruption |
| Persistent cache | ✅ | ✅ | <100ms cache hits |
| Session-scoped state | ❌ | ✅ | No state leakage between clients |
| Crash recovery | ❌ | ✅ | Pending operations survive restart |
| Expanded ReDoS protection | 6 patterns | 15+ patterns | Better security |
| Auto-persist before eviction | ❌ | ✅ | Cache data preserved |
| Feature | Description |
|---|---|
| 🔒 Session-scoped state | Each MCP client gets isolated locks, confirmation store, rate limiter (no state leakage) |
| 💾 Crash recovery | SQLite-backed pending operations store - survive restarts |
| 🔍 Expanded ReDoS protection | 15+ patterns (was 6) - better protection against regex DoS |
| ⚡ Auto-persist before eviction | CacheManager now persists before LRU eviction |
| 📊 Higher file limits | MAX_FILES_REPO_MAP = 2000 (was 500) |
| 🧪 Multi-client tests | New integration tests for concurrent MCP clients |
📝 New tools: get_session_stats, clear_session_cache, list_pending_operations | Session-aware operations |
| Feature | Description |
|---|---|
| ⚡ Persistent Cache | WASM SQLite cache — <100ms hits, 10× faster on repeated reads |
| 📝 Structured Logging | pino JSON logging to stderr (MCP-safe, never pollutes stdio) |
| 👁️ File Watcher | chokidar auto-invalidates cache on file changes |
| 🔍 Fuzzy Search | fuse.js finds authUser when you search authenticateUser |
| 📄 Pagination | Search defaults to 10 results with startIndex for navigation |
| 🔒 Multi-process Safe | Filesystem locks via proper-lockfile (was in-memory) |
| 💾 OS Temp Backups | Backups in os.tmpdir() — no more hot-reload loops |
| 🧪 74 Tests | Unit + integration + performance + stress tests |
| 🎯 Token Savings | 50-80% reduction: compact diffs, no Phase 2 repeat, auto-optimize output |
className to scope disambiguation (e.g., getting multiple build() methods in Dart).require(), Python imports, PHP use/require_once/include, and Dart imports..gitignore and .repomixignore rules. Automatically excludes node_modules, dist, vendor, .git, etc.className parameter.confirmationToken by default. Changes are only applied after explicit confirmation.rollback_file tool._ and __ prefixed symbols in Dart and Python.| Language | Read (Compress + Extract) | Write (Replace + Insert + Rename + Remove) | Import Analysis |
|---|---|---|---|
| TypeScript / JavaScript | ✅ AST (Tree-sitter WASM) | ✅ AST (Tree-sitter WASM) | ✅ |
| PHP | ✅ AST (Tree-sitter WASM) | ✅ AST + line-splice | ✅ |
| Dart | ✅ AST (Tree-sitter WASM) | ✅ AST + line-splice | ✅ |
| Python | ✅ AST (Tree-sitter WASM) | ✅ Indentation-aware | ✅ |
| Others (JSON, YAML, CSS, etc.) | Passthrough / truncation | — | — |
rename_symbol ToolAll languages: The definition file is renamed using AST (Tree-sitter) — safe and precise. ✅
Cross-file rename (dependent files): Updated using regex word-boundaries for all languages, including TypeScript, JavaScript, and PHP.
import 'package:...', from module import name) is less reliably matched by the current regex patternswrite_file_surgical to rename within a single file safelyget_semantic_repo_map Tool@folder syntax to target specific directoriesrollback_file if something goes wrong.# Global installation (recommended)
npm install -g mcp-code-context
# Or use directly with npx (no installation)
npx -y mcp-code-context
Note: Unlike v2.x, this version uses web-tree-sitter (WASM) instead of native bindings. No Visual Studio, Python, or node-gyp required!
Important: v3.7.1 introduces session-scoped state for each MCP client connection. This prevents state leakage when multiple agents (Amazon Q, Kiro, Cursor, etc.) use the same server instance.
| Before (v3.6.x) | After (v3.7.1) |
|---|---|
Global LockManager (shared by all clients) | Session-scoped sessionStates Map |
Global ConfirmationStore (in-memory Map) | Session-scoped confirmation store + SQLite persistence |
Global RateLimiter (shared tokens) | Per-session token bucket |
| No crash recovery | SQLite-backed pending operations store |
No additional configuration needed. Session isolation is automatic. Just configure your MCP server normally:
{
"mcpServers": {
"mcp-code-context": {
"command": "npx",
"args": ["-y", "mcp-code-context"]
}
}
}
get_session_stats — Get stats for current session onlyclear_session_cache — Clear cache for current session onlylist_pending_operations — List pending operations for recoveryAdd to your claude_desktop_config.json:
{
"mcpServers": {
"mcp-code-context": {
"command": "npx",
"args": ["-y", "mcp-code-context"]
}
}
}
Add to your Cursor MCP settings (.cursor/mcp.json):
{
"mcpServers": {
"mcp-code-context": {
"command": "npx",
"args": ["-y", "mcp-code-context"]
}
}
}
Add to your Windsurf MCP config:
{
"mcpServers": {
"mcp-code-context": {
"command": "npx",
"args": ["-y", "mcp-code-context"]
}
}
}
Add to your Amazon Q MCP config:
{
"mcpServers": {
"mcp-code-context": {
"command": "npx",
"args": ["-y", "mcp-code-context"]
}
}
}
Add to your Kiro MCP config (.kiro/settings/mcp.json):
{
"mcpServers": {
"mcp-code-context": {
"command": "npx",
"args": ["-y", "mcp-code-context"]
}
}
}
Add to your Antigravity MCP config (.antigravity/mcp.json):
{
"mcpServers": {
"mcp-code-context": {
"command": "npx",
"args": ["-y", "mcp-code-context"]
}
}
}
Any MCP-compatible client can use this server. The transport is stdio (JSON-RPC over stdin/stdout). Point your client to npx -y mcp-code-context.
| Tool | Key Params | Description |
|---|---|---|
get_semantic_repo_map | directoryPath, projectRoot, format | Compressed XML/Markdown repo overview with AST symbols |
read_file_surgical | filePath, projectRoot, symbolName?, className? | Extract one symbol or full file |
analyze_impact | filePath, projectRoot, rootDir? | All files that depend on this file |
read_file_lines | filePath, projectRoot, startLine?, endLine?, aroundPattern? | Read a line range or pattern context |
search_code_pattern | rootDir, projectRoot, pattern, fileExtensions?, fuzzyMatch? | Regex search across files (ripgrep-fast) |
parse_file | filePath, projectRoot | All symbols with line numbers (cheap index) |
search_symbols | rootDir, projectRoot, query, fuzzy?, types? | AST symbol search by name, not text |
explain_symbol | filePath, projectRoot, symbolName, rootDir? | Signature + location + callers in one call |
batch_read | reads[], projectRoot | N symbols from N files in 1 round-trip |
get_rate_limit_status | — | Token balance + canAfford map |
All write tools require two calls:
diff + confirmationTokenconfirm: true + confirmationToken → applies changesnewContent/code are not required in Phase 2 — the server stores them from Phase 1.
| Tool | Key Params | Description |
|---|---|---|
write_file_surgical | filePath, projectRoot, symbolName, newContent, className? | Replace a symbol with new code |
insert_symbol | filePath, projectRoot, code, anchorSymbol?, position?, className? | Insert code before/after/inside a symbol |
remove_symbol | filePath, projectRoot, symbolName, className?, force? | Remove a symbol (with dependency check) |
rename_symbol | filePath, projectRoot, oldName, newName, rootDir? | Rename across entire repo (AST + regex) |
ast_transform | filePath, projectRoot, symbolName, transform, className? | Declarative transforms: wrap_with_try_catch, add_parameter, add_decorator, change_return_type, extract_variable |
| Tool | Key Params | Description |
|---|---|---|
rollback_file | filePath, projectRoot, steps? | Restore file from rolling backup (up to 5 versions) |
clean_backups | projectRoot | Delete all backups for this project |
get_server_stats | — | Telemetry, audit stats, rate limiter state |
get_cache_stats | projectRoot | Cache entries, size, hit rate |
clear_cache | projectRoot | Invalidate cache for this project |
configure_file_watcher | projectRoot, action (start/stop), debounceMs? | Auto-invalidate cache on file changes |
get_file_watcher_status | projectRoot | Watcher state + watched paths |
get_session_stats | — | Per-session: pending ops, locks, tokens |
clear_session_cache | projectRoot? | Clear cache for current session only |
list_pending_operations | — | List pending Phase 1 tokens (crash recovery) |
get_semantic_repo_map to see the architectureread_file_surgical with symbol name for specific implementationsanalyze_impact before modifying shared filesdiff and confirmationTokenconfirm: true to applyrollback_file if something goes wrong after confirmationThis tool was born in Caracas, Venezuela 🇻🇪, where economic limitations mean every API token counts. What started as a personal script to save money on Claude API became a full MCP server when I realized others faced the same problem.
Current Reality:
If this tool saves you time or money, consider supporting its development.
Ko-fi (PayPal + Cards, 0% fees)
ko-fi.com/achatainga
PayPal (Direct)
paypal.me/achatainga
Binance (USDT) (Crypto, lowest fees)
0xa68d53f7853ce0175eb96aaad4a30c068ca96444367669339Recommended: TRC20 for lower gas fees
Ko-fi Membership
ko-fi.com/achatainga/tiers
Monthly tiers:
Need custom MCP tools or AI integrations?
📧 Contact: a.chataing.a@gmail.com
📄 Details: HIRE_ME.md
I believe in radical transparency:
Current Status:
(Updated monthly)
Thank you to these amazing supporters:
(No sponsors yet - be the first!)
See full list: SPONSORS.md
Can't donate? No problem! You can still help:
Every contribution matters, financial or not.
# Build
npm run build
# Run tests
npm test
# Development (build + start)
npm run dev
ignore npm package (full .gitignore spec support)| Component | Change | Benefit |
|---|---|---|
| State management | Session-scoped instead of global | No state leakage between clients |
| Pending operations | SQLite-backed | Survive server restarts |
| ReDoS patterns | 6 → 15+ | Better security |
| Cache eviction | Auto-persist before close | Cache data preserved |
| File limits | MAX_FILES = 2000 (was 500) | Better support for large projects |
| Tests | Added multi-client concurrency tests | Production readiness verified |
See CONTRIBUTING.md for guidelines.
See SECURITY.md for security policies and reporting vulnerabilities.
See TROUBLESHOOTING.md for common issues and solutions.
Because MCP uses stdout for protocol communication, all logs are safely routed to stderr. You can view them in your client's log files:
~/Library/Logs/Claude/mcp-server-mcp-code-context.log%APPDATA%\Claude\logs\mcp-server-mcp-code-context.logOutput panel → Select mcp-code-context from the dropdownstderr output in the MCP server configurationEnvironment Variables (optional):
{
"mcpServers": {
"mcp-code-context": {
"command": "npx",
"args": ["-y", "mcp-code-context"],
"env": {
"NODE_ENV": "development",
"LOG_LEVEL": "debug"
}
}
}
}
Supported LOG_LEVEL values: fatal, error, warn, info, debug, trace (default: info).
See CHANGELOG.md for version history.
Built with ❤️ from Caracas, Venezuela 🇻🇪
FAQs
Powerful MCP server with Tree-sitter WASM parsers for 100% AST accuracy. Zero native dependencies. Production-ready with persistent caching, structured logging, file watching, fuzzy search, rate limiting, file locking, and ReDoS protection. Supports TypeS
The npm package mcp-code-context receives a total of 29 weekly downloads. As such, mcp-code-context popularity was classified as not popular.
We found that mcp-code-context demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.