Token导航 LogoToken导航TokenDH.com
Search Context logo
搜索检索stdio官方级别未说明来源级核验

Search Context

MCP Server

github

一个通用的MCP服务器,通过Gemini文件搜索提供文档的语义搜索功能,适用于需要快速获取AI生成答案和来源引用的场景。

工具数

1

提示词数

0

GitHub Stars

1

资源数

0
搜索文档检索JavaScriptClaudeClaude DesktopClaude

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

ain3sh

提供方

ain3sh

最后核验

2026/5/17 20:22

运行时

Node.js

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

npx -y github:ain3sh/search-context

详细介绍

搜索上下文MCP服务器

一个通用的MCP服务器,使用Gemini文件搜索对文档进行语义搜索。

它做什么:查询云中的Gemini FileSearchStores,并返回AI生成的答案和源引用。

它不做什么:索引文件、管理git仓库或运行工作流。索引是单独进行的(例如,通过文档仓库中的GitHub Actions或任何自定义管道)。

特性

  • 🔍 使用Gemini File search API进行语义搜索
  • 🤝 通过Gemini API动态发现存储(无需本地配置)
  • 🧠 带有源引用的自然语言查询
  • ⚡ 令牌高效响应(默认情况下约500-1000个令牌)
  • 📊 双格式:Markdown(人类可读)和JSON(程序化)
  • 🌐 通用:适用于您创建的任何Gemini FileSearchStores

______________________________________________________________________

建筑

Your indexing pipeline → Gemini FileSearchStores (cloud)
                              ↓
                         search-context MCP server (local)
                              ↓
                            Claude

要点:

  • MCP服务器 仅查询 基于云的FileSearchStores
  • 是否 与git repos或本地文件交互
  • 商店由以下人员创建和更新 你的 索引工作流程
  • 服务器通过以下方式动态发现存储 client.file_search_stores.list()

______________________________________________________________________

快速开始

推荐: npx

npx -y github:ain3sh/search-context

不需要克隆。始终使用GitHub上的最新版本。

来源

git clone https://github.com/ain3sh/search-context.git
cd search-context
npm install
npm run build
npm start

______________________________________________________________________

配置

环境变量

  • GEMINI_API_KEY (必填):您的Gemini API密钥
  • LOG_LEVEL *(可选)*: debug, info,或 error (默认值: info)

获取API密钥: https://aistudio.google.com/apikey

克劳德桌面

增添 ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "search-context": {
      "command": "npx",
      "args": ["-y", "github:ain3sh/search-context"],
      "env": {
        "GEMINI_API_KEY": "your_api_key_here"
      }
    }
  }
}

克劳德代码(项目级)

创建 .mcp.json 在项目根目录中:

{
  "mcpServers": {
    "search-context": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "github:ain3sh/search-context"],
      "env": {
        "GEMINI_API_KEY": "${GEMINI_API_KEY}"
      }
    }
  }
}

然后设置:

export GEMINI_API_KEY=your_api_key_here

______________________________________________________________________

用法

发现商店

商店作为MCP资源公开。客户可以通过以下方式发现它们 resources/list.

服务器在启动时查询Gemini的API以查找所有可用的FileSearchStores,并将其公开为URI:

store://context
store://Factory-AI/factory
store://other-docs

备注:店铺名称来自 displayName 您在创建FileSearchStore时设置的字段。

搜索文档

使用 search_context 带有自然语言查询的工具:

// Minimal query (common case)
search_context({
  store: "context",
  query: "How does File Search chunking work?"
})
// → ~500–1000 tokens, answer + citations

// With evidence chunks (for verification)
search_context({
  store: "context",
  query: "authentication flow setup",
  include_chunks: true
})
// → ~2000–3000 tokens, answer + citations + chunk previews

参数

  • store (字符串,必填):MCP资源中的存储名称

例如 "context", "Factory-AI/factory"

  • query (字符串,必填):自然语言查询
  • include_chunks *(布尔值,可选)*:包括块预览(默认值: false)
  • top_k *(数字,可选)*:检索块时 include_chunks=true

违约: 3,最大值: 20

  • response_format *(字符串,可选)*: "markdown""json" (默认值: "markdown")
  • metadata_filter *(字符串,可选)*:使用高级过滤器 列表筛选器语法

响应格式

默认值(response_format="markdown", include_chunks=false):

# Search Results: context

**Query**: How does chunking work?

**Response**:
[Synthesized answer from semantic search]

---

**Sources** (2 files):
  - ai.google.dev_gemini-api_docs_file-search.md
  - CONTEXT_SEARCH_MCP_SPEC.md

有大块(include_chunks=true):

[... same as above, plus ...]

---

## Retrieved Context Chunks

### [1] ai.google.dev_gemini-api_docs_file-search.md

Files are automatically chunked when imported into a file search store...
[truncated to 500 chars per chunk]

---

JSON响应包括结构化 query, response, sources,可选 chunks[].

______________________________________________________________________

性能和成本

代币效率

优化响应以避免上下文垃圾邮件:

模式代币(约)内容
默认值(include_chunks=false)~500–1000综合答案+源引用
有大块(include_chunks=true)~2000–3000答案+来源+500个字符块预览

保障措施:

  • 块预览截断为500个字符
  • 完整回复,最多25000个字符
  • 将元数据缓存5分钟

成本模型(Gemini文件搜索)

对于MCP服务器 (查询):

  • 查询:免费;检索到的区块作为正常上下文令牌向您的Gemini API使用收费

用于索引 (由您的管道单独完成):

  • 索引:每1M代币约0.15美元(每个文件一次;仅在文件更改时重新运行)
  • 存储:免费

月度估算示例 (如果使用每日索引工作流):

  • 100个文件(约150k个令牌):每次同步约0.0225美元
  • 每日同步,小变化: 约0.25美元至1美元/月
  • 重度流失/积极开发: 约3至6美元/月

______________________________________________________________________

设置索引(与MCP服务器分开)

MCP服务器 仅查询 现有的Gemini文件搜索商店。您需要一个单独的过程来创建和更新这些存储。

选项1:GitHub操作工作流

如果你有一个文档存储库,你可以使用GitHub Actions自动索引。

示例:参见 ain3sh/docs 为了完整实施:

  • mirrors.json:要索引的存储库/目录的配置
  • .github/scripts/sync.py:创建/更新FileSearchStores的脚本
  • .github/workflows/sync.yml:每天运行并随变化而变化的工作流

关键步骤:

  1. GEMINI_API_KEY 作为存储库秘密
  2. 创建一个工作流,该工作流:

- 克隆/获取文档文件 - 使用Gemini文件搜索API创建/更新存储 - 设置a displayName 对于每个商店(这将成为MCP中的商店名称)

  1. 运行每日或文件更改

选项2:自定义管道

您可以从任何环境中进行索引:

from google import genai

client = genai.Client(api_key=os.getenv("GEMINI_API_KEY"))

# Create a store
store = client.file_search_stores.create(
    display_name="my-docs"  # This becomes store://my-docs in MCP
)

# Upload files
for file_path in doc_files:
    client.file_search_stores.upload_file(
        store_id=store.id,
        path=file_path
    )

店铺命名

displayName 创建FileSearchStore时设置为其MCP资源URI:

# In your indexing script:
store = client.file_search_stores.create(display_name="context")

# In MCP:
search_context({ store: "context", query: "..." })

______________________________________________________________________

发展

本地开发

# Install dependencies
npm install

# Build
npm run build

# Development mode (auto-reload)
npm run dev

# Run with API key
GEMINI_API_KEY=your_key npm start

项目结构

search-context/
├── src/
│   └── index.ts            # Main MCP server implementation
├── dist/
│   └── index.js            # Compiled output (committed for npx)
├── package.json            # Includes bin field for CLI
├── tsconfig.json
└── README.md

快速本地测试

npm run build
timeout 5s GEMINI_API_KEY=your_key npx .

MCP服务器寿命长;真正的测试最好通过MCP客户端(Claude Desktop、Claude Code等)进行。

______________________________________________________________________

故障排除

未找到商店

错误: Error: Store 'xyz' not found

检查:

  • 商店位于Gemini(访问 谷歌人工智能工作室)
  • 商店已上传文件
  • 商店 displayName 匹配您正在查询的内容
  • 重新启动MCP服务器(启动时缓存存储列表)

API关键问题

症状: UNAUTHENTICATED, Invalid API key

检查:

  • GEMINI_API_KEY 在environment/config中设置
  • 主要工作地点 https://aistudio.google.com/apikey
  • 已启用文件搜索API访问
  • 未超过配额(免费等级~1500 RPD)

无结果

症状: "No results found"

尝试:

  • 更广泛或更精确的查询措辞
  • 确认文件存在于商店中(检查Google AI Studio)
  • 确认索引已成功完成
  • 使用更接近文档措辞的术语
  • 确保文件使用支持的格式(Markdown、文本、PDF等)

速率限制

错误: 429, RESOURCE_EXHAUSTED

  • 自由层:~15转/分
  • 等待60秒后重试
  • 降低查询率
  • 如果需要,升级到付费级别

客户端中未加载服务器

症状:MCP客户端未显示 search-context

检查:

  • npm run build 无错误地完成
  • MCP配置JSON有效
  • 客户端日志(例如。 ~/Library/Logs/Claude/mcp*.log)
  • npx 可以访问GitHub
  • 手动运行工作:
  GEMINI_API_KEY=key npx -y github:ain3sh/search-context

______________________________________________________________________

许可证

MIT许可证——见 LICENSE.

目录标签

目录标签

搜索文档检索JavaScriptClaude语义搜索本地部署AI问答GeminiAPIMCP服务器

支持客户端

Claude DesktopClaude

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

api-key

运行时(runtime,运行环境)

Node.js

来源包(packageName,安装包名)

github

工具数量(toolCount,工具数)

1

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdioapi-key部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP