@mcp-web/app 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +159 -0
  2. package/package.json +7 -2
package/README.md ADDED
@@ -0,0 +1,159 @@
1
+ # MCP Web App
2
+
3
+ Tooling for simplify creating MCP Apps from UI components. The packages bundles components into single HTML files that AI agents can render inline in chat interfaces like Claude Desktop.
4
+
5
+ > [!IMPORTANT]
6
+ > We currently only support React. Support for more frameworks will be added in the future.
7
+
8
+ ## Overview
9
+
10
+ MCP Apps combine a tool (that AI can call) with a visual React component. When the AI calls the tool, the handler returns props which are passed to your component via the [ext-apps protocol](https://github.com/anthropics/anthropic-cookbook/tree/main/misc/model_context_protocol/ext-apps). A Vite plugin handles bundling each app into a self-contained HTML file.
11
+
12
+ ## Quick Start
13
+
14
+ ### Installation
15
+
16
+ ```bash
17
+ npm install @mcp-web/app
18
+ ```
19
+
20
+ ### 1. Define an App
21
+
22
+ Create a file that exports your apps (e.g. `src/mcp-apps.ts`):
23
+
24
+ ```typescript
25
+ import { createApp } from '@mcp-web/app';
26
+ import { Statistics } from './components/Statistics';
27
+
28
+ export const statsApp = createApp({
29
+ name: 'show_stats',
30
+ description: 'Display statistics visualization',
31
+ component: Statistics,
32
+ handler: () => ({
33
+ completionRate: 0.75,
34
+ totalTasks: 100,
35
+ }),
36
+ });
37
+ ```
38
+
39
+ ### 2. Add the Vite Build Config
40
+
41
+ Create a separate Vite config for building apps (e.g. `vite.apps.config.ts`):
42
+
43
+ ```typescript
44
+ import react from '@vitejs/plugin-react';
45
+ import { defineMCPAppsConfig } from '@mcp-web/app/vite';
46
+
47
+ export default defineMCPAppsConfig({
48
+ plugins: [react()],
49
+ });
50
+ ```
51
+
52
+ Build with:
53
+
54
+ ```bash
55
+ vite build --config vite.apps.config.ts
56
+ ```
57
+
58
+ This auto-discovers apps in `src/mcp-apps.ts` and outputs bundled HTML files to `public/mcp-web-apps/`.
59
+
60
+ ### 3. Register with MCPWeb
61
+
62
+ In your web app, register the app so the AI agent can call it:
63
+
64
+ ```typescript
65
+ import { statsApp } from './mcp-apps';
66
+
67
+ mcp.addApp(statsApp);
68
+ ```
69
+
70
+ ## Input Schemas
71
+
72
+ Apps can accept input from the AI agent using Zod schemas:
73
+
74
+ ```typescript
75
+ import { createApp } from '@mcp-web/app';
76
+ import { z } from 'zod';
77
+ import { Chart } from './components/Chart';
78
+
79
+ export const chartApp = createApp({
80
+ name: 'show_chart',
81
+ description: 'Display a chart with the given data',
82
+ component: Chart,
83
+ inputSchema: z.object({
84
+ chartType: z.enum(['bar', 'line', 'pie']).describe('Type of chart'),
85
+ title: z.string().describe('Chart title'),
86
+ }),
87
+ handler: ({ chartType, title }) => ({
88
+ chartType,
89
+ title,
90
+ data: getChartData(),
91
+ }),
92
+ });
93
+ ```
94
+
95
+ ## Host Theming
96
+
97
+ MCP Apps automatically inherit the host's theme. Use these hooks to access it:
98
+
99
+ ```tsx
100
+ import { useMCPHostTheme, useMCPHostContext } from '@mcp-web/app';
101
+
102
+ function MyApp(props: MyProps) {
103
+ const theme = useMCPHostTheme(); // "light" or "dark"
104
+ const hostContext = useMCPHostContext(); // full context (theme, locale, display mode, etc.)
105
+
106
+ return <div className={theme === 'dark' ? 'dark' : ''}>{/* ... */}</div>;
107
+ }
108
+ ```
109
+
110
+ ## Receiving Props
111
+
112
+ Use the `useMCPAppProps` hook to receive props from the tool handler:
113
+
114
+ ```tsx
115
+ import { useMCPAppProps } from '@mcp-web/app';
116
+
117
+ function Statistics() {
118
+ const props = useMCPAppProps<{ completionRate: number; totalTasks: number }>();
119
+
120
+ if (!props) return <div>Loading...</div>;
121
+
122
+ return (
123
+ <div>
124
+ <p>Completion: {Math.round(props.completionRate * 100)}%</p>
125
+ <p>Total tasks: {props.totalTasks}</p>
126
+ </div>
127
+ );
128
+ }
129
+ ```
130
+
131
+ ## Vite Plugin Options
132
+
133
+ ```typescript
134
+ defineMCPAppsConfig(
135
+ { plugins: [react()] },
136
+ {
137
+ appsConfig: 'src/mcp-apps.ts', // Path to apps config (auto-detected by default)
138
+ outDir: 'public/mcp-web-apps', // Output directory (default)
139
+ silenceOverrideWarnings: false, // Suppress build setting override warnings
140
+ }
141
+ );
142
+ ```
143
+
144
+ ## Exports
145
+
146
+ | Export | Description |
147
+ |--------|-------------|
148
+ | `createApp` | Define an app with a handler and component |
149
+ | `useMCPAppProps` | React hook to receive props from the tool handler |
150
+ | `useMCPApp` | Access the ext-apps `App` instance |
151
+ | `useMCPHostTheme` | Get the current host theme (`"light"` or `"dark"`) |
152
+ | `useMCPHostContext` | Get the full host context |
153
+ | `renderMCPApp` | Manually render a component (auto-generated by Vite plugin) |
154
+ | `MCPAppProvider` | Context provider (set up automatically by `renderMCPApp`) |
155
+ | `defineMCPAppsConfig` | Create a Vite config for building MCP Apps (via `@mcp-web/app/vite`) |
156
+
157
+ ## Learn More
158
+
159
+ For full documentation, guides, and examples, visit [mcp-web.dev](https://mcp-web.dev).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcp-web/app",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Build tooling for MCP Apps - bundle React components into single HTML files for AI UI rendering",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "@modelcontextprotocol/ext-apps": "^1.0.1",
24
24
  "vite-plugin-singlefile": "^2.3.0",
25
25
  "zod": "~4.1.12",
26
- "@mcp-web/types": "0.1.0"
26
+ "@mcp-web/types": "0.1.2"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/node": "^25.0.9",
@@ -45,6 +45,11 @@
45
45
  "optional": true
46
46
  }
47
47
  },
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "https://github.com/flekschas/mcp-web",
51
+ "directory": "packages/app"
52
+ },
48
53
  "scripts": {
49
54
  "build": "tsc",
50
55
  "clean": "rm -rf dist",