Skip to main content
Glama
Glean Chatbot

Glean Chatbot

Glean Chatbot

将一小批内部合同文档索引到 Glean,通过 Search + Chat 解答这些文档中的问题,并将同一流程以 MCP 工具(ask_glean)的形式提供。

要求

  • Python 3.10+

  • 一个 Glean 实例

  • 一个 Indexing API 令牌

  • 一个包含 Search 和 Chat 作用域的 Client API 令牌

Related MCP server: search-context

安装与设置

  1. 克隆并进入仓库:

git clone <your-repo-url>
cd glean-chatbot
  1. 安装依赖:

pip install -r requirements.txt
  1. 根据示例创建 .env 并填入你的取值:

# macOS / Linux
cp .env.example .env

# Windows (PowerShell)
copy .env.example .env

变量

是否必需

用途

GLEAN_INSTANCE

是

实例名称(https://<instance>-be.glean.com)

GLEAN_INDEXING_TOKEN

是

Indexing API 令牌

GLEAN_CLIENT_TOKEN

是

Client API 令牌(支持 Search + Chat)

GLEAN_ACT_AS

是*

用于 X-Glean-ActAs 的用户邮箱(*使用全局 Client API 令牌时需要)

GLEAN_DATASOURCE

否

数据源名称(默认为 interviewds)

GLEAN_DATASOURCE_DISPLAY

否

在 Glean UI 中显示的名称

GLEAN_URL_REGEX

否

每个文档 viewURL 必须匹配的正则表达式

.env 由 config.py 自动加载(通过 python-dotenv),无需手动 source。

运行

为文档建立索引

python scripts/index_documents.py
# optional: wait until Search can find them
python scripts/index_documents.py --verify

从 CLI 提问

python scripts/ask.py "Who owns the Enronry Tony contract?"
python scripts/ask.py "What must OKLightning Tony deliver before go-live?" --top-k 3

MCP (Cursor)

项目配置文件位于 .cursor/mcp.json(包含 src/mcp_server.py 的绝对路径以及环境变量)。编辑后重启 Cursor / 重新加载 MCP。工具名为 ask_glean。

单独对服务器进行冒烟测试:

python src/mcp_server.py

测试

python tests/test_pipeline.py

不访问网络;模拟 Search/Chat。

工作原理

scripts/index_documents.py 通过 Indexing API 将 data/documents.json 推送为索引。查询时,src/pipeline.py 先调用 Search,然后在存在命中结果时,把命中内容作为闭卷上下文调用 Chat,并返回答案和来源。CLI 和 MCP 都调用同一个 pipeline。结果被限制在我们自己的文档范围内;如果 Search 没有返回任何内容,我们会推荐相近的文档标题,而不是凭空编造答案。

备注 / 限制

  • 共享沙箱会忽略 datasourcesFilter;我们在客户端按文档 id 前缀(CUSTOM_<DATASOURCE>_Contract_)进行过滤。

  • 索引是异步的——文档可能需要几分钟才能被搜索到。

  • 演示文档使用了 allowAnonymousAccess: true。请勿将其带到生产环境。

  • 文档的 viewURL 必须匹配 GLEAN_URL_REGEX,否则索引会将其拒绝。

关于 API 的取舍与生产环境注意事项,请参阅 DESIGN_NOTE.md。

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants and developer tools to securely access and interact with an organization's enterprise knowledge, documents, and people through natural language while respecting existing access permissions.
      166
      MIT
    • A
      license
      A
      quality
      F
      maintenance
      Enables semantic search across documentation stored in Gemini FileSearchStores, returning AI-generated answers with source citations.
      1
      1
      MIT