mcp-use
Version:
Opinionated MCP Framework for TypeScript (@modelcontextprotocol/sdk compatible) - Build MCP Agents, Clients and Servers with support for ChatGPT Apps, Code Mode, OAuth, Notifications, Sampling, Observability and more.
61 lines • 2.72 kB
TypeScript
import type { z } from "zod";
import type { GetPromptResult } from "@mcp-use/modelcontextprotocol-sdk/types.js";
import type { PromptDefinition, PromptDefinitionWithoutCallback, PromptCallback } from "../types.js";
export interface PromptServerContext {
server: {
registerPrompt(name: string, metadata: {
title?: string;
description: string;
argsSchema: z.ZodObject<any> | Record<string, z.ZodSchema> | undefined;
}, getPromptCallback: (params: Record<string, unknown>, extra?: any) => Promise<GetPromptResult>): void;
};
registeredPrompts: string[];
createParamsSchema: (args: import("../types/common.js").InputDefinition[]) => Record<string, z.ZodSchema>;
convertZodSchemaToParams: (schema: z.ZodObject<any>) => Record<string, z.ZodSchema>;
}
/**
* Define a prompt template
*
* Registers a prompt template with the MCP server that clients can use to generate
* structured prompts for AI models. Prompts can now use the same response helpers
* as tools (text(), object(), markdown(), etc.) for a unified API.
*
* Supports two patterns:
* 1. Old API: Single object with cb property
* 2. New API: Definition object + separate callback (like tools and resources)
*
* @param promptDefinition - Configuration object containing prompt metadata
* @param promptDefinition.name - Unique identifier for the prompt template
* @param promptDefinition.description - Human-readable description of the prompt's purpose
* @param promptDefinition.args - Array of argument definitions (legacy, use schema instead)
* @param promptDefinition.schema - Zod object schema for input validation (preferred)
* @param callback - Optional separate callback function (new API pattern)
* @returns The server instance for method chaining
*
* @example
* ```typescript
* // New API: Using response helpers (recommended)
* server.prompt(
* {
* name: 'code-review',
* description: 'Generates a code review prompt',
* schema: z.object({ language: z.string(), code: z.string() })
* },
* async ({ language, code }) => text(`Please review this ${language} code:\n\n${code}`)
* )
*
* // Old API: Still supported for backward compatibility
* server.prompt({
* name: 'greeting',
* args: [{ name: 'name', type: 'string', required: true }],
* cb: async ({ name }) => ({
* messages: [{
* role: 'user',
* content: { type: 'text', text: `Hello, ${name}!` }
* }]
* })
* })
* ```
*/
export declare function registerPrompt(this: PromptServerContext, promptDefinition: PromptDefinition | PromptDefinitionWithoutCallback, callback?: PromptCallback): PromptServerContext;
//# sourceMappingURL=index.d.ts.map