import { ServerContext } from "@modelcontextprotocol/server"; interface PromptData { toolName: string; userPrompt: string; } interface IntentMiddlewareOptions { handler?: (prompt: PromptData) => Promise | void; /** When provided, only these tool names have the `user_intent` field injected and their prompts captured; all other tools are left untouched. */ tools?: string[]; /** Maps tool names to an existing argument (e.g. `query`) captured as the intent; for these tools no synthetic `user_intent` argument is injected and the value is read from the call arguments without being stripped. */ argumentNameOverride?: Record; } /** Structurally compatible with `skybridge/server`'s `McpMiddlewareFn` so skybridge users can still pass the result into `server.mcpMiddleware(...)`. */ type McpMiddlewareFn = (request: { method: string; params: Record; }, extra: unknown, next: () => Promise) => Promise | unknown; /** Captures the user's natural-language intent behind each tool call: the LLM fills in `user_intent` from the original user message, which the server has no other way to access. */ export declare function intentMiddleware(options?: IntentMiddlewareOptions): McpMiddlewareFn; interface CaptureOptions { message?: string; /** Duration of the operation the event describes, in milliseconds. */ duration?: number; isError?: boolean; error?: string; /** Freeform event detail. Not indexed — filtering on a property key is a query-time scan. */ properties?: Record; } interface Analytics { /** Records a custom event on the current session's timeline, interleaved with tool calls. */ capture(name: string, options?: CaptureOptions): void; /** Replaces the current request user's trait snapshot (e.g. email, name, plan); the target user is resolved by Alpic from the request auth context — no id or sessionId is passed. */ identify(traits: Record): void; } interface AnalyticsExtra extends ServerContext { analytics: Analytics; } interface AnalyticsEvent extends CaptureOptions { name: string; timestamp: number; } interface AnalyticsBatch { events: AnalyticsEvent[]; traits?: Record; } interface AnalyticsMiddlewareOptions { /** Receives each request's analytics locally, whether or not the server is hosted by Alpic. */ handler?: (batch: AnalyticsBatch) => Promise | void; } /** Buffers `extra.analytics.capture(...)` / `identify(...)` calls during each request; on Alpic, private environment-provided `_meta` keys carry them to the proxy for ingestion, while locally a handler receives them without exposing analytics in the MCP response. */ export declare function analyticsMiddleware(options?: AnalyticsMiddlewareOptions): McpMiddlewareFn; interface FeedbackData { content: string; source: "model" | "user"; } interface FeedbackMiddlewareOptions { /** Invoked with the user's feedback in addition to Alpic's dashboard delivery — the middleware still attaches the feedback to the response `_meta`. */ handler?: (feedback: FeedbackData) => Promise | void; } /** Injects a `send_feedback` tool at `tools/list` time and short-circuits calls to it at `tools/call` time (the tool has no server-side handler), invoking `options.handler` or attaching the feedback to the response `_meta`. */ export declare function feedbackMiddleware(options?: FeedbackMiddlewareOptions): McpMiddlewareFn; /** Injects a `send_feedback` tool by patching the server's `tools/list` and `tools/call` handlers, surfacing captured feedback via `options.handler` (or via the response `_meta` when `ALPIC_FEEDBACK_META_KEY` is set). */ export declare const captureFeedback: (server: object, options?: FeedbackMiddlewareOptions) => void; /** Captures the user's natural-language intent behind each tool call by patching the server's `tools/list` and `tools/call` handlers, surfacing it via `options.handler` (or via the response `_meta` when `ALPIC_INTENT_META_KEY` is set). */ export declare const captureIntents: (server: object, options?: IntentMiddlewareOptions) => void; /** Enables custom analytics events by patching the server's `tools/call` handlers so tool handlers can call `extra.analytics.capture(...)` / `identify(...)`; pass `options.handler` to receive analytics when running outside Alpic. */ export declare const track: (server: object, options?: AnalyticsMiddlewareOptions) => void; export type { Analytics, AnalyticsBatch, AnalyticsEvent, AnalyticsExtra, AnalyticsMiddlewareOptions, CaptureOptions, FeedbackData, FeedbackMiddlewareOptions, IntentMiddlewareOptions, McpMiddlewareFn, PromptData };