Problem
The QueryKnowledgeBases tool currently only supports filtering by data_source_ids. The underlying Bedrock Retrieve API supports rich metadata filtering (equals, notEquals, greaterThan, lessThan, in, etc.) via the vectorSearchConfiguration.filter field, but this capability is not exposed through the MCP tool.
Users who have indexed metadata attributes in their knowledge bases cannot leverage them for filtered retrieval.
Proposed solution
Add an optional metadata_filter parameter to QueryKnowledgeBases that accepts a raw Bedrock retrieval filter object and passes it through to the API. This is the most generic approach — it doesn't impose any schema opinions and lets users use any filter expression the Bedrock API supports.
When both data_source_ids and metadata_filter are provided, they are composed with andAll.
Changes
- Add
metadata_filter: dict | None parameter to query_knowledge_base() and the MCP tool
- Refactor filter construction from a single hardcoded filter to a composable list with
andAll
- Update README and tests