# Custom Prompts

You can use [MCP prompts](https://modelcontextprotocol.io/docs/concepts/prompts) to create reusable prompt templates and workflows for MCP. Custom prompts allow you to define structured interactions that can be invoked by MCP clients.

## Building and registering custom MCP prompts

Below are examples of custom MCP prompts that demonstrate different patterns for prompt creation:

```typescript filename="custom/customPrompts.ts"

const myNameArg = { first_name: z.string(), last_name: z.string() };

const prompt$aboutSpeakeasy: PromptDefinition<undefined> = {
  name: "tell-me-about-speakeasy",
  prompt: (_client, _extra) =>
    formatResult("Please tell me about the company Speakeasy"),
};
```

```typescript filename="server.extensions.ts"

  register.prompt(prompt$aboutSpeakeasy);
}
```

## Prompt patterns

### Simple prompts

For basic prompts without parameters:

```typescript

```

### Parameterized prompts

For prompts that accept arguments:

```typescript
const codeReviewArgs = {
  language: z.string(),
  code: z.string(),
  focus: z.enum(["security", "performance", "style", "all"]).optional()
};

```

### Multi-step prompts

For complex workflows with multiple interactions:

```typescript
const troubleshootArgs = {
  issue: z.string(),
  system: z.string(),
  urgency: z.enum(["low", "medium", "high"])
};

```

## Setting up MCP extensions

To register your custom prompts, add them to your `server.extensions.ts` file:

```typescript filename="server.extensions.ts"

  register.prompt(prompt$codeReview);
  register.prompt(prompt$troubleshoot);
}
```

After adding the `server.extensions.ts` file and defining your custom prompts, execute `speakeasy run` to regenerate your MCP server with the new prompts.

## Best practices

- **Use clear, descriptive names** for your prompts that indicate their purpose
- **Provide detailed descriptions** to help users understand when to use each prompt
- **Validate input parameters** using Zod schemas for type safety
- **Structure messages logically** with appropriate roles (system, user, assistant)
- **Handle edge cases** gracefully with fallback content
- **Test prompts thoroughly** with various input combinations
- **Keep prompts focused** on specific tasks rather than trying to handle everything
- **Use consistent formatting** for similar types of prompts across your server
