GLSI——Go本地搜索索引器
一个Go工具,在网络上搜索给定的查询,同时抓取前N个结果页面,并在SQLite中本地缓存合并文本24小时。
三重接口: 用于手动使用的CLI,用于编程访问的HTTP API,以及用于AI辅助集成的MCP服务器(stdio)。
快速开始
# Build
go build -o glsi ./cmd/glsi/
# Search the web
./glsi search -q "golang concurrency" -n 3
# Force a fresh scrape (bypass cache)
./glsi search -q "golang concurrency" -f
# Start the HTTP API server
./glsi serve -p 3000
# Start the MCP server (stdio transport)
./glsi mcp安装
go install github.com/user/glsi/cmd/glsi@latest或者克隆并构建:
git clone https://github.com/user/glsi.git
cd glsi
go build -o glsi ./cmd/glsi/CLI使用情况
glsi [flags]
Commands:
search Search the web, scrape pages, and return consolidated text
serve Start the HTTP API server
mcp Start the MCP stdio serversearch
| 标志 | 描述 | 默认值 |
|---|---|---|
-q | 搜索查询(必填) | -- |
-n | 要抓取的结果数量 | 5 |
-f | 绕过缓存,强制刷新抓取 | false |
serve
| 标志 | 描述 | 默认值 |
|---|---|---|
-p | HTTP服务器端口 | 8080 |
mcp
没有其他标志。启动MCP stdio服务器以集成AI助手。
HTTP API
使用启动服务器 glsi serve,然后使用以下端点:
| 方法 | 路径 | 描述 |
|---|---|---|
GET | /search | 搜索+抓取+缓存。查询参数: q (必填), count (可选,默认值5), force (可选,默认为false)。 |
DELETE | /cache | 清除缓存。查询参数: q (可选——如果省略,则全部刷新)。 |
GET | /health | 健康检查-退货 {"status": "ok"}. |
例子
# Search
curl "http://localhost:8080/search?q=golang+concurrency&count=3"
# Force fresh scrape
curl "http://localhost:8080/search?q=golang+concurrency&force=true"
# Clear specific cache entry
curl -X DELETE "http://localhost:8080/cache?q=golang+concurrency"
# Flush all cache
curl -X DELETE "http://localhost:8080/cache"
# Health check
curl "http://localhost:8080/health"MCP服务器
GLSI通过stdio传输公开了两个MCP工具:
web_search
| 参数 | 类型 | 必填 | 默认 | 说明 |
|---|---|---|---|---|
query | string | ✅ | — | 搜索查询 |
count | 整数 | -- | 5 | 要抓取的结果数量 |
force | boolean | -- | false | 绕过缓存 |
clear_cache
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
query | string | -- | 要删除的特定查询。如果省略,则全部刷新。 |
MCP配置
添加到您的MCP客户端配置中(例如,Claude Desktop、Cursor):
{
"mcpServers": {
"glsi": {
"command": "glsi",
"args": ["mcp"]
}
}
}环境变量
| 变量 | 必填 | 描述 |
|---|---|---|
GLSI_SEARCH_ENGINE | 否 | 要抓取的搜索引擎: google (默认)或 duckduckgo |
GLSI_RATE_LIMIT | 否 | 传出HTTP请求之间的延迟,例如。 500ms, 1s (默认值: 1s) |
GLSI_DB_PATH | 否 | 覆盖默认缓存数据库路径(~/.glsi/cache.db) |
GLSI_PORT | 否 | HTTP API服务器的默认端口(默认值: 8080) |
建筑
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ CLI │ │ HTTP API │ │ MCP Server │
│ (search) │ │ (REST) │ │ (stdio) │
└──────┬──────┘ └──────┬──────┘ └──────┬──────┘
│ │ │
└────────────────┼────────────────┘
│
┌──────▼──────┐
│ Engine │ ← orchestrates everything
│ Run(q,n,f) │
└──┬───────┬──┘
│ │
┌──────▼──┐ ┌─▼──────────┐
│ Cache │ │ Search │
│ (SQLite)│ │ (goquery) │
└─────────┘ └──────┬─────┘
│
┌──────▼──────┐
│ Scraper │
│ (concurrent)│
└─────────────┘依赖项
所有依赖都是纯Go-- 无需CGO.
| 包装 | 用途 |
|---|---|
modernc.org/sqlite | 纯Go SQLite驱动程序 |
github.com/PuerkitoBio/goquery | HTML解析和CSS选择器 |
github.com/go-shiori/go-readability | HTML→ 可读文本提取 |
github.com/modelcontextprotocol/go-sdk | 官方MCP SDK(stdio服务器) |
测试
go test ./... -v许可证
麻省理工学院
