@modelcontextprotocol/server-basic-svelte 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -0
- package/dist/index.js +34183 -0
- package/dist/mcp-app.html +112 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.js +27273 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Example: Basic Server (Svelte)
|
|
2
|
+
|
|
3
|
+
An MCP App example with a Svelte 5 UI using runes for reactivity.
|
|
4
|
+
|
|
5
|
+
> [!TIP]
|
|
6
|
+
> Looking for a vanilla JavaScript example? See [`basic-server-vanillajs`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/basic-server-vanillajs)!
|
|
7
|
+
|
|
8
|
+
## MCP Client Configuration
|
|
9
|
+
|
|
10
|
+
Add to your MCP client configuration (stdio transport):
|
|
11
|
+
|
|
12
|
+
```json
|
|
13
|
+
{
|
|
14
|
+
"mcpServers": {
|
|
15
|
+
"basic-svelte": {
|
|
16
|
+
"command": "npx",
|
|
17
|
+
"args": [
|
|
18
|
+
"-y",
|
|
19
|
+
"--silent",
|
|
20
|
+
"--registry=https://registry.npmjs.org/",
|
|
21
|
+
"@modelcontextprotocol/server-basic-svelte",
|
|
22
|
+
"--stdio"
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Local Development
|
|
30
|
+
|
|
31
|
+
To test local modifications, use this configuration (replace `~/code/ext-apps` with your clone path):
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"mcpServers": {
|
|
36
|
+
"basic-svelte": {
|
|
37
|
+
"command": "bash",
|
|
38
|
+
"args": [
|
|
39
|
+
"-c",
|
|
40
|
+
"cd ~/code/ext-apps/examples/basic-server-svelte && npm run build >&2 && node dist/index.js --stdio"
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Overview
|
|
48
|
+
|
|
49
|
+
- Tool registration with a linked UI resource
|
|
50
|
+
- Svelte 5 UI using the [`App`](https://modelcontextprotocol.github.io/ext-apps/api/classes/app.App.html) class
|
|
51
|
+
- App communication APIs: [`callServerTool`](https://modelcontextprotocol.github.io/ext-apps/api/classes/app.App.html#callservertool), [`sendMessage`](https://modelcontextprotocol.github.io/ext-apps/api/classes/app.App.html#sendmessage), [`sendLog`](https://modelcontextprotocol.github.io/ext-apps/api/classes/app.App.html#sendlog), [`openLink`](https://modelcontextprotocol.github.io/ext-apps/api/classes/app.App.html#openlink)
|
|
52
|
+
|
|
53
|
+
## Key Files
|
|
54
|
+
|
|
55
|
+
- [`server.ts`](server.ts) - MCP server with tool and resource registration
|
|
56
|
+
- [`mcp-app.html`](mcp-app.html) / [`src/App.svelte`](src/App.svelte) - Svelte 5 UI using `App` class
|
|
57
|
+
|
|
58
|
+
## Getting Started
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npm install
|
|
62
|
+
npm run dev
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## How It Works
|
|
66
|
+
|
|
67
|
+
1. The server registers a `get-time` tool with metadata linking it to a UI HTML resource (`ui://get-time/mcp-app.html`).
|
|
68
|
+
2. When the tool is invoked, the Host renders the UI from the resource.
|
|
69
|
+
3. The UI uses the MCP App SDK API to communicate with the host and call server tools.
|
|
70
|
+
|
|
71
|
+
## Build System
|
|
72
|
+
|
|
73
|
+
This example bundles into a single HTML file using Vite with `vite-plugin-singlefile` — see [`vite.config.ts`](vite.config.ts). This allows all UI content to be served as a single MCP resource. Alternatively, MCP apps can load external resources by defining [`_meta.ui.csp.resourceDomains`](https://modelcontextprotocol.github.io/ext-apps/api/interfaces/app.McpUiResourceCsp.html#resourcedomains) in the UI resource metadata.
|