@modelcontextprotocol/server-basic-vanillajs 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 ADDED
@@ -0,0 +1,74 @@
1
+ # Example: Basic Server (Vanilla JS)
2
+
3
+ An MCP App example with a vanilla JavaScript UI (no framework).
4
+
5
+ > [!TIP]
6
+ > Looking for a React-based example? See [`basic-server-react`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/basic-server-react)!
7
+
8
+ ## MCP Client Configuration
9
+
10
+ Add to your MCP client configuration (stdio transport):
11
+
12
+ ```json
13
+ {
14
+ "mcpServers": {
15
+ "basic-vanillajs": {
16
+ "command": "npx",
17
+ "args": [
18
+ "-y",
19
+ "--silent",
20
+ "--registry=https://registry.npmjs.org/",
21
+ "@modelcontextprotocol/server-basic-vanillajs",
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-vanillajs": {
37
+ "command": "bash",
38
+ "args": [
39
+ "-c",
40
+ "cd ~/code/ext-apps/examples/basic-server-vanillajs && 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
+ - Vanilla JS UI using the [`App`](https://modelcontextprotocol.github.io/ext-apps/api/classes/app.App.html) class directly
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
+ - Theme integration via [`applyDocumentTheme()`](https://modelcontextprotocol.github.io/ext-apps/api/functions/app.applyDocumentTheme.html), [`applyHostStyleVariables()`](https://modelcontextprotocol.github.io/ext-apps/api/functions/app.applyHostStyleVariables.html), and [`applyHostFonts()`](https://modelcontextprotocol.github.io/ext-apps/api/functions/app.applyHostFonts.html)
53
+
54
+ ## Key Files
55
+
56
+ - [`server.ts`](server.ts) - MCP server with tool and resource registration
57
+ - [`mcp-app.html`](mcp-app.html) / [`src/mcp-app.ts`](src/mcp-app.ts) - Vanilla JS UI using `App` class
58
+
59
+ ## Getting Started
60
+
61
+ ```bash
62
+ npm install
63
+ npm run dev
64
+ ```
65
+
66
+ ## How It Works
67
+
68
+ 1. The server registers a `get-time` tool with metadata linking it to a UI HTML resource (`ui://get-time/mcp-app.html`).
69
+ 2. When the tool is invoked, the Host renders the UI from the resource.
70
+ 3. The UI uses the MCP App SDK API to communicate with the host and call server tools.
71
+
72
+ ## Build System
73
+
74
+ 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.