🚀 Solr MCP 服务器
这是一个基于 Spring AI 模型上下文协议(MCP)的服务器,能提供与 Apache Solr 交互的工具。借助该服务器,像 Claude 这样的 AI 助手可通过 MCP 协议对 Apache Solr 进行搜索、索引和管理操作。
🚀 快速开始
Solr MCP 服务器是一个允许 AI 助手与 Apache Solr 交互的工具。以下是使用该服务器的快速入门步骤:
前提条件
- Java 21 或更高版本
- Docker 和 Docker Compose(用于运行 Solr)
- Gradle(用于构建项目)
安装和设置
1. 克隆仓库
git clone https://github.com/yourusername/solr-mcp-server.git
cd solr-mcp-server
2. 使用 Docker Compose 启动 Solr
docker-compose up -d
这将以 SolrCloud 模式启动一个 Solr 实例,并创建两个示例集合:
books
- 包含示例书籍数据的集合
films
- 包含示例电影数据的集合
3. 构建并运行 MCP 服务器
./gradlew bootRun
✨ 主要特性
- 高级搜索:可使用高级查询选项搜索 Solr 集合。
- 文档索引:能将 JSON 文档索引到 Solr 集合中。
- 集合管理:可管理和监控 Solr 集合。
- 模式检索:能检索和分析 Solr 模式信息。
📦 安装指南
前提条件
- Java 21 或更高版本
- Docker 和 Docker Compose(用于运行 Solr)
- Gradle(用于构建项目)
安装步骤
1. 克隆仓库
git clone https://github.com/yourusername/solr-mcp-server.git
cd solr-mcp-server
2. 使用 Docker Compose 启动 Solr
docker-compose up -d
这将以 SolrCloud 模式启动一个 Solr 实例,并创建两个示例集合:
books
- 包含示例书籍数据的集合
films
- 包含示例电影数据的集合
3. 构建并运行 MCP 服务器
./gradlew bootRun
💻 使用示例
基础用法
搜索书籍
I need to search for fantasy books in the Solr collection. Can you help me?
Claude 可以使用搜索工具查询书籍集合:
I'll search for fantasy books in the Solr collection.
Using the Search tool with:
- collection: books
- query: genre_s:fantasy
- rows: 5
Here are the fantasy books I found:
1. "A Game of Thrones" by George R.R. Martin
2. "A Clash of Kings" by George R.R. Martin
...
索引新文档
I have some new book data I'd like to add to Solr. Can you help me index it?
Claude 可以使用 index_documents
工具:
I'll help you index that book data into Solr.
Using the index_documents tool with:
- collection: books
- json: [{"id":"123456789","name":["The New Book"],"author":["Jane Author"],"genre_s":"mystery","price":[12.99]}]
The document has been successfully indexed into the books collection.
列出集合
What Solr collections are available in the system?
Claude 可以使用 listCollections
工具:
I'll check what Solr collections are available.
Using the listCollections tool.
The following collections are available:
1. books
2. films
获取集合统计信息
Can you tell me more about the 'books' collection? I'd like to know its size and other metrics.
Claude 可以使用 getCollectionStats
工具:
I'll get statistics for the 'books' collection.
Using the getCollectionStats tool with:
- collection: books
Here are the statistics for the 'books' collection:
- Number of documents: 1,245
- Segment count: 5
- Query performance:
- Average query time: 12ms
- Cache hit ratio: 0.85
- Handler statistics:
- Select handler requests: 1,532
- Update handler requests: 245
检查集合健康状态
Is the 'films' collection healthy and responding properly?
Claude 可以使用 checkHealth
工具:
I'll check the health of the 'films' collection.
Using the checkHealth tool with:
- collection: films
Health status:
- Healthy: Yes
- Response time: 8ms
- Total documents: 532
- Last checked: 2023-06-15 14:32:45
检索模式信息
What fields are defined in the 'books' collection schema?
Claude 可以使用 getSchema
工具:
I'll retrieve the schema for the 'books' collection.
Using the getSchema tool with:
- collection: books
The 'books' collection has the following fields:
- id (string): Unique identifier
- name (text_general): Book title
- author (text_general): Book author
- genre_s (string): Genre
- price (float): Book price
- in_stock_b (boolean): Whether the book is in stock
- publish_date (date): Publication date
📚 详细文档
可用工具
服务器提供了以下可供 MCP 客户端使用的工具:
1. 搜索
使用高级查询选项搜索 Solr 集合。
Tool: Search
Description: Search specified Solr collection with query, optional filters, facets, sorting, and pagination.
Parameters:
- collection: Solr collection to query
- query: Solr q parameter (defaults to "*:*" if not specified)
- filterQueries: Solr fq parameter (optional)
- facetFields: Solr facet fields (optional)
- sortClauses: Solr sort parameter (optional)
- start: Starting offset for pagination (optional)
- rows: Number of rows to return (optional)
2. 索引文档
将 JSON 文档索引到 Solr 集合中。
Tool: index_documents
Description: Index documents from JSON string into Solr collection
Parameters:
- collection: Solr collection to index into
- json: JSON string containing documents to index
3. 列出集合
列出所有可用的 Solr 集合。
Tool: listCollections
Description: List solr collections
Parameters: None
4. 获取集合统计信息
获取 Solr 集合的详细统计信息和指标。
Tool: getCollectionStats
Description: Get stats/metrics on a Solr collection
Parameters:
- collection: Name of the collection
5. 检查集合健康状态
检查 Solr 集合的健康状态。
Tool: checkHealth
Description: Check health of a Solr collection
Parameters:
- collection: Name of the collection
6. 获取模式
检索 Solr 集合的模式。
Tool: getSchema
Description: Get schema for a Solr collection
Parameters:
- collection: Name of the collection
添加到 Claude Desktop
要将此 MCP 服务器添加到 Claude Desktop,请按照以下步骤操作:
- 将项目构建为独立的 JAR 文件:
./gradlew bootJar
-
在 Claude Desktop 中,转到“设置”>“工具”>“添加工具”。
-
选择“MCP 服务器”作为工具类型。
-
配置工具:
- 名称:Solr MCP 服务器
- 描述:与 Apache Solr 交互的工具
- 命令:java -jar /path/to/solr-mcp-server-0.0.1-SNAPSHOT.jar
- 工作目录:/path/to/solr-mcp-server
-
点击“添加工具”
或者,你可以将以下配置添加到 MCP 客户端配置文件中:
"solr-search-mcp": {
"command": "~/.sdkman/candidates/java/current/bin/java",
"args": [
"-jar",
"~/solr-mcp-server/build/libs/solr-mcp-server-0.0.1-SNAPSHOT.jar"
],
"env": {
"SOLR_URL": "http://localhost:8983/solr/"
}
}
注意:请调整路径以匹配你的 Java 安装位置和项目位置。
🔧 技术细节
该项目实现了 Spring AI MCP 协议,使用 SolrJ(Solr 的官方 Java 客户端)与 Solr 实例进行通信。服务器提供了一系列工具,允许 MCP 客户端与 Solr 进行交互,包括搜索、索引、管理和监控 Solr 集合,以及检索和分析 Solr 模式信息。
📄 许可证
本项目采用 Apache 许可证 2.0 进行许可。
💡 使用建议
- 若遇到问题,要确保 Solr 正在运行且可访问。默认情况下,服务器连接到
http://localhost:8983/solr/
,你也可以设置 SOLR_URL
环境变量指向其他 Solr 实例。
- 查看日志,以获取可能存在的错误信息。
- 利用 Solr 管理界面验证集合是否存在。
🤝 贡献
欢迎贡献代码!请随时提交拉取请求。