The Code Reference Optimizer MCP Server is an advanced tool that optimizes code context for AI assistants through intelligent extraction, analysis, and optimization.
Smart Context Extraction: Uses AST parsing to extract minimal, relevant code sections for specified symbols while managing imports automatically
Multi-language Support: Compatible with TypeScript/JavaScript, Python, Go, Rust, Java, C++, and more
Intelligent Caching: Retrieves previously extracted code context for fast access without re-parsing
Token Optimization: Filters unnecessary code while maintaining semantic completeness, reducing token usage for AI assistants
Diff Analysis: Analyzes code differences with semantic understanding and provides minimal update suggestions
Import Optimization: Eliminates redundant imports and improves code efficiency by analyzing used symbols
Configuration Management: Allows retrieval, updating, and resetting of server settings including cache behavior, extraction parameters, and token limits
Simple Integration: Operates as a stdio-based MCP server for easy integration with any MCP client
Provides code analysis and optimization tools for JavaScript files, including context extraction, diff analysis, and import optimization to reduce token usage
Provides code analysis and optimization tools for Python files, including context extraction, diff analysis, and import optimization to reduce token usage
Provides code analysis and optimization tools for Rust files, including context extraction, diff analysis, and import optimization to reduce token usage
Provides code analysis and optimization tools for TypeScript files, including context extraction, diff analysis, and import optimization to reduce token usage
Code Reference Optimizer MCP Server
An advanced MCP (Model Context Protocol) server that intelligently extracts minimal, relevant code context using AST parsing, analyzes code differences, and optimizes imports to dramatically reduce token usage for AI assistants.
Key Features
- Smart Context Extraction: Uses AST parsing to identify and extract only relevant code sections
- Multi-language Support: TypeScript/JavaScript, Python, Go, Rust, Java, C++, and more
- Intelligent Caching: LRU cache with configurable persistence and customizable storage paths
- Token Optimization: Filters unnecessary code while maintaining semantic completeness
- Diff Analysis: Provides minimal, focused code differences with semantic understanding
- Import Optimization: Eliminates unused imports and suggests consolidation opportunities
- Configurable: Runtime configuration via tools with persistent settings
- Simple Integration: stdio-based server and optional HTTP server, easy to integrate with any MCP client
Quick Start (STDIO)
- One-off (recommended):
You should see: Code Reference Optimizer MCP server running on stdio
.
- Global (optional):
HTTP Mode
Start the HTTP server on port 8081 (default):
Configure your MCP client to use the HTTP binary if supported, e.g.:
Use with an MCP client
Add to your MCP client config (example mcpServers.json
):
Available Tools
The server provides 7 powerful tools for code analysis and optimization:
🔍 extract_code_context
Extracts minimal, focused code context using AST parsing. Intelligently identifies relevant code sections, imports, and dependencies for specific symbols.
Required: filePath
| Optional: targetSymbols
, includeImports
, maxTokens
💾 get_cached_context
Retrieves previously extracted and cached code context for fast access without re-parsing.
Required: filePath
| Optional: cacheKey
📊 analyze_code_diff
Performs intelligent analysis of code differences with semantic understanding and minimal update suggestions.
Required: filePath
, oldContent
, newContent
🧹 optimize_imports
Analyzes and optimizes import statements to eliminate redundancy and improve code efficiency.
Required: filePath
| Optional: usedSymbols
⚙️ get_config
Retrieves current configuration settings for cache behavior, extraction parameters, and more.
Optional: section
(cache, extraction, imports, diff, performance, languages, logging, security)
🔧 update_config
Updates configuration settings including cache policies, token limits, and performance thresholds.
Required: config
🔄 reset_config
Resets all configuration settings to default values.
No parameters required
Note: Tool results are returned as MCP content with a single text
item containing JSON of the result, e.g.
Additional MCP Capabilities
- Prompts: listed but empty;
get_prompt
returns MethodNotFound. - Resources: listed but empty; reading a resource returns MethodNotFound.
- Roots: exposes the current working directory as a single root
workspace
. - Sampling: stubbed;
sampling/createMessage
returns MethodNotFound.
Examples
See docs/EXAMPLES.md
for end‑to‑end request examples of each tool.
Configuration
- Call
get_config
,update_config
,reset_config
to manage runtime settings. - You may also set environment variables via your MCP client if supported (e.g.,
LOG_LEVEL
).
Structured Logging
The server uses a lightweight structured logger. Configure via get_config
/update_config
or env:
- Level:
config.logging.level
(trace|debug|info|warn|error) - File logging:
config.logging.enableFileLogging
andconfig.logging.logPath
Development
Publishing (maintainers)
License
MIT — see LICENSE
.
local-only server
The server can only run on the client's local machine because it depends on local resources.
Tools
Extracts minimal, relevant code context from multiple programming languages while analyzing diffs and optimizing imports to reduce token usage for AI assistants. Supports TypeScript/JavaScript, Python, Go, and Rust with token-aware caching.
Related MCP Servers
- AsecurityAlicenseAqualityFetches and extracts comprehensive package documentation from multiple programming language ecosystems (JavaScript, Python, Java, etc.) for LLMs like Claude without requiring API keys.Last updated -42514MIT License
- AsecurityAlicenseAqualityProvides code context and analysis for AI assistants by extracting directory structures and code symbols using WebAssembly Tree-sitter parsers with zero native dependencies.Last updated -13715MIT License
- AsecurityAlicenseAqualityProvides intelligent context management for AI development sessions, allowing users to track token usage, manage conversation context, and seamlessly restore context when reaching token limits.Last updated -832Apache 2.0
- -securityAlicense-qualityProvides AI coding assistants with context optimization tools including targeted file analysis, intelligent terminal command execution with LLM-powered output extraction, and web research capabilities. Helps reduce token usage by extracting only relevant information instead of processing entire files and command outputs.Last updated -2141TypeScriptMIT License