Skip to content

[BUG][TAGS]: get_entities_by_tag fails on PostgreSQL - uses SQLite json_extract function #2607

@crivetimihai

Description

@crivetimihai

Bug Summary

The /tags/{tag_name}/entities endpoint fails with 500 error on PostgreSQL due to using SQLite-specific json_extract() function instead of the cross-database json_extract_text() helper.

Affected Component

  • mcpgateway/services/tag_service.py - get_entities_by_tag() method (line 401)

Root Cause

Line 401 uses:

stmt = select(model).where(func.json_extract(model.tags, "$").op("LIKE")(f'%"{tag_name}"%'))

This should use the json_extract_text() helper from db.py which handles PostgreSQL vs SQLite:

  • PostgreSQL: Uses ->> operator
  • SQLite: Uses json_extract() function

Error Message

psycopg.errors.UndefinedFunction: function json_extract(json, character varying) does not exist

Steps to Reproduce

curl -X GET "http://localhost:8080/tags/test/entities" \
  -H "Authorization: Bearer $TOKEN"

Expected Behavior

Returns list of entities tagged with the specified tag name.

Actual Behavior

Returns 500 Internal Server Error on PostgreSQL deployments.

Fix

Replace line 401 in tag_service.py with cross-database compatible query using json_extract_text() from db.py, or use PostgreSQL-compatible JSON operators.

Discovered During

Locust load testing with TagsExtendedUser class.

Metadata

Metadata

Assignees

Labels

SHOULDP2: Important but not vital; high-value items that are not crucial for the immediate releasebugSomething isn't workinggood first issueGood for newcomerspythonPython / backend development (FastAPI)

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions