Skip to content

Commit 3455a42

Browse files
test(fastmcp): Wrap prompt in Message for mcp v3 (#5411)
1 parent 55e0b59 commit 3455a42

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

tests/integrations/fastmcp/test_fastmcp.py

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ async def __call__(self, *args, **kwargs):
4343
from mcp.server.sse import SseServerTransport
4444
from mcp.server.streamable_http_manager import StreamableHTTPSessionManager
4545

46+
try:
47+
from fastmcp.prompts import Message
48+
except ImportError:
49+
Message = None
50+
51+
4652
from starlette.responses import Response
4753
from starlette.routing import Mount, Route
4854
from starlette.applications import Starlette
@@ -611,15 +617,18 @@ async def test_fastmcp_prompt_sync(
611617
@mcp.prompt()
612618
def code_help_prompt(language: str):
613619
"""Get help for a programming language"""
614-
return [
615-
{
616-
"role": "user",
617-
"content": {
618-
"type": "text",
619-
"text": f"Tell me about {language}",
620-
},
621-
}
622-
]
620+
message = {
621+
"role": "user",
622+
"content": {
623+
"type": "text",
624+
"text": f"Tell me about {language}",
625+
},
626+
}
627+
628+
if FASTMCP_VERSION is not None and FASTMCP_VERSION.startswith("3"):
629+
message = Message(message)
630+
631+
return [message]
623632

624633
with start_transaction(name="fastmcp tx"):
625634
result = await stdio(
@@ -692,19 +701,24 @@ async def test_fastmcp_prompt_async(
692701
@mcp.prompt()
693702
async def async_prompt(topic: str):
694703
"""Get async prompt for a topic"""
695-
return [
696-
{
697-
"role": "user",
698-
"content": {"type": "text", "text": f"What is {topic}?"},
699-
},
700-
{
701-
"role": "assistant",
702-
"content": {
703-
"type": "text",
704-
"text": "Let me explain that",
705-
},
704+
message1 = {
705+
"role": "user",
706+
"content": {"type": "text", "text": f"What is {topic}?"},
707+
}
708+
709+
message2 = {
710+
"role": "assistant",
711+
"content": {
712+
"type": "text",
713+
"text": "Let me explain that",
706714
},
707-
]
715+
}
716+
717+
if FASTMCP_VERSION is not None and FASTMCP_VERSION.startswith("3"):
718+
message1 = Message(message1)
719+
message2 = Message(message2)
720+
721+
return [message1, message2]
708722

709723
_, result = json_rpc(
710724
app,

0 commit comments

Comments
 (0)