prefecthq--fastmcp
60e0ffc959
Upgrade checks / Notify on failure (push) Has been cancelled
Upgrade checks / Close issue on success (push) Has been cancelled
Schema Crash Test / Real-world schema crash test (232K schemas) (push) Has been cancelled
Run static analysis / static_analysis (push) Has been cancelled
Tests / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Tests / Tests with lowest-direct dependencies (push) Has been cancelled
Tests / MCP conformance tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
Tests / Package install smoke (push) Has been cancelled
Upgrade checks / Static analysis (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Upgrade checks / Integration tests (push) Has been cancelled
Update MCPServerConfig Schema / update-config-schema (push) Has been cancelled
Update SDK Documentation / update-sdk-docs (push) Has been cancelled
51 行
1.7 KiB
Python
51 行
1.7 KiB
Python
"""Tests for prompt mounting."""
|
|
|
|
from fastmcp import FastMCP
|
|
|
|
|
|
class TestPrompts:
|
|
"""Test mounting with prompts."""
|
|
|
|
async def test_mount_with_prompts(self):
|
|
"""Test mounting a server with prompts."""
|
|
main_app = FastMCP("MainApp")
|
|
assistant_app = FastMCP("AssistantApp")
|
|
|
|
@assistant_app.prompt
|
|
def greeting(name: str) -> str:
|
|
return f"Hello, {name}!"
|
|
|
|
# Mount the assistant app
|
|
main_app.mount(assistant_app, "assistant")
|
|
|
|
# Prompt should be accessible through main app
|
|
prompts = await main_app.list_prompts()
|
|
assert any(p.name == "assistant_greeting" for p in prompts)
|
|
|
|
# Render the prompt
|
|
result = await main_app.render_prompt("assistant_greeting", {"name": "World"})
|
|
assert result.messages is not None
|
|
# The message should contain our greeting text
|
|
|
|
async def test_adding_prompt_after_mounting(self):
|
|
"""Test adding a prompt after mounting."""
|
|
main_app = FastMCP("MainApp")
|
|
assistant_app = FastMCP("AssistantApp")
|
|
|
|
# Mount the assistant app before adding prompts
|
|
main_app.mount(assistant_app, "assistant")
|
|
|
|
# Add a prompt after mounting
|
|
@assistant_app.prompt
|
|
def farewell(name: str) -> str:
|
|
return f"Goodbye, {name}!"
|
|
|
|
# Prompt should be accessible through main app
|
|
prompts = await main_app.list_prompts()
|
|
assert any(p.name == "assistant_farewell" for p in prompts)
|
|
|
|
# Render the prompt
|
|
result = await main_app.render_prompt("assistant_farewell", {"name": "World"})
|
|
assert result.messages is not None
|
|
# The message should contain our farewell text
|