MCPcopy Create free account
hub / github.com/modelcontextprotocol/typescript-sdk / registerPrompt

Method registerPrompt

src/server/mcp.ts:1139–1166  ·  view source on GitHub ↗

* Registers a prompt with a config object and callback.

(
        name: string,
        config: {
            title?: string;
            description?: string;
            argsSchema?: Args;
        },
        cb: PromptCallback<Args>
    )

Source from the content-addressed store, hash-verified

1137 * Registers a prompt with a config object and callback.
1138 */
1139 registerPrompt<Args extends PromptArgsRawShape>(
1140 name: string,
1141 config: {
1142 title?: string;
1143 description?: string;
1144 argsSchema?: Args;
1145 },
1146 cb: PromptCallback<Args>
1147 ): RegisteredPrompt {
1148 if (this._registeredPrompts[name]) {
1149 throw new Error(`Prompt ${name} is already registered`);
1150 }
1151
1152 const { title, description, argsSchema } = config;
1153
1154 const registeredPrompt = this._createRegisteredPrompt(
1155 name,
1156 title,
1157 description,
1158 argsSchema,
1159 cb as PromptCallback<PromptArgsRawShape | undefined>
1160 );
1161
1162 this.setPromptRequestHandlers();
1163 this.sendPromptListChanged();
1164
1165 return registeredPrompt;
1166 }
1167
1168 /**
1169 * Checks if the server is connected to a transport.

Callers 5

getServerFunction · 0.95
getServerFunction · 0.95
index.test.tsFile · 0.80
title.test.tsFile · 0.80
mcp.test.tsFile · 0.80

Calls 3

sendPromptListChangedMethod · 0.95

Tested by

no test coverage detected