spences10/mcp-svelte-docs
mcp-svelte-docs is hosted online, so all tools can be tested directly either in theInspector tabor in theOnline Client.
If you are the rightful owner of mcp-svelte-docs and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
A Model Context Protocol (MCP) server that provides a comprehensive reference guide for Svelte 5, helping LLMs provide accurate guidance when users are working with Svelte.
Try mcp-svelte-docs with chat:
Has a README
Github repo has a README.md.
Has a License
Github repo has license info.
Server can be inspected
View server inspector
Server schema can be extracted
Can get at lease one tool info from the README or server.
Online hosted on MCPHub
Can be automatically deployed by MCPHub.
Has social accounts
Do not have any social accounts.
Claimed by the author or certified by MCPHub
If you are the author, claim authorship
AI Evaluation ReportTotal Score: 9/10
The agent demonstrates a comprehensive understanding of Svelte 5 features, particularly focusing on runes, snippets, and migration from Svelte 4. It effectively identifies common mistakes and provides clear, actionable advice to avoid them. The explanations are detailed and include examples, enhancing clarity and practical application. However, the responses could be improved by including more varied examples and a deeper dive into edge cases or less common scenarios. Overall, the agent excels in delivering relevant and structured information, making it a valuable resource for Svelte 5 developers.
Test case 1
Score: 9/10What are the common mistakes developers make when using the $props rune in Svelte 5, and how can they be avoided?Here are some common mistakes developers make when using the
$propsrune in Svelte 5, along with strategies to avoid them:- Forgetting to Destructure Props
- Incorrect Usage: Using the entire props object without destructuring means changes to individual props won’t trigger reactivity.
- Correct Usage: Destructure the props you need to access them reactively.
- Not Providing Default Values
- Incorrect Usage: Not providing default values might cause errors if props are undefined.
- Correct Usage: Always provide default values for optional props to prevent errors.
- Forgetting to Use
$bindablefor Two-Way Binding- Incorrect Usage: Not using
$bindablemeans changes won’t update the parent component. - Correct Usage: Use the
$bindablerune to enable two-way binding, allowing the child component to update the parent’s value.
- Incorrect Usage: Not using
- Modifying Props Directly
- Incorrect Usage: Modifying a prop directly treats props as mutable.
- Correct Usage: Treat props as immutable, create a new object, and use a callback prop to inform the parent component of the change.
- Not Using TypeScript for Complex Props
- Incorrect Usage: Not using TypeScript might cause runtime errors due to lack of type checking.
- Correct Usage: Use TypeScript for complex props to prevent runtime errors and improve developer experience with better autocompletion and documentation. By avoiding these common mistakes, developers can create more robust, maintainable, and reactive components in Svelte 5.
- Forgetting to Destructure Props
Test case 2
Score: 9/10How do snippets in Svelte 5 enhance code reusability and flexibility compared to slots in Svelte 4, and can you provide an example of their usage?Snippets in Svelte 5 enhance code reusability and flexibility compared to slots in Svelte 4 by allowing reusable chunks of markup that can be passed to components, accepting parameters for greater customization, having lexical scoping rules to reduce naming conflicts, and supporting recursive capabilities for rendering hierarchical data. Example usage includes defining snippets in a parent component and rendering them in a child component, as shown in the provided code snippets for header, default content, and item rendering.
Test case 3
Score: 10/10What are the key differences between the `$props` rune in Svelte 5 and the `export let` syntax in Svelte 4, and how does `$props` improve component property management?Key Differences between
$propsin Svelte 5 andexport letin Svelte 4- Declaration Method:
- Svelte 4: Uses the
export letsyntax to declare properties for components. - Svelte 5: Introduces the
$propsrune, which allows for a more dynamic and flexible approach to handling component properties.
- Svelte 4: Uses the
- Destructuring:
- Svelte 4: Properties must be declared individually with
export let, which can lead to repetitive code. - Svelte 5: With
$props, properties can be destructured directly from the result of$props(), making it more concise and readable. For example:let { name, age = 21} = $props();
- Svelte 4: Properties must be declared individually with
- Default Values and Renaming:
- Svelte 4: Default values must be set separately, and renaming properties requires additional syntax.
- Svelte 5: Supports default values and renaming in a single line, enhancing clarity:
let { class: className, age = 21} = $props();
- Rest Props:
- Svelte 4: Handling additional properties requires manual management.
- Svelte 5: Easily collect remaining properties using the rest operator:
let { id, ...rest} = $props();
- Bindable Props:
- Svelte 4: Bindable properties must be explicitly defined.
- Svelte 5: Introduces
$bindablefor easier binding:let { value = $bindable(0)} = $props();
Improvements in Component Property Management with
$props- Efficiency: The
$propsrune streamlines the declaration and management of component properties, reducing boilerplate code. - Readability: By allowing destructuring and default values to be handled in one place, code becomes cleaner and easier to read.
- Flexibility: The ability to handle rest props and bindable props directly enhances the flexibility of components, allowing for better integration and usage in larger applications.
- Type Safety: Using TypeScript in conjunction with
$propscan improve type safety and developer experience. Overall,$propsin Svelte 5 significantly enhances the way components manage properties, making it a more powerful feature compared to theexport letsyntax used in Svelte 4.
- Declaration Method:
Test case 4
Score: 8/10What are the common mistakes developers make when using the $state rune in Svelte 5?Here are some common mistakes developers make when using the
$staterune in Svelte 5:- Exporting State Variables Directly: Exporting a stateful variable directly loses its reactivity when imported elsewhere. Instead, export functions that access and modify the state.
- Using Object Getters/Setters Incorrectly: Using getters and setters maintains reactivity when the object is used in other components, ensuring state is accessed and modified correctly.
- Mutating State Objects Directly: Avoid direct mutations; create new objects for state changes to make them more predictable and reduce bugs.
- Forgetting to Use
$state.rawfor Large Collections: For large collections, using$state.rawis more performant as it only triggers reactivity upon reassignment, not on individual property changes. - Circular Dependencies in Derived Values: Circular dependencies can lead to infinite update loops. Ensure a unidirectional reactive flow with clear inputs and outputs.
Test case 5
Score: 9/10What are the key differences between Svelte 5 snippets and Svelte 4 slots, and how can snippets be effectively utilized in a Svelte 5 project?Key Differences Between Svelte 5 Snippets and Svelte 4 Slots
- Definition and Purpose:
- Slots in Svelte 4 were used to define placeholder content within a component, allowing customization of specific parts of the component's layout.
- Snippets in Svelte 5 serve a similar purpose but provide enhanced flexibility by allowing you to define reusable chunks of markup that can be passed as props to components.
- Syntax:
- In Svelte 4, slots were declared using the
<slot>tag:<slot name="header">Default header</slot> - In Svelte 5, snippets are defined using
{#snippet ...}syntax:{#snippet header()}<h1>Title</h1>{/snippet}
- In Svelte 4, slots were declared using the
- Rendering:
- Svelte 4 required you to use the
<slot>tag directly in the markup. - In Svelte 5, you use the
{@render ...}directive to render snippets:{@render header?.()}
- Svelte 4 required you to use the
- Scope:
- Snippets have lexical scoping, meaning they are only visible in the scope they are defined in. This makes them more predictable compared to slots.
- Recursive and Nested Snippets:
- Snippets allow recursive definitions, enabling you to define complex structures more easily. For example, you can pass a snippet that references itself to create a tree structure.
Effective Utilization of Snippets in Svelte 5
To effectively utilize snippets in your Svelte 5 projects, consider the following best practices:
- Reduce Duplication:
- Use snippets to encapsulate reusable markup components, reducing redundancy across your templates. This leads to cleaner and more maintainable code.
- Parameterization:
- Make snippets flexible by passing parameters. This allows you to customize snippets based on the context where they are used.
- Use with Components:
- Pass snippets as props to components. This enables you to keep your components generic and reusable while configuring them with specific snippets.
- Leverage Recursive Snippets:
- For hierarchical data structures, utilize recursive snippets to render nested items. This is useful for structures like trees or nested lists.
- Testing and Debugging:
- As with any new feature, ensure you thoroughly test snippets in various scenarios to identify potential issues early.
- Definition and Purpose: