Skip to content

Commit 9d67841

Browse files
QuantGeekDevclaude
andcommitted
docs: add React section to MCP Apps documentation
Add React-specific scaffolding instructions, generated file structure, dependency install commands, build instructions, and a useApp() code example to the apps docs page. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4ea299f commit 9d67841

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

docs/apps.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,70 @@ await app.connect();
256256
257257
React hooks are available via `@modelcontextprotocol/ext-apps/react`.
258258
259+
### React Apps
260+
261+
The fastest way to create a React-based MCP App:
262+
263+
```bash
264+
# Standalone app (Mode A)
265+
mcp add app my-dashboard --react
266+
267+
# Individual tool with React UI (Mode B)
268+
mcp add tool my-widget --react
269+
```
270+
271+
This generates a complete React project in `src/app-views/<name>/`:
272+
273+
```
274+
src/app-views/my-dashboard/
275+
├── App.tsx # React component with useApp() wired up
276+
├── styles.css # Host theme fallbacks + base styles
277+
├── index.html # Vite entry point
278+
├── vite.config.ts # react() + viteSingleFile()
279+
└── tsconfig.json # Client-side config (react-jsx, DOM)
280+
```
281+
282+
Install the React dependencies:
283+
284+
```bash
285+
npm install @modelcontextprotocol/ext-apps @modelcontextprotocol/sdk react react-dom
286+
npm install -D @types/react @types/react-dom @vitejs/plugin-react vite vite-plugin-singlefile
287+
```
288+
289+
Build the view into a single HTML file:
290+
291+
```bash
292+
cd src/app-views/my-dashboard && npx vite build
293+
```
294+
295+
The generated React component uses `useApp()` from `@modelcontextprotocol/ext-apps/react` to handle the MCP Apps protocol automatically:
296+
297+
```tsx
298+
import { useApp } from "@modelcontextprotocol/ext-apps/react";
299+
300+
function MyDashboard() {
301+
const [toolResult, setToolResult] = useState(null);
302+
303+
const { app, error } = useApp({
304+
appInfo: { name: "my-dashboard", version: "1.0.0" },
305+
onAppCreated: (app) => {
306+
app.ontoolresult = (result) => setToolResult(result);
307+
},
308+
});
309+
310+
if (!app) return <div>Connecting...</div>;
311+
312+
return (
313+
<div>
314+
<h2>Dashboard</h2>
315+
{/* Your interactive UI here */}
316+
</div>
317+
);
318+
}
319+
```
320+
321+
Host theme variables are automatically applied, so your app matches the look of Claude, ChatGPT, or VS Code.
322+
259323
## UI Configuration
260324
261325
### Content Security Policy (CSP)

0 commit comments

Comments
 (0)