Skip to main content
Glama
Svelte LSP as MCP

Svelte LSP as MCP

by pacnpal
README.md
# Svelte LSP as MCP

Send a Svelte component to an MCP tool and get compiler diagnostics, type information, completions or edit previews. The npm package includes the official Svelte Language Server, Svelte 5, TypeScript and the MCP runtime. Inline source works from an empty directory.

## Run with npx

Use Node.js 22.12 or newer.

```sh
npx --yes @pacnpal/svelte-lsp-as-mcp
```

The process waits for MCP messages on standard input. Use `--help` for the command options or `--version` to check the installed release.

### Connect a local MCP client

Add this entry to a client that accepts `mcpServers` configuration, then reload the client.

```json
{
  "mcpServers": {
    "svelte": {
      "command": "npx",
      "args": ["-y", "@pacnpal/svelte-lsp-as-mcp"]
    }
  }
}
```

Call `svelte_diagnostics` with the following arguments. The bundled language server reports TypeScript error `2322` because the initializer is a string and `count` is declared as a number.

```json
{
  "source": "<script lang=\"ts\">let count: number = 'two';</script>\n<p>{count}</p>"
}
```

To pin a release, append a version to the package name, for example `@pacnpal/svelte-lsp-as-mcp@0.2.0`. To run from GitHub, use `github:pacnpal/svelte-lsp-as-mcp#main` in the package argument slot. You can replace `main` with a commit SHA.

## Deploy with MCPElevator

1. Open **Servers → Add server → Import JSON** and paste the client configuration above. In the manual form, select the `npx` runner, set the command to `npx` and enter the two arguments `-y` and `@pacnpal/svelte-lsp-as-mcp`.
2. Save and start the server. Open the tools list and call `svelte_diagnostics` with the inline example above. The source travels in the MCP request, so the runner can serve any client's component without a mounted checkout.
3. Copy the server's MCP URL into a Streamable HTTP client. With the default local port and the slug `svelte`, the URL is `http://127.0.0.1:8080/s/svelte/mcp`. Remote clients use the MCPElevator base URL and the access credentials configured for that server. [MCPElevator setup and client connections](https://github.com/pacnpal/mcpelevator#adding-a-server)

## Optional project files

For cross-file navigation, project-specific imports, preprocessors and configuration, run against a trusted checkout with its dependencies installed. Project configuration can execute JavaScript.

```sh
npx --yes @pacnpal/svelte-lsp-as-mcp --workspace /absolute/path/to/svelte-project
```

Call a tool with `{"file":"src/App.svelte"}` to read the saved component. Relative file paths start at `--workspace`, or at the server's current directory when the flag is omitted. With MCPElevator in Docker, mount the project into its container for file-based calls and pass the container path to `--workspace`.

## Tools

Every tool accepts either `source` (the full component text) or `file` (a saved component path). Inline requests are independent. Pass the source again on each call. Inline imports can use the bundled Svelte package. Use project files to resolve your own modules. A `position` has a zero-based `line` and a zero-based `character` measured in UTF-16 code units. Locations returned by the language server use file URIs and the same coordinates.

| Tool | Additional arguments | Result |
| --- | --- | --- |
| `svelte_diagnostics` | — | Current diagnostics, including severity, message and source range |
| `svelte_hover` | `position` | Type information and documentation |
| `svelte_definition` | `position` | Declaration locations, including imported symbols |
| `svelte_type_definition` | `position` | Type declaration locations |
| `svelte_references` | `position`, optional `includeDeclaration` (default `true`) | Symbol references in the project |
| `svelte_document_symbols` | — | Component outline with source ranges |
| `svelte_signature_help` | `position` | Call signatures and the active parameter |
| `svelte_completions` | `position`, optional `offset` (default 0) and `limit` (default 50, max 200) | Suggestions, total count and LSP's `isIncomplete` flag |
| `svelte_rename` | `position`, `newName` | Proposed LSP workspace edit |
| `svelte_format` | Optional `tabSize` (default 2) and `insertSpaces` (default `true`) | Proposed formatting edits |

For a position-based example, call `svelte_hover` with `{"source":"<script>let count = 2;</script>\n<p>{count}</p>","position":{"line":1,"character":5}}` to inspect `count`.

Inline results refer to `Component.svelte` under a private temporary directory owned by the server. Each inline request supplies its text through the language server’s open-document buffer. Results are available as JSON text and under `structuredContent.result`. An empty array or `null` can be a valid answer when the language server has no matches. Rename and format return edits for the client to review and apply. Server logs go to stderr.

## Troubleshooting

- **Client cannot launch npx.** Check `node --version` and `npx --version` in the runner environment. A desktop client may need the absolute path to `npx` and Node's bin directory on its `PATH`.
- **File missing or outside the workspace.** Check the path from the server process. In Docker, use the mount destination. Symlinks supplied as input must also resolve inside the workspace.
- **Missing project types or unresolved local imports.** Use file mode, install dependencies and run the project's type-generation or SvelteKit sync step. Point `--workspace` at the project or monorepo containing its configuration.
- **Unexpected position or stale editor content.** Save the file and check the zero-based coordinates. An emoji outside the Basic Multilingual Plane occupies two UTF-16 code units.

## Development

```sh
npm ci
npm test
npm start
npm pack --dry-run
```

Integration tests exercise all ten tools with inline source in an empty directory and with saved project files. CI also installs the packed tarball offline with an empty npm cache and runs the inline tests against that installation.

## Publishing

The GitHub Actions workflow tests pushes to `main` and pull requests. Pushing a version tag such as `v0.2.0` runs the tests and package smoke check, verifies the tag matches `package.json`, then publishes the public package with provenance to npm using OIDC.

The npm package's GitHub Actions trusted publisher uses owner `pacnpal`, repository `svelte-lsp-as-mcp`, workflow filename `publish.yml`, and an empty environment field. Enable the `npm publish` action. The GitHub-hosted publish job requests `id-token: write`. [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/)

For the next patch release, run these commands from a clean, up-to-date `main` checkout. npm updates the manifest and lockfile, commits the change and tags the version.

```sh
npm version patch
git push --follow-tags origin main
```

## License

[MIT](LICENSE)

TDQS

A3.5/5.0

Scored across 10 tools

Disambiguation5/5

Each tool maps to a distinct LSP capability with clear resource/action intent. Definition vs. type_definition and hover vs. signature_help are adjacent but descriptions make their boundaries clear.

Naming Consistency5/5

All tools follow a consistent svelte_ prefix plus snake_case noun/action pattern. The naming is predictable and easy to scan.

Tool Count5/5

Ten tools is well-scoped for a language-server bridge, covering the most common diagnostic, navigation, completion, formatting, and rename workflows without bloat.

Completeness4/5

The surface covers core LSP interactions well: diagnostics, symbols, formatting, hover, navigation, references, completions, and rename preview. Notable gaps remain around code actions/quick fixes and some secondary LSP features like document highlights or implementation lookup.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues