Skip to content

fix(prompts): fetch gateway-backed prompt content in server listing - #6505

Open
Ewertonslv wants to merge 1 commit into
IBM:mainfrom
Ewertonslv:fix/6440-server-prompts-empty-template
Open

fix(prompts): fetch gateway-backed prompt content in server listing#6505
Ewertonslv wants to merge 1 commit into
IBM:mainfrom
Ewertonslv:fix/6440-server-prompts-empty-template

Conversation

@Ewertonslv

Copy link
Copy Markdown

🔗 Related Issue

Closes #6440

📝 Summary

GET /v1/servers/{server_id}/prompts returned "template": "" for every
auto-discovered (gateway-backed) prompt. Custom prompts returned their
content correctly; getting a gateway-backed prompt's actual content required
a separate GET /v1/prompts/{id} call per prompt.

Root cause

Gateway-backed prompts are synced into the catalog as metadata only — the
MCP prompts/list protocol call doesn't return content, so template is
stored as "" at sync time. The single-prompt endpoint (GET /v1/prompts/{id}
get_prompt()) already detects this via _should_fetch_gateway_prompt() and
fetches the content live from upstream via _fetch_gateway_prompt_result().
list_server_prompts() in prompt_service.py never applied that same check,
so it always returned the empty stored value.

Fix

After the listing query, identify gateway-backed prompts with
_should_fetch_gateway_prompt() (existing helper, unchanged) and fetch their
live content concurrently via asyncio.gather(...), applying the fetched text
onto the already-built PromptRead objects. A per-prompt fetch failure is
caught, logged, and leaves that prompt's template as the empty string it
already was — one unreachable gateway doesn't fail the whole listing.

Tests (before → after)

  • test_gateway_backed_prompt_template_fetched_live: a gateway-backed prompt
    (empty template) and a local custom prompt (populated template) in the same
    listing — asserts the gateway-backed one gets its live content, the local one
    is untouched. Without the fix, _fetch_gateway_prompt_result is never
    called (Awaited 0 times) and the read stays empty; with the fix, both
    assertions hold. Verified RED→GREEN via git stash.
  • test_gateway_backed_prompt_fetch_failure_leaves_template_empty: an
    unreachable gateway raises PromptError — the listing still returns the
    prompt, with template left as "" (graceful degradation, no 500).

pytest tests/unit/mcpgateway/services/test_prompt_service.py — full file
green (all tests, not just the two new ones).

📏 Reviewability

  • This PR has one clear purpose
  • The linked issue is not labeled triage
  • Unrelated bugs or improvements are tracked in separate issues/PRs
  • Tests are included with the code they validate
  • If AI-assisted, I understand and can explain the generated changes

🏷️ Type of Change

  • Bug fix

GET /v1/servers/{server_id}/prompts returned "template": "" for every
auto-discovered (gateway-backed) prompt. list_server_prompts() never
applied the same "does this prompt need a live fetch?" check that the
single-prompt GET /v1/prompts/{id} endpoint already applies via
_should_fetch_gateway_prompt() / _fetch_gateway_prompt_result() -
gateway-backed prompts are synced into the catalog as metadata only
(prompts/list has no content), so template stays "" until fetched.

Concurrently fetch live content for gateway-backed prompts after the
listing query, mirroring the existing single-prompt code path. A
per-prompt fetch failure is logged and leaves that prompt's template
as the empty string it already was, rather than failing the whole
list.

Closes IBM#6440

Signed-off-by: Ewerton Silva <ewertoncom297@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: GET /v1/servers/{server_id}/prompts returns empty template for auto-discovered (gateway-backed) prompts

1 participant