mcpay
Version:
SDK and CLI for MCPay functionality - MCP servers with payment capabilities
38 lines • 1.5 kB
JavaScript
import { createMcpHandler as baseCreateMcpHandler } from "mcp-handler";
/** Preserve tuple info so TS can infer exact augmented type. */
export function makePlugins(...plugins) {
return plugins;
}
/** Compose to a single plugin (right-to-left) if you like function style. */
export function composePlugins(...plugins) {
return (server) => {
let result = server;
for (let i = plugins.length - 1; i >= 0; i--) {
result = plugins[i]?.(result);
}
return result;
};
}
/**
* 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(initializeServer, serverOptions, config) {
return baseCreateMcpHandler(async (server) => {
// Apply plugins in-place (support plugins that return same instance or a new one)
const ws = (serverOptions?.plugins ?? []);
let augmented = server;
for (const w of ws) {
const out = w(augmented);
// If plugin returns a new object, keep it; otherwise keep the original.
augmented = (out ?? augmented);
}
// Call the user's initializer with the *augmented* type
await initializeServer(augmented);
},
// Pass through options and config unchanged
serverOptions, config);
}
//# sourceMappingURL=index.js.map