Skip to content

fix: custom prompts return a list of Message so FastMCP can render them - #481

Open
rgeissen wants to merge 1 commit into
Teradata:mainfrom
rgeissen:fix/custom-prompt-returns-list
Open

rgeissen wants to merge 1 commit into
Teradata:mainfrom
rgeissen:fix/custom-prompt-returns-list

Conversation

@rgeissen

Copy link
Copy Markdown
Contributor

Problem

Every prompt registered through make_custom_prompt (the *_objects.yml prompts, with and without parameters) fails on prompts/get:

Error rendering prompt '<name>': Prompt must return str, list[Message], or PromptResult, got Message

make_custom_prompt returns a bare Message from both prompt functions. FastMCP 4.x, which this project requires (fastmcp>=4.0.2), only renders a prompt that returns str, list[Message] or PromptResult. Tools are unaffected; only prompt rendering breaks.

Reproduced in-process on fastmcp 4.1.4 / mcp 2.3.0: a prompt returning Message(...) fails with the error above, the same prompt returning [Message(...)] renders.

Fix

Both branches of make_custom_prompt now return [Message(...)] (two lines in src/teradata_mcp_server/app.py).

Test

tests/phase0/test_custom_prompt_return_shape.py, no database needed:

  • the FastMCP contract: a bare Message is rejected, a list renders;
  • both prompt functions in make_custom_prompt return a list.

It fails before the change and passes after (pytest tests/phase0/test_custom_prompt_return_shape.py → 3 passed).

make_custom_prompt registered every YAML-defined prompt (with and without
parameters) as a function returning a bare Message. FastMCP 4.x, which this
project requires (fastmcp>=4.0.2), renders a prompt only when it returns str,
list[Message] or PromptResult, so every custom prompt failed on prompts/get:

    Prompt must return str, list[Message], or PromptResult, got Message

Both branches now return [Message(...)]. Tools were never affected.

Adds tests/phase0/test_custom_prompt_return_shape.py (no database needed):
the FastMCP contract (bare Message rejected, list rendered) and a check that
both prompt functions in make_custom_prompt return a list. Fails before the
change, passes after.

This branch has not been deployed

No deployments
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.

1 participant