Skip to content

Commit dd14521

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 <[email protected]>
1 parent 9963d0f commit dd14521

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

docs/quickstart.md

Lines changed: 28 additions & 23 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

@@ -99,63 +103,64 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
99103
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
100104
import {
101105
RESOURCE_MIME_TYPE,
102-
type McpUiToolMeta,
106+
RESOURCE_URI_META_KEY,
103107
} from "@modelcontextprotocol/ext-apps";
104108
import cors from "cors";
105109
import express from "express";
106110
import fs from "node:fs/promises";
107111
import path from "node:path";
108-
import * as z from "zod";
109112

110113
const server = new McpServer({
111114
name: "My MCP App Server",
112115
version: "1.0.0",
113116
});
114117

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

121+
// Register a tool with UI metadata. When the host calls this tool, it reads
122+
// `_meta[RESOURCE_URI_META_KEY]` to know which resource to fetch and render as
123+
// an interactive UI.
118124
server.registerTool(
119125
"get-time",
120126
{
121127
title: "Get Time",
122128
description: "Returns the current server time.",
123129
inputSchema: {},
124-
outputSchema: { time: z.string() },
125-
_meta: { ui: { resourceUri } as McpUiToolMeta }, // Links tool to UI
130+
_meta: { ui: { resourceUri } } as const,
126131
},
127132
async () => {
128133
const time = new Date().toISOString();
129134
return {
130135
content: [{ type: "text", text: time }],
131-
structuredContent: { time },
132136
};
133137
},
134138
);
135139

140+
// Register the resource, which returns the bundled HTML/JavaScript for the UI.
136141
server.registerResource(
137142
resourceUri,
138143
resourceUri,
139-
{ mimeType: "text/html;profile=mcp-app" },
144+
{ mimeType: RESOURCE_MIME_TYPE },
140145
async () => {
141146
const html = await fs.readFile(
142147
path.join(import.meta.dirname, "dist", "mcp-app.html"),
143148
"utf-8",
144149
);
145150
return {
146151
contents: [
147-
{ uri: resourceUri, mimeType: "text/html;profile=mcp-app", text: html },
152+
{ uri: resourceUri, mimeType: RESOURCE_MIME_TYPE, text: html },
148153
],
149154
};
150155
},
151156
);
152157

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

158-
app.post("/mcp", async (req, res) => {
163+
expressApp.post("/mcp", async (req, res) => {
159164
const transport = new StreamableHTTPServerTransport({
160165
sessionIdGenerator: undefined,
161166
enableJsonResponse: true,
@@ -165,7 +170,7 @@ app.post("/mcp", async (req, res) => {
165170
await transport.handleRequest(req, res, req.body);
166171
});
167172

168-
app.listen(3001, (err) => {
173+
expressApp.listen(3001, (err) => {
169174
if (err) {
170175
console.error("Error starting server:", err);
171176
process.exit(1);
@@ -180,7 +185,7 @@ app.listen(3001, (err) => {
180185
Then, verify your server compiles:
181186

182187
```bash
183-
npx tsc --noEmit server.ts
188+
npx tsc --noEmit
184189
```
185190

186191
No output means success. If you see errors, check for typos in `server.ts`.
@@ -220,30 +225,30 @@ const app = new App({ name: "Get Time App", version: "1.0.0" });
220225

221226
// Register handlers BEFORE connecting
222227
app.ontoolresult = (result) => {
223-
const { time } = (result.structuredContent as { time?: string }) ?? {};
228+
const time = result.content?.find((c) => c.type === "text")?.text;
224229
serverTimeEl.textContent = time ?? "[ERROR]";
225230
};
226231

227232
// Wire up button click
228233
getTimeBtn.addEventListener("click", async () => {
229234
const result = await app.callServerTool({ name: "get-time", arguments: {} });
230-
const { time } = (result.structuredContent as { time?: string }) ?? {};
235+
const time = result.content?.find((c) => c.type === "text")?.text;
231236
serverTimeEl.textContent = time ?? "[ERROR]";
232237
});
233238

234239
// Connect to host
235-
app.connect(new PostMessageTransport(window.parent));
240+
app.connect();
236241
```
237242

243+
> [!NOTE]
244+
> **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)
245+
238246
Build the UI:
239247

240248
```bash
241249
npm run build
242250
```
243251

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-
247252
This produces `dist/mcp-app.html` which contains your bundled app:
248253

249254
```console

0 commit comments

Comments
 (0)