Skip to main content
Glama

get_auth_examples

Retrieve authentication code examples and snippets for Better Auth features like email-password, GitHub, or two-factor authentication to implement secure authentication in web applications.

Instructions

Get usage examples and code snippets for Better Auth features

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
featureNameYesFeature to get examples for (e.g., "email-password", "github", "two-factor")
frameworkNoOptional framework filter for examples

Implementation Reference

  • Primary handler function that executes the get_auth_examples tool. Validates input, fetches examples via helper, and formats success response.
    /** * Handle the get_auth_examples tool request */ private async handleGetAuthExamples(args: any) { const featureName = this.validateFeatureName(args); const framework = args?.framework; try { const examples = await this.fetchAuthExamples(featureName, framework); return this.createSuccessResponse({ feature: featureName, framework: framework || "all", examples, }); } catch (error) { this.handleAxiosError(error, `Examples for "${featureName}"`); } }
  • Helper method that fetches code examples for a Better Auth feature from documentation, combining general feature examples and optional framework-specific examples using Cheerio for parsing.
    /** * Fetch examples for a specific feature */ private async fetchAuthExamples(featureName: string, framework?: string): Promise<BetterAuthExample[]> { const examples: BetterAuthExample[] = []; // Get feature details first const feature = await this.fetchFeatureDetails(featureName); if (feature.examples) { examples.push(...feature.examples); } // If framework specified, also get framework-specific examples if (framework) { try { const exampleUrl = `${this.BETTER_AUTH_DOCS_URL}/docs/examples/${framework}`; const response = await this.axiosInstance.get(exampleUrl); const $ = cheerio.load(response.data); const frameworkExamples = this.extractExamples($); examples.push(...frameworkExamples.map(ex => ({ ...ex, framework, }))); } catch (error) { // Continue if framework examples not found } } return examples; }
  • src/index.ts:177-194 (registration)
    Registration of the get_auth_examples tool in the tools list returned by list_tools, including name, description, and input schema.
    { name: "get_auth_examples", description: "Get usage examples and code snippets for Better Auth features", inputSchema: { type: "object", properties: { featureName: { type: "string", description: "Feature to get examples for (e.g., \"email-password\", \"github\", \"two-factor\")", }, framework: { type: "string", description: "Optional framework filter for examples", }, }, required: ["featureName"], }, },
  • src/index.ts:229-230 (registration)
    Dispatch case in the call_tool request handler that routes get_auth_examples calls to the specific handler method.
    case "get_auth_examples": return await this.handleGetAuthExamples(request.params.arguments);
  • Input schema defining the expected arguments: required featureName (string) and optional framework (string).
    inputSchema: { type: "object", properties: { featureName: { type: "string", description: "Feature to get examples for (e.g., \"email-password\", \"github\", \"two-factor\")", }, framework: { type: "string", description: "Optional framework filter for examples", }, }, required: ["featureName"], },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dabhivijay2478/better-auth-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server