import type { PostHog } from 'posthog-node'; import { deriveSessionIdFromMCPSession, newSessionId } from './extensions/session'; import type { McpAnalytics, MCPAnalyticsOptions } from './types'; /** * Instruments an MCP server so PostHog auto-captures tool calls, tool listings, initialize * requests, identity, and exceptions. Returns a handle whose `capture()` method records * custom events, so you don't pass the server around after wiring it up. * * **Idempotent per server instance.** Per-server tracking state lives in a module-level * `WeakMap` (`internal.ts`); a second `instrument()` call * on the same server reuses it rather than double-wrapping handlers. * * @param server - The MCP server to instrument (low-level `Server` or high-level `McpServer`). * @param posthog - A `posthog-node` client you construct and own (matching `@posthog/ai`); call `posthog.shutdown()` on exit to flush. * @param options - Optional configuration. See `MCPAnalyticsOptions`. * * @example * ```ts * import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js" * import { PostHog } from "posthog-node" * import { instrument } from "@posthog/mcp" * * const posthog = new PostHog(process.env.POSTHOG_PROJECT_TOKEN, { host: "https://us.i.posthog.com" }) * const server = new McpServer({ name: "my-mcp", version: "1.0.0" }) * const analytics = instrument(server, posthog) * * await analytics.capture({ event: "feedback_submitted", properties: { rating: 5 } }) * ``` */ declare function instrument(server: unknown, posthog: PostHog, options?: MCPAnalyticsOptions): McpAnalytics; /** * A point-free `(server) => server` helper for framework server-mutation hooks (e.g. * `@rekog/mcp-nest`'s `serverMutator`). It instruments the server and returns it, so you * don't trip over {@link instrument} returning the analytics handle rather than the server — * the bare `(s) => instrument(s, posthog)` would replace the server with the handle. * * @example * ```ts * McpModule.forRoot({ serverMutator: instrumentMutator(posthog) }) * ``` * * Need the handle for custom events? Call {@link instrument} directly inside your own mutator * and return the server. See https://posthog.com/docs/mcp-analytics/installation. * * @param posthog - A `posthog-node` client you construct and own. * @param options - Optional configuration. See `MCPAnalyticsOptions`. * @returns A `(server) => server` mutator that instruments the server and returns it. */ declare function instrumentMutator(posthog: PostHog, options?: MCPAnalyticsOptions): (server: TServer) => TServer; export { deriveSessionIdFromMCPSession, newSessionId }; export { MCP_SESSION_HEADER, decodeSessionId, encodeSessionId, type SessionTokenPayload, } from './extensions/session-token'; export { POSTHOG_MCP_ANALYTICS_SOURCE, PostHogMCPAnalyticsEvent, PostHogMCPAnalyticsProperty, } from './extensions/constants'; export { getRequestHeaders } from './extensions/request-headers'; export { PostHogMCP, type PostHogMCPOptions } from './extensions/posthog-mcp'; export { getMoreToolsResult } from './extensions/tools'; export { setLogger } from './extensions/logger'; export { PostHog, type PostHogOptions } from 'posthog-node'; export type { BeforeSendFn, CaptureEventData, InitializeCaptureData, McpAnalytics, McpCaptureCommon, MCPAnalyticsContextOptions, MCPAnalyticsIntentSource, MCPAnalyticsOptions, MissingCapabilityCaptureData, PreparedToolCall, PrepareToolListOptions, RequestHeaderBag, ToolCallCaptureData, ToolsListCaptureData, UserIdentity, } from './types'; export type IdentifyFunction = MCPAnalyticsOptions['identify']; export { instrument, instrumentMutator }; //# sourceMappingURL=index.d.ts.map