UNPKG

mcpay

Version:

SDK and CLI for MCPay functionality - MCP servers with payment capabilities

25 lines 1.95 kB
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { createMcpHandler as baseCreateMcpHandler } from "mcp-handler"; type InnerServerOptions = NonNullable<Parameters<typeof baseCreateMcpHandler>[1]>; type Config = NonNullable<Parameters<typeof baseCreateMcpHandler>[2]>; /** A plugin takes a server and returns an augmented server type. */ export type ServerPlugin<S extends McpServer = McpServer, R extends McpServer = S> = (server: S) => R; /** Apply a tuple of plugins to a server type (left-to-right) for typing. */ export type ApplyPlugins<S extends McpServer, W extends readonly ServerPlugin[]> = W extends readonly [] ? S : W extends readonly [infer F, ...infer R] ? F extends ServerPlugin<infer _In, infer Out> ? ApplyPlugins<Out, Extract<R, readonly ServerPlugin[]>> : S : S; /** Preserve tuple info so TS can infer exact augmented type. */ export declare function makePlugins<W extends readonly ServerPlugin[]>(...plugins: W): W; /** Compose to a single plugin (right-to-left) if you like function style. */ export declare function composePlugins<W extends readonly ServerPlugin[]>(...plugins: W): <S extends McpServer>(server: S) => ApplyPlugins<S, W>; export type ServerOptions<W extends readonly ServerPlugin[] = []> = InnerServerOptions & { /** Dynamically augment the McpServer instance with your plugins. */ plugins?: W; }; /** * createMcpHandlerWithPlugins * Wraps your existing handler to: * - apply plugins at runtime (mutating/augmenting the same server instance) * - thread plugin types to the `initializeServer` callback (no casts needed) */ export default function createMcpHandler<W extends readonly ServerPlugin[] = []>(initializeServer: ((server: ApplyPlugins<McpServer, W>) => Promise<void>) | ((server: ApplyPlugins<McpServer, W>) => void), serverOptions?: ServerOptions<W>, config?: Config): (request: Request) => Promise<Response>; export {}; //# sourceMappingURL=index.d.ts.map