Skip to content

feat(bedrock-kb-retrieval-mcp-server): expose metadata filtering in QueryKnowledgeBases tool #2859

@dgokcin

Description

@dgokcin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    To triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions