Enterprise Code Search MCP Server

Enterprise Code Search MCP Server

Enables semantic code search across local projects and Git repositories using AI embeddings with ChromaDB. Supports both OpenAI and local Ollama models for private, enterprise-ready code analysis and similar code discovery.

Category
访问服务器

README

Enterprise Code Search MCP Server

A powerful Model Context Protocol (MCP) server for semantic code search with shared vector database. Supports both OpenAI and Ollama for embeddings, and can index local projects or Git repositories.

🚀 Features

  • Semantic code search using AI embeddings
  • Dual provider support: OpenAI or Ollama (local, private)
  • Flexible indexing: Local projects or Git repositories
  • Shared vector database with ChromaDB
  • Multi-project management: Handle multiple projects simultaneously
  • Automatic project structure analysis
  • Similar code search based on code snippets
  • Enterprise-ready: Private, secure, self-hosted

📋 Requirements

  • Node.js 18+
  • Docker and Docker Compose
  • Git (for repository indexing)

🛠️ Quick Start

1. Clone the repository

git clone https://github.com/your-username/semantic-context-mcp.git
cd semantic-context-mcp

2. Install dependencies

npm install

3. Configure environment

cp .env.example .env
# Edit .env with your configuration

4. Start services

# Start ChromaDB and Ollama
docker-compose up -d

# Wait for Ollama to download models
docker-compose logs -f ollama-setup

5. Build and run

npm run build
npm start

⚙️ Configuration

Using Ollama (Recommended for Enterprise)

# .env
EMBEDDING_PROVIDER=ollama
OLLAMA_HOST=http://localhost:11434
OLLAMA_MODEL=nomic-embed-text
CHROMA_HOST=localhost
CHROMA_PORT=8000

Using OpenAI

# .env
EMBEDDING_PROVIDER=openai
OPENAI_API_KEY=your-api-key
OPENAI_MODEL=text-embedding-3-small

🔧 Claude Desktop Integration

To use this MCP server with Claude Desktop, add to your claude_desktop_config.json:

{
  "mcpServers": {
    "enterprise-code-search": {
      "command": "node",
      "args": ["/path/to/semantic-context-mcp/dist/index.js"],
      "env": {
        "EMBEDDING_PROVIDER": "ollama",
        "OLLAMA_HOST": "http://localhost:11434",
        "OLLAMA_MODEL": "nomic-embed-text",
        "CHROMA_HOST": "localhost",
        "CHROMA_PORT": "8000",
        "COMPANY_NAME": "YourCompany"
      }
    }
  }
}

🎯 Usage Examples

1. Index a local project

Index my local project at /home/user/my-app with the name "frontend-app"

2. Search in code

Search for "main application function" in all indexed projects

3. Find similar code

Find code similar to:
```python
def authenticate_user(username, password):
    return check_credentials(username, password)

4. Analyze project structure

Analyze the structure of project "frontend-app"

🛠️ Available Tools

Tool Description
index_local_project Index a local directory
search_codebase Semantic search in code
list_indexed_projects List all indexed projects
get_embedding_provider_info Get embedding provider information

📊 Example Queries

Functional searches

  • "Where is the authentication logic?"
  • "Functions that handle database operations"
  • "Environment variable configuration"
  • "Unit tests for the API"

Code analysis

  • "What design patterns are used?"
  • "Most complex functions in the project"
  • "Error handling in the code"

Technology-specific search

  • "Code using React hooks"
  • "PostgreSQL queries"
  • "Docker configuration"

🔧 Advanced Configuration

Recommended Ollama Models

# For code embeddings
ollama pull nomic-embed-text    # Best for code (384 dims)
ollama pull all-minilm         # Lightweight alternative (384 dims)
ollama pull mxbai-embed-large  # Higher precision (1024 dims)

File Patterns

The server supports extensive file type recognition including:

  • Programming Languages: Python, JavaScript/TypeScript, Java, C/C++, Go, Rust, PHP, Ruby, Swift, Kotlin, Scala, and more
  • Web Technologies: HTML, CSS, SCSS, Vue, Svelte
  • Configuration: JSON, YAML, TOML, Docker, Terraform
  • Documentation: Markdown, reStructuredText, AsciiDoc
  • Database: SQL files

Performance Tuning

# Maximum chunk size (characters)
MAX_CHUNK_SIZE=1500

# Maximum file size (KB)
MAX_FILE_SIZE=500

# Batch size for indexing
BATCH_SIZE=100

🏢 Enterprise Deployment

Option 1: Dedicated Server

# On enterprise server
docker-compose up -d

Option 2: Network Deployment

# Configure for network access
CHROMA_HOST=192.168.1.100
OLLAMA_HOST=http://192.168.1.100:11434

🔒 Security Considerations

Key Benefits

  1. Private Data: Ollama keeps everything local
  2. No External APIs: When using Ollama, no data leaves your network
  3. Self-hosted: Full control over your code and embeddings
  4. Isolated Environment: Docker containers provide isolation

Security Best Practices

# Restrict ChromaDB access
CHROMA_SERVER_HOST=127.0.0.1  # Localhost only

# Use HTTPS for production
OLLAMA_HOST=https://ollama.company.com

📈 Monitoring & Troubleshooting

Useful Logs

# View indexing logs
docker-compose logs -f enterprise-mcp-server

# ChromaDB performance
docker-compose logs -f chromadb

# Monitor Ollama
curl http://localhost:11434/api/tags

Common Issues

Ollama not responding:

curl http://localhost:11434/api/tags
# If it fails: docker-compose restart ollama

ChromaDB slow:

# Check disk space
docker system df
# Clean if necessary
docker system prune

Poor embedding quality:

  • Try different model: all-minilm vs nomic-embed-text
  • Adjust chunk size
  • Verify source file quality

🤝 Collaborative Workflow

Typical Enterprise Workflow

  1. DevOps indexes main projects
  2. Developers search code using Claude
  3. Automatic updates via CI/CD
  4. Code analysis for code reviews

Best Practices

  • Index after important merges
  • Use descriptive project names
  • Maintain project-specific search filters
  • Document naming conventions

🛠️ Development

Project Structure

src/
├── index.ts          # Main MCP server
└── http-server.ts    # HTTP server variant

scripts/              # Setup and utility scripts
docker-compose.yml    # Service orchestration
package.json         # Dependencies and scripts

Available Scripts

npm run build        # Compile TypeScript
npm run dev          # Development mode
npm run start        # Production mode
npm run clean        # Clean build directory

📚 API Reference

The MCP server implements the standard Model Context Protocol with these specific tools:

  • index_local_project: Index local directories with configurable file patterns
  • search_codebase: Semantic search with project filtering and similarity scoring
  • list_indexed_projects: Enumerate all indexed projects with metadata
  • get_embedding_provider_info: Get current provider status and configuration

Each tool includes detailed JSON schema with examples and validation.

🤖 Recommended AI Models

For embeddings (Ollama)

  • nomic-embed-text: Optimized for code
  • all-minilm: Balanced, fast
  • mxbai-embed-large: High precision

For embeddings (OpenAI)

  • text-embedding-3-small: Cost-effective
  • text-embedding-3-large: Higher precision

🐳 Docker Support

The project includes a complete Docker setup:

  • ChromaDB: Vector database for embeddings
  • Ollama: Local embedding generation
  • PostgreSQL: Optional metadata storage

All services are orchestrated with Docker Compose for easy deployment.

☕ Support

If this project helps you with your development workflow, consider supporting it:

Buy Me A Coffee

📄 License

MIT License - see LICENSE file for details.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📞 Support & Issues

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选