prompt-design

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Create xmcp Prompt

创建xmcp提示词

You are helping the user create a new xmcp prompt. Follow this interactive workflow.
你正在协助用户创建新的xmcp提示词,请遵循以下交互式工作流程。

Step 1: Gather Information

步骤1:收集信息

Before generating any code, ask the user these questions using AskUserQuestion:
  1. Prompt name (if not provided): What should the prompt be named? (Use kebab-case)
  2. Prompt type: Ask which type of prompt they need:
    • Simple - Static prompt text without parameters
    • Parameterized - Prompt with user-provided parameters (most common)
    • Multi-content - Returns multiple content blocks (text, images, etc.)
  3. Parameters (if parameterized): What inputs should the prompt accept?
    • Parameter name
    • Type (string, number, enum)
    • Description
    • Whether it's optional
    • Any validation or default values
  4. Role: What role should the prompt assume?
    • user - Prompt from user perspective (most common)
    • assistant - Prompt as assistant response template
  5. Use case: What is the prompt designed for?
    • Code review
    • Documentation generation
    • Data analysis
    • Content creation
    • Other specific task
在生成任何代码之前,使用AskUserQuestion向用户询问以下问题:
  1. 提示词名称(若未提供):提示词应命名为什么?(使用短横线分隔式命名kebab-case)
  2. 提示词类型:询问用户需要哪种类型的提示词:
    • 简单型 - 无参数的静态提示词文本
    • 参数化型 - 包含用户提供参数的提示词(最常见)
    • 多内容型 - 返回多个内容块(文本、图片等)
  3. 参数(若为参数化型):提示词应接受哪些输入?
    • 参数名称
    • 类型(字符串、数字、枚举)
    • 描述
    • 是否为可选参数
    • 任何验证规则或默认值
  4. 角色:提示词应扮演什么角色?
    • user - 从用户视角出发的提示词(最常见)
    • assistant - 作为助手回复模板的提示词
  5. 使用场景:该提示词的设计用途是什么?
    • 代码评审
    • 文档生成
    • 数据分析
    • 内容创作
    • 其他特定任务

Step 2: Generate the Prompt

步骤2:生成提示词

Create the prompt file in
src/prompts/
:
src/prompts/
目录下创建提示词文件:

File Location

文件路径

src/prompts/{prompt-name}.ts
src/prompts/{prompt-name}.ts

Prompt Structure Reference

提示词结构参考

Every xmcp prompt has three main exports:
typescript
// 1. Schema (optional) - Define parameters with Zod
export const schema = { /* ... */ };

// 2. Metadata (optional) - Prompt configuration
export const metadata: PromptMetadata = { /* ... */ };

// 3. Handler (required) - Default export function
export default function handler(params?) { /* ... */ }
每个xmcp提示词包含三个主要导出项:
typescript
// 1. Schema (optional) - Define parameters with Zod
export const schema = { /* ... */ };

// 2. Metadata (optional) - Prompt configuration
export const metadata: PromptMetadata = { /* ... */ };

// 3. Handler (required) - Default export function
export default function handler(params?) { /* ... */ }

Quick Reference

快速参考

Essential Imports

必要导入

typescript
import { type PromptMetadata } from "xmcp";

// For parameterized prompts
import { z } from "zod";
import { type InferSchema, type PromptMetadata } from "xmcp";
typescript
import { type PromptMetadata } from "xmcp";

// For parameterized prompts
import { z } from "zod";
import { type InferSchema, type PromptMetadata } from "xmcp";

Metadata Fields

元数据字段

FieldTypeRequiredDescription
name
stringNo*Unique prompt identifier
title
stringNoHuman-readable title
description
stringNoWhat this prompt does
role
stringNo"user" or "assistant" (default: user)
*When metadata is omitted, xmcp uses the filename as the prompt name.
字段类型是否必填描述
name
string否*唯一的提示词标识符
title
string易读的标题
description
string该提示词的功能说明
role
string"user"或"assistant"(默认值:user)
*当省略元数据时,xmcp会将文件名作为提示词名称。

Handler Return Types

处理器返回类型

Return TypeUse Case
string
Simple text prompt
{ type: "text", text: string }
Explicit text content
{ type: "image", data: base64, mimeType: string }
Image content
Array<Content>
Multiple content blocks
返回类型应用场景
string
纯文本提示词
{ type: "text", text: string }
显式文本内容
{ type: "image", data: base64, mimeType: string }
图片内容
Array<Content>
多个内容块

Use Cases for Server-Exposed Prompts

服务器端可访问提示词的应用场景

MCP prompts are useful for:
  1. Standardized workflows - Consistent code review, documentation patterns
  2. Complex templates - Multi-step analysis prompts with structure
  3. Domain expertise - Specialized prompts for specific domains
  4. Reusable patterns - Common tasks that benefit from parameterization
  5. Client integration - Prompts that MCP clients can discover and use
MCP提示词适用于:
  1. 标准化工作流程 - 统一的代码评审、文档生成模式
  2. 复杂模板 - 具有结构化的多步骤分析提示词
  3. 领域专业能力 - 针对特定领域的专用提示词
  4. 可复用模式 - 可从参数化中获益的常见任务
  5. 客户端集成 - MCP客户端可发现并使用的提示词

Detailed Templates

详细模板

For complete code templates including:
  • Simple prompt patterns
  • Parameterized prompts with Zod schemas
  • Multi-role conversation prompts
  • Autocompletion support
  • Code review and documentation examples
Read:
references/patterns.md

完整的代码模板包括:
  • 简单提示词模式
  • 结合Zod schema的参数化提示词
  • 多角色对话提示词
  • 自动补全支持
  • 代码评审和文档生成示例
查看:
references/patterns.md

Checklist After Generation

生成后的检查清单

  1. File created in
    src/prompts/{prompt-name}.ts
  2. If using metadata, ensure it has
    name
    ,
    title
    , and
    description
  3. Schema uses
    .describe()
    for all parameters (if parameterized)
  4. Handler returns appropriate content format
  5. Role is set appropriately for the use case
Suggest running
pnpm build
to verify the prompt compiles correctly.
  1. 文件已创建在
    src/prompts/{prompt-name}.ts
    路径下
  2. 若使用元数据,确保包含
    name
    title
    description
    字段
  3. 若为参数化提示词,Schema中所有参数均使用
    .describe()
    添加描述
  4. 处理器返回了合适的内容格式
  5. 已根据使用场景正确设置角色
建议运行
pnpm build
来验证提示词是否能正确编译。