svelte_definition
Look up Svelte 5 and SvelteKit definitions from TypeScript declarations, covering runes like $state and $derived, features, and patterns with syntax, quick, or full detail levels.
Instructions
Lookup Svelte 5 & SvelteKit definitions from TypeScript declarations. Covers all runes ($state, $derived, $props, $effect), features (snippets, onclick, component-events), and patterns. Supports syntax/quick/full format for varying detail levels.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| identifier | Yes | Svelte 5 identifier: $state, $derived, $props, $effect, snippets, onclick, component-events | |
| format | No | Output detail level: "syntax" (signature only), "quick" (with example), "full" (complete docs) | full |
Implementation Reference
- src/tools/definition-tools.ts:195-250 (handler)The main execution logic for the svelte_definition tool: validates input, retrieves definition from database, formats output based on 'syntax/quick/full', handles errors with suggestionsasync function definition_handler(args: any) { try { // Validate input const { identifier, format = 'full' } = v.parse( DefinitionSchema, args, ); // Find the definition const definition = get_definition_by_identifier(identifier); if (!definition) { throw create_definition_error(identifier, definitions); } // Validate that definition content exists if ( !definition.content || definition.content.trim().length === 0 ) { throw new Error( `Definition for '${identifier}' exists but appears to be empty. Please try again later or contact support.`, ); } // Format the content based on requested format const formatted_content = format_definition_content( definition.content, format, ); // Add format info for context let response_content = formatted_content; if (format === 'syntax') { response_content += `\n\n*Use format="quick" or format="full" for more details.*`; } else if (format === 'quick') { response_content += `\n\n*Use format="full" for complete documentation.*`; } return { content: [ { type: 'text' as const, text: response_content, }, ], }; } catch (error) { // Re-throw with additional context for debugging const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; throw new Error(`Error in svelte_definition: ${errorMessage}`); } }
- src/tools/definition-tools.ts:16-30 (schema)Valibot input schema defining parameters: identifier (required string) and format (optional: syntax/quick/full)const DefinitionSchema = v.object({ identifier: v.pipe( v.string(), v.minLength(1), v.description( 'Svelte 5 identifier: $state, $derived, $props, $effect, snippets, onclick, component-events', ), ), format: v.pipe( v.optional(v.picklist(['syntax', 'quick', 'full']), 'full'), v.description( 'Output detail level: "syntax" (signature only), "quick" (with example), "full" (complete docs)', ), ), });
- src/tools/definition-tools.ts:298-306 (registration)Tool registration call within register_definition_tools function, specifying name, description, schema, and handlerserver.tool<typeof DefinitionSchema>( { name: 'svelte_definition', description: 'Lookup Svelte 5 & SvelteKit definitions from TypeScript declarations. Covers all runes ($state, $derived, $props, $effect), features (snippets, onclick, component-events), and patterns. Supports syntax/quick/full format for varying detail levels.', schema: DefinitionSchema, }, definition_handler, );
- src/index.ts:64-65 (registration)Top-level call to register the svelte_definition tool during server initialization// Register definition tools (single svelte_definition tool) register_definition_tools(this.server);
- src/tools/definition-tools.ts:37-50 (helper)Helper function to format definition content based on requested detail level (syntax/quick/full)function format_definition_content( content: string, format: FormatType, ): string { switch (format) { case 'syntax': return extract_syntax_only(content); case 'quick': return extract_definition_and_example(content); case 'full': default: return content; } }