Basic prompt
collect() registers it. Clients list prompts with prompts/list and render them with prompts/get.
Return formats
Return a list of role/content tuples:None for prompts that produce no messages.
Reusable message templates for AI agents
from dedalus_mcp import MCPServer, prompt
@prompt(
"code-review",
description="Review code for issues",
arguments=[{"name": "language", "required": True}],
)
def code_review(arguments):
lang = arguments.get("language", "python")
return [
("assistant", "You are a senior code reviewer."),
("user", f"Review the following {lang} code for bugs and style issues."),
]
server = MCPServer("assistant")
server.collect(code_review)
collect() registers it. Clients list prompts with prompts/list and render them with prompts/get.
@prompt("summarize", description="Summarize a document")
def summarize(arguments):
return [
("assistant", "You summarize documents concisely."),
("user", "Summarize this document in 3 bullet points."),
]
@prompt("status")
def status_prompt(arguments):
return {
"description": "Status template",
"messages": [
("assistant", "You summarize status reports."),
],
}
None for prompts that produce no messages.
from dedalus_mcp.types import PromptArgument
@prompt(
"translate",
description="Translate text",
arguments=[
PromptArgument(name="text", description="Text to translate", required=True),
PromptArgument(name="target_lang", description="Target language", required=False),
],
)
def translate(arguments):
text = arguments["text"]
lang = arguments.get("target_lang", "English")
return [("user", f"Translate this to {lang}: {text}")]
@prompt("db-summary", description="Summarize database state")
async def db_summary(arguments):
stats = await fetch_db_stats()
return [
("assistant", "You analyze database metrics."),
("user", f"Here are the current stats: {stats}"),
]
@prompt(
"analyze",
description="Analyze code", # Shown to users
title="Code Analysis", # Human-friendly name
arguments=[...], # User inputs
icons=[{"type": "url", "url": "https://example.com/icon.png"}],
meta={"category": "code"}, # Custom metadata
)
def analyze(arguments):
...
def test_code_review_prompt():
result = code_review({"language": "python"})
assert len(result) == 2
assert "python" in result[1][1]
async def test_prompt_rendering():
server = MCPServer("test")
server.collect(code_review)
result = await server.invoke_prompt("code-review", arguments={"language": "rust"})
assert result.messages[1].content.text == "Review the following rust code for bugs and style issues."
Was this page helpful?