import type { App, BeforeRequestMiddleware, Bundle, Create, Function, Search, Trigger, ZObject } from 'zapier-platform-core'; import { Client } from '@modelcontextprotocol/sdk/client/index.js'; import { Tool } from '@modelcontextprotocol/sdk/types.js'; import { Config, AppMiddleware, GetAccessTokenResult, ClientInstance, CallToolOptions } from './types.js'; /** * Main class for integrating with Model Context Protocol (MCP) servers in Zapier integrations. * * @example * ```ts * import { MCPIntegration } from '@zapier/mcp-integration'; * * const mcp = new MCPIntegration({ * name: 'my-integration', * version: '1.0.0', * serverUrl: process.env.SERVER_URL, * transport: 'sse', * }); * ``` */ export declare class MCPIntegration { private client; private config; /** * Creates a new MCPIntegration instance for MCP server integration. * * @param config - Configuration options * @param config.name - Name of the integration * @param config.version - Version of the integration * @param config.serverUrl - URL of the MCP server * @param config.transport - Transport protocol ('sse' or 'streamable') * @param config.auth - Authentication configuration (optional) * @param config.transformer - Function to transform actions (optional) */ constructor(config?: Partial); /** * Updates the configuration options * * @param config - Partial configuration to merge with existing config */ configure(config: Partial): void; /** * Gets a connected MCP client instance, creating and connecting if necessary. * * @returns Promise that resolves to a connected MCP client */ getConnectedClient(): Promise; /** * SHORTHANDS * * Functions that reduce boilerplate to wire up a MCP powered integration. */ /** * Returns a partial Zapier App configuration with MCP integration setup. * * @param options - Configuration options for the app * @param options.handleAuth - Whether to handle authentication automatically (default: true) * @returns Partial Zapier App configuration with MCP integration * * @example * ```ts * export default defineApp({ * ...mcp.app(), * // your other app configuration * }); * ``` * * @example * ```ts * // Handle authentication yourself * export default defineApp({ * ...mcp.app({ handleAuth: false }), * authentication: yourAuthConfig, * }); * ``` */ defineApp | undefined = undefined, const $Creates extends Record | undefined = undefined, const $Searches extends Record | undefined = undefined>(baseApp: App<$Triggers, $Creates, $Searches>): App<$Triggers, $Creates, $Searches>; /** * Returns middleware for before app execution to configure authentication. * * @returns Middleware function that configures auth from bundle.authData */ defineBeforeApp(): AppMiddleware; /** * Returns cleanup function for after app execution. * * @returns Cleanup function that closes the MCP client connection */ defineAfterApp(): AppMiddleware; /** * Returns OAuth authentication configuration for Zapier. * * @returns OAuth authentication config or undefined */ defineAuthentication(): { type: "oauth2"; test: Function; connectionLabel: Function; oauth2Config: { authorizeUrl: (z: ZObject, bundle: Bundle) => Promise; getAccessToken: (z: ZObject, bundle: Bundle) => Promise; refreshAccessToken: (_z: ZObject, bundle: Bundle) => Promise<{}>; }; } | undefined; /** * Returns middleware for injecting Bearer tokens into API requests. * * @returns Middleware function that adds Authorization header from bundle.authData */ defineBeforeRequest(): BeforeRequestMiddleware; /** * Initiates OAuth authorization flow and returns the authorization URL. * * @param z - Zapier Z object * @param bundle - Zapier bundle with inputData containing redirect_uri and state * @returns Promise that resolves to the OAuth authorization URL * * @example * ```ts * // Used in Zapier OAuth configuration * authentication: { * type: 'oauth2', * oauth2Config: { * authorizeUrl: mcp.authorizeUrl.bind(mcp), * // ... * }, * } * ``` */ authorizeUrl(z: ZObject, bundle: Bundle): Promise; /** * Exchanges OAuth authorization code for access tokens. * * @param z - Zapier Z object * @param bundle - Zapier bundle with inputData containing redirect_uri, state, and code * @returns Promise that resolves to access token result with tokens and client information * * @example * ```ts * // Used in Zapier OAuth configuration * authentication: { * type: 'oauth2', * oauth2Config: { * getAccessToken: mcp.getAccessToken.bind(mcp), * // ... * }, * } * ``` */ getAccessToken(z: ZObject, bundle: Bundle): Promise; /** * Refreshes expired OAuth access tokens using the refresh token. * * @param z - Zapier Z object * @param bundle - Zapier bundle with inputData and authData containing tokens * @returns Promise that resolves to updated token information * * @throws {ExpiredAuthError} When refresh token is missing or refresh fails * * @example * ```ts * // Used in Zapier OAuth configuration * authentication: { * type: 'oauth2', * oauth2Config: { * refreshAccessToken: mcp.refreshAccessToken.bind(mcp), * // ... * }, * } * ``` */ refreshAccessToken(_z: ZObject, bundle: Bundle): Promise<{}>; /** * Returns a test function for verifying MCP server connectivity. * * @returns Function that tests the MCP server connection and returns server info * * @example * ```ts * // Used in Zapier authentication configuration * authentication: { * test: mcp.defineTest(), * // ... * } * ``` */ defineTest(): Function; /** * Returns a function that generates connection labels for Zapier. * * @returns Function that generates a human-readable connection label * * @example * ```ts * // Used in Zapier authentication configuration * authentication: { * connectionLabel: mcp.defineConnectionLabel(), * // ... * } * ``` */ defineConnectionLabel(): Function; /** * PROXIES * * Pretty much 1:1 wrappers on the MCP Client class. */ /** * Gets version information from the MCP server. * * @returns Promise that resolves to server version and metadata * * @example * ```ts * const serverInfo = await mcp.getServerVersion(); * console.log(`Connected to ${serverInfo.name} v${serverInfo.version}`); * ``` */ getServerVersion(): Promise>; /** * Lists available MCP tools with pagination support. * * @param params - Pagination parameters * @param params.cursor - Cursor for pagination (optional) * @returns Promise that resolves to tools and next cursor * * @example * ```ts * const { tools, cursor } = await mcp.listTools(); * console.log(`Found ${tools.length} tools`); * * // Get next page if available * if (cursor) { * const nextPage = await mcp.listTools({ cursor }); * } * ``` */ listTools(params: { cursor?: string; }): Promise<{ tools: Tool[]; cursor: string; }>; /** * Lists all available MCP tools by automatically handling pagination. * * @returns Promise that resolves to array of all available tools * * @example * ```ts * const allTools = await mcp.listAllTools(); * console.log(`Server has ${allTools.length} tools available`); * ``` */ listAllTools(): Promise; /** * Retrieves a specific MCP tool by name. * * @param name - Name of the tool to retrieve * @returns Promise that resolves to the tool if found, undefined otherwise * * @example * ```ts * const weatherTool = await mcp.getTool('get_weather'); * if (weatherTool) { * console.log(weatherTool.description); * } * ``` */ getTool(name: string): Promise; /** * Calls an MCP tool with the specified arguments and options. * * @param params - Tool call parameters and options * @param params.name - Name of the tool to call * @param params.arguments - Arguments to pass to the tool * @param params.error - Whether to throw on MCP errors (default: true) * @param params.parse - Whether to parse JSON responses (default: true) * @param params.filter - JSONata filter expression to apply to the response * @returns Promise that resolves to the tool's response * * @throws {Error} When the tool call fails and error is true * * @example * ```ts * const result = await mcp.callTool({ * name: 'get_weather', * arguments: { location: 'San Francisco' }, * parse: true, * filter: 'data.temperature' * }); * ``` */ callTool(params: CallToolOptions): Promise>>; /** * Closes the MCP client connection and cleans up resources. * * @returns Promise that resolves when the connection is closed * * @example * ```ts * // Usually called automatically via app.afterApp * await mcp.close(); * ``` */ close(): Promise; /** * Gets the transformer from the configuration. * * @returns The transformer if configured, undefined otherwise */ getTransformer(): import("./types.js").Transformer | undefined; /** * PRIVATE */ private getClient; private getConfig; private getConfigValue; private getServerUrl; private getTransport; private getConnectedAuthProvider; private firstLegCacheKey; } //# sourceMappingURL=lib.d.ts.map