mcp-code-context
Provides code context and surgical editing tools for AI agents within Amazon Q.
Provides code context and surgical editing tools for AI agents within GitHub Copilot.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-code-contextextract the function 'login' from user.js"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mcp-code-context
MCP server with Tree-sitter WASM parsers for 100% AST accuracy. Zero native dependencies. Production-ready with persistent caching, structured logging, fuzzy search, and multi-process safety.
๐ Quick Start (Claude Desktop)
Install:
npm install -g mcp-code-contextConfigure: Add to
claude_desktop_config.json:
{
"mcpServers": {
"code-context": {
"command": "npx",
"args": ["-y", "mcp-code-context"]
}
}
}Enjoy: Use symbols like
@code-contextto 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.
๐ก Why This Exists
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.
The Problem
LLMs working with code face two bottlenecks:
Reading: Sending raw source files wastes the context window on function bodies and boilerplate. A 500-line file might contain only 30 lines of structural information the LLM needs.
Writing: Rewriting entire files to change one function is error-prone, token-expensive, and risks corrupting unrelated code.
The Solution
mcp-code-context provides 13 tools โ 6 for reading, 2 for cleanup, and 5 for writing โ that operate at the symbol level (functions, classes, methods). Furthermore, tools support a className scope which correctly isolates identical symbol names in the same file (e.g. Flutter build() methods) to avoid reading or changing the wrong logic. 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% |
Reliability & Testing
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.
Features
What's New in v3.6.3
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 |
๐ Pagination | Search defaults to 10 results with |
๐ Multi-process Safe | Filesystem locks via |
๐พ OS Temp Backups | Backups in |
๐งช 74 Tests | Unit + integration + performance + stress tests |
๐ฏ Token Savings | 50-80% reduction: compact diffs, no Phase 2 repeat, auto-optimize output |
Read
๐ณ AST-based compression โ Real Tree-sitter WASM parsers for TypeScript/JavaScript/Python/PHP/Dart. Zero regex-based parsing.
๐ฌ Surgical symbol extraction โ Extract a single function, class, or method from a file by name. Use
classNameto scope disambiguation (e.g., getting multiplebuild()methods in Dart).๐ฅ Impact analysis โ Discover all files that depend on a given file before refactoring. Supports ES imports, CommonJS
require(), Python imports, PHPuse/require_once/include, and Dart imports.๐ Smart file walking โ Respects
.gitignoreand.repomixignorerules. Automatically excludesnode_modules,dist,vendor,.git, etc.๐ Multi-format output โ XML (optimized for LLM consumption) or Markdown (human-readable).
Write
โ๏ธ Surgical symbol replacement โ Replace a function, method, or class body without touching the rest of the file. Narrow down the target using the
classNameparameter.โ Precise code insertion โ Insert new code before/after a symbol, or inside a class at the start/end.
๐ Repository-wide rename โ Rename a symbol in its definition AND all files that import it, atomically.
๐๏ธ Safe symbol removal โ Delete code with automatic dependency checking to prevent breakage.
๐ Mandatory dry-run flow โ Write tools return a preview diff and a
confirmationTokenby default. Changes are only applied after explicit confirmation.๐พ Robust rolling backups โ Automatically keeps the last 5 versions of modified files in a hidden
.mcp-backups/directory.โช Surgical rollback โ Revert files to any of the 5 previous states using the
rollback_filetool.๐ค Fuzzy symbol matching โ When a symbol is not found, the server provides structured suggestions based on Levenshtein distance.
๐ Private symbol support โ Full support for
_and__prefixed symbols in Dart and Python.
Supported Languages
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 | โ | โ |
โ ๏ธ Known Limitations
rename_symbol Tool
All 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.
Risk: Regex may match strings, comments, or unrelated identifiers sharing the same name
Dart and Python: Higher risk โ import syntax (
import 'package:...',from module import name) is less reliably matched by the current regex patternsRecommendation: Always review the generated diff carefully before confirming
Alternative: Use
write_file_surgicalto rename within a single file safely
get_semantic_repo_map Tool
Max files: Limited to 500 files to prevent timeouts
Performance: Synchronous I/O may take 10-30 seconds on large repositories
Recommendation: Use
@foldersyntax to target specific directories
General
Validation: No automatic syntax checking after edits. Always review diffs carefully before confirming.
Backups: 5-version rolling backup system. Use
rollback_fileif something goes wrong.Large files: Files >10MB are skipped for safety.
Installation
# Global installation (recommended)
npm install -g mcp-code-context
# Or use directly with npx (no installation)
npx -y mcp-code-contextNote: Unlike v2.x, this version uses web-tree-sitter (WASM) instead of native bindings. No Visual Studio, Python, or node-gyp required!
Configuration
Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"mcp-code-context": {
"command": "npx",
"args": ["-y", "mcp-code-context"]
}
}
}Cursor
Add to your Cursor MCP settings (.cursor/mcp.json):
{
"mcpServers": {
"mcp-code-context": {
"command": "npx",
"args": ["-y", "mcp-code-context"]
}
}
}Windsurf
Add to your Windsurf MCP config:
{
"mcpServers": {
"mcp-code-context": {
"command": "npx",
"args": ["-y", "mcp-code-context"]
}
}
}Amazon Q / Other MCP Clients
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.
Tools
Read Tools
1. get_semantic_repo_map
Generate a compressed architectural overview of an entire repository.
directoryPath(required) โ Path to the repo rootformat(optional) โ"xml"(default) or"markdown"
2. read_file_surgical
Read a file, or extract only a specific named symbol. Returns structured suggestions if the symbol is missing.
filePath(required) โ Path to the source filesymbolName(optional) โ Name of a function, class, method, or typeclassName(optional) โ Scope the symbol to a specific class (to avoid duplicates)
3. analyze_impact
Find all files that depend on a given file.
filePath(required) โ Path to the file being modifiedrootDir(optional) โ Repository root (auto-detected)
4. read_file_lines
Read specific line ranges from a file without loading the entire content. More efficient than read_file_surgical for small fragments.
filePath(required) โ Path to the source filestartLine(optional) โ Starting line number (1-indexed)endLine(optional) โ Ending line number (1-indexed)aroundPattern(optional) โ Search pattern to find and return surrounding linescontextLines(optional) โ Number of lines before/after pattern (default: 5)
5. search_code_pattern
Search for code patterns across multiple files with context. Respects .gitignore rules.
rootDir(required) โ Repository root directorypattern(required) โ Regular expression pattern to searchfileExtensions(optional) โ Array of extensions to search (e.g.,[".ts", ".dart"])excludeDirs(optional) โ Directories to exclude (default:["node_modules", "dist", "build"])maxResults(optional) โ Maximum matches per page (default: 10)startIndex(optional) โ Pagination offset (default: 0)fuzzyMatch(optional) โ Enable fuzzy/typo-tolerant matching (default: false)fuzzyThreshold(optional) โ Fuzzy sensitivity 0.0โ1.0 (default: 0.4)
6. rollback_file
Surgically restore a file to a previous state from the automated backup system.
filePath(required) โ Path to the file to restoresteps(optional) โ Number of versions to go back (1-5, default: 1)
7. clean_backups
Remove all backup files for a project to keep the working directory clean.
projectRoot(required) โ Absolute path to the project root
Note: Backups are stored centrally at [project-root]/.mcp-backups/ to keep your project organized.
Write Tools (Two-Phase Workflow)
All write tools follow a Two-Phase Workflow:
Call without token: Returns a unified
diffand aconfirmationToken.Call with token: Set
confirm: trueand provide the token to apply the changes.
8. write_file_surgical
Replace the full source code of a named symbol in a file.
filePath(required) โ Path to the filesymbolName(required) โ Symbol to replacenewContent(required) โ Replacement code (signature + body)confirmationToken(optional) โ Token from Phase 1 to apply changesconfirm(optional) โ Set totrueto applyclassName(optional) โ Scope the symbol to a specific class
9. insert_symbol
Insert new code at a precise location relative to an existing symbol.
filePath(required) โ Path to the filecode(required) โ Code to insertanchorSymbol(optional) โ Symbol to position relative toposition(optional) โ"before","after","inside_start","inside_end"className(optional) โ Scope the anchor to a specific classconfirmationToken,confirm(optional)
10. rename_symbol
Rename a symbol across the entire repository (definition + all usages).
filePath(required) โ File where the symbol is definedoldName(required) โ Current namenewName(required) โ New namerootDir(optional) โ Repository rootconfirmationToken,confirm(optional)
11. remove_symbol
Safely remove a symbol from a file with dependency checking.
filePath(required) โ Path to the filesymbolName(required) โ Symbol to removeclassName(optional) โ Scope the symbol to a specific classforce(optional) โ Skip dependency checkconfirmationToken,confirm(optional)
Recommended Workflow
Understand โ
get_semantic_repo_mapto see the architectureRead โ
read_file_surgicalwith symbol name for specific implementationsAssess โ
analyze_impactbefore modifying shared filesEdit (Preview) โ Call write tools to generate a
diffandconfirmationTokenConfirm โ Call the same write tool with the token and
confirm: trueto applyRecovery โ Use
rollback_fileif something goes wrong after confirmation
๐ฐ Support This Project
Why Support?
This 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:
โฐ ~10 hours/week of maintenance
๐ต ~$20/month in costs (npm, testing, domain)
๐ 100% free and open source (always will be)
If this tool saves you time or money, consider supporting its development.
๐ณ Ways to Support
๐น One-Time Donation
Ko-fi (PayPal + Cards, 0% fees)
ko-fi.com/achatainga
PayPal (Direct)
paypal.me/achatainga
Binance (USDT) (Crypto, lowest fees)
TRC20/ERC20:
0xa68d53f7853ce0175eb96aaad4a30c068ca96444Binance Pay ID:
367669339
Recommended: TRC20 for lower gas fees
Suggested Amounts:
โ $5 - A coffee (1 hour of development)
๐ $25 - A pizza (testing a new language)
๐ $100 - Rocket fuel (major feature development)
๐น Recurring Support
Ko-fi Membership
ko-fi.com/achatainga/tiers
Monthly tiers:
$5/month - Supporter (name in SPONSORS.md)
$25/month - Contributor (priority support, early access)
$100/month - Sponsor (feature requests, 1-on-1 consultation)
๐น Hire Me
Need custom MCP tools or AI integrations?
๐ผ Available for: Freelance contracts
๐ Location: Caracas, Venezuela (Remote)
๐ป Skills: TypeScript, Node.js, MCP, AI/LLM integrations
๐ต Rate: $50-75/hour
๐ง Contact: a.chataing.a@gmail.com
๐ Details: HIRE_ME.md
๐ Transparency
I believe in radical transparency:
Current Status:
๐ฐ Donations received: $0
๐ธ Expenses: $20/month (npm, testing)
โฐ Time invested: ~10 hours/week
๐ฆ Downloads: 10,000+/month
(Updated monthly)
๐ Hall of Fame
Thank you to these amazing supporters:
(No sponsors yet - be the first!)
See full list: SPONSORS.md
โค๏ธ Non-Financial Support
Can't donate? No problem! You can still help:
โญ Star the repo on GitHub
๐ Report bugs or suggest features
๐ Improve documentation
๐ฃ๏ธ Share with others who might benefit
๐ฌ Join discussions and help other users
Every contribution matters, financial or not.
Development
# Build
npm run build
# Run tests
npm test
# Development (build + start)
npm run devTechnical Details
Transport: stdio (JSON-RPC over stdin/stdout)
Runtime: Node.js >= 18
Protocol: Model Context Protocol
AST Engines: web-tree-sitter@0.25.1 (WASM) for TypeScript/JS/Python/PHP/Dart
Language Grammars: tree-sitter-wasms@0.1.13 (ABI v15)
Cache: sql.js@1.14.1 (WASM SQLite, zero native deps)
Logging: pino@10.3.1 (JSON to stderr, MCP-safe)
File Watcher: chokidar@5.0.0 (auto cache invalidation)
Fuzzy Search: fuse.js@7.3.0 (typo-tolerant matching)
File Locking: proper-lockfile@4.1.2 (multi-process safe, OS temp)
Diff: diff-match-patch@1.0.5 (Myers algorithm, O(n+dยฒ))
Ignore Engine:
ignorenpm package (full .gitignore spec support)Safety Features: Mandatory two-phase confirmation, rolling 5-version backups, fuzzy matching, dependency checking, surgical restoration, ReDoS protection via worker_threads.
Portability: 100% WASM - no native dependencies, works on all platforms
Tests: 74 passing (unit + integration + performance + stress)
Contributing
See CONTRIBUTING.md for guidelines.
Security
See SECURITY.md for security policies and reporting vulnerabilities.
Troubleshooting
See TROUBLESHOOTING.md for common issues and solutions.
Viewing Logs
Because MCP uses stdout for protocol communication, all logs are safely routed to stderr. You can view them in your client's log files:
Claude Desktop (macOS):
~/Library/Logs/Claude/mcp-server-mcp-code-context.logClaude Desktop (Windows):
%APPDATA%\Claude\logs\mcp-server-mcp-code-context.logCursor:
Outputpanel โ Selectmcp-code-contextfrom the dropdown
Environment 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).
Changelog
See CHANGELOG.md for version history.
License
Built with โค๏ธ from Caracas, Venezuela ๐ป๐ช
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/achatainga/mcp-code-context'
If you have feedback or need assistance with the MCP directory API, please join our Discord server