| name | add-prompt |
| description | Scaffold a new MCP prompt template. Use when the user asks to add a prompt, create a reusable message template, or define a prompt for LLM interactions.
|
| metadata | {"author":"cyanheads","version":"1.3","audience":"external","type":"reference"} |
Context
Prompts use the prompt() builder from @cyanheads/mcp-ts-core. Each prompt lives in src/mcp-server/prompts/definitions/ with a .prompt.ts suffix. The standard registration pattern uses a definitions/index.ts barrel that collects all prompts into an allPromptDefinitions array for createApp(). Fresh scaffolds start with direct imports in src/index.ts — the barrel is introduced as definitions grow. Match the pattern already used by the project you're editing.
Prompts are pure message templates — no Context, no auth, no side effects. generate can be sync or async (returns PromptMessage[] | Promise<PromptMessage[]>).
Steps
- Gather the prompt's name, purpose, and arguments from the user's request — ask only if genuinely absent
- Create the file at
src/mcp-server/prompts/definitions/{{prompt-name}}.prompt.ts
- Register the prompt in the project's existing
createApp() prompt list (directly in src/index.ts for fresh scaffolds, or via a barrel if the repo already has one)
- Run
bun run devcheck to verify
Template
import { completable, prompt, z } from '@cyanheads/mcp-ts-core';
export const {{PROMPT_EXPORT}} = prompt('{{prompt_name}}', {
description: '{{PROMPT_DESCRIPTION}}',
args: z.object({
}),
generate: (args) => [
{
role: 'user',
content: {
type: 'text',
text: `{{PROMPT_TEMPLATE_TEXT}}`,
},
},
],
});
Multi-message prompt
generate: (args) => [
{
role: 'user',
content: {
type: 'text',
text: `Here is the ${args.type} to review:\n\n${args.content}`,
},
},
{
role: 'assistant',
content: {
type: 'text',
text: 'I will analyze this carefully. Let me start with...',
},
},
],
Registration
import { createApp } from '@cyanheads/mcp-ts-core';
import { {{PROMPT_EXPORT}} } from './mcp-server/prompts/definitions/{{prompt-name}}.prompt.js';
await createApp({
tools: [],
resources: [],
prompts: [{{PROMPT_EXPORT}}],
});
If the repo already uses src/mcp-server/prompts/definitions/index.ts, add the export to that barrel instead:
export { {{PROMPT_EXPORT}} } from './{{prompt-name}}.prompt.js';
Argument autocompletion
Wrap any args field with completable() (re-exported from @cyanheads/mcp-ts-core) to enable argument autocompletion. The SDK auto-installs completion/complete handling and advertises the completions capability when any registered prompt has a completable argument — no other changes are needed.
import { completable, prompt, z } from '@cyanheads/mcp-ts-core';
export const codeReview = prompt('code_review', {
description: 'Review code for issues.',
title: 'Code Review',
args: z.object({
language: completable(
z.string().describe('Programming language'),
async (partial) => ['typescript', 'python', 'rust'].filter((l) => l.startsWith(partial)),
),
code: z.string().describe('Code to review'),
}),
generate: (args) => [
{ role: 'user', content: { type: 'text', text: `Review this ${args.language} code:\n${args.code}` } },
],
});
completable() is transparent to the linter — it does not affect describe-on-fields or schema-serializable rules. All completable-wrapped fields still require .describe() on the underlying schema.
Checklist