| 1017 | * @category Prompts |
| 1018 | */ |
| 1019 | export const registerPrompt = < |
| 1020 | E, |
| 1021 | R, |
| 1022 | Params = {}, |
| 1023 | ParamsI extends Record<string, string> = {}, |
| 1024 | ParamsR = never, |
| 1025 | const Completions extends { |
| 1026 | readonly [K in keyof Params]?: ( |
| 1027 | input: string |
| 1028 | ) => Effect.Effect<Array<Params[K]>, any, any> |
| 1029 | } = {} |
| 1030 | >(options: { |
| 1031 | readonly name: string |
| 1032 | readonly description?: string | undefined |
| 1033 | readonly parameters?: Schema.Schema<Params, ParamsI, ParamsR> | undefined |
| 1034 | readonly completion?: |
| 1035 | | ValidateCompletions<Completions, Extract<keyof Params, string>> |
| 1036 | | undefined |
| 1037 | readonly content: ( |
| 1038 | params: Params |
| 1039 | ) => Effect.Effect<Array<typeof PromptMessage.Type> | string, E, R> |
| 1040 | }): Effect.Effect< |
| 1041 | void, |
| 1042 | never, |
| 1043 | Exclude<ParamsR | R, McpServerClient> | McpServer |
| 1044 | > => { |
| 1045 | const args = Arr.empty<typeof PromptArgument.Type>() |
| 1046 | const props: Record<string, Schema.Schema.Any> = {} |
| 1047 | const propSignatures = options.parameters |
| 1048 | ? AST.getPropertySignatures(options.parameters.ast) |
| 1049 | : [] |
| 1050 | for (const prop of propSignatures) { |
| 1051 | args.push({ |
| 1052 | name: prop.name as string, |
| 1053 | description: Option.getOrUndefined(AST.getDescriptionAnnotation(prop)), |
| 1054 | required: !prop.isOptional |
| 1055 | }) |
| 1056 | props[prop.name as string] = Schema.make(prop.type) |
| 1057 | } |
| 1058 | const prompt = new Prompt({ |
| 1059 | name: options.name, |
| 1060 | description: options.description, |
| 1061 | arguments: args |
| 1062 | }) |
| 1063 | const decode = options.parameters |
| 1064 | ? Schema.decodeUnknown(options.parameters) |
| 1065 | : () => Effect.succeed({} as Params) |
| 1066 | const completion: Record<string, (input: string) => Effect.Effect<any>> = options.completion ?? {} |
| 1067 | return Effect.gen(function*() { |
| 1068 | const registry = yield* McpServer |
| 1069 | const context = yield* Effect.context<Exclude<R | ParamsR, McpServerClient>>() |
| 1070 | const completions: Record< |
| 1071 | string, |
| 1072 | ( |
| 1073 | input: string |
| 1074 | ) => Effect.Effect<CompleteResult, InternalError, McpServerClient> |
| 1075 | > = {} |
| 1076 | for (const [param, handle] of Object.entries(completion)) { |