Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ public List<String> listCollections() {
public SolrMetrics getCollectionStats(
@McpToolParam(description = "Solr collection to get stats/metrics for") String collection)
throws SolrServerException, IOException {
if (collection == null || collection.isBlank()) {
throw new IllegalArgumentException(BLANK_COLLECTION_NAME_ERROR);
}

// Extract actual collection name from shard name if needed
String actualCollection = extractCollectionName(collection);

Expand Down Expand Up @@ -957,6 +961,10 @@ private boolean validateCollectionExists(String collection) {
*/
@McpTool(name = "check-health", description = "Check health of a Solr collection")
public SolrHealthStatus checkHealth(@McpToolParam(description = "Solr collection") String collection) {
if (collection == null || collection.isBlank()) {
throw new IllegalArgumentException(BLANK_COLLECTION_NAME_ERROR);
}

String actualCollection = extractCollectionName(collection);
try {
// Ping Solr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ public IndexingService(SolrClient solrClient, IndexingDocumentCreator indexingDo
public void indexJsonDocuments(@McpToolParam(description = "Solr collection to index into") String collection,
@McpToolParam(description = "JSON string containing documents to index") String json)
throws IOException, SolrServerException {
if (collection == null || collection.isBlank()) {
throw new IllegalArgumentException("Collection name must not be blank");
}

List<SolrInputDocument> schemalessDoc = indexingDocumentCreator.createSchemalessDocumentsFromJson(json);
indexDocuments(collection, schemalessDoc);
}
Expand Down Expand Up @@ -262,6 +266,10 @@ public void indexJsonDocuments(@McpToolParam(description = "Solr collection to i
public void indexCsvDocuments(@McpToolParam(description = "Solr collection to index into") String collection,
@McpToolParam(description = "CSV string containing documents to index") String csv)
throws IOException, SolrServerException {
if (collection == null || collection.isBlank()) {
throw new IllegalArgumentException("Collection name must not be blank");
}

List<SolrInputDocument> schemalessDoc = indexingDocumentCreator.createSchemalessDocumentsFromCsv(csv);
indexDocuments(collection, schemalessDoc);
}
Expand Down Expand Up @@ -352,6 +360,10 @@ public void indexCsvDocuments(@McpToolParam(description = "Solr collection to in
public void indexXmlDocuments(@McpToolParam(description = "Solr collection to index into") String collection,
@McpToolParam(description = "XML string containing documents to index") String xml)
throws ParserConfigurationException, SAXException, IOException, SolrServerException {
if (collection == null || collection.isBlank()) {
throw new IllegalArgumentException("Collection name must not be blank");
}

List<SolrInputDocument> schemalessDoc = indexingDocumentCreator.createSchemalessDocumentsFromXml(xml);
indexDocuments(collection, schemalessDoc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ public SchemaService(SolrClient solrClient, ObjectMapper objectMapper) {
*/
@McpResource(uri = "solr://{collection}/schema", name = "solr-collection-schema", description = "Schema definition for a Solr collection including fields, field types, and copy fields", mimeType = "application/json")
public String getSchemaResource(String collection) {
if (collection == null || collection.isBlank()) {
throw new IllegalArgumentException("Collection name must not be blank");
}

try {
return toJson(objectMapper, getSchema(collection));
} catch (Exception e) {
Expand Down Expand Up @@ -251,6 +255,10 @@ public String getSchemaResource(String collection) {
*/
@McpTool(name = "get-schema", description = "Get schema for a Solr collection")
public SchemaRepresentation getSchema(String collection) throws Exception {
if (collection == null || collection.isBlank()) {
throw new IllegalArgumentException("Collection name must not be blank");
}

SchemaRequest schemaRequest = new SchemaRequest();
return schemaRequest.process(solrClient, collection).getSchemaRepresentation();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ public SearchResponse search(@McpToolParam(description = "Solr collection to que
@McpToolParam(description = "Number of rows to return", required = false) Integer rows)
throws SolrServerException, IOException {

if (collection == null || collection.isBlank()) {
throw new IllegalArgumentException("Collection name must not be blank");
}

// query
final SolrQuery solrQuery = new SolrQuery("*:*");
if (StringUtils.hasText(query)) {
Expand Down