Watch activity in the DevTools console!
+ +
+ Server Time: {serverTime}
+
diff --git a/.prettierignore b/.prettierignore index e2a4cdb1..9c9b32ba 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,6 +1,4 @@ examples/basic-host/**/*.ts examples/basic-host/**/*.tsx -examples/basic-server-react/**/*.ts -examples/basic-server-react/**/*.tsx -examples/basic-server-vanillajs/**/*.ts -examples/basic-server-vanillajs/**/*.tsx +examples/basic-server-*/**/*.ts +examples/basic-server-*/**/*.tsx diff --git a/README.md b/README.md index d7cb04fe..c7ef87a6 100644 --- a/README.md +++ b/README.md @@ -47,9 +47,13 @@ Or edit your `package.json` manually: Start with these foundational examples to learn the SDK: -- [`examples/basic-server-vanillajs`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/basic-server-vanillajs) — Example MCP server with tools that return UI Apps (vanilla JS) -- [`examples/basic-server-react`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/basic-server-react) — Example MCP server with tools that return UI Apps (React) -- [`examples/basic-host`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/basic-host) — Bare-bones example of hosting MCP Apps +- [`examples/basic-server-vanillajs`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/basic-server-vanillajs) — MCP server + MCP App using vanilla JS +- [`examples/basic-server-react`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/basic-server-react) — MCP server + MCP App using [React](https://github.com/facebook/react) +- [`examples/basic-server-vue`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/basic-server-vue) — MCP server + MCP App using [Vue](https://github.com/vuejs/vue) +- [`examples/basic-server-svelte`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/basic-server-svelte) — MCP server + MCP App using [Svelte](https://github.com/sveltejs/svelte) +- [`examples/basic-server-preact`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/basic-server-preact) — MCP server + MCP App using [Preact](https://github.com/preactjs/preact) +- [`examples/basic-server-solid`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/basic-server-solid) — MCP server + MCP App using [Solid](https://github.com/solidjs/solid) +- [`examples/basic-host`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/basic-host) — MCP host application supporting MCP Apps The [`examples/`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples) directory contains additional demo apps showcasing real-world use cases. diff --git a/examples/basic-server-preact/README.md b/examples/basic-server-preact/README.md new file mode 100644 index 00000000..cc98ecb6 --- /dev/null +++ b/examples/basic-server-preact/README.md @@ -0,0 +1,30 @@ +# Example: Basic Server (Preact) + +An MCP App example with a Preact UI. + +> [!TIP] +> Looking for a vanilla JavaScript example? See [`basic-server-vanillajs`](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/basic-server-vanillajs)! + +## Overview + +- Tool registration with a linked UI resource +- Preact UI using the [`App`](https://modelcontextprotocol.github.io/ext-apps/api/classes/app.App.html) class +- 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) + +## Key Files + +- [`server.ts`](server.ts) - MCP server with tool and resource registration +- [`mcp-app.html`](mcp-app.html) / [`src/mcp-app.tsx`](src/mcp-app.tsx) - Preact UI using `App` class + +## Getting Started + +```bash +npm install +npm run dev +``` + +## How It Works + +1. The server registers a `get-time` tool with metadata linking it to a UI HTML resource (`ui://get-time/mcp-app.html`). +2. When the tool is invoked, the Host renders the UI from the resource. +3. The UI uses the MCP App SDK API to communicate with the host and call server tools. diff --git a/examples/basic-server-preact/mcp-app.html b/examples/basic-server-preact/mcp-app.html new file mode 100644 index 00000000..205ff4e7 --- /dev/null +++ b/examples/basic-server-preact/mcp-app.html @@ -0,0 +1,14 @@ + + +
+ + + +Watch activity in the DevTools console!
+ +
+ Server Time: {serverTime}
+
- Server Time: {serverTime}
+ Server Time: {serverTime}
Watch activity in the DevTools console!
+ +
+ Server Time: {serverTime()}
+
Watch activity in the DevTools console!
+ +Server Time: {serverTime}