Context Optimizer MCP Server
Provides 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.
README
Context Optimizer MCP Server
A Model Context Protocol (MCP) server that provides context optimization tools for AI coding assistants including GitHub Copilot, Cursor AI, Claude Desktop, and other MCP-compatible assistants. It enables AI assistants to extract targeted information rather than processing large files and command outputs in their entirety.
This server provides context optimization functionality similar to the VS Code Copilot Context Optimizer extension, but with compatibility across MCP-supporting applications.
Features
- 🔍 File Analysis Tool (
askAboutFile) - Extract specific information from files without loading entire contents - 🖥️ Terminal Execution Tool (
runAndExtract) - Execute commands and extract relevant information using LLM analysis - ❓ Follow-up Questions Tool (
askFollowUp) - Continue conversations about previous terminal executions - 🔬 Research Tools (
researchTopic,deepResearch) - Conduct web research using Exa.ai's API - 🔒 Security Controls - Path validation, command filtering, and session management
- 🔧 Multi-LLM Support - Works with Google Gemini, Claude (Anthropic), and OpenAI
- ⚙️ Environment Variable Configuration - API key management through system environment variables
- 🏗️ Simple Configuration - Environment variables only, no config files to manage
- 🧪 Comprehensive Testing - Unit tests, integration tests, and security validation
Quick Start
1. Install globally:
npm install -g context-optimizer-mcp-server
2. Set environment variables (see docs/guides/usage.md for OS-specific instructions):
export CONTEXT_OPT_LLM_PROVIDER="gemini"
export CONTEXT_OPT_GEMINI_KEY="your-gemini-api-key"
export CONTEXT_OPT_EXA_KEY="your-exa-api-key"
export CONTEXT_OPT_ALLOWED_PATHS="/path/to/your/projects"
3. Add to your MCP client configuration:
For Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"context-optimizer": {
"command": "context-optimizer-mcp"
}
}
}
For VS Code (mcp.json):
{
"servers": {
"context-optimizer": {
"command": "context-optimizer-mcp"
}
}
}
For complete setup instructions including OS-specific environment variable configuration and AI assistant setup, see docs/guides/usage.md.
Available Tools
-
askAboutFile- Extract specific information from files without loading entire contents into chat context. Perfect for checking if files contain specific functions, extracting import/export statements, or understanding file purpose without reading the full content. -
runAndExtract- Execute terminal commands and intelligently extract relevant information using LLM analysis. Supports non-interactive commands with security validation, timeouts, and session management for follow-up questions. -
askFollowUp- Continue conversations about previous terminal executions without re-running commands. Access complete context from previousrunAndExtractcalls including full command output and execution details. -
researchTopic- Conduct quick, focused web research on software development topics using Exa.ai's research capabilities. Get current best practices, implementation guidance, and up-to-date information on evolving technologies. -
deepResearch- Comprehensive research and analysis using Exa.ai's exhaustive capabilities for critical decision-making and complex architectural planning. Ideal for strategic technology decisions, architecture planning, and long-term roadmap development.
For detailed tool documentation and examples, see docs/tools.md and docs/guides/usage.md.
Documentation
All documentation is organized under the docs/ directory:
| Topic | Location | Description |
|---|---|---|
| Architecture | docs/architecture.md |
System design and component overview |
| Tools Reference | docs/tools.md |
Complete tool documentation and examples |
| Usage Guide | docs/guides/usage.md |
Complete setup and configuration |
| VS Code Setup | docs/guides/vs-code-setup.md |
VS Code specific configuration |
| Troubleshooting | docs/guides/troubleshooting.md |
Common issues and solutions |
| API Keys | docs/reference/api-keys.md |
API key management |
| Testing | docs/reference/testing.md |
Testing framework and procedures |
| Changelog | docs/reference/changelog.md |
Version history |
| Contributing | docs/reference/contributing.md |
Development guidelines |
| Security | docs/reference/security.md |
Security policy |
| Code of Conduct | docs/reference/code-of-conduct.md |
Community guidelines |
Quick Links
- Get Started: See
docs/guides/usage.mdfor complete setup instructions - Tools Reference: Check
docs/tools.mdfor detailed tool documentation - Troubleshooting: Check
docs/guides/troubleshooting.mdfor common issues - VS Code Setup: Follow
docs/guides/vs-code-setup.mdfor VS Code configuration
Testing
# Run all tests (skips LLM integration tests without API keys)
npm test
# Run tests with API keys for full integration testing
# Set environment variables first:
export CONTEXT_OPT_LLM_PROVIDER="gemini"
export CONTEXT_OPT_GEMINI_KEY="your-gemini-key"
export CONTEXT_OPT_EXA_KEY="your-exa-key"
npm test # Now runs all tests including LLM integration
# Run in watch mode
npm run test:watch
For detailed testing setup, see docs/reference/testing.md.
Contributing
Contributions are welcome! Please read docs/reference/contributing.md for guidelines on development workflow, coding standards, testing, and submitting pull requests.
Community
- Code of Conduct: See docs/reference/code-of-conduct.md
- Security Reports: Follow docs/reference/security.md for responsible disclosure
- Issues: Use GitHub Issues for bugs & feature requests
- Pull Requests: Ensure tests pass and docs are updated
- Discussions: (If enabled) Use for open-ended questions/ideas
License
MIT License - see LICENSE file for details.
Related Projects
- VS Code Copilot Context Optimizer – Original VS Code extension (companion project)
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。