Skip to content

Commit 678e896

Browse files
Add prompts support to SDK (#4)
Add prompts support to SDK * Prompts can be accessed via dynamic proxy syntax (client.servers.foo.prompts.bar()) or explicit methods. * Client-level methods namespace prompt names as serverName__promptName to prevent collisions across multiple servers. * API documentation in README. --------- Co-authored-by: Khaled Osman <thisiskhaled@proton.me>
1 parent d4efd98 commit 678e896

File tree

8 files changed

+1196
-38
lines changed

8 files changed

+1196
-38
lines changed

README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,108 @@ if (await client.servers[serverName].hasTool("get_current_time")) {
228228
}
229229
```
230230

231+
#### `client.getPrompts(options?)`
232+
233+
Returns prompt schemas from all (or specific) servers with names transformed to `serverName__promptName` format.
234+
235+
**IMPORTANT**: Prompt names are automatically transformed to prevent naming clashes and identify server origin. Original prompt name `create_pr` on server `github` becomes `github__create_pr`.
236+
237+
This is useful for:
238+
239+
- Aggregating prompts from multiple servers
240+
- Prompt inspection and discovery across all servers
241+
- Custom tooling that needs raw MCP prompt schemas with unique names
242+
243+
```typescript
244+
// Get all prompts from all servers
245+
const allPrompts = await client.getPrompts();
246+
// Returns: [
247+
// { name: "github__create_pr", description: "...", arguments: [...] },
248+
// { name: "slack__post_message", description: "...", arguments: [...] }
249+
// ]
250+
251+
// Get prompts from specific servers only
252+
const somePrompts = await client.getPrompts({ servers: ["github"] });
253+
```
254+
255+
#### `client.generatePrompt(namespacedName, args?)`
256+
257+
Generate a prompt by its namespaced name (in `serverName__promptName` format).
258+
259+
```typescript
260+
// Generate a prompt with namespaced name
261+
const result = await client.generatePrompt("github__create_pr", {
262+
title: "Fix bug",
263+
description: "Fixed authentication issue",
264+
});
265+
// Returns: { messages: [...], description: "...", ... }
266+
```
267+
268+
#### `client.servers.<server>.getPrompts()`
269+
270+
Returns prompt schemas for a specific server.
271+
272+
```typescript
273+
// Get prompts for a specific server
274+
const githubPrompts = await client.servers.github.getPrompts();
275+
// Returns: [{ name: 'create_pr', description: '...', arguments: [...] }]
276+
```
277+
278+
#### `client.servers.<server>.prompts.<prompt>(args)`
279+
280+
Dynamically generate any prompt using natural syntax via the `.prompts` namespace. Prompt names must match exactly as returned by the MCP server.
281+
282+
```typescript
283+
// Generate a prompt with parameters using property access (recommended)
284+
const result = await client.servers.github.prompts.create_pr({
285+
title: "Fix bug",
286+
description: "Fixed authentication issue",
287+
});
288+
289+
// Generate without parameters (if prompt has no required args)
290+
const result = await client.servers.templates.prompts.default_template();
291+
```
292+
293+
#### `client.servers.<server>.generatePrompt(promptName, args?)`
294+
295+
Generate a prompt by name with the given arguments. This is useful for programmatic prompt generation when the prompt name is in a variable.
296+
297+
```typescript
298+
// Generate with dynamic prompt name
299+
const promptName = "create_pr";
300+
const result = await client.servers.github.generatePrompt(promptName, {
301+
title: "Fix bug",
302+
description: "Fixed authentication issue",
303+
});
304+
305+
// Using with dynamic server name too
306+
const serverName = "github";
307+
const result2 = await client.servers[serverName].generatePrompt(promptName, {
308+
title: "Fix bug",
309+
});
310+
```
311+
312+
#### `client.servers.<server>.hasPrompt(promptName)`
313+
314+
Check if a specific prompt exists on a server. Prompt names must match exactly as returned by the MCP server.
315+
316+
```typescript
317+
// Check if prompt exists before generating it
318+
if (await client.servers.github.hasPrompt("create_pr")) {
319+
const result = await client.servers.github.generatePrompt("create_pr", {
320+
title: "Fix bug",
321+
});
322+
}
323+
324+
// Using with dynamic server names
325+
const serverName = "github";
326+
if (await client.servers[serverName].hasPrompt("create_pr")) {
327+
const result = await client.servers[serverName].prompts.create_pr({
328+
title: "Fix bug",
329+
});
330+
}
331+
```
332+
231333
#### `client.getServerHealth(serverName?: string)`
232334

233335
Get health information for one or all servers.
@@ -402,6 +504,9 @@ npm run test:coverage
402504
### Linting and Formatting
403505

404506
```bash
507+
# Run all checks (format, lint, typecheck, test, build)
508+
npm run check
509+
405510
# Run linter
406511
npm run lint
407512

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"typecheck": "tsc --noEmit",
2626
"typecheck:tests": "tsc --noEmit --project tsconfig.test.json",
2727
"typecheck:all": "npm run typecheck && npm run typecheck:tests",
28+
"check": "npm run format && npm run lint:fix && npm run typecheck:all && npm test && npm run build",
2829
"prepublishOnly": "npm run build"
2930
},
3031
"keywords": [

src/apiPaths.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ export const API_PATHS = {
1717
TOOL_CALL: (serverName: string, toolName: string) =>
1818
`${SERVERS_BASE}/${encodeURIComponent(serverName)}/tools/${encodeURIComponent(toolName)}`,
1919

20+
// Prompts
21+
SERVER_PROMPTS: (serverName: string, cursor?: string) => {
22+
const base = `${SERVERS_BASE}/${encodeURIComponent(serverName)}/prompts`;
23+
return cursor ? `${base}?cursor=${encodeURIComponent(cursor)}` : base;
24+
},
25+
PROMPT_GET_GENERATED: (serverName: string, promptName: string) =>
26+
`${SERVERS_BASE}/${encodeURIComponent(serverName)}/prompts/${encodeURIComponent(promptName)}`,
27+
2028
// Health
2129
HEALTH_ALL: HEALTH_SERVERS_BASE,
2230
HEALTH_SERVER: (serverName: string) =>

0 commit comments

Comments
 (0)