Skip to content

feat(collection): add create-collection tool and dedicated collection package#57

Merged
epugh merged 7 commits intoapache:mainfrom
adityamparikh:create-collections
Mar 9, 2026
Merged

feat(collection): add create-collection tool and dedicated collection package#57
epugh merged 7 commits intoapache:mainfrom
adityamparikh:create-collections

Conversation

@adityamparikh
Copy link
Contributor

Summary

  • Moves CollectionService, CollectionUtils, and Dtos from the metadata package into a new dedicated collection package, separating collection management from schema introspection (SchemaService stays in metadata)
  • Adds a create-collection MCP tool to CollectionService that creates Solr collections/cores with sensible defaults
  • Adds CollectionCreationResult DTO returned by the new tool

New tool: create-collection

{
  "name": "my_collection",
  "configSet": "_default",
  "numShards": 1,
  "replicationFactor": 1
}

All fields except name are optional and default to _default, 1, and 1 respectively. Works with both SolrCloud and standalone Solr via Http2SolrClient.

Test plan

  • All 219 existing tests continue to pass (./gradlew build)
  • New unit tests cover: success with CloudSolrClient, success with plain SolrClient, default parameter application, blank name validation, SolrServerException propagation
  • New integration test (createCollection_createsAndListable) creates a collection against a live Testcontainers Solr instance and verifies it appears in listCollections()
  • Package rename verified: metadata imports replaced with collection in Main, MainTest, McpToolRegistrationTest

Notes

  • SchemaService is intentionally left in metadata — a follow-up PR will rename that package to schema
  • A companion PR applies the same changes on the sb4 branch (Spring Boot 4 / Spring AI 2.0)

🤖 Generated with Claude Code

@adityamparikh adityamparikh marked this pull request as draft March 6, 2026 15:01
adityamparikh and others added 4 commits March 6, 2026 20:26
Move CollectionService, CollectionUtils, and Dtos from the metadata
package into a new dedicated collection package. This separates
collection management from schema introspection (SchemaService stays
in metadata).

Add create-collection MCP tool to CollectionService:
- Accepts name (required), configSet, numShards, replicationFactor
- Defaults: configSet=_default, numShards=1, replicationFactor=1
- Uses CollectionAdminRequest.createCollection() for both SolrCloud
  and standalone Solr via Http2SolrClient
- Returns CollectionCreationResult DTO with name, success, message,
  and createdAt timestamp

Add CollectionCreationResult record to Dtos.java.

Update unit tests with correct 2-arg Mockito stubs to match
CollectionAdminRequest.process() call signature.
Add integration test asserting the new collection appears in
listCollections() after creation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: adityamparikh <aditya.m.parikh@gmail.com>
116 session documents covering all tracks and days (March 4-6 2026)
for use with the create-collection and index-documents MCP tools.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: adityamparikh <aditya.m.parikh@gmail.com>
- Add isBlank() guard in createCollection() to throw
  IllegalArgumentException before calling SolrJ, ensuring consistent
  behavior regardless of SolrJ version
- Update README: add create-collection to feature list, fix all tool
  names to kebab-case, split into Search/Indexing/Collections/Schema
  sections, list all three indexing tools separately

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: adityamparikh <aditya.m.parikh@gmail.com>
Add @PreAuthorize("isAuthenticated()") to the createCollection method
to prevent unauthorized collection creation via the MCP tool, consistent
with the pattern used in SearchService and IndexingService.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: adityamparikh <aditya.m.parikh@gmail.com>
@adityamparikh adityamparikh marked this pull request as ready for review March 8, 2026 20:46
adityamparikh and others added 3 commits March 8, 2026 19:18
Add ConferenceEndToEndIntegrationTest using the DevNexus 2026 sample
data in a 'conferences' collection. Tests the full workflow:
create collection → index 116 JSON documents → search, filter,
facet, and paginate results → verify collection stats.

Signed-off-by: Aditya Parikh <adityamparikh@gmail.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: adityamparikh <aditya.m.parikh@gmail.com>
- S1118: Add private constructor to CollectionUtils utility class
- S1488: Inline shardMatch variable that was immediately returned
- S7467: Replace unused caught exceptions with _ (Java 25)

Signed-off-by: Aditya Parikh <aditya.m.parikh@gmail.com>

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: adityamparikh <aditya.m.parikh@gmail.com>
Merges upstream observability additions (OpenTelemetry, tracing config)
from apache#41 and docs fixes from apache#51 into create-collections branch.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: adityamparikh <aditya.m.parikh@gmail.com>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this to src/test/resources?

}

/**
* Creates a new Solr collection (SolrCloud) or core (standalone Solr).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove standalone, it's our past, not our future, and we don't do much aroudn testing of it.

@epugh epugh merged commit e4f223e into apache:main Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants