Prompts
MCP Prompts: Reusable Templates
Prompts are reusable message templates that help users interact with your server's capabilities. They're like shortcuts — instead of explaining what they want, users select a prompt template.
typescript
server.prompt(
"code_review",
"Review code for bugs and improvements",
{ code: z.string(), language: z.string().optional() },
({ code, language }) => ({
messages: [{
role: "user",
content: {
type: "text",
text: `Review this ${language || ""} code for bugs, security issues, and improvements:\n\n${code}`,
},
}],
})
);Tip:Prompts are optional but useful for complex workflows. They appear in the client's UI (like Claude Desktop's slash commands).
PreviewTypeScriptRead Only
Copy this code and run it locally with
npx tsx server.ts