svelte-grab
Give coding agents eyes into your Svelte app.
svelte-grab runs inside your Svelte 5 app in dev and answers your coding agent over MCP: what is on the page, which component rendered it, the file and line to edit, its props, state, styles and accessibility, and whether the page still looks right after the edit. Only code running in the page can read the __svelte_meta that Svelte attaches in dev builds, so every element the agent sees comes with its component and source location. The agent stops grepping for "the button in the header" and goes straight to src/lib/Header.svelte:42.
It is not a browser driver. Real clicks, screenshots, viewports and network stay with Playwright MCP / chrome-devtools MCP; every element svelte-grab reports carries a [data-sg-ref="eN"] locator those tools can use. For Svelte docs and code fixes, pair it with the official Svelte MCP.
For humans there is still the original toolbox: Alt+Click any element to copy its component stack, inspect state, styles, accessibility, errors and renders (Human tools). Dev only: every tool turns itself off in production builds.
60-second quickstart
1. Install (the MCP SDK and zod are what svelte-grab-mcp --stdio runs on):
npm install -D svelte-grab @modelcontextprotocol/sdk zod
2. Set up the project:
npx svelte-grab init # --dry-run to preview
init sets the project up for Claude Code and OpenAI Codex at once (what it writes for each): it writes or merges the MCP config (.mcp.json and .codex/config.toml: the svelte-grab server, plus the official Svelte MCP), adds svelteGrab() from svelte-grab/vite to your Vite config, puts <SvelteDevKit enableMcp /> in src/routes/+layout.svelte (or src/App.svelte), gated by dev, copies the agent skills into .claude/skills/ and .agents/skills/ and adds a short svelte-grab section to AGENTS.md. It never replaces existing entries, shows a diff of what it changes and is safe to run twice. With sv, npx sv add svelte-grab does the same, and also adds svelte-grab (plus @modelcontextprotocol/sdk and zod when it writes .mcp.json) as dev dependencies, so step 1 is not needed. The add-on ships inside the svelte-grab package (svelte-grab/sv) and asks:
| Option | Default | Question |
|---|
mcpJson | yes | Write the MCP config (.mcp.json; .codex/config.toml for Codex) so your agent starts the MCP server? |
svelteMcp | yes | Also add the official Svelte MCP? (asked only with mcpJson) |
playwrightMcp | no | Also add Playwright MCP? (asked only with mcpJson) |
vitePlugin | yes | Add the svelte-grab Vite plugin? |
skills | yes | Install the svelte-grab agent skills into .claude/skills/ (and .agents/skills/ with codex)? |
codex | yes | Also set up OpenAI Codex (.codex/config.toml, skills in .agents/skills/, AGENTS.md section)? |
Skip the prompts with npx sv add svelte-grab="playwrightMcp:yes+skills:no" (codex:no for Claude Code only). Running it twice changes nothing. What it cannot do (a Vite config it cannot edit safely, skill files a newer version no longer ships) is listed in the next steps.
The resulting .mcp.json:
{
"mcpServers": {
"svelte-grab": { "type": "stdio", "command": "npx", "args": ["svelte-grab-mcp", "--stdio"] },
"svelte": { "type": "stdio", "command": "npx", "args": ["-y", "@sveltejs/mcp"] }
}
}
Add --with-playwright-mcp for a playwright entry (npx -y @playwright/mcp@latest). Codex gets the same servers in .codex/config.toml. Another client? See Agent setup.
3. Run it. Start the dev server (npm run dev), open the app in a browser, and start your agent in the project. Claude Code reads .mcp.json on start (approve the project servers when asked); Codex reads .codex/config.toml once you trust the project. Either one launches the MCP server itself; the page finds it on 127.0.0.1:4723 (next free port up to 4732).
4. Let the agent loop:
ui_snapshot -> ui_find -> ui_inspect -> (edit the file) -> ui_wait_for_hmr -> ui_verify
A short session, asking for "make the Save button in the settings card more prominent":