API →.md

@lazarv/react-server/mcp

Model Context Protocol primitives. Build typed tools, resources, and prompts, then expose them through an MCP server route handler.

function createPrompt<S extends InputSchemaShape, R>(def: PromptDefinition<S, R>): (input: { [K in keyof S]: z.infer<S[K]>; }) => Promise<R>;

Creates a prompt that can be used in the Model Context Protocol (MCP). The prompt can be used to gather input from the user and return a result based on the provided input schema.

Parameters

Returns — A function that takes input matching the schema and returns a promise that resolves to the result of the prompt's action.

function createResource<T extends string & {}, R>(def: ResourceDefinition<T, R>): (input: ParamsFromTemplate<T>) => Promise<R>;

Creates a resource that can be used in the Model Context Protocol (MCP). The resource can be accessed using a template string, allowing for dynamic parameters.

Parameters

Returns — A function that takes input matching the template parameters and returns a promise that resolves to the result of the resource's action.

function createServer<T, R, P>({ tools, resources, prompts, }: { tools?: T; resources?: R; prompts?: P; }): (context: HttpContext) => Promise<Response>;

Creates a Model Context Protocol (MCP) server that can handle requests and responses. The server can be configured with tools, resources, and prompts.

Parameters

Returns — A function that takes an HttpContext and returns a promise that resolves to a Response. A @lazarv/react-server server middleware can use this function to handle requests.

function createTool<S extends InputSchemaShape, R>(def: ToolDefinition<S, R>): (input: { [K in keyof S]: z.infer<S[K]>; }) => Promise<R>;

Creates a tool that can be used in the Model Context Protocol (MCP). The tool can be used to perform actions or retrieve data based on the provided input schema.

Parameters

Returns — A function that takes input matching the schema and returns a promise that resolves to the result of the tool's action.

function isMCPCall(): boolean;

Checks if the current call is an MCP call. This function can be used to determine if the current request is being handled by an MCP server.

Returns — true if the current call is an MCP call, otherwise false.

function useMCPServer(): McpServer | undefined;

Retrieves the current Model Context Protocol (MCP) server from the request context. This function is typically used within a server-side component to access the MCP server instance.

Returns — The current MCP server instance, or undefined if not available.