Skip to content

feat: make collection_name parameter optional in MCP tools#89

Open
wggcch wants to merge 1 commit intoqdrant:masterfrom
wggcch:feature/optional-collection-parameter
Open

feat: make collection_name parameter optional in MCP tools#89
wggcch wants to merge 1 commit intoqdrant:masterfrom
wggcch:feature/optional-collection-parameter

Conversation

@wggcch
Copy link
Copy Markdown

@wggcch wggcch commented Sep 8, 2025

Summary

Makes the collection_name parameter optional in both qdrant-store and qdrant-find MCP tools, enabling true multi-collection usage while maintaining full backward compatibility.

Problem

Previously, when COLLECTION_NAME environment variable was configured, the collection_name parameter was completely hidden from the MCP tools via make_partial_function calls. This created a limitation where users with a default collection configured could not access multiple collections with the same embedding configuration.

Related Issues & Context

Previous Implementation (PR #21 - closed): An alternative multi-collection approach was proposed but closed in favor of the current architecture in PR #26. Our implementation builds on the accepted foundation.

Solution

Changes Made

  1. Made collection_name optional in both tool function signatures:

    • Parameter type: str | None with default None
    • Clear parameter descriptions indicating optionality
  2. Implemented intelligent defaulting:

    • When collection_name is None → use configured default collection
    • When collection_name is provided → use the specified collection
    • Logic: effective_collection = collection_name or self.qdrant_settings.collection_name
  3. Removed parameter hiding:

    • Eliminated make_partial_function calls that hid the collection parameter
    • Collection parameter is now always visible and discoverable
  4. Updated documentation:

    • README.md now correctly describes parameters as optional
    • Tool descriptions updated for clarity

Comprehensive Testing

Added 10 thorough test cases covering:

  • ✅ Default collection fallback behavior
  • ✅ Custom collection override functionality
  • ✅ Collection isolation (content separation)
  • ✅ Backward compatibility with existing usage
  • ✅ Edge cases and validation scenarios
  • ✅ Both connector-level and MCP server-level functionality

Backward Compatibility

Fully backward compatible:

  • Existing configurations continue to work unchanged
  • Users calling tools without collection_name get the same behavior
  • Default collection functionality preserved

Benefits

For Users With Default Collection Configured

  • Before: Could only access the default collection
  • After: Can access default collection (when collection_name is None) OR override with any custom collection

For Users Without Default Collection

  • Before: Required explicit collection name (still works)
  • After: Same requirement, no change in behavior

Multi-Collection Scenarios

Now supports the originally requested use case:

# Same embedding config, multiple collections
COLLECTION_NAME="main-docs" uvx mcp-server-qdrant

# Can now access:
# - "main-docs" (when collection_name is None/omitted)  
# - "project-specific" (when collection_name="project-specific")
# - Any other collection (when explicitly specified)

Testing

All 34 tests pass including:

  • 24 existing tests (ensuring no regressions)
  • 10 new tests specifically for optional collection parameter functionality

Implementation Details

Technical Changes

  • Modified store and find functions in mcp_server.py
  • Updated parameter annotations and descriptions
  • Replaced hidden parameter logic with explicit optional handling
  • Added comprehensive logging for debugging

MCP Best Practices

This implementation follows MCP guidelines:

  • ✅ Clear parameter schemas with optional/required distinction
  • ✅ Discoverable tool interfaces
  • ✅ Consistent behavior across transport protocols
  • ✅ Backward compatibility preservation

Impact

This change completes the multi-collection support that was partially implemented in PR #26, making it fully usable for real-world multi-collection scenarios while maintaining the convenience of default collections.

Closes the gap between "multi-collection support exists" and "multi-collection support is actually accessible to users."

Allow collection_name to be optional in both qdrant-store and qdrant-find
tools, enabling multi-collection usage while maintaining backward compatibility.

- Make collection_name optional with None default in tool functions
- Use configured default collection when collection_name is None
- Allow explicit collection override when collection_name is provided
- Remove make_partial_function calls that hid collection parameter
- Add comprehensive tests covering all usage scenarios
- Update README.md to reflect optional parameter behavior

This completes the multi-collection support originally added in qdrant#26 by
making the collection parameter always visible and optional rather than
hidden when a default collection is configured.

Fixes the limitation where users with COLLECTION_NAME set could not
access multiple collections with the same embedding configuration.
mahmoudimus pushed a commit to mahmoudimus/mcp-server-qdrant that referenced this pull request Nov 17, 2025
This commit consolidates changes from PRs qdrant#92, qdrant#75, qdrant#77, qdrant#90, qdrant#20, qdrant#89, qdrant#78, qdrant#76, and qdrant#68:

Infrastructure & Configuration (PR qdrant#75, qdrant#77):
- Upgrade Dockerfile to Python 3.13-slim
- Use UV 0.8.3 from official image
- Add FASTMCP_HOST="0.0.0.0" for container networking
- Add SettingsConfigDict for proper None value parsing

New Embedding Providers (PR qdrant#76, qdrant#92):
- Add Model2Vec support for fast, lightweight embeddings
- Add OpenAI-compatible API support (oai_compat)
- New settings: OAI_COMPAT_ENDPOINT, OAI_COMPAT_API_KEY, OAI_COMPAT_VEC_SIZE

Unnamed Vectors & Multiple Collections (PR qdrant#78):
- Add support for Qdrant unnamed vectors
- Create UnnamedVectorProvider wrapper
- Add USE_UNNAMED_VECTORS and COLLECTION_NAMES settings
- Update qdrant.py to handle both named and unnamed vectors
- Add __main__.py for python -m execution

Hybrid Search (PR qdrant#90):
- Implement hybrid search combining dense and sparse vectors
- Add find_hybrid() method with RRF and DBSF fusion methods
- New tool: qdrant-hybrid-find
- Add SPARSE_EMBEDDING_MODEL setting
- Support configurable limits for dense, sparse, and final results

Optional Collection Names (PR qdrant#89):
- Make collection_name parameter optional in store() and find()
- Use default collection when not specified
- Simplify tool usage with fallback to COLLECTION_NAME env var

Additional Tools (PR qdrant#68):
- Add qdrant-get-point: Retrieve point by ID
- Add qdrant-delete-point: Delete point by ID
- Add qdrant-update-point-payload: Update point metadata
- Add qdrant-get-collections: List all collections
- Add qdrant-get-collection-details: Get collection info
- Implement corresponding methods in QdrantConnector

Documentation:
- Update README with all new features
- Document new embedding providers
- Add examples for unnamed vectors and multiple collections
- Update environment variables table
- Document hybrid search functionality
- Expand tools documentation

Dependencies:
- Add model2vec==0.6.0
- Add openai>=1.109.1
mahmoudimus added a commit to mahmoudimus/mcp-server-qdrant that referenced this pull request Nov 17, 2025
This commit consolidates changes from PRs qdrant#92, qdrant#75, qdrant#77, qdrant#90, qdrant#20, qdrant#89, qdrant#78, qdrant#76, and qdrant#68:

Infrastructure & Configuration (PR qdrant#75, qdrant#77):
- Upgrade Dockerfile to Python 3.13-slim
- Use UV 0.8.3 from official image
- Add FASTMCP_HOST="0.0.0.0" for container networking
- Add SettingsConfigDict for proper None value parsing

New Embedding Providers (PR qdrant#76, qdrant#92):
- Add Model2Vec support for fast, lightweight embeddings
- Add OpenAI-compatible API support (oai_compat)
- New settings: OAI_COMPAT_ENDPOINT, OAI_COMPAT_API_KEY, OAI_COMPAT_VEC_SIZE

Unnamed Vectors & Multiple Collections (PR qdrant#78):
- Add support for Qdrant unnamed vectors
- Create UnnamedVectorProvider wrapper
- Add USE_UNNAMED_VECTORS and COLLECTION_NAMES settings
- Update qdrant.py to handle both named and unnamed vectors
- Add __main__.py for python -m execution

Hybrid Search (PR qdrant#90):
- Implement hybrid search combining dense and sparse vectors
- Add find_hybrid() method with RRF and DBSF fusion methods
- New tool: qdrant-hybrid-find
- Add SPARSE_EMBEDDING_MODEL setting
- Support configurable limits for dense, sparse, and final results

Optional Collection Names (PR qdrant#89):
- Make collection_name parameter optional in store() and find()
- Use default collection when not specified
- Simplify tool usage with fallback to COLLECTION_NAME env var

Additional Tools (PR qdrant#68):
- Add qdrant-get-point: Retrieve point by ID
- Add qdrant-delete-point: Delete point by ID
- Add qdrant-update-point-payload: Update point metadata
- Add qdrant-get-collections: List all collections
- Add qdrant-get-collection-details: Get collection info
- Implement corresponding methods in QdrantConnector

Documentation:
- Update README with all new features
- Document new embedding providers
- Add examples for unnamed vectors and multiple collections
- Update environment variables table
- Document hybrid search functionality
- Expand tools documentation

Dependencies:
- Add model2vec==0.6.0
- Add openai>=1.109.1

Co-authored-by: Claude <noreply@anthropic.com>
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.

1 participant