fa-mcp-sdk 0.4.74 → 0.4.77

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 (202) hide show
  1. package/README.md +319 -314
  2. package/bin/fa-mcp.js +85 -68
  3. package/cli-template/.claude/agents/javascript-pro.md +276 -276
  4. package/cli-template/.claude/settings.json +50 -50
  5. package/cli-template/.claude/skills/mcp-app-add-to-server/SKILL.md +427 -0
  6. package/cli-template/.claude/skills/mcp-app-create/SKILL.md +222 -0
  7. package/cli-template/.claude/skills/upgrade-guide/SKILL.md +2 -1
  8. package/cli-template/.oxfmtrc.json +41 -0
  9. package/cli-template/.oxlintrc.json +120 -0
  10. package/cli-template/CLAUDE.md +358 -355
  11. package/cli-template/FA-MCP-SDK-DOC/00-FA-MCP-SDK-index.md +132 -132
  12. package/cli-template/FA-MCP-SDK-DOC/01-getting-started.md +146 -146
  13. package/cli-template/FA-MCP-SDK-DOC/02-1-tools-and-api.md +431 -431
  14. package/cli-template/FA-MCP-SDK-DOC/02-2-prompts-and-resources.md +201 -201
  15. package/cli-template/FA-MCP-SDK-DOC/03-configuration.md +384 -384
  16. package/cli-template/FA-MCP-SDK-DOC/04-authentication.md +412 -412
  17. package/cli-template/FA-MCP-SDK-DOC/05-ad-authorization.md +196 -196
  18. package/cli-template/FA-MCP-SDK-DOC/06-utilities.md +163 -163
  19. package/cli-template/FA-MCP-SDK-DOC/07-testing-and-operations.md +127 -127
  20. package/cli-template/FA-MCP-SDK-DOC/08-agent-tester-and-headless-api.md +681 -659
  21. package/cli-template/README.md +193 -191
  22. package/cli-template/jest.config.js +27 -30
  23. package/cli-template/package.json +10 -5
  24. package/cli-template/prompt-example-new-MCP.md +101 -101
  25. package/cli-template/readme-docs/SKILLS.md +86 -1
  26. package/cli-template/tsconfig.json +58 -58
  27. package/cli-template/update.cjs +41 -38
  28. package/config/custom-environment-variables.yaml +63 -63
  29. package/config/development.yaml +4 -4
  30. package/config/production.yaml +4 -4
  31. package/config/test.yaml +26 -26
  32. package/dist/core/_types_/TNtlm.d.ts.map +1 -1
  33. package/dist/core/_types_/active-directory-config.d.ts.map +1 -1
  34. package/dist/core/_types_/config.d.ts.map +1 -1
  35. package/dist/core/_types_/types.d.ts.map +1 -1
  36. package/dist/core/ad/group-checker.d.ts.map +1 -1
  37. package/dist/core/ad/group-checker.js.map +1 -1
  38. package/dist/core/agent-tester/agent-tester-router.d.ts.map +1 -1
  39. package/dist/core/agent-tester/agent-tester-router.js +6 -6
  40. package/dist/core/agent-tester/agent-tester-router.js.map +1 -1
  41. package/dist/core/agent-tester/check-llm.d.ts.map +1 -1
  42. package/dist/core/agent-tester/check-llm.js.map +1 -1
  43. package/dist/core/agent-tester/services/SummaryMemory.d.ts.map +1 -1
  44. package/dist/core/agent-tester/services/SummaryMemory.js +3 -9
  45. package/dist/core/agent-tester/services/SummaryMemory.js.map +1 -1
  46. package/dist/core/agent-tester/services/TesterAgentService.d.ts.map +1 -1
  47. package/dist/core/agent-tester/services/TesterAgentService.js +25 -27
  48. package/dist/core/agent-tester/services/TesterAgentService.js.map +1 -1
  49. package/dist/core/agent-tester/services/TesterMcpClientService.d.ts.map +1 -1
  50. package/dist/core/agent-tester/services/TesterMcpClientService.js +26 -25
  51. package/dist/core/agent-tester/services/TesterMcpClientService.js.map +1 -1
  52. package/dist/core/auth/admin-auth.d.ts.map +1 -1
  53. package/dist/core/auth/admin-auth.js +5 -5
  54. package/dist/core/auth/admin-auth.js.map +1 -1
  55. package/dist/core/auth/agent-tester-auth.d.ts.map +1 -1
  56. package/dist/core/auth/agent-tester-auth.js +1 -6
  57. package/dist/core/auth/agent-tester-auth.js.map +1 -1
  58. package/dist/core/auth/basic.d.ts.map +1 -1
  59. package/dist/core/auth/basic.js.map +1 -1
  60. package/dist/core/auth/ip-check.d.ts.map +1 -1
  61. package/dist/core/auth/ip-check.js +1 -1
  62. package/dist/core/auth/ip-check.js.map +1 -1
  63. package/dist/core/auth/jwt.d.ts.map +1 -1
  64. package/dist/core/auth/jwt.js +1 -1
  65. package/dist/core/auth/jwt.js.map +1 -1
  66. package/dist/core/auth/middleware.d.ts.map +1 -1
  67. package/dist/core/auth/middleware.js +9 -6
  68. package/dist/core/auth/middleware.js.map +1 -1
  69. package/dist/core/auth/multi-auth.d.ts.map +1 -1
  70. package/dist/core/auth/multi-auth.js +6 -6
  71. package/dist/core/auth/multi-auth.js.map +1 -1
  72. package/dist/core/auth/revocation.d.ts.map +1 -1
  73. package/dist/core/auth/revocation.js +2 -6
  74. package/dist/core/auth/revocation.js.map +1 -1
  75. package/dist/core/auth/token-generator/ntlm/ntlm-auth-options.d.ts.map +1 -1
  76. package/dist/core/auth/token-generator/ntlm/ntlm-auth-options.js +2 -2
  77. package/dist/core/auth/token-generator/ntlm/ntlm-auth-options.js.map +1 -1
  78. package/dist/core/auth/token-generator/ntlm/ntlm-domain-config.js +1 -1
  79. package/dist/core/auth/token-generator/ntlm/ntlm-domain-config.js.map +1 -1
  80. package/dist/core/auth/token-generator/ntlm/ntlm-integration.d.ts.map +1 -1
  81. package/dist/core/auth/token-generator/ntlm/ntlm-integration.js +4 -2
  82. package/dist/core/auth/token-generator/ntlm/ntlm-integration.js.map +1 -1
  83. package/dist/core/auth/token-generator/server.d.ts.map +1 -1
  84. package/dist/core/auth/token-generator/server.js.map +1 -1
  85. package/dist/core/bootstrap/init-config.d.ts.map +1 -1
  86. package/dist/core/bootstrap/init-config.js +2 -2
  87. package/dist/core/bootstrap/init-config.js.map +1 -1
  88. package/dist/core/bootstrap/startup-info.d.ts.map +1 -1
  89. package/dist/core/bootstrap/startup-info.js +3 -7
  90. package/dist/core/bootstrap/startup-info.js.map +1 -1
  91. package/dist/core/cache/cache.d.ts.map +1 -1
  92. package/dist/core/cache/cache.js +2 -2
  93. package/dist/core/cache/cache.js.map +1 -1
  94. package/dist/core/consul/deregister.d.ts.map +1 -1
  95. package/dist/core/consul/deregister.js.map +1 -1
  96. package/dist/core/consul/get-consul-api.d.ts.map +1 -1
  97. package/dist/core/consul/get-consul-api.js +1 -2
  98. package/dist/core/consul/get-consul-api.js.map +1 -1
  99. package/dist/core/db/pg-db.d.ts.map +1 -1
  100. package/dist/core/db/pg-db.js +3 -3
  101. package/dist/core/db/pg-db.js.map +1 -1
  102. package/dist/core/debug.d.ts.map +1 -1
  103. package/dist/core/debug.js.map +1 -1
  104. package/dist/core/errors/BaseMcpError.d.ts.map +1 -1
  105. package/dist/core/errors/BaseMcpError.js.map +1 -1
  106. package/dist/core/errors/ValidationError.d.ts.map +1 -1
  107. package/dist/core/errors/ValidationError.js.map +1 -1
  108. package/dist/core/errors/errors.d.ts.map +1 -1
  109. package/dist/core/errors/errors.js +1 -1
  110. package/dist/core/errors/errors.js.map +1 -1
  111. package/dist/core/index.d.ts +6 -6
  112. package/dist/core/index.d.ts.map +1 -1
  113. package/dist/core/index.js +5 -5
  114. package/dist/core/index.js.map +1 -1
  115. package/dist/core/init-mcp-server.d.ts.map +1 -1
  116. package/dist/core/init-mcp-server.js.map +1 -1
  117. package/dist/core/logger.d.ts.map +1 -1
  118. package/dist/core/logger.js +1 -1
  119. package/dist/core/logger.js.map +1 -1
  120. package/dist/core/mcp/create-mcp-server.d.ts.map +1 -1
  121. package/dist/core/mcp/create-mcp-server.js +1 -1
  122. package/dist/core/mcp/create-mcp-server.js.map +1 -1
  123. package/dist/core/mcp/prompts.d.ts.map +1 -1
  124. package/dist/core/mcp/prompts.js.map +1 -1
  125. package/dist/core/mcp/readme-assembler.d.ts.map +1 -1
  126. package/dist/core/mcp/readme-assembler.js +3 -1
  127. package/dist/core/mcp/readme-assembler.js.map +1 -1
  128. package/dist/core/mcp/resources.d.ts.map +1 -1
  129. package/dist/core/mcp/resources.js.map +1 -1
  130. package/dist/core/mcp/server-stdio.d.ts.map +1 -1
  131. package/dist/core/utils/formatToolResult.d.ts.map +1 -1
  132. package/dist/core/utils/formatToolResult.js.map +1 -1
  133. package/dist/core/utils/port-checker.d.ts.map +1 -1
  134. package/dist/core/utils/port-checker.js.map +1 -1
  135. package/dist/core/utils/rate-limit.d.ts.map +1 -1
  136. package/dist/core/utils/rate-limit.js +2 -8
  137. package/dist/core/utils/rate-limit.js.map +1 -1
  138. package/dist/core/utils/testing/BaseMcpClient.d.ts.map +1 -1
  139. package/dist/core/utils/testing/BaseMcpClient.js.map +1 -1
  140. package/dist/core/utils/testing/McpHttpClient.d.ts.map +1 -1
  141. package/dist/core/utils/testing/McpHttpClient.js +2 -2
  142. package/dist/core/utils/testing/McpHttpClient.js.map +1 -1
  143. package/dist/core/utils/testing/McpSseClient.d.ts.map +1 -1
  144. package/dist/core/utils/testing/McpSseClient.js +3 -8
  145. package/dist/core/utils/testing/McpSseClient.js.map +1 -1
  146. package/dist/core/utils/testing/McpStdioClient.d.ts.map +1 -1
  147. package/dist/core/utils/testing/McpStdioClient.js.map +1 -1
  148. package/dist/core/utils/testing/McpStreamableHttpClient.d.ts.map +1 -1
  149. package/dist/core/utils/testing/McpStreamableHttpClient.js +7 -8
  150. package/dist/core/utils/testing/McpStreamableHttpClient.js.map +1 -1
  151. package/dist/core/utils/utils.d.ts.map +1 -1
  152. package/dist/core/utils/utils.js +3 -5
  153. package/dist/core/utils/utils.js.map +1 -1
  154. package/dist/core/web/admin-router.d.ts.map +1 -1
  155. package/dist/core/web/admin-router.js +3 -3
  156. package/dist/core/web/admin-router.js.map +1 -1
  157. package/dist/core/web/cors.d.ts.map +1 -1
  158. package/dist/core/web/cors.js.map +1 -1
  159. package/dist/core/web/favicon-svg.d.ts.map +1 -1
  160. package/dist/core/web/favicon-svg.js +1 -5
  161. package/dist/core/web/favicon-svg.js.map +1 -1
  162. package/dist/core/web/home-api.d.ts.map +1 -1
  163. package/dist/core/web/home-api.js +7 -8
  164. package/dist/core/web/home-api.js.map +1 -1
  165. package/dist/core/web/openapi.d.ts.map +1 -1
  166. package/dist/core/web/openapi.js +1 -3
  167. package/dist/core/web/openapi.js.map +1 -1
  168. package/dist/core/web/server-http.d.ts.map +1 -1
  169. package/dist/core/web/server-http.js +4 -4
  170. package/dist/core/web/server-http.js.map +1 -1
  171. package/dist/core/web/static/agent-tester/index.html +323 -323
  172. package/dist/core/web/static/agent-tester/script.js +311 -200
  173. package/dist/core/web/static/agent-tester/styles.css +1840 -1840
  174. package/dist/core/web/static/home/index.html +220 -220
  175. package/dist/core/web/static/home/script.js +72 -43
  176. package/dist/core/web/static/styles.css +927 -927
  177. package/dist/core/web/static/token-gen/index.html +136 -136
  178. package/dist/core/web/static/token-gen/script.js +58 -56
  179. package/dist/core/web/svg-icons.d.ts.map +1 -1
  180. package/dist/core/web/svg-icons.js +1 -5
  181. package/dist/core/web/svg-icons.js.map +1 -1
  182. package/package.json +10 -5
  183. package/{cli-template/.claude/hooks/eslint-fix.cjs → scripts/cc-hook-oxlint-oxfmt-fix.cjs} +109 -100
  184. package/scripts/generate-jwt.js +5 -9
  185. package/scripts/kill-port.js +5 -2
  186. package/scripts/npm/run.js +1 -2
  187. package/scripts/remove-nul.js +1 -1
  188. package/scripts/update-sdk.js +36 -14
  189. package/src/template/api/router.ts +3 -3
  190. package/src/template/prompts/agent-brief.ts +0 -1
  191. package/src/template/start.ts +3 -8
  192. package/src/template/tools/handle-tool-call.ts +3 -3
  193. package/src/template/tools/tools.ts +3 -7
  194. package/src/tests/jest-simple-reporter.js +1 -1
  195. package/src/tests/mcp/sse/mcp-sse-client-handling.md +111 -111
  196. package/src/tests/mcp/sse/test-sse-npm-package.js +2 -3
  197. package/src/tests/mcp/test-cases.js +6 -7
  198. package/src/tests/mcp/test-http.js +2 -2
  199. package/src/tests/mcp/test-sse.js +9 -7
  200. package/src/tests/mcp/test-stdio.js +12 -8
  201. package/src/tests/utils.ts +4 -3
  202. package/cli-template/eslint.config.js +0 -27
@@ -0,0 +1,427 @@
1
+ ---
2
+ name: mcp-app-add-to-server
3
+ description: This skill should be used when the user asks to "add an app to my MCP server", "add UI to my MCP server", "add a view to my MCP tool", "enrich MCP tools with UI", "add interactive UI to existing server", "add MCP Apps to my server", or needs to add interactive UI capabilities to an existing MCP server that already has tools. Provides guidance for analyzing existing tools and adding MCP Apps UI resources.
4
+ ---
5
+
6
+ # Add UI to MCP Server
7
+
8
+ Enrich an existing MCP server's tools with interactive UIs using the MCP Apps SDK (`@modelcontextprotocol/ext-apps`).
9
+
10
+ ## How It Works
11
+
12
+ Existing tools get paired with HTML resources that render inline in the host's conversation. The tool continues to work for text-only clients — UI is an enhancement, not a replacement. Each tool that benefits from UI gets linked to a resource via `_meta.ui.resourceUri`, and the host renders that resource in a sandboxed iframe when the tool is called.
13
+
14
+ ## Getting Reference Code
15
+
16
+ Clone the MCP Apps SDK repository (`@modelcontextprotocol/ext-apps`) for working examples and API documentation:
17
+
18
+ ```bash
19
+ git clone --branch "v$(npm view @modelcontextprotocol/ext-apps version)" --depth 1 https://github.com/modelcontextprotocol/ext-apps.git ./mcp-ext-apps
20
+ ```
21
+
22
+ > Add `mcp-ext-apps/` to the project's `.gitignore` — it's a reference clone, not part of the project.
23
+
24
+ ### Protocol Specification
25
+
26
+ The formal MCP Apps spec lives in the same repository — read it for authoritative protocol
27
+ semantics that source files and examples only illustrate:
28
+
29
+ | File | Contents |
30
+ |------|----------|
31
+ | `./mcp-ext-apps/specification/2026-01-26/apps.mdx` | **SEP-1865** (Stable, 2026-01-26) — `ui://` URI scheme, `_meta.ui` contract, iframe sandboxing, host↔UI JSON-RPC messages, security model |
32
+
33
+ **Where to look first:**
34
+
35
+ - For **protocol questions** (wire format, required `_meta` keys, mandatory host/server behaviors,
36
+ message semantics) — consult `./mcp-ext-apps/specification/2026-01-26/apps.mdx`. The spec is the source of
37
+ truth for what MUST happen.
38
+ - For **TypeScript API questions** (which helper to call, handler signatures, idiomatic usage) —
39
+ consult `@modelcontextprotocol/ext-apps` sources under `./mcp-ext-apps/src/` and its examples.
40
+ The package is the source of truth for *how* to invoke the protocol from code.
41
+
42
+ ### API Reference (Source Files)
43
+
44
+ Read JSDoc documentation directly from `./mcp-ext-apps/src/`:
45
+
46
+ | File | Contents |
47
+ |------|----------|
48
+ | `src/app.ts` | `App` class, handlers (`ontoolinput`, `ontoolresult`, `onhostcontextchanged`, `onteardown`), lifecycle |
49
+ | `src/server/index.ts` | `registerAppTool`, `registerAppResource`, `getUiCapability`, tool visibility options |
50
+ | `src/spec.types.ts` | All type definitions: `McpUiHostContext`, CSS variable keys, display modes |
51
+ | `src/styles.ts` | `applyDocumentTheme`, `applyHostStyleVariables`, `applyHostFonts` |
52
+ | `src/react/useApp.tsx` | `useApp` hook for React apps |
53
+ | `src/react/useHostStyles.ts` | `useHostStyles`, `useHostStyleVariables`, `useHostFonts` hooks |
54
+
55
+ ### Key Examples (Mixed Tool Patterns)
56
+
57
+ These examples demonstrate servers with both App-enhanced and plain tools — the exact pattern you're adding:
58
+
59
+ | Example | Pattern |
60
+ |---------|---------|
61
+ | `examples/map-server/` | `show-map` (App tool) + `geocode` (plain tool) |
62
+ | `examples/pdf-server/` | `display_pdf` (App tool) + `list_pdfs` (plain tool) + `read_pdf_bytes` (app-only tool) |
63
+ | `examples/system-monitor-server/` | `get-system-info` (App tool) + `poll-system-stats` (app-only polling tool) |
64
+
65
+ ### Domain-Specific Examples
66
+
67
+ When the new UI matches one of these domains, consult the corresponding example for patterns
68
+ the basic templates and mixed examples don't cover. All paths are under `./mcp-ext-apps/`:
69
+
70
+ | Domain | Example | What it shows |
71
+ |---|---|---|
72
+ | Charts / dashboards | `examples/scenario-modeler-server/` | Chart.js with structured React (`hooks/`, `lib/`, `components/`); multi-scenario comparison |
73
+ | Analytics drill-down | `examples/cohort-heatmap-server/` | Heatmap with hover tooltips and click drilldown (React) |
74
+ | 3D visualization | `examples/threejs-server/` | Three.js + streaming tool input into canvas, OrbitControls, post-processing |
75
+ | WebGL / shaders | `examples/shadertoy-server/` | GLSL live compilation, fullscreen mode, `vendor/` pattern for custom JS libs |
76
+ | Graph visualization | `examples/wiki-explorer-server/` | 3D force-directed graph (`force-graph`), web scraping with `cheerio` |
77
+ | Audio / music | `examples/sheet-music-server/` | ABC notation → SVG render + MIDI synthesis (`abcjs`) |
78
+ | Streaming + audio | `examples/say-server/` | `ontoolinputpartial` + async audio queue + multi-view lock (**Python FastMCP**) |
79
+ | Browser APIs | `examples/transcript-server/` | Web Speech API for live transcription |
80
+ | Binary / media resources | `examples/video-resource-server/` | Base64 video blobs, `ResourceTemplate`, large-payload limits |
81
+ | SDK surface reference | `examples/debug-server/` | All content types in one place — PNG/WAV blobs, structured output, stateful counter, resource downloads |
82
+
83
+ ### Framework Templates
84
+
85
+ Learn and adapt from `./mcp-ext-apps/examples/basic-server-{framework}/`:
86
+
87
+ | Template | Key Files |
88
+ |----------|-----------|
89
+ | `basic-server-vanillajs/` | `server.ts`, `src/mcp-app.ts`, `mcp-app.html` |
90
+ | `basic-server-react/` | `server.ts`, `src/mcp-app.tsx` (uses `useApp` hook) |
91
+ | `basic-server-vue/` | `server.ts`, `src/App.vue` |
92
+ | `basic-server-svelte/` | `server.ts`, `src/App.svelte` |
93
+ | `basic-server-preact/` | `server.ts`, `src/mcp-app.tsx` |
94
+ | `basic-server-solid/` | `server.ts`, `src/mcp-app.tsx` |
95
+
96
+ ## Step 1: Analyze Existing Tools
97
+
98
+ Before writing any code, analyze the server's existing tools and determine which ones benefit from UI.
99
+
100
+ 1. Read the server source and list all registered tools
101
+ 2. For each tool, assess whether it would benefit from UI (returns data that could be visualized, involves user interaction, etc.) vs. is fine as text-only (simple lookups, utility functions)
102
+ 3. Identify tools that could become **app-only helpers** (data the UI needs to poll/fetch but the model doesn't need to call directly)
103
+ 4. Present the analysis to the user and confirm which tools to enhance
104
+
105
+ ### Decision Framework
106
+
107
+ | Tool output type | UI benefit | Example |
108
+ |---|---|---|
109
+ | Structured data / lists / tables | High — interactive table, search, filtering | List of items, search results |
110
+ | Metrics / numbers over time | High — charts, gauges, dashboards | System stats, analytics |
111
+ | Media / rich content | High — viewer, player, renderer | Maps, PDFs, images, video |
112
+ | Simple text / confirmations | Low — text is fine | "File created", "Setting updated" |
113
+ | Data for other tools | Consider app-only | Polling endpoints, chunk loaders |
114
+
115
+ ## Step 2: Add Dependencies
116
+
117
+ ```bash
118
+ npm install @modelcontextprotocol/ext-apps
119
+ npm install -D vite vite-plugin-singlefile
120
+ ```
121
+
122
+ Plus framework-specific dependencies if needed (e.g., `react`, `react-dom`, `@vitejs/plugin-react` for React).
123
+
124
+ Use `npm install` to add dependencies rather than manually writing version numbers. This lets npm resolve the latest compatible versions. Never specify version numbers from memory.
125
+
126
+ ## Step 3: Set Up the Build Pipeline
127
+
128
+ ### Vite Configuration
129
+
130
+ Create `vite.config.ts` with `vite-plugin-singlefile` to bundle the UI into a single HTML file:
131
+
132
+ ```typescript
133
+ import { defineConfig } from "vite";
134
+ import { viteSingleFile } from "vite-plugin-singlefile";
135
+
136
+ export default defineConfig({
137
+ plugins: [viteSingleFile()],
138
+ build: {
139
+ outDir: "dist",
140
+ rollupOptions: {
141
+ input: "mcp-app.html", // one per UI, or one shared entry
142
+ },
143
+ },
144
+ });
145
+ ```
146
+
147
+ ### HTML Entry Point
148
+
149
+ Create `mcp-app.html` (or one per distinct UI if tools need different views):
150
+
151
+ ```html
152
+ <!doctype html>
153
+ <html lang="en">
154
+ <head>
155
+ <meta charset="UTF-8" />
156
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
157
+ <title>MCP App</title>
158
+ </head>
159
+ <body>
160
+ <div id="root"></div>
161
+ <script type="module" src="./src/mcp-app.ts"></script>
162
+ </body>
163
+ </html>
164
+ ```
165
+
166
+ ### Build Scripts
167
+
168
+ Add build scripts to `package.json`. The UI must be built before the server code bundles it:
169
+
170
+ ```json
171
+ {
172
+ "scripts": {
173
+ "build:ui": "vite build",
174
+ "build:server": "tsc",
175
+ "build": "npm run build:ui && npm run build:server",
176
+ "serve": "tsx server.ts"
177
+ }
178
+ }
179
+ ```
180
+
181
+ ## Step 4: Convert Tools to App Tools
182
+
183
+ Transform plain MCP tools into App tools with UI.
184
+
185
+ **Before** (plain MCP tool):
186
+ ```typescript
187
+ server.tool("my-tool", { param: z.string() }, async (args) => {
188
+ const data = await fetchData(args.param);
189
+ return { content: [{ type: "text", text: JSON.stringify(data) }] };
190
+ });
191
+ ```
192
+
193
+ **After** (App tool with UI):
194
+ ```typescript
195
+ import { registerAppTool, registerAppResource, RESOURCE_MIME_TYPE } from "@modelcontextprotocol/ext-apps/server";
196
+
197
+ const resourceUri = "ui://my-tool/mcp-app.html";
198
+
199
+ registerAppTool(server, "my-tool", {
200
+ description: "Shows data with an interactive UI",
201
+ inputSchema: { param: z.string() },
202
+ _meta: { ui: { resourceUri } },
203
+ }, async (args) => {
204
+ const data = await fetchData(args.param);
205
+ return {
206
+ content: [{ type: "text", text: JSON.stringify(data) }], // text fallback for non-UI hosts
207
+ structuredContent: { data }, // structured data for the UI
208
+ };
209
+ });
210
+ ```
211
+
212
+ Key guidance:
213
+ - **Always keep the `content` array** with a text fallback for text-only clients
214
+ - Add `structuredContent` for data the UI needs to render
215
+ - Link the tool to its resource via `_meta.ui.resourceUri`
216
+ - Leave tools that don't benefit from UI unchanged — they stay as plain tools
217
+
218
+ ## Step 5: Register Resources
219
+
220
+ Register the HTML resource so the host can fetch it:
221
+
222
+ ```typescript
223
+ import fs from "node:fs/promises";
224
+ import path from "node:path";
225
+
226
+ const resourceUri = "ui://my-tool/mcp-app.html";
227
+
228
+ registerAppResource(server, {
229
+ uri: resourceUri,
230
+ name: "My Tool UI",
231
+ mimeType: RESOURCE_MIME_TYPE,
232
+ }, async () => {
233
+ const html = await fs.readFile(
234
+ path.resolve(import.meta.dirname, "dist", "mcp-app.html"),
235
+ "utf-8",
236
+ );
237
+ return { contents: [{ uri: resourceUri, mimeType: RESOURCE_MIME_TYPE, text: html }] };
238
+ });
239
+ ```
240
+
241
+ If multiple tools share the same UI, they can reference the same `resourceUri` and the same resource registration.
242
+
243
+ ## Step 6: Build the UI
244
+
245
+ ### Handler Registration
246
+
247
+ Register ALL handlers BEFORE calling `app.connect()`:
248
+
249
+ ```typescript
250
+ import { App, PostMessageTransport, applyDocumentTheme, applyHostStyleVariables, applyHostFonts } from "@modelcontextprotocol/ext-apps";
251
+
252
+ const app = new App({ name: "My App", version: "1.0.0" });
253
+
254
+ app.ontoolinput = (params) => {
255
+ // Render the UI using params.arguments and/or params.structuredContent
256
+ };
257
+
258
+ app.ontoolresult = (result) => {
259
+ // Update UI with final tool result
260
+ };
261
+
262
+ app.onhostcontextchanged = (ctx) => {
263
+ if (ctx.theme) applyDocumentTheme(ctx.theme);
264
+ if (ctx.styles?.variables) applyHostStyleVariables(ctx.styles.variables);
265
+ if (ctx.styles?.css?.fonts) applyHostFonts(ctx.styles.css.fonts);
266
+ if (ctx.safeAreaInsets) {
267
+ const { top, right, bottom, left } = ctx.safeAreaInsets;
268
+ document.body.style.padding = `${top}px ${right}px ${bottom}px ${left}px`;
269
+ }
270
+ };
271
+
272
+ app.onteardown = async () => {
273
+ return {};
274
+ };
275
+
276
+ await app.connect(new PostMessageTransport());
277
+ ```
278
+
279
+ ### Host Styling
280
+
281
+ Use host CSS variables for theme integration:
282
+
283
+ ```css
284
+ .container {
285
+ background: var(--color-background-secondary);
286
+ color: var(--color-text-primary);
287
+ font-family: var(--font-sans);
288
+ border-radius: var(--border-radius-md);
289
+ }
290
+ ```
291
+
292
+ Key variable groups: `--color-background-*`, `--color-text-*`, `--color-border-*`, `--font-sans`, `--font-mono`, `--font-text-*-size`, `--font-heading-*-size`, `--border-radius-*`. See `src/spec.types.ts` for the full list.
293
+
294
+ For React apps, use the `useApp` and `useHostStyles` hooks instead — see `basic-server-react/` for the pattern.
295
+
296
+ ## Optional Enhancements
297
+
298
+ ### App-Only Helper Tools
299
+
300
+ Tools the UI calls but the model doesn't need to invoke directly (polling, pagination, chunk loading):
301
+
302
+ ```typescript
303
+ registerAppTool(server, "poll-data", {
304
+ description: "Polls latest data for the UI",
305
+ _meta: { ui: { resourceUri, visibility: ["app"] } },
306
+ }, async () => {
307
+ const data = await getLatestData();
308
+ return { content: [{ type: "text", text: JSON.stringify(data) }] };
309
+ });
310
+ ```
311
+
312
+ The UI calls these via `app.callServerTool("poll-data", {})`.
313
+
314
+ ### CSP Configuration
315
+
316
+ If the UI needs to load external resources (fonts, APIs, CDNs), declare the domains:
317
+
318
+ ```typescript
319
+ registerAppResource(server, {
320
+ uri: resourceUri,
321
+ name: "My Tool UI",
322
+ mimeType: RESOURCE_MIME_TYPE,
323
+ _meta: {
324
+ ui: {
325
+ connectDomains: ["api.example.com"], // fetch/XHR targets
326
+ resourceDomains: ["cdn.example.com"], // scripts, styles, images
327
+ frameDomains: ["embed.example.com"], // nested iframes
328
+ },
329
+ },
330
+ }, async () => { /* ... */ });
331
+ ```
332
+
333
+ ### Streaming Partial Input
334
+
335
+ For large tool inputs, show progress during LLM generation:
336
+
337
+ ```typescript
338
+ app.ontoolinputpartial = (params) => {
339
+ const args = params.arguments; // Healed partial JSON - always valid
340
+ // Render preview with partial data
341
+ };
342
+
343
+ app.ontoolinput = (params) => {
344
+ // Final complete input - switch to full render
345
+ };
346
+ ```
347
+
348
+ ### Graceful Degradation with `getUiCapability()`
349
+
350
+ Conditionally register App tools only when the client supports UI, falling back to text-only tools:
351
+
352
+ ```typescript
353
+ import { getUiCapability, registerAppTool, RESOURCE_MIME_TYPE } from "@modelcontextprotocol/ext-apps/server";
354
+
355
+ server.server.oninitialized = () => {
356
+ const clientCapabilities = server.server.getClientCapabilities();
357
+ const uiCap = getUiCapability(clientCapabilities);
358
+
359
+ if (uiCap?.mimeTypes?.includes(RESOURCE_MIME_TYPE)) {
360
+ // Client supports UI — register App tool
361
+ registerAppTool(server, "my-tool", {
362
+ description: "Shows data with interactive UI",
363
+ _meta: { ui: { resourceUri } },
364
+ }, appToolHandler);
365
+ } else {
366
+ // Text-only client — register plain tool
367
+ server.tool("my-tool", "Shows data", { param: z.string() }, plainToolHandler);
368
+ }
369
+ };
370
+ ```
371
+
372
+ ### Fullscreen Mode
373
+
374
+ Allow the UI to expand to fullscreen:
375
+
376
+ ```typescript
377
+ app.onhostcontextchanged = (ctx) => {
378
+ if (ctx.availableDisplayModes?.includes("fullscreen")) {
379
+ fullscreenBtn.style.display = "block";
380
+ }
381
+ if (ctx.displayMode) {
382
+ container.classList.toggle("fullscreen", ctx.displayMode === "fullscreen");
383
+ }
384
+ };
385
+
386
+ async function toggleFullscreen() {
387
+ const newMode = currentMode === "fullscreen" ? "inline" : "fullscreen";
388
+ const result = await app.requestDisplayMode({ mode: newMode });
389
+ currentMode = result.mode;
390
+ }
391
+ ```
392
+
393
+ ## Common Mistakes to Avoid
394
+
395
+ 1. **Forgetting text `content` fallback** — Always include `content` array with text for non-UI hosts
396
+ 2. **Registering handlers after `connect()`** — Register ALL handlers BEFORE calling `app.connect()`
397
+ 3. **Missing `vite-plugin-singlefile`** — Without it, assets won't load in the sandboxed iframe
398
+ 4. **Forgetting resource registration** — The tool references a `resourceUri` that must have a matching resource
399
+ 5. **Hardcoding styles** — Use host CSS variables (`var(--color-*)`) for theme integration
400
+ 6. **Not handling safe area insets** — Always apply `ctx.safeAreaInsets` in `onhostcontextchanged`
401
+
402
+ ## Testing
403
+
404
+ ### Using basic-host
405
+
406
+ Test the enhanced server with the basic-host example:
407
+
408
+ ```bash
409
+ # Terminal 1: Build and run your server
410
+ npm run build && npm run serve
411
+
412
+ # Terminal 2: Run basic-host (from cloned repo)
413
+ cd ./mcp-ext-apps/examples/basic-host
414
+ npm install
415
+ SERVERS='["http://localhost:3001/mcp"]' npm run start
416
+ # Open http://localhost:8080
417
+ ```
418
+
419
+ Configure `SERVERS` with a JSON array of your server URLs (default: `http://localhost:3001/mcp`).
420
+
421
+ ### Verify
422
+
423
+ 1. Plain tools still work and return text output
424
+ 2. App tools render their UI in the iframe
425
+ 3. `ontoolinput` handler fires with tool arguments
426
+ 4. `ontoolresult` handler fires with tool result
427
+ 5. Host styling (theme, fonts, colors) applies correctly
@@ -0,0 +1,222 @@
1
+ ---
2
+ name: mcp-app-create
3
+ description: This skill should be used when the user asks to "create an MCP App", "add a UI to an MCP tool", "build an interactive MCP View", "scaffold an MCP App", or needs guidance on MCP Apps SDK patterns, UI-resource registration, MCP App lifecycle, or host integration. Provides comprehensive guidance for building MCP Apps with interactive UIs.
4
+ ---
5
+
6
+ # Create MCP App
7
+
8
+ Build interactive UIs that run inside MCP-enabled hosts like Claude Desktop. An MCP App combines an MCP tool with an HTML resource to display rich, interactive content.
9
+
10
+ ## Core Concept: Tool + Resource
11
+
12
+ Every MCP App requires two parts linked together:
13
+
14
+ 1. **Tool** - Called by the LLM/host, returns data
15
+ 2. **Resource** - Serves the bundled HTML UI that displays the data
16
+
17
+ The tool's `_meta.ui.resourceUri` references the resource's URI.
18
+
19
+ Host calls tool → Host renders resource UI → Server returns result → UI receives result.
20
+
21
+ ## Quick Start Decision Tree
22
+
23
+ ### Framework Selection
24
+
25
+ | Framework | `@modelcontextprotocol/ext-apps` Support | Best For |
26
+ |-----------|-------------|----------|
27
+ | React | `useApp` hook provided | Teams familiar with React |
28
+ | Vanilla JS | Manual lifecycle | Simple apps, no build complexity |
29
+ | Vue/Svelte/Preact/Solid | Manual lifecycle | Framework preference |
30
+
31
+ ### Project Context
32
+
33
+ **Adding to existing MCP server:**
34
+ - Import `registerAppTool`, `registerAppResource` from `@modelcontextprotocol/ext-apps`
35
+ - Add tool registration with `_meta.ui.resourceUri`
36
+ - Add resource registration serving bundled HTML
37
+
38
+ **Creating new MCP server:**
39
+ - Set up server with transport (stdio or HTTP)
40
+ - Register tools and resources
41
+ - Configure build system with `vite-plugin-singlefile`
42
+
43
+ ## Getting Reference Code
44
+
45
+ Clone the MCP Apps SDK repository (`@modelcontextprotocol/ext-apps`) for working examples and API documentation:
46
+
47
+ ```bash
48
+ git clone --branch "v$(npm view @modelcontextprotocol/ext-apps version)" --depth 1 https://github.com/modelcontextprotocol/ext-apps.git ./mcp-ext-apps
49
+ ```
50
+
51
+ > Add `mcp-ext-apps/` to the project's `.gitignore` — it's a reference clone, not part of the project.
52
+
53
+ ### Protocol Specification
54
+
55
+ The formal MCP Apps spec lives in the same repository — read it for authoritative protocol
56
+ semantics that source files and examples only illustrate:
57
+
58
+ | File | Contents |
59
+ |------|----------|
60
+ | `./mcp-ext-apps/specification/2026-01-26/apps.mdx` | **SEP-1865** (Stable, 2026-01-26) — `ui://` URI scheme, `_meta.ui` contract, iframe sandboxing, host↔UI JSON-RPC messages, security model |
61
+
62
+ **Where to look first:**
63
+
64
+ - For **protocol questions** (wire format, required `_meta` keys, mandatory host/server behaviors,
65
+ message semantics) — consult `./mcp-ext-apps/specification/2026-01-26/apps.mdx`. The spec is the source of
66
+ truth for what MUST happen.
67
+ - For **TypeScript API questions** (which helper to call, handler signatures, idiomatic usage) —
68
+ consult `@modelcontextprotocol/ext-apps` sources under `./mcp-ext-apps/src/` and its examples.
69
+ The package is the source of truth for *how* to invoke the protocol from code.
70
+
71
+ ### Framework Templates
72
+
73
+ Learn and adapt from `./mcp-ext-apps/examples/basic-server-{framework}/`:
74
+
75
+ | Template | Key Files |
76
+ |----------|-----------|
77
+ | `basic-server-vanillajs/` | `server.ts`, `src/mcp-app.ts`, `mcp-app.html` |
78
+ | `basic-server-react/` | `server.ts`, `src/mcp-app.tsx` (uses `useApp` hook) |
79
+ | `basic-server-vue/` | `server.ts`, `src/App.vue` |
80
+ | `basic-server-svelte/` | `server.ts`, `src/App.svelte` |
81
+ | `basic-server-preact/` | `server.ts`, `src/mcp-app.tsx` |
82
+ | `basic-server-solid/` | `server.ts`, `src/mcp-app.tsx` |
83
+
84
+ Each template includes:
85
+ - `server.ts` with `registerAppTool` and `registerAppResource`
86
+ - `main.ts` entry point with HTTP and stdio transport setup
87
+ - Client-side app (e.g., `src/mcp-app.ts`, `src/mcp-app.tsx`) with lifecycle handlers
88
+ - `src/global.css` with global styles and host style variable fallbacks
89
+ - `vite.config.ts` using `vite-plugin-singlefile`
90
+ - `package.json` with `npm run` scripts and required dependencies
91
+ - `.gitignore` excluding `node_modules/` and `dist/`
92
+
93
+ ### Domain-Specific Examples
94
+
95
+ When the App's UI matches one of these domains, consult the corresponding example for patterns
96
+ the basic templates don't cover. All paths are under `./mcp-ext-apps/`:
97
+
98
+ | Domain | Example | What it shows |
99
+ |---|---|---|
100
+ | Charts / dashboards | `examples/scenario-modeler-server/` | Chart.js with structured React (`hooks/`, `lib/`, `components/`); multi-scenario comparison |
101
+ | Analytics drill-down | `examples/cohort-heatmap-server/` | Heatmap with hover tooltips and click drilldown (React) |
102
+ | 3D visualization | `examples/threejs-server/` | Three.js + streaming tool input into canvas, OrbitControls, post-processing |
103
+ | WebGL / shaders | `examples/shadertoy-server/` | GLSL live compilation, fullscreen mode, `vendor/` pattern for custom JS libs |
104
+ | Graph visualization | `examples/wiki-explorer-server/` | 3D force-directed graph (`force-graph`), web scraping with `cheerio` |
105
+ | Audio / music | `examples/sheet-music-server/` | ABC notation → SVG render + MIDI synthesis (`abcjs`) |
106
+ | Streaming + audio | `examples/say-server/` | `ontoolinputpartial` + async audio queue + multi-view lock (**Python FastMCP**) |
107
+ | Browser APIs | `examples/transcript-server/` | Web Speech API for live transcription |
108
+ | Binary / media resources | `examples/video-resource-server/` | Base64 video blobs, `ResourceTemplate`, large-payload limits |
109
+ | SDK surface reference | `examples/debug-server/` | All content types in one place — PNG/WAV blobs, structured output, stateful counter, resource downloads |
110
+
111
+ ### API Reference (Source Files)
112
+
113
+ Read JSDoc documentation directly from `./mcp-ext-apps/src/`:
114
+
115
+ | File | Contents |
116
+ |------|----------|
117
+ | `src/app.ts` | `App` class, handlers (`ontoolinput`, `ontoolresult`, `onhostcontextchanged`, `onteardown`, etc.), lifecycle |
118
+ | `src/server/index.ts` | `registerAppTool`, `registerAppResource`, helper functions |
119
+ | `src/spec.types.ts` | All type definitions: `McpUiHostContext`, `McpUiStyleVariableKey` (CSS variable names), `McpUiResourceCsp` (CSP configuration), etc. |
120
+ | `src/styles.ts` | `applyDocumentTheme`, `applyHostStyleVariables`, `applyHostFonts` |
121
+ | `src/react/useApp.tsx` | `useApp` hook for React apps |
122
+
123
+ ### Advanced Patterns
124
+
125
+ See `./mcp-ext-apps/docs/patterns.md` for detailed recipes:
126
+
127
+ - **App-only tools** — `visibility: ["app"]`, hiding tools from model
128
+ - **Polling** — real-time dashboards, interval management
129
+ - **Chunked responses** — large files, pagination, base64 encoding
130
+ - **Error handling** — `isError`, informing model of failures
131
+ - **Binary resources** — audio/video/etc via `resources/read`, blob field
132
+ - **Network requests** — assets, fetch, CSP, `_meta.ui.csp`, CORS, `_meta.ui.domain`
133
+ - **Host context** — theme, styling, fonts, safe area insets
134
+ - **Fullscreen mode** — `requestDisplayMode`, display mode changes
135
+ - **Model context** — `updateModelContext`, `sendMessage`, keeping model informed
136
+ - **View state** — `viewUUID`, localStorage, state recovery
137
+ - **Visibility-based pause** — IntersectionObserver, pausing animations/WebGL
138
+ - **Streaming input** — `ontoolinputpartial`, progressive rendering
139
+
140
+ ### Reference Host Implementation
141
+
142
+ `./mcp-ext-apps/examples/basic-host/` shows one way an MCP Apps-capable host could be implemented. Real-world hosts like Claude Desktop are more sophisticated—use basic-host for local testing and protocol understanding, not as a guarantee of host behavior.
143
+
144
+ ## Critical Implementation Notes
145
+
146
+ ### Adding Dependencies
147
+
148
+ **Always** use `npm install` to add dependencies rather than manually writing version numbers:
149
+
150
+ ```bash
151
+ npm install @modelcontextprotocol/ext-apps @modelcontextprotocol/sdk zod express cors
152
+ npm install -D typescript vite vite-plugin-singlefile concurrently cross-env @types/node @types/express @types/cors
153
+ ```
154
+
155
+ This lets npm resolve the latest compatible versions. **Never** specify version numbers from memory.
156
+
157
+ ### TypeScript Server Execution
158
+
159
+ Unless the user has specified otherwise, use `tsx` for running TypeScript server files. For example:
160
+
161
+ ```bash
162
+ npm install -D tsx
163
+
164
+ npm pkg set scripts.dev="cross-env NODE_ENV=development concurrently 'cross-env INPUT=mcp-app.html vite build --watch' 'tsx --watch main.ts'"
165
+ ```
166
+
167
+ > [!NOTE]
168
+ > The `@modelcontextprotocol/ext-apps` examples use `bun` but generated projects should default to `tsx` for broader compatibility.
169
+
170
+ ### Handler Registration Order
171
+
172
+ Register ALL handlers BEFORE calling `app.connect()`:
173
+
174
+ ```typescript
175
+ const app = new App({ name: "My App", version: "1.0.0" });
176
+
177
+ // Register handlers first
178
+ app.ontoolinput = (params) => { /* handle input */ };
179
+ app.ontoolresult = (result) => { /* handle result */ };
180
+ app.onhostcontextchanged = (ctx) => { /* handle context */ };
181
+ app.onteardown = async () => { return {}; };
182
+ // etc.
183
+
184
+ // Then connect
185
+ await app.connect();
186
+ ```
187
+
188
+ ## Common Mistakes to Avoid
189
+
190
+ 1. **No text fallback** - Always provide `content` array for non-UI hosts
191
+ 2. **Missing CSP configuration** - MCP Apps HTML is served as an MCP resource with no same-origin server; ALL network requests—even to `localhost`—require a CSP configuration
192
+ 3. **CSP or CORS config in wrong _meta object** - `_meta.ui.csp` and `_meta.ui.domain` go in the `contents[]` objects returned by `registerAppResource()`'s read callback, not in `registerAppResource()`'s config object
193
+ 4. **Handlers after app.connect()** - Register ALL handlers BEFORE calling `app.connect()`
194
+ 5. **No streaming for large inputs** - Use `ontoolinputpartial` to show progress during input generation
195
+
196
+ ## Testing
197
+
198
+ ### Using basic-host
199
+
200
+ Test MCP Apps locally with the basic-host example:
201
+
202
+ ```bash
203
+ # Terminal 1: Build and run your server
204
+ npm run build && npm run serve
205
+
206
+ # Terminal 2: Run basic-host (from cloned repo)
207
+ cd ./mcp-ext-apps/examples/basic-host
208
+ npm install
209
+ SERVERS='["http://localhost:3001/mcp"]' npm run start
210
+ # Open http://localhost:8080
211
+ ```
212
+
213
+ Configure `SERVERS` with a JSON array of your server URLs (default: `http://localhost:3001/mcp`).
214
+
215
+ ### Debug with sendLog
216
+
217
+ Send debug logs to the host application (rather than just the iframe's dev console):
218
+
219
+ ```typescript
220
+ await app.sendLog({ level: "info", data: "Debug message" });
221
+ await app.sendLog({ level: "error", data: { error: err.message } });
222
+ ```
@@ -204,7 +204,8 @@ Map of template file → project file (the CLI `bin/fa-mcp.js` applies these tra
204
204
  |-------------------------------------------------------------------|---------------------------------------------|-------|
205
205
  | `node_modules/fa-mcp-sdk/cli-template/package.json` | `package.json` | **Merge carefully** — see rule below |
206
206
  | `node_modules/fa-mcp-sdk/cli-template/tsconfig.json` | `tsconfig.json` | overwrite (unless customized) |
207
- | `node_modules/fa-mcp-sdk/cli-template/eslint.config.js` | `eslint.config.js` | overwrite (unless customized) |
207
+ | `node_modules/fa-mcp-sdk/cli-template/.oxlintrc.json` | `.oxlintrc.json` | overwrite (unless customized) |
208
+ | `node_modules/fa-mcp-sdk/cli-template/.oxfmtrc.json` | `.oxfmtrc.json` | overwrite (unless customized) |
208
209
  | `node_modules/fa-mcp-sdk/cli-template/CLAUDE.md` | `CLAUDE.md` | merge — project may add custom sections |
209
210
  | `node_modules/fa-mcp-sdk/cli-template/jest.config.js` | `jest.config.js` | overwrite (unless customized) |
210
211
  | `node_modules/fa-mcp-sdk/cli-template/deploy/` | `deploy/` | merge per file |