Skip to content

Commit 487f8c6

Browse files
Update quickstart guide
- Reorganize prerequisites to emphasize MCP concepts first - Add tip linking to official MCP quickstart for newcomers - Update install command to use published npm package - Remove zod dependency and `structuredContent` usage - Use `RESOURCE_MIME_TYPE` constant for consistency - Add clearer comments explaining tool/resource registration - Simplify UI to extract time from text content 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c7ef5f0 commit 487f8c6

1 file changed

Lines changed: 27 additions & 25 deletions

File tree

docs/quickstart.md

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ A simple app that fetches the current server time and displays it in a clickable
1515
1616
## Prerequisites
1717

18-
- Node.js 18+
18+
- Familiarity with MCP concepts, especially [Tools](https://modelcontextprotocol.io/docs/learn/server-concepts#tools) and [Resources](https://modelcontextprotocol.io/docs/learn/server-concepts#resources)
1919
- Familiarity with the [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)
20+
- Node.js 18+
21+
22+
> [!TIP]
23+
> New to building MCP servers? Start with the [official MCP quickstart guide](https://modelcontextprotocol.io/docs/develop/build-server) to learn the core concepts first.
2024
2125
## 1. Project Setup
2226

@@ -30,7 +34,7 @@ npm init -y
3034
Install dependencies:
3135

3236
```bash
33-
npm install github:modelcontextprotocol/ext-apps @modelcontextprotocol/sdk zod
37+
npm install @modelcontextprotocol/ext-apps @modelcontextprotocol/sdk
3438
npm install -D typescript vite vite-plugin-singlefile express cors @types/express @types/cors tsx
3539
```
3640

@@ -97,65 +101,63 @@ Create `server.ts`:
97101
```typescript
98102
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
99103
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
100-
import {
101-
RESOURCE_MIME_TYPE,
102-
type McpUiToolMeta,
103-
} from "@modelcontextprotocol/ext-apps";
104+
import { RESOURCE_MIME_TYPE } from "@modelcontextprotocol/ext-apps";
104105
import cors from "cors";
105106
import express from "express";
106107
import fs from "node:fs/promises";
107108
import path from "node:path";
108-
import * as z from "zod";
109109

110110
const server = new McpServer({
111111
name: "My MCP App Server",
112112
version: "1.0.0",
113113
});
114114

115-
// Two-part registration: tool + resource
115+
// Two-part registration: tool + resource, tied together by the resource URI.
116116
const resourceUri = "ui://get-time/mcp-app.html";
117117

118+
// Register a tool with UI metadata. When the host calls this tool, it reads
119+
// `_meta.ui.resourceUri` to know which resource to fetch and render as an
120+
// interactive UI.
118121
server.registerTool(
119122
"get-time",
120123
{
121124
title: "Get Time",
122125
description: "Returns the current server time.",
123126
inputSchema: {},
124-
outputSchema: { time: z.string() },
125-
_meta: { ui: { resourceUri } as McpUiToolMeta }, // Links tool to UI
127+
_meta: { ui: { resourceUri } } as const,
126128
},
127129
async () => {
128130
const time = new Date().toISOString();
129131
return {
130132
content: [{ type: "text", text: time }],
131-
structuredContent: { time },
132133
};
133134
},
134135
);
135136

137+
// Register the resource, which returns the bundled HTML/JavaScript for the UI.
136138
server.registerResource(
137139
resourceUri,
138140
resourceUri,
139-
{ mimeType: "text/html;profile=mcp-app" },
141+
{ mimeType: RESOURCE_MIME_TYPE },
140142
async () => {
141143
const html = await fs.readFile(
142144
path.join(import.meta.dirname, "dist", "mcp-app.html"),
143145
"utf-8",
144146
);
145147
return {
146148
contents: [
147-
{ uri: resourceUri, mimeType: "text/html;profile=mcp-app", text: html },
149+
{ uri: resourceUri, mimeType: RESOURCE_MIME_TYPE, text: html },
148150
],
149151
};
150152
},
151153
);
152154

153-
// Express server for MCP endpoint
154-
const app = express();
155-
app.use(cors());
156-
app.use(express.json());
155+
// Start an Express server that exposes the MCP endpoint.
156+
const expressApp = express();
157+
expressApp.use(cors());
158+
expressApp.use(express.json());
157159

158-
app.post("/mcp", async (req, res) => {
160+
expressApp.post("/mcp", async (req, res) => {
159161
const transport = new StreamableHTTPServerTransport({
160162
sessionIdGenerator: undefined,
161163
enableJsonResponse: true,
@@ -165,7 +167,7 @@ app.post("/mcp", async (req, res) => {
165167
await transport.handleRequest(req, res, req.body);
166168
});
167169

168-
app.listen(3001, (err) => {
170+
expressApp.listen(3001, (err) => {
169171
if (err) {
170172
console.error("Error starting server:", err);
171173
process.exit(1);
@@ -220,30 +222,30 @@ const app = new App({ name: "Get Time App", version: "1.0.0" });
220222

221223
// Register handlers BEFORE connecting
222224
app.ontoolresult = (result) => {
223-
const { time } = (result.structuredContent as { time?: string }) ?? {};
225+
const time = result.content?.find((c) => c.type === "text")?.text;
224226
serverTimeEl.textContent = time ?? "[ERROR]";
225227
};
226228

227229
// Wire up button click
228230
getTimeBtn.addEventListener("click", async () => {
229231
const result = await app.callServerTool({ name: "get-time", arguments: {} });
230-
const { time } = (result.structuredContent as { time?: string }) ?? {};
232+
const time = result.content?.find((c) => c.type === "text")?.text;
231233
serverTimeEl.textContent = time ?? "[ERROR]";
232234
});
233235

234236
// Connect to host
235-
app.connect(new PostMessageTransport(window.parent));
237+
app.connect();
236238
```
237239

240+
> [!NOTE]
241+
> **Full files:** [`mcp-app.html`](https://github.com/modelcontextprotocol/ext-apps/blob/main/examples/basic-server-vanillajs/mcp-app.html), [`src/mcp-app.ts`](https://github.com/modelcontextprotocol/ext-apps/blob/main/examples/basic-server-vanillajs/src/mcp-app.ts)
242+
238243
Build the UI:
239244

240245
```bash
241246
npm run build
242247
```
243248

244-
> [!NOTE]
245-
> **Full files:** [`mcp-app.html`](https://github.com/modelcontextprotocol/ext-apps/blob/main/examples/basic-server-vanillajs/mcp-app.html), [`src/mcp-app.ts`](https://github.com/modelcontextprotocol/ext-apps/blob/main/examples/basic-server-vanillajs/src/mcp-app.ts)
246-
247249
This produces `dist/mcp-app.html` which contains your bundled app:
248250

249251
```console

0 commit comments

Comments
 (0)