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
// ResourceLinks let tools return references without file content
208
+
{
209
+
type: "resource_link",
210
+
uri: "file:///project/README.md",
211
+
name: "README.md",
212
+
mimeType: "text/markdown",
213
+
description: 'A README file'
214
+
},
215
+
{
216
+
type: "resource_link",
217
+
uri: "file:///project/src/index.ts",
218
+
name: "index.ts",
219
+
mimeType: "text/typescript",
220
+
description: 'An index file'
221
+
}
222
+
]
223
+
})
224
+
);
170
225
```
171
226
227
+
#### ResourceLinks
228
+
229
+
Tools can return `ResourceLink` objects to reference resources without embedding their full content. This is essential for performance when dealing with large files or many resources - clients can then selectively read only the resources they need using the provided URIs.
230
+
172
231
### Prompts
173
232
174
233
Prompts are reusable templates that help LLMs interact with your server effectively:
175
234
176
235
```typescript
177
-
server.prompt(
236
+
server.registerPrompt(
178
237
"review-code",
179
-
{ code: z.string() },
238
+
{
239
+
title: "Code Review",
240
+
description: "Review code for best practices and potential issues",
241
+
arguments: { code: z.string() }
242
+
},
180
243
({ code }) => ({
181
244
messages: [{
182
245
role: "user",
@@ -189,6 +252,44 @@ server.prompt(
189
252
);
190
253
```
191
254
255
+
### Display Names and Metadata
256
+
257
+
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.
258
+
259
+
**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.
260
+
261
+
#### Title Precedence for Tools
262
+
263
+
For tools specifically, there are two ways to specify a title:
264
+
-`title` field in the tool configuration
265
+
-`annotations.title` field (when using the older `tool()` method with annotations)
266
+
267
+
The precedence order is: `title` → `annotations.title` → `name`
268
+
269
+
```typescript
270
+
// Using registerTool (recommended)
271
+
server.registerTool("my_tool", {
272
+
title: "My Tool", // This title takes precedence
273
+
annotations: {
274
+
title: "Annotation Title"// This is ignored if title is set
275
+
}
276
+
}, handler);
277
+
278
+
// Using tool with annotations (older API)
279
+
server.tool("my_tool", "description", {
280
+
title: "Annotation Title"// This is used as title
281
+
}, handler);
282
+
```
283
+
284
+
When building clients, use the provided utility to get the appropriate display name:
// Automatically handles the precedence: title → annotations.title → name
290
+
const displayName =getDisplayName(tool);
291
+
```
292
+
192
293
## Running Your Server
193
294
194
295
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