View the source code for this module on GitHub: https://github.com/mcp-use/mcp-use/blob/main/libraries/typescript/packages/mcp-use/src/server/mcp-server.ts
server.prompt(), validate its arguments with a Zod schema, and return either a GetPromptResult directly or a response helper result (such as text()) that the server converts for you. To give clients IDE-style autocomplete on prompt arguments, wrap individual schema fields with completable().
Methods
Registers a prompt template that clients can use to generate formatted messages for a language model.prompt
Registers a prompt template on the server and returns the server instance for method chaining. The prompt accepts arguments validated by its Zod schema and returns prompt messages. The callback may be supplied two ways: as a separatecallback argument (recommended), or as a cb property on the definition object (legacy). At least one of them must be present, otherwise registration throws.
The callback can return a GetPromptResult (an object with a messages array) directly, or any response helper result such as text(), markdown(), or object(). When the returned value has a messages array it is used as-is; any other value is treated as a CallToolResult and converted to a GetPromptResult before being sent. The prompt name is added to the server’s registered prompt list. After registering at runtime, call server.sendPromptsListChanged() so connected clients refresh their list.
ReturnsPrompt configuration object. See PromptDefinition for all fields. UsePromptDefinitionWithoutCallback(nocbfield) when passing the callback as the second argument.Optional callback that receives the validated arguments and returns the prompt result. Required unless the definition includes acbproperty. The argument type is inferred frompromptDefinition.schema. See PromptCallback.
ThrowsThe server instance, for method chaining.
SignatureThrown synchronously during registration when the prompt has neither acbproperty nor acallbackargument. The message isPrompt '<name>' must have either a cb property or a callback parameter.
Functions
completable()
Attaches autocompletion to a Zod schema so clients can request suggestions.completion/complete request. Use it on individual fields inside a prompt’s (or resource template’s) schema. It returns the same schema with completion metadata attached, so the field still validates exactly as before.
There are two ways to supply suggestions:
- List-based (primitives only): pass an array of allowed values. The server filters them with a case-insensitive prefix match against what the user has typed. Only
z.string(),z.number(), andz.enum([...])schemas are accepted in this form. - Callback-based (any schema): pass a function that receives the current input value and an optional
CompletionContextand returns the suggestions (or a promise of them). Use this for dynamic or contextual completion, including suggestions that depend on other already-provided arguments viacontext.arguments.
ReturnsThe Zod schema for the argument (for examplez.string(),z.number(),z.enum([...])). For the list-based overload,Tis constrained toz.ZodString | z.ZodNumber | z.ZodEnum<any>.Either an array of allowed values (primitives), or a completion callback(value: SchemaInput<T>, context?: CompletionContext) => Promise<SchemaInput<T>[]> | SchemaInput<T>[].
SignatureThe same schema with completion metadata attached. SeeCompletable.
Types
PromptDefinition
Configuration object describing a prompt, including its callback (legacy single-object pattern).cb field. When passing the callback as a separate argument to server.prompt(), use PromptDefinitionWithoutCallback (the same shape minus the cb field). The interface is generic over TInput (the validated argument type) and HasOAuth (whether OAuth is configured, which affects ctx.auth availability).
SignatureUnique identifier for the prompt (for example"code-review-template").Human-readable title displayed in prompt lists.Description of what the prompt does; helps users choose the right prompt. Defaults to an empty string when omitted.Argument definitions. Deprecated, useschemainstead.Zod object schema for input validation. Call.describe()on each field for user guidance, and wrap fields withcompletable()to enable autocompletion.Async callback that generates the prompt. Required on this interface; omit it (and pass the callback separately) by usingPromptDefinitionWithoutCallback.
PromptCallback
The function signature for a prompt’s handler.EnhancedPromptContext as an optional second parameter, and returns a promise. The context exposes auth (when OAuth is configured), req (the Hono request), and client (a capability checker). Parameters are checked bivariantly so you can freely destructure the argument object.
The return type is a union: a CallToolResult, a GetPromptResult, or a TypedCallToolResult<any>. In practice this means you can return a response helper such as text() or markdown(), or return a GetPromptResult object literal with a messages array. See PromptResult for the shape server.prompt() ultimately sends.
SignatureType of the validated argument object. Inferred from the definition’sschema.Whether OAuth is configured, which controls availability ofctx.auth.
PromptResult
The value a prompt resolves to. An alias ofGetPromptResult.
GetPromptResult, re-exported from the MCP SDK for convenience. Use it wherever you want to refer to the result a prompt produces. It is the exact same type as GetPromptResult; the two are interchangeable.
GetPromptResult
The structured result returned to a client for aprompts/get request.
@modelcontextprotocol/sdk. It carries an array of messages plus an optional description and _meta. Each message has a role of "user" or "assistant" and a content object whose type is one of "text", "image", "audio", or an embedded resource. When server.prompt() detects a returned value with a messages array it forwards it unchanged; otherwise it converts the value (a CallToolResult from a response helper) into this shape.
SignatureOrdered list of messages that make up the prompt. Each is{ role: "user" | "assistant"; content: ... }.Optional human-readable description of the prompt result.Optional protocol metadata.
Completable
A type alias for a schema that has completion metadata attached.completable(). Use it when you need to annotate or reference a completable schema’s type. It is generic over the wrapped Zod schema type T.
SignatureThe wrapped Zod schema type.
CompletionContext
Context passed to a completion callback, exposing the other argument values.completable(). It carries the other argument values already supplied for the same prompt or resource template, which lets you produce contextual suggestions (for example, narrowing project suggestions by an earlier userId). The arguments property is optional, so guard for undefined before reading from it.
SignatureOther argument values from the same prompt or resource template. Useful for contextual completion based on previously provided values.