@lazarv/react-server/mcp
この API リファレンスはまだ翻訳されていません。以下は英語版の内容です。
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
def— The definition of the prompt, including its ID, title, optional description, input schema, and handler function.
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
def— The definition of the resource, including its ID, template, list function, optional completion functions for parameters, title, description, and handler function.
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
tools— An optional object containing tools defined usingcreateTool.resources— An optional object containing resources defined usingcreateResource.prompts— An optional object containing prompts defined usingcreatePrompt.
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
def— The definition of the tool, including its ID, title, description, input schema, and handler function.
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.