这是一个基于 Spring AI 模型上下文协议(MCP)的服务器,提供了与 Apache Solr 交互的工具。借助该服务器,像 Claude 这样的 AI 助手能够通过 MCP 协议对 Apache Solr 进行搜索、索引和管理等操作。
此项目提供了一套工具,可让 AI 助手与强大的开源搜索平台 Apache Solr 进行交互。通过实现 Spring AI MCP 协议,这些工具可供包括 Claude Desktop 在内的任何兼容 MCP 的客户端使用。项目使用 Solr 的官方 Java 客户端 SolrJ 与 Solr 实例进行通信。
服务器具备以下功能:
git clone https://github.com/yourusername/solr-mcp-server.git
cd solr-mcp-server
docker-compose up -d
这将以 SolrCloud 模式启动一个 Solr 实例,并创建两个示例集合:
books
- 包含示例书籍数据的集合。films
- 包含示例电影数据的集合。./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 客户端使用的工具:
使用高级查询选项搜索 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)
将 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
列出所有可用的 Solr 集合。
Tool: listCollections
Description: List solr collections
Parameters: None
获取 Solr 集合的详细统计信息和指标。
Tool: getCollectionStats
Description: Get stats/metrics on a Solr collection
Parameters:
- collection: Name of the collection
检查 Solr 集合的健康状态。
Tool: checkHealth
Description: Check health of a Solr collection
Parameters:
- collection: Name of the collection
检索 Solr 集合的架构。
Tool: getSchema
Description: Get schema for a Solr collection
Parameters:
- collection: Name of the collection
要将此 MCP 服务器添加到 Claude Desktop,请按以下步骤操作:
./gradlew bootJar
或者,你可以将以下配置添加到 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 安装和项目位置。
如果你遇到问题,请按以下步骤操作:
SOLR_URL
环境变量以指向不同的 Solr 实例。本项目采用 Apache 许可证 2.0 进行许可。
欢迎贡献代码!请随时提交拉取请求。