You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Prompts are reusable templates that help LLMs interact with your server effectively:
175
200
176
201
```typescript
177
-
server.prompt(
202
+
server.registerPrompt(
178
203
"review-code",
179
-
{ code: z.string() },
204
+
{
205
+
title: "Code Review",
206
+
description: "Review code for best practices and potential issues",
207
+
arguments: { code: z.string() }
208
+
},
180
209
({ code }) => ({
181
210
messages: [{
182
211
role: "user",
@@ -189,6 +218,44 @@ server.prompt(
189
218
);
190
219
```
191
220
221
+
### Display Names and Metadata
222
+
223
+
All resources, tools, and prompts support an optional `title` field for better UI presentation. The `title` is used as a display name, while `name` remains the unique identifier.
224
+
225
+
**Note:** The `register*` methods (`registerTool`, `registerPrompt`, `registerResource`) are the recommended approach for new code. The older methods (`tool`, `prompt`, `resource`) remain available for backwards compatibility.
226
+
227
+
#### Title Precedence for Tools
228
+
229
+
For tools specifically, there are two ways to specify a title:
230
+
-`title` field in the tool configuration
231
+
-`annotations.title` field (when using the older `tool()` method with annotations)
232
+
233
+
The precedence order is: `title` → `annotations.title` → `name`
234
+
235
+
```typescript
236
+
// Using registerTool (recommended)
237
+
server.registerTool("my_tool", {
238
+
title: "My Tool", // This title takes precedence
239
+
annotations: {
240
+
title: "Annotation Title"// This is ignored if title is set
241
+
}
242
+
}, handler);
243
+
244
+
// Using tool with annotations (older API)
245
+
server.tool("my_tool", "description", {
246
+
title: "Annotation Title"// This is used as title
247
+
}, handler);
248
+
```
249
+
250
+
When building clients, use the provided utility to get the appropriate display name:
// Automatically handles the precedence: title → annotations.title → name
256
+
const displayName =getDisplayName(tool);
257
+
```
258
+
192
259
## Running Your Server
193
260
194
261
MCP servers in TypeScript need to be connected to a transport to communicate with clients. How you start the server depends on the choice of transport:
0 commit comments