import { AuthInfo } from "./schemas/auth.js"; import { z, ZodRawShape } from "zod"; import { McpServer, RegisteredTool } from "@modelcontextprotocol/sdk/server/mcp.js"; import { CallToolResult, ServerRequest, ServerNotification, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js"; import { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js"; /** * Enhanced request handler extra that includes auth info and outbound token function */ export interface AuthenticatedExtra extends RequestHandlerExtra { authInfo: AuthInfo; getOutboundToken: (appId: string, scopes?: string[]) => Promise; } /** * Type helper for inferring Zod schema output */ export type Inferred = S extends ZodRawShape ? z.infer> : void; /** * Function signature for getting outbound tokens within a tool */ export type GetOutboundTokenFunction = (appId: string, scopes?: string[]) => Promise; /** * Validates scopes against the authenticated user's scopes */ export declare function validateScopes(authInfo: AuthInfo, requiredScopes?: string[]): { isValid: boolean; error?: string; }; /** * Checks if the user has a specific scope */ export declare function hasScope(authInfo: AuthInfo, scope: string): boolean; /** * Checks if the user has any of the provided scopes */ export declare function hasAnyScope(authInfo: AuthInfo, scopes: string[]): boolean; /** * Checks if the user has all of the provided scopes */ export declare function hasAllScopes(authInfo: AuthInfo, scopes: string[]): boolean; export declare function registerAuthenticatedTool(name: string, config: { title?: string; description?: string; inputSchema: I; outputSchema?: O; annotations?: ToolAnnotations; }, cb: (args: z.infer>, extra: AuthenticatedExtra) => CallToolResult | Promise, requiredScopes?: string[]): (server: McpServer) => RegisteredTool; export declare function registerAuthenticatedTool(name: string, config: { title?: string; description?: string; inputSchema?: undefined; outputSchema?: O; annotations?: ToolAnnotations; }, cb: (extra: AuthenticatedExtra) => CallToolResult | Promise, requiredScopes?: string[]): (server: McpServer) => RegisteredTool; /** * Defines an authenticated tool using object-based configuration. * This provides a more ergonomic API compared to registerAuthenticatedTool. * * @example * ```typescript * const getUserTool = defineTool({ * name: "get_user", * description: "Get user information", * input: z.object({ userId: z.string() }), * scopes: ["profile"], * handler: async (args, extra) => { * const externalToken = await extra.getOutboundToken('external-app-id', ['read']); * return { * content: [{ type: "text", text: JSON.stringify({ userId: args.userId }) }] * }; * } * }); * ``` */ export declare function defineTool(cfg: { name: string; title?: string; description?: string; input?: I; output?: O; scopes?: string[]; annotations?: ToolAnnotations; handler: I extends ZodRawShape ? (args: z.infer>, extra: AuthenticatedExtra) => CallToolResult | Promise : (extra: AuthenticatedExtra) => CallToolResult | Promise; }): (server: McpServer) => RegisteredTool; //# sourceMappingURL=utils.d.ts.map