Solr Mcp Server

Solr Mcp Server

🚀 Solr MCP 服务器

这是一个基于 Spring AI 模型上下文协议(MCP)的服务器,提供了与 Apache Solr 交互的工具。借助该服务器,像 Claude 这样的 AI 助手能够通过 MCP 协议对 Apache Solr 进行搜索、索引和管理等操作。

🚀 快速开始

此项目提供了一套工具,可让 AI 助手与强大的开源搜索平台 Apache Solr 进行交互。通过实现 Spring AI MCP 协议,这些工具可供包括 Claude Desktop 在内的任何兼容 MCP 的客户端使用。项目使用 Solr 的官方 Java 客户端 SolrJ 与 Solr 实例进行通信。

✨ 主要特性

服务器具备以下功能:

  • 运用高级查询选项搜索 Solr 集合。
  • 将文档索引到 Solr 集合中。
  • 管理和监控 Solr 集合。
  • 获取并分析 Solr 架构信息。

📦 安装指南

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,请按以下步骤操作:

  1. 将项目构建为独立的 JAR 文件:
./gradlew bootJar
  1. 在 Claude Desktop 中,转到“设置”>“工具”>“添加工具”。
  2. 选择“MCP 服务器”作为工具类型。
  3. 配置工具:
    • 名称:Solr MCP 服务器
    • 描述:与 Apache Solr 交互的工具
    • 命令:java -jar /path/to/solr-mcp-server-0.0.1-SNAPSHOT.jar
    • 工作目录:/path/to/solr-mcp-server
  4. 点击“添加工具”

或者,你可以将以下配置添加到 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 安装和项目位置。

🔧 技术细节

先决条件

  • Java 21 或更高版本
  • Docker 和 Docker Compose(用于运行 Solr)
  • Gradle(用于构建项目)

故障排除

如果你遇到问题,请按以下步骤操作:

  1. 确保 Solr 正在运行且可访问。默认情况下,服务器连接到 http://localhost:8983/solr/,但你可以设置 SOLR_URL 环境变量以指向不同的 Solr 实例。
  2. 检查日志中是否有错误消息。
  3. 使用 Solr 管理界面验证集合是否存在。

📄 许可证

本项目采用 Apache 许可证 2.0 进行许可。

贡献说明

欢迎贡献代码!请随时提交拉取请求。

  • 0 关注
  • 0 收藏,8 浏览
  • system 提出于 2025-09-22 16:03

相似服务问题