@auth0/auth0-mcp-server
Version:
Auth0 Model Context Protocol (MCP) Server (Beta) — A secure and extendable implementation of an MCP server that provides AI assistants with controlled access to the Auth0 Management API through natural language. This project is in beta and not intended fo
88 lines (87 loc) • 4.46 kB
TypeScript
import { HandlerConfig, HandlerRequest, HandlerResponse, ServerMode, Tool } from './types.js';
/**
* Filters the provided tools collection based on specified glob patterns and readOnly flag.
* This function processes the input patterns against available tools to determine
* which tools should be returned. It handles special cases like wildcard patterns,
* empty pattern arrays, and pattern matching errors. When readOnly is true,
* it only returns tools that have _meta.readOnly set to true or tools that follow read-only patterns.
*
* IMPORTANT: The readOnly flag takes priority over pattern matching for security reasons.
* Even if patterns match non-read-only tools, when readOnly=true is specified,
* only read-only tools will be returned.
*
* @param allTools - Complete collection of available tools to be filtered
* @param patterns - Optional glob patterns to filter tools by (e.g., 'auth0*', 'jwt-*')
* If omitted or empty, all tools will be returned
* A single '*' pattern will return all tools
* @param readOnly - Optional flag to only return read-only tools
* When true, only returns tools marked as readOnly
* Takes priority over pattern matching for security
* @returns Array of Tool objects that match the specified criteria
* Returns all tools if no patterns provided or on error
*
* @example
* // Return all tools that start with "auth"
* const authTools = getAvailableTools(tools, ['auth*']);
*
* @example
* // Return all read-only tools (regardless of pattern matching)
* const readOnlyTools = getAvailableTools(tools, ['*'], true);
*
* @example
* // Return only read-only tools that match the pattern
* // Note: --read-only takes priority, so even if the pattern matches non-read-only tools,
* // only the read-only ones will be returned
* const readOnlyAuthTools = getAvailableTools(tools, ['auth0_*_application'], true);
*/
export declare function getAvailableTools(allTools: Tool[], patterns?: string[], readOnly?: boolean): Tool[];
/**
* Validates tool patterns against available tools to ensure each pattern matches at least one tool.
* This function verifies that each provided pattern (including glob patterns) corresponds to
* at least one available tool, throwing specific errors for different validation scenarios.
*
* @param patterns - Array of tool name patterns to validate
* Can include glob patterns with wildcards (e.g., 'auth0*')
* Empty array or undefined will skip validation
* @param availableTools - Collection of Tool objects to validate patterns against
*
* @throws {Error} If availableTools is not a valid array or is empty
* @throws {Error} If any pattern doesn't match at least one tool name, with different
* error messages for exact matches vs. wildcard patterns
*
* @example
* // Validate specific tool names
* validatePatterns(['auth0-jwt', 'auth0-management'], tools);
*
* @example
* // Validate with glob patterns
* validatePatterns(['auth0*', 'jwt-*'], tools);
*
* @see {@link Glob} for the pattern matching implementation
* @see {@link getAvailableTools} for filtering tools using these patterns
*/
export declare function validatePatterns(patterns: string[], availableTools: Tool[]): void;
/**
* Returns all tools, or a filtered subset based on mode and scope options.
* In StreamableHttp mode, local-only tools (e.g. auth0_save_credentials_to_file) are excluded.
* When withScope is true, tools without _meta.requiredScopes are excluded.
*
* @param options.mode - Server mode; StreamableHttp excludes local-only tools
* @param options.withScope - When true, only returns tools that declare requiredScopes in _meta.
*
*/
export declare function getTools(options?: {
mode?: ServerMode;
withScope?: boolean;
}): Tool[];
/**
* Returns all handlers, or a mode/headers-filtered subset.
* In StreamableHttp mode, local-only tool handlers are excluded and each handler is wrapped
* to auto-inject the mode into HandlerConfig so handlers can adapt their responses.
* Headers provided here are merged into every handler invocation (per-call config.headers
* take precedence over these defaults).
*/
export declare function getHandlers(options?: {
mode?: ServerMode;
headers?: Record<string, string>;
}): Record<string, (request: HandlerRequest, config: HandlerConfig) => Promise<HandlerResponse>>;