Fix MCP servers/gateway tags not persisting in DB#2250
Conversation
Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
a247f59 to
d3279e1
Compare
Additional Fixes AppliedThe original PR correctly identified that 1. Tag Filtering (High Priority)Problem: Fix: Added new
Updated all 6 services (gateway, tool, server, prompt, resource, a2a) to use this function. 2. Catalog Service Re-validation Loop (Medium Priority)Problem: Fix: Added format detection before calling 3. Legacy Tag Handling in
|
Address issues with dict-format tag storage introduced by migration: - Add json_contains_tag_expr() to handle both List[str] and List[Dict] tag formats in database queries (SQLite, PostgreSQL, MySQL) - Update all services (gateway, tool, server, prompt, resource, a2a) to use json_contains_tag_expr for tag filtering - Fix catalog_service.py to pass through dict-format tags without re-validation - Restore legacy tag handling in _prepare_gateway_for_read for backward compatibility - Update tests to mock json_contains_tag_expr instead of json_contains_expr Closes #2203 Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
d3279e1 to
e7f2ef0
Compare
* fix tags in mcp servers Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com> * fix(tags): handle dict-format tags in filtering and read paths Address issues with dict-format tag storage introduced by migration: - Add json_contains_tag_expr() to handle both List[str] and List[Dict] tag formats in database queries (SQLite, PostgreSQL, MySQL) - Update all services (gateway, tool, server, prompt, resource, a2a) to use json_contains_tag_expr for tag filtering - Fix catalog_service.py to pass through dict-format tags without re-validation - Restore legacy tag handling in _prepare_gateway_for_read for backward compatibility - Update tests to mock json_contains_tag_expr instead of json_contains_expr Closes IBM#2203 Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
🐛 Bug-fix PR
📌 Summary
Closes #2203
Fixed tags not being properly stored in the database for MCP servers/gateways. Tags were being validated and converted to list of dictionaries [{"id": "tag", "label": "Tag"}] by the Pydantic schema, but the database model type annotation incorrectly specified List[str], causing tags to be stored as empty lists [] instead of the expected format.
🔁 Reproduction Steps
🐞 Root Cause
mcpgateway/db.pyhad an incorrect type annotation:The
validate_tags_field()function is used as a Pydantic field validator in bothGatewayCreateandGatewayUpdateschemas. This function:The Problem:
💡 Fix Description
mcpgateway/db.pyUpdated the Gateway model's tags type annotation to match what validate_tags_field() actually returns:
This aligns the database model with:
1. The output of validate_tags_field()
2. The format used by virtual servers and tools (which were working correctly)
3. The UI's expectation of [{"id": "tag", "label": "Tag"}] format
mcpgateway/services/gateway_service.pyOnly call the tag conversion in convert_gateway_to_read() method in the tags are List[str], otherwise the fucntion call is not needed. Previously, this method was calling validate_tags_field() again on already-validated tags from the database, which was redundant. Now it passes tags through directly with backward compatibility:
🧪 Verification
make lintmake testmake coverage📐 MCP Compliance (if relevant)
✅ Checklist
make black isort pre-commit)