React MCP SPA
A React single-page application served as an MCP server that renders different UI pages based on the invoked tool name from the host context. It enables embedding interactive React components directly within MCP clients like Claude Desktop through tool calls.
README
React MCP SPA
A minimal React single-page app that is bundled into one HTML blob and served by an MCP Apps server. The SPA doesn't use URL path routing — it picks which page to render by reading the current tool name from the MCP host context.
Layout
- packages/ui/ — React + Vite SPA, built to a single-file HTML blob via
vite-plugin-singlefile. - packages/mcp/ — MCP server using
@modelcontextprotocol/ext-apps/server. Registers tools (show-home,show-counter,show-profile) that all point to the sameui://resource. - packages/playground/ — dev-only harness that renders the SPA inside a mock chat UI with JSON inputs for
hostContextandtoolResult, so pages can be exercised without an MCP host.
Install
Requires Node.js ≥ 20 and pnpm ≥ 9.
pnpm install
Develop the UI in isolation
pnpm run dev:ui
Open the printed URL (e.g. http://localhost:5173). The SPA detects that there's no MCP host and shows a route picker so you can preview each page.
Playground — test rendering without MCP
pnpm run dev:playground
Opens on http://localhost:5174. The playground reuses the SPA's real route renderer (RouteRenderer from packages/ui/src/Router.tsx) and wraps it in a mock chat UI. The header has two JSON textareas — one for the hostContext (drives which page renders via toolInfo.tool.name) and one for the toolResult passed to the page. Preset buttons load ready-made context+result pairs for each registered tool; edits to either textarea re-render the assistant's tool-output bubble live.
Build and run the MCP server
pnpm run build # builds packages/ui → dist/index.html, then packages/mcp
pnpm run serve:mcp # starts Streamable HTTP server on http://localhost:3001/mcp
For stdio transport:
pnpm --filter @react-mcp-spa/mcp run serve:stdio
Exposing the server with cloudflared
Some MCP clients (including hosted ones) can't reach localhost. Use cloudflared to open a quick tunnel that assigns a public HTTPS URL.
Install cloudflared via your OS package manager:
# macOS (Homebrew)
brew install cloudflared
# Linux (Debian/Ubuntu)
# See https://pkg.cloudflare.com/ for the apt repo, or grab the .deb from
# https://github.com/cloudflare/cloudflared/releases
# Windows (winget)
winget install --id Cloudflare.cloudflared
Start the server locally:
pnpm run serve:mcp
In another terminal, run:
cloudflared tunnel --url http://localhost:3001
# or: pnpm run tunnel
cloudflared prints a URL like https://<random>.trycloudflare.com. Append /mcp and use it as your MCP server URL:
https://<random>.trycloudflare.com/mcp
The tunnel stays up until you kill cloudflared. For a stable hostname, configure a named Cloudflare tunnel instead of a quick tunnel.
Packaging as a Claude Desktop extension (.mcpb)
The repo ships a packer that produces an installable MCP Bundle for Claude Desktop. The extension runs the server over stdio — no tunnel required.
pnpm run pack:mcpb
This builds both packages, stages the compiled server + UI HTML + prod node_modules under build/mcpb-staging/, and invokes mcpb pack to produce:
build/react-mcp-spa.mcpb
To install it, double-click the .mcpb in Finder/Explorer (or drag it onto Claude Desktop). Claude validates the manifest and registers the server; after installation the three tools (show-home, show-counter, show-profile) are available and each renders its page as an inline React UI.
The bundle manifest lives at mcpb/manifest.json — bump version there (and in packages/mcp/package.json) when cutting a new extension release.
How routing works
The SPA never reads window.location. Instead, packages/ui/src/App.tsx uses useApp() from @modelcontextprotocol/ext-apps/react and:
- Reads
app.getHostContext().toolInfo.tool.nameto know which tool the host invoked — this is the "route". - Subscribes to
app.ontoolresultto receive theCallToolResultfrom the server and pass it to the page as data. - Watches
app.onhostcontextchangedso theme / safe-area / locale updates re-render correctly.
Adding a new page is a two-step change:
- Register a tool in packages/mcp/src/server.ts with
_meta.ui.resourceUripointing at the sharedui://react-mcp-spa/app.htmlresource. - Add a case for the tool name in
renderRoute()inside packages/ui/src/App.tsx.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。