-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathprompt.ts
More file actions
39 lines (37 loc) · 1.22 KB
/
prompt.ts
File metadata and controls
39 lines (37 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { PromptMessage } from "@modelcontextprotocol/sdk/types.js";
import { McpContext, ServerFeature } from "./types";
import { getDefaultFeatureAvailabilityCheck } from "./util/availability";
export interface ServerPrompt {
mcp: {
name: string;
description?: string;
arguments?: { name: string; description?: string; required?: boolean }[];
omitPrefix?: boolean;
annotations?: {
title?: string;
};
_meta?: {
/** Prompts are grouped by feature. --only can configure what prompts is available. */
feature?: string;
};
};
fn: (args: Record<string, string>, ctx: McpContext) => Promise<PromptMessage[]>;
isAvailable: (ctx: McpContext) => Promise<boolean>;
}
export function prompt(
feature: ServerFeature,
options: ServerPrompt["mcp"],
fn: ServerPrompt["fn"],
isAvailable?: (ctx: McpContext) => Promise<boolean>,
): ServerPrompt {
return {
mcp: options,
fn,
isAvailable: (ctx) => {
// default to the feature level availability check, but allow override
// We resolve this at runtime to allow for easier testing/mocking
const isAvailableFunc = isAvailable || getDefaultFeatureAvailabilityCheck(feature);
return isAvailableFunc(ctx);
},
};
}