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
| Name | Required | Description | Default |
|---|---|---|---|
| featureName | Yes | Feature to get examples for (e.g., "email-password", "github", "two-factor") | |
| framework | No | Optional framework filter for examples |
Implementation Reference
- src/index.ts:458-475 (handler)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}"`); } }
- src/index.ts:477-508 (helper)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);
- src/index.ts:180-193 (schema)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"], },