经 AI Skill Hub 精选评估,代码搜索工具 获评「强烈推荐」。这款MCP工具在功能完整性、社区活跃度和易用性方面表现出色,AI 评分 8.0 分,适合有一定技术背景的用户使用。
本地优先的混合语义代码搜索工具,支持PostgreSQL索引
代码搜索工具 是一款遵循 MCP(Model Context Protocol)标准协议的 AI 工具扩展。通过 MCP 协议,它可以让 Claude、Cursor 等主流 AI 客户端直接访问和操作外部工具、数据源和服务,实现 AI 能力的无缝扩展。无论是文件操作、数据库查询还是 API 调用,都可以通过自然语言在 AI 对话中直接触发,极大提升生产效率。
本地优先的混合语义代码搜索工具,支持PostgreSQL索引
代码搜索工具 是一款遵循 MCP(Model Context Protocol)标准协议的 AI 工具扩展。通过 MCP 协议,它可以让 Claude、Cursor 等主流 AI 客户端直接访问和操作外部工具、数据源和服务,实现 AI 能力的无缝扩展。无论是文件操作、数据库查询还是 API 调用,都可以通过自然语言在 AI 对话中直接触发,极大提升生产效率。
# 方式一:通过 Claude Code CLI 一键安装
claude skill install https://github.com/VioletCranberry/coco-search
# 方式二:手动配置 claude_desktop_config.json
{
"mcpServers": {
"------": {
"command": "npx",
"args": ["-y", "coco-search"]
}
}
}
# 配置文件位置
# macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
# Windows: %APPDATA%/Claude/claude_desktop_config.json
# 安装后在 Claude 对话中直接使用 # 示例: 用户: 请帮我用 代码搜索工具 执行以下任务... Claude: [自动调用 代码搜索工具 MCP 工具处理请求] # 查看可用工具列表 # 在 Claude 中输入:"列出所有可用的 MCP 工具"
// claude_desktop_config.json 配置示例
{
"mcpServers": {
"______": {
"command": "npx",
"args": ["-y", "coco-search"],
"env": {
// "API_KEY": "your-api-key-here"
}
}
}
}
// 保存后重启 Claude Desktop 生效
<p align="center"> <img src="./docs/banner-terminal.svg" alt="Coco[-S]earch — Local-first hybrid semantic code search" width="960"> </p>
<p align="center"> <a href="https://pypi.org/project/cocosearch/"><img src="https://img.shields.io/pypi/v/cocosearch?color=blue&logo=pypi&logoColor=white" alt="PyPI"></a> <a href="https://www.python.org/"><img src="https://img.shields.io/badge/python-%3E%3D3.11-blue?logo=python&logoColor=white" alt="Python >= 3.11"></a> <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="License: MIT"></a> <a href="https://github.com/astral-sh/ruff"><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff"></a> <a href="https://github.com/astral-sh/uv"><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json" alt="uv"></a> <a href="https://docs.pytest.org/"><img src="https://img.shields.io/badge/tests-pytest-blue?logo=pytest&logoColor=white" alt="pytest"></a> <a href="https://modelcontextprotocol.io/"><img src="https://img.shields.io/badge/MCP-compatible-8A2BE2?logo=anthropic&logoColor=white" alt="MCP"></a> </p>
<p align="center"> <a href="#supported-languages"><img src="https://img.shields.io/badge/Bash-4EAA25?logo=gnubash&logoColor=white" alt="Bash"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/C-A8B9CC?logo=c&logoColor=white" alt="C"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/C%2B%2B-00599C?logo=cplusplus&logoColor=white" alt="C++"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/C%23-512BD4?logo=csharp&logoColor=white" alt="C#"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/CSS-1572B6?logo=css3&logoColor=white" alt="CSS"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/Dockerfile-2496ED?logo=docker&logoColor=white" alt="Dockerfile"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/DTD-7A7A7A" alt="DTD"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/Fortran-734F96?logo=fortran&logoColor=white" alt="Fortran"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/Go-00ADD8?logo=go&logoColor=white" alt="Go"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/Groovy-4298B8?logo=apachegroovy&logoColor=white" alt="Groovy"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/HCL-844FBA?logo=terraform&logoColor=white" alt="HCL"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/HTML-E34F26?logo=html5&logoColor=white" alt="HTML"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/Java-ED8B00?logo=openjdk&logoColor=white" alt="Java"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/JavaScript-F7DF1E?logo=javascript&logoColor=black" alt="JavaScript"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/JSON-000000?logo=json&logoColor=white" alt="JSON"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/Kotlin-7F52FF?logo=kotlin&logoColor=white" alt="Kotlin"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/Markdown-000000?logo=markdown&logoColor=white" alt="Markdown"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/Pascal-0364B8" alt="Pascal"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/PHP-777BB4?logo=php&logoColor=white" alt="PHP"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/Python-3776AB?logo=python&logoColor=white" alt="Python"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/R-276DC3?logo=r&logoColor=white" alt="R"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/Ruby-CC342D?logo=ruby&logoColor=white" alt="Ruby"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/Rust-000000?logo=rust&logoColor=white" alt="Rust"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/Scala-DC322F?logo=scala&logoColor=white" alt="Scala"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/Solidity-363636?logo=solidity&logoColor=white" alt="Solidity"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/SQL-336791" alt="SQL"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/Swift-F05138?logo=swift&logoColor=white" alt="Swift"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/TOML-9C4121?logo=toml&logoColor=white" alt="TOML"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/TypeScript-3178C6?logo=typescript&logoColor=white" alt="TypeScript"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/XML-0060AC" alt="XML"></a> <a href="#supported-languages"><img src="https://img.shields.io/badge/YAML-CB171E?logo=yaml&logoColor=white" alt="YAML"></a> </p>
<p align="center"> <a href="#supported-grammars"><img src="https://img.shields.io/badge/ArgoCD-EF7B4D?logo=argo&logoColor=white" alt="ArgoCD"></a> <a href="#supported-grammars"><img src="https://img.shields.io/badge/Docker_Compose-2496ED?logo=docker&logoColor=white" alt="Docker Compose"></a> <a href="#supported-grammars"><img src="https://img.shields.io/badge/GitHub_Actions-2088FF?logo=githubactions&logoColor=white" alt="GitHub Actions"></a> <a href="#supported-grammars"><img src="https://img.shields.io/badge/GitLab_CI-FC6D26?logo=gitlab&logoColor=white" alt="GitLab CI"></a> <a href="#supported-grammars"><img src="https://img.shields.io/badge/Helm_Chart-0F1689?logo=helm&logoColor=white" alt="Helm Chart"></a> <a href="#supported-grammars"><img src="https://img.shields.io/badge/Helm_Template-0F1689?logo=helm&logoColor=white" alt="Helm Template"></a> <a href="#supported-grammars"><img src="https://img.shields.io/badge/Helm_Values-0F1689?logo=helm&logoColor=white" alt="Helm Values"></a> <a href="#supported-grammars"><img src="https://img.shields.io/badge/Kubernetes-326CE5?logo=kubernetes&logoColor=white" alt="Kubernetes"></a> <a href="#supported-grammars"><img src="https://img.shields.io/badge/Terraform-844FBA?logo=terraform&logoColor=white" alt="Terraform"></a> </p>
<p align="center"><em>Give your AI assistant a search engine instead of a thousand grep calls — 32 languages, 9 grammars, dependency graphs, cross-repo search, fewer tokens, less hallucination.</em></p>
Typical code RAG splits files into chunks that break across function and class boundaries, losing the structure that makes code meaningful. CocoSearch preserves it — CocoIndex and Tree-sitter provide syntax-aware chunking that keeps functions, classes, and config blocks intact; search results expand to enclosing scope boundaries via Tree-sitter AST; grammar handlers split infrastructure configs at domain-aware boundaries (Terraform resources, CI/CD jobs, Compose services); and a dependency graph maps how files connect across code, config, and documentation.
That structure is also what cuts agent round-trips and context burn: because each hit comes back as a complete, scope-expanded unit, the agent doesn't grep → read file → grep again → read again to rebuild a function that got sliced mid-body. One call returns ranked, symbol-aware results plus their dependency edges — so the loop converges in fewer steps and less wasted context. It's not about beating grep on raw latency (grep is milliseconds); it's fewer steps and capabilities grep doesn't have — transitive impact across resolved imports.
Coco[-S]earch is a local-first hybrid semantic code search tool. It combines vector similarity and keyword matching (via RRF fusion) to find code by meaning, not just text. Powered by CocoIndex for indexing, Tree-sitter for syntax-aware chunking and symbol extraction, PostgreSQL with pgvector for storage, and Ollama for local embeddings by default. Optional remote embedding providers (OpenAI, OpenRouter) available for teams that prefer managed infrastructure — your code still never leaves your machine, only chunk text is sent for embedding.
Available as a WEB dashboard, CLI, MCP server, or interactive REPL. Incremental indexing, .gitignore-aware. Supports 32 languages with symbol-level filtering for 15+, plus domain-specific grammars for structured config files. Since 0.1.22: dependency graph extraction with forward trees (deps tree), reverse impact analysis (deps impact), and dependency-enriched search — for Python, JavaScript/TypeScript, Go, Docker Compose, GitHub Actions, Terraform, and Helm.
--hybrid. Definition symbols (functions, classes) get a 2x score boost. RRF constant k=60."how does login work" → "authentication session credential login user token"). Disabled by default — when off, search is byte-for-byte identical and no generative model runs. Configured like the embedding provider (ollama/openai/openrouter), defaults to local Ollama (qwen2.5:3b). Never breaks search: falls back to the original query on any error, timeout, or disabled state. Opt out per call with --no-rewrite (CLI/analyze) or rewrite_query=False (MCP). See Query Rewrite.function, class, method, or interface with --symbol-type; match symbol names with glob patterns (User*, *Handler) via --symbol-name. Supported for 15 languages with Tree-sitter .scm queries. Filters apply before RRF fusion for better ranking quality.--no-smart or set explicit line counts with -B/-A/-C.deps tree), reverse impact analysis (deps impact), batch queries, and dependency-enriched search results (include_deps). Incremental extraction with SHA-256 tracking. Add extractors for new languages by copying a template.--indexes or linkedIndexes config. Query embedding computed once, parallel per-index search, results merged by score. Linked indexes auto-expand single-index searches — missing indexes are skipped gracefully..gitignore-aware by default.--no-cache.ok, partial (Tree-sitter produced a tree with ERROR nodes), error (parse failure), and no_grammar. Detects index staleness by comparing the indexed commit hash and branch against your current HEAD — the dashboard and CLI show warnings when the index drifts behind. View with cocosearch stats --pretty.cocosearch analyze runs the search pipeline with full diagnostics: see identifier detection, mode selection, RRF fusion breakdown, definition boost effects, and per-stage timings. Available as CLI and MCP tool. Cross-index analysis with per-index breakdowns.Run CocoSearch as a centralized service — the host CLI forwards commands transparently over HTTP. Both the app and ollama services are opt-in via profiles; docker compose up -d starts only PostgreSQL.
```bash
The Docker container runs an SSE-based MCP server. Connect your AI assistant directly to it instead of spawning a local process:
Claude Code:
claude mcp add --scope user cocosearch --url http://localhost:3000/sse
Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"cocosearch": {
"url": "http://localhost:3000/sse"
}
}
}
OpenCode (opencode.json):
{
"mcp": {
"cocosearch": {
"type": "remote",
"url": "http://localhost:3000/sse",
"enabled": true
}
}
}
Note: Replace3000with yourCOCOSEARCH_MCP_PORTif customized.
```bash
export COCOSEARCH_EMBEDDING_PROVIDER=openai # or openrouter export COCOSEARCH_EMBEDDING_API_KEY=sk-...
> **Tip:** If using a remote embedding provider (OpenAI, OpenRouter), export the environment variables in your shell profile (`~/.zshrc`, `~/.bashrc`) before starting Claude Code — the plugin's MCP server inherits them from your shell. Alternatively, use manual MCP registration with `--env` flags (see [MCP Configuration](./docs/mcp-configuration.md#remote-embedding-providers)).
**Option B — Manual MCP registration:**
bash claude mcp add --scope user cocosearch -- uvx cocosearch mcp --project-from-cwd
> **Note:** The MCP server automatically opens a web dashboard in your browser on a random port. Set `COCOSEARCH_DASHBOARD_PORT=8080` to pin it to a fixed port, or `COCOSEARCH_NO_DASHBOARD=1` to disable it.
**Option C — OpenCode:**
Add to `~/.config/opencode/opencode.json` (global) or `opencode.json` (project):
json { "$schema": "https://opencode.ai/config.json", "mcp": { "cocosearch": { "type": "local", "command": ["uvx", "--from", "cocosearch", "cocosearch", "mcp", "--project-from-cwd"], "enabled": true } } } ```
Note: OpenCode usesAGENTS.mdfor project instructions (equivalent toCLAUDE.md). Runuvx cocosearch initto generate it, or create a symlink:ln -s CLAUDE.md AGENTS.md. Skills are compatible — see Skills README for installation.
Run cocosearch init to generate a starter config file and optionally set up CLAUDE.md tool routing for Claude Code integration:
uv run cocosearch init
init also offers to install an optional nudge hook for Claude Code — a non-blocking PreToolUse hook that reminds the agent to prefer search_code over raw Grep/Glob/grep/find when CocoSearch is running, and stays completely silent when it isn't (so your normal grep fallback is never blocked). It's an opt-in prompt; skip it with --no-claude-hook.
Or create cocosearch.yaml in your project root manually to customize indexing:
```yaml indexing: # See also https://cocoindex.io/docs/ops/functions#supported-languages include_patterns: - ".py" - ".js" - ".ts" - ".go" - "*.rs" exclude_patterns: - "_test.go" - ".min.js" chunk_size: 1000 # bytes chunk_overlap: 300 # bytes
embedding: provider: ollama # ollama (default), openai, openrouter model: nomic-embed-text # default depends on provider # baseUrl: http://localhost:8080 # custom OpenAI-compatible endpoint
controller: enabled: false # when false, search is byte-for-byte unchanged provider: ollama # ollama (default), openai, openrouter model: qwen2.5:3b # default depends on provider # baseUrl: http://localhost:11434 # timeout: 5.0 # seconds; on timeout, falls back to the original query
logging: file: false # true -> ~/.cocosearch/logs/cocosearch.log (10MB rotation) ```
uv run cocosearch config check
| Provider | Default Model | API Key Required |
|----------|--------------|-----------------|
| `ollama` | `nomic-embed-text` | No (local) |
| `openai` | `text-embedding-3-small` | Yes (optional with `baseUrl`) |
| `openrouter` | `openai/text-embedding-3-small` | Yes (optional with `baseUrl`) |
Switching providers on an existing index requires `--fresh` to reindex with the new embedding model.
#### Custom Endpoints
Use `embedding.baseUrl` (or `COCOSEARCH_EMBEDDING_BASE_URL`) to point any provider at a local OpenAI-compatible server such as [Infinity](https://github.com/michaelfeil/infinity), [text-embeddings-inference](https://github.com/huggingface/text-embeddings-inference), or [vLLM](https://github.com/vllm-project/vllm):
yaml embedding: provider: openai model: BAAI/bge-small-en-v1.5 baseUrl: http://localhost:8080 ```
When baseUrl is set, the API key is not required. For the ollama provider, baseUrl overrides COCOSEARCH_OLLAMA_URL.
CocoSearch retrieval is already adaptive without any LLM. Per query, it auto-selects hybrid vs. vector-only search from code-identifier patterns, sizes prefetch dynamically, applies a definition boost, caches at two levels (exact + semantic), and auto-expands to linked indexes — all deterministic, local, and fast. The query-rewrite controller below is an optional layer on top for vague natural-language queries (mainly the CLI/REPL, where there's no LLM in front). It is not required and not a fix for anything. When you use CocoSearch via MCP, the calling agent already reformulates queries, so leave the controller off or opt out per call.
When enabled, an LLM rewrites/expands a natural-language query into better search terms before retrieval:
"how does login work" → "authentication session credential login user token"
It is disabled by default — when off, search behaves exactly as before and no generative model is ever called. On any error, timeout, or empty output it falls back to the original query, so search never breaks. Configure it exactly like the embedding provider:
```yaml
Search your code four ways — pick what fits your workflow:
| Interface | Best for | How to start |
|---|---|---|
| **CLI** | One-off searches, scripting, CI | cocosearch search "auth flow" |
| **Interactive REPL** | Exploratory sessions — tweak filters, switch indexes, iterate on queries without restarting | cocosearch search --interactive |
| **Web Dashboard** | Visual search + index management in the browser — multi-project discovery, filters, syntax-highlighted results, charts, open-in-editor, retro terminal theme | cocosearch dashboard |
| **MCP Server** | AI assistant integration ([Claude Code](https://claude.com/product/claude-code), [Claude Desktop](https://claude.com/download), [OpenCode](https://opencode.ai/)) | cocosearch mcp --project-from-cwd |
uvx cocosearch analyze "getUserById"
nomic-embed-text) running locally. Also supports OpenAI and OpenRouter for remote embeddings.Dashboard shows "Indexing" but CLI shows "Indexed"
The web dashboard and CLI now share a status sync mechanism: when the dashboard detects a live indexing thread, it corrects the database status so both interfaces agree. If you still see a discrepancy, check whether indexing is genuinely running (CPU usage, docker stats for Ollama activity).
Index appears stuck in "Indexing" status
After 1 hour with no progress updates, the status auto-recovers to "Indexed". You can also run cocosearch index . again to force a fresh index, which will reset the status.
High CPU after indexing appears complete
Ollama may still be processing embeddings in its queue. Check with docker stats or ps aux | grep ollama. CocoIndex may also perform background cleanup after the main indexing loop finishes.
高质量的代码搜索工具,支持混合语义搜索
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ MIT 协议 — 最宽松的开源协议之一,可自由商用、修改、分发,仅需保留版权声明。
AI Skill Hub 点评:代码搜索工具 的核心功能完整,质量优秀。对于Claude Desktop / Claude Code 用户来说,这是一个值得纳入个人工具库的选择。建议先在非生产环境试用,再逐步推广。
| 原始名称 | coco-search |
| Topics | 代码搜索语义搜索PostgreSQL |
| GitHub | https://github.com/VioletCranberry/coco-search |
| License | MIT |
| 语言 | Python |
收录时间:2026-06-04 · 更新时间:2026-06-04 · License:MIT · AI Skill Hub 不对第三方内容的准确性作法律背书。
选择 Agent 类型,复制安装指令后粘贴到对应客户端