fix: Tag filtering in /tools endpoint after schema migration to dict format#2588
Merged
crivetimihai merged 1 commit intomainfrom Jan 31, 2026
Merged
fix: Tag filtering in /tools endpoint after schema migration to dict format#2588crivetimihai merged 1 commit intomainfrom
crivetimihai merged 1 commit intomainfrom
Conversation
Fixes #2329 Updates tag filtering in TagService.get_entities_by_tag() to use the cross-database compatible json_contains_tag_expr helper instead of the raw json_extract LIKE query that only worked with string arrays. Changes: - Replace func.json_extract(tags, "$").LIKE query with json_contains_tag_expr which supports both legacy string tags and new dict-format tags - Update PostgreSQL implementation to use table_valued() pattern for idiomatic SQLAlchemy handling of jsonb_array_elements (elem.c.value) - Update unit tests to mock database dialect for json_contains_tag_expr - Improve test mocking to use patch.object context manager - Fix docstring to reflect new implementation (was "JSON LIKE queries") - Add comprehensive tests for dict-format tags [{id, label}] - Add rigorous PostgreSQL SQL compilation tests with regex validation - Document design decision: DB filters by 'id' only (TagValidator ensures id is always present; label is for display only) The json_contains_tag_expr helper handles both formats: - Legacy: ["tag1", "tag2"] - Dict format: [{"id": "tag1", "label": "Tag 1"}, ...] PostgreSQL implementation uses table_valued() for explicit column reference: - func.jsonb_array_elements(...).table_valued("value").alias("elem") - elem.c.value.op("->>")("id") for proper column access Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
258b0d7 to
04b0c91
Compare
Member
Review Changes AppliedRebased on main and squashed 7 commits into 1 clean commit. Made the following improvements based on code review: PostgreSQL Implementation Fix
Documentation & Tests
Verification
|
crivetimihai
approved these changes
Jan 31, 2026
hughhennelly
pushed a commit
to hughhennelly/mcp-context-forge
that referenced
this pull request
Feb 8, 2026
…2588) Fixes IBM#2329 Updates tag filtering in TagService.get_entities_by_tag() to use the cross-database compatible json_contains_tag_expr helper instead of the raw json_extract LIKE query that only worked with string arrays. Changes: - Replace func.json_extract(tags, "$").LIKE query with json_contains_tag_expr which supports both legacy string tags and new dict-format tags - Update PostgreSQL implementation to use table_valued() pattern for idiomatic SQLAlchemy handling of jsonb_array_elements (elem.c.value) - Update unit tests to mock database dialect for json_contains_tag_expr - Improve test mocking to use patch.object context manager - Fix docstring to reflect new implementation (was "JSON LIKE queries") - Add comprehensive tests for dict-format tags [{id, label}] - Add rigorous PostgreSQL SQL compilation tests with regex validation - Document design decision: DB filters by 'id' only (TagValidator ensures id is always present; label is for display only) The json_contains_tag_expr helper handles both formats: - Legacy: ["tag1", "tag2"] - Dict format: [{"id": "tag1", "label": "Tag 1"}, ...] PostgreSQL implementation uses table_valued() for explicit column reference: - func.jsonb_array_elements(...).table_valued("value").alias("elem") - elem.c.value.op("->>")("id") for proper column access Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com> Signed-off-by: hughhennnelly <hughhennelly06@gmail.com>
kcostell06
pushed a commit
to kcostell06/mcp-context-forge
that referenced
this pull request
Feb 24, 2026
…2588) Fixes IBM#2329 Updates tag filtering in TagService.get_entities_by_tag() to use the cross-database compatible json_contains_tag_expr helper instead of the raw json_extract LIKE query that only worked with string arrays. Changes: - Replace func.json_extract(tags, "$").LIKE query with json_contains_tag_expr which supports both legacy string tags and new dict-format tags - Update PostgreSQL implementation to use table_valued() pattern for idiomatic SQLAlchemy handling of jsonb_array_elements (elem.c.value) - Update unit tests to mock database dialect for json_contains_tag_expr - Improve test mocking to use patch.object context manager - Fix docstring to reflect new implementation (was "JSON LIKE queries") - Add comprehensive tests for dict-format tags [{id, label}] - Add rigorous PostgreSQL SQL compilation tests with regex validation - Document design decision: DB filters by 'id' only (TagValidator ensures id is always present; label is for display only) The json_contains_tag_expr helper handles both formats: - Legacy: ["tag1", "tag2"] - Dict format: [{"id": "tag1", "label": "Tag 1"}, ...] PostgreSQL implementation uses table_valued() for explicit column reference: - func.jsonb_array_elements(...).table_valued("value").alias("elem") - elem.c.value.op("->>")("id") for proper column access Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2329
Fixes tag-based filtering in the /tools endpoint after the migration from List[str] to List[Dict[str, str]].
Introduces a unified tag-filtering helper to correctly handle both legacy string tags and {id, label} tags across SQLite and PostgreSQL.
Resolves failures in both database-backed and in-memory filtering paths.
Adds unit tests to validate tag filtering behavior.
The same tag-filtering functionality is verified for resources, prompts, A2A server, server export, and tag servers.
Example for Verify tag-based filtering --