Code Reference Optimizer MCP Server
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
Click on "Deploy 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., "@Code Reference Optimizer MCP Server extract the relevant context from my React component file"
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.
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
Related MCP server: diffctx
Quick Start (STDIO)
One-off (recommended):
npx -y @fosterg4/mcpsaverYou should see: Code Reference Optimizer MCP server running on stdio.
Global (optional):
npm i -g @fosterg4/mcpsaver
mcpsaverHTTP Mode
Start the HTTP server on port 8081 (default):
npx -y @fosterg4/mcpsaver mcpsaver-http
# or after build
npm run start:httpConfigure your MCP client to use the HTTP binary if supported, e.g.:
{
"mcpServers": {
"mcpsaver": { "command": "mcpsaver-http", "env": { "PORT": "8081", "LOG_LEVEL": "info" } }
}
}Use with an MCP client
Add to your MCP client config (example mcpServers.json):
{
"mcpServers": {
"mcpsaver": {
"command": "npx",
"args": ["-y", "@fosterg4/mcpsaver"],
"env": {}
}
}
}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.
{
"filePath": "path/to/file.ts",
"targetSymbols": ["myFunc", "MyClass"],
"includeImports": true,
"maxTokens": 1000
}Required: filePath | Optional: targetSymbols, includeImports, maxTokens
πΎ get_cached_context
Retrieves previously extracted and cached code context for fast access without re-parsing.
{ "filePath": "path/to/file.ts", "cacheKey": "optional-key" }Required: filePath | Optional: cacheKey
π analyze_code_diff
Performs intelligent analysis of code differences with semantic understanding and minimal update suggestions.
{
"filePath": "path/to/file.ts",
"oldContent": "export function a() { return 1 }",
"newContent": "export function a() { return 2 }"
}Required: filePath, oldContent, newContent
π§Ή optimize_imports
Analyzes and optimizes import statements to eliminate redundancy and improve code efficiency.
{ "filePath": "path/to/file.ts", "usedSymbols": ["useEffect", "useMemo"] }Required: filePath | Optional: usedSymbols
βοΈ get_config
Retrieves current configuration settings for cache behavior, extraction parameters, and more.
{ "section": "cache" }Optional: section (cache, extraction, imports, diff, performance, languages, logging, security)
π§ update_config
Updates configuration settings including cache policies, token limits, and performance thresholds.
{
"config": {
"cache": { "enablePersistence": true, "persistencePath": "/custom/cache/path" },
"extraction": { "maxTokens": 2000 }
}
}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.
{
"content": [{ "type": "text", "text": "{\n \"...\": true\n}" }]
}Additional MCP Capabilities
Prompts: listed but empty;
get_promptreturns MethodNotFound.Resources: listed but empty; reading a resource returns MethodNotFound.
Roots: exposes the current working directory as a single root
workspace.Sampling: stubbed;
sampling/createMessagereturns MethodNotFound.
Examples
See docs/EXAMPLES.md for endβtoβend request examples of each tool.
Configuration
Call
get_config,update_config,reset_configto 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.enableFileLoggingandconfig.logging.logPath
Development
npm ci
npm run build
npm start # run built server (stdio)
npm run start:http # run built server (http)
npm run dev # tsc --watch
npm test
npm run lint
npm run type-checkPublishing (maintainers)
npm login
npm run clean && npm run build
npm version patch
npm publish --access publicLicense
MIT β see LICENSE.
Available Tools
7 toolsanalyze_code_diffC
Analyze differences between code versions and provide minimal updates
Inputs: filePath (required), newContent (required), oldContent (required).
extract_code_contextC
Extract minimal code context from files using AST parsing
Inputs: filePath (required), includeImports, maxTokens, targetSymbols.
get_cached_contextB
Retrieve cached code context for a file
Inputs: filePath (required), cacheKey.
get_configC
Get current configuration settings
Inputs: section.
optimize_importsC
Analyze and optimize import statements to reduce redundancy
Inputs: filePath (required), usedSymbols.
reset_configB
Reset configuration to default values
Inputs: no named parameters.
update_configC
Update configuration settings
Inputs: config (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogβ¦
TDQS
Scored across 7 tools
Each tool has a clearly distinct purpose with no ambiguity: analyze_code_diff handles code version comparisons, extract_code_context and get_cached_context manage code context retrieval (one for extraction, one for caching), get_config, update_config, and reset_config handle configuration operations, and optimize_imports focuses on import optimization. The descriptions clearly differentiate their functions, making misselection unlikely.
All tools follow a consistent verb_noun pattern using snake_case, such as analyze_code_diff, extract_code_context, and optimize_imports. This uniformity makes the tool set predictable and easy to understand, with no deviations in naming conventions.
With 7 tools, the count is well-scoped for a code reference optimizer server. Each tool serves a specific role in code analysis, context management, and configuration, with no apparent bloat or missing essential functions, fitting the server's purpose appropriately.
The tool set covers core areas like code analysis, context extraction/caching, and configuration management, providing good lifecycle coverage. A minor gap exists in direct code editing or refactoring tools beyond imports, but agents can work around this using the provided tools for most optimization tasks.
Maintenance
Related MCP Connectors
Deterministic context layer for your codebase: change impact, blast radius, answers with receipts.
Code intelligence for LLMs. Analyze, search, and retrieve code from any public git repository.
Codebase intelligence for AI agents β dead code, blast radius, ownership.
Codebase intelligence for AI coding agents: graph, git history, docs, decisions, code health.
Related MCP Servers
- AlicenseAqualityCmaintenanceProvides intelligent code context and analysis through semantic compression, AST parsing, and multi-language support. Offers 60-80% token reduction while enabling AI assistants to understand codebases through local analysis, OpenAI-enhanced insights, and GitHub repository integration.620 npm3MIT
- AlicenseAqualityBmaintenanceSelects the minimum code context an LLM needs to understand a git diff: graph-based fragment selection under a token budget, deterministic output, 30+ tree-sitter languages.1315 PyPI6Apache 2.0
- AlicenseNot gradedqualityBmaintenanceReduces token consumption for AI coding agents by 50-70% through intelligent code context filtering, Git delta tracking, and local SQLite/Tree-sitter indexing.167 npmMIT
- AlicenseNot gradedqualityCmaintenanceProvides structured, token-efficient code context for AI assistants by indexing codebases with AST-level analysis, supporting 17+ languages, enabling semantic search, call-site tracking, and PR attribution.45 PyPI42MIT