Skip to content

Commit 3f982d0

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 6f14cf3 commit 3f982d0

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

docs/quickstart.md

Lines changed: 22 additions & 17 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,57 +101,58 @@ 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 { RESOURCE_URI_META_KEY } from "@modelcontextprotocol/ext-apps";
104+
import { RESOURCE_MIME_TYPE, RESOURCE_URI_META_KEY } from "@modelcontextprotocol/ext-apps";
101105
import cors from "cors";
102106
import express from "express";
103107
import fs from "node:fs/promises";
104108
import path from "node:path";
105-
import * as z from "zod";
106109

107110
const server = new McpServer({
108111
name: "My MCP App Server",
109112
version: "1.0.0",
110113
});
111114

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

118+
// Register a tool with UI metadata. When the host calls this tool, it reads
119+
// `_meta[RESOURCE_URI_META_KEY]` to know which resource to fetch and render as
120+
// an interactive UI.
115121
server.registerTool(
116122
"get-time",
117123
{
118124
title: "Get Time",
119125
description: "Returns the current server time.",
120126
inputSchema: {},
121-
outputSchema: { time: z.string() },
122-
_meta: { [RESOURCE_URI_META_KEY]: resourceUri }, // Links tool to UI
127+
_meta: { [RESOURCE_URI_META_KEY]: resourceUri },
123128
},
124129
async () => {
125130
const time = new Date().toISOString();
126131
return {
127132
content: [{ type: "text", text: time }],
128-
structuredContent: { time },
129133
};
130134
},
131135
);
132136

137+
// Register the resource, which returns the bundled HTML/JavaScript for the UI.
133138
server.registerResource(
134139
resourceUri,
135140
resourceUri,
136-
{ mimeType: "text/html;profile=mcp-app" },
141+
{ mimeType: RESOURCE_MIME_TYPE },
137142
async () => {
138143
const html = await fs.readFile(
139144
path.join(import.meta.dirname, "dist", "mcp-app.html"),
140145
"utf-8",
141146
);
142147
return {
143148
contents: [
144-
{ uri: resourceUri, mimeType: "text/html;profile=mcp-app", text: html },
149+
{ uri: resourceUri, mimeType: RESOURCE_MIME_TYPE, text: html },
145150
],
146151
};
147152
},
148153
);
149154

150-
// Express server for MCP endpoint
155+
// Start an Express server that exposes the MCP endpoint.
151156
const app = express();
152157
app.use(cors());
153158
app.use(express.json());
@@ -177,7 +182,7 @@ app.listen(3001, (err) => {
177182
Then, verify your server compiles:
178183

179184
```bash
180-
npx tsc --noEmit server.ts
185+
npx tsc --noEmit
181186
```
182187

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

218223
// Register handlers BEFORE connecting
219224
app.ontoolresult = (result) => {
220-
const { time } = (result.structuredContent as { time?: string }) ?? {};
225+
const time = result.content?.find((c) => c.type === "text")?.text;
221226
serverTimeEl.textContent = time ?? "[ERROR]";
222227
};
223228

224229
// Wire up button click
225230
getTimeBtn.addEventListener("click", async () => {
226231
const result = await app.callServerTool({ name: "get-time", arguments: {} });
227-
const { time } = (result.structuredContent as { time?: string }) ?? {};
232+
const time = result.content?.find((c) => c.type === "text")?.text;
228233
serverTimeEl.textContent = time ?? "[ERROR]";
229234
});
230235

231236
// Connect to host
232237
app.connect(new PostMessageTransport(window.parent));
233238
```
234239

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+
235243
Build the UI:
236244

237245
```bash
238246
npm run build
239247
```
240248

241-
> [!NOTE]
242-
> **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)
243-
244249
This produces `dist/mcp-app.html` which contains your bundled app:
245250

246251
```console

0 commit comments

Comments
 (0)