React MCP SPA
React MCP SPA
1つのHTMLブロブにバンドルされ、MCP Appsサーバーによって提供される最小限のReactシングルページアプリケーションです。このSPAはURLパスルーティングを使用せず、MCPホストコンテキストから現在のツール名を読み取ることで、どのページをレンダリングするかを決定します。
レイアウト
packages/ui/ — React + Vite SPA。
vite-plugin-singlefileを使用して単一ファイルのHTMLブロブにビルドされます。packages/mcp/ —
@modelcontextprotocol/ext-apps/serverを使用したMCPサーバー。すべて同じui://リソースを指すツール(show-home、show-counter、show-profile)を登録します。packages/playground/ —
hostContextとtoolResultのJSON入力を備えたモックチャットUI内でSPAをレンダリングする開発専用のハーネス。MCPホストなしでページを試すことができます。
Related MCP server: @businessmaps/mcp
インストール
Node.js ≥ 20 および pnpm ≥ 9 が必要です。
pnpm installUIを分離して開発する
pnpm run dev:ui表示されたURL(例: http://localhost:5173)を開きます。SPAはMCPホストが存在しないことを検出し、各ページをプレビューできるようにルートピッカーを表示します。
プレイグラウンド — MCPなしでレンダリングをテストする
pnpm run dev:playgroundhttp://localhost:5174 で開きます。プレイグラウンドはSPAの実際のルートレンダラー(packages/ui/src/Router.tsx の RouteRenderer)を再利用し、モックチャットUIでラップします。ヘッダーには2つのJSONテキストエリアがあります。1つは hostContext(toolInfo.tool.name を介してどのページをレンダリングするかを制御)、もう1つはページに渡される toolResult 用です。プリセットボタンで、登録済みの各ツール用に用意されたコンテキストと結果のペアを読み込むことができます。テキストエリアを編集すると、アシスタントのツール出力バブルがライブで再レンダリングされます。
MCPサーバーのビルドと実行
pnpm run build # builds packages/ui → dist/index.html, then packages/mcp
pnpm run serve:mcp # starts Streamable HTTP server on http://localhost:3001/mcpstdioトランスポートの場合:
pnpm --filter @react-mcp-spa/mcp run serve:stdiocloudflaredによるサーバーの公開
一部のMCPクライアント(ホスト型を含む)はlocalhostに到達できません。 cloudflared を使用して、パブリックHTTPS URLを割り当てるクイックトンネルを開きます。
OSのパッケージマネージャーを使用してcloudflaredをインストールします:
# 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ローカルでサーバーを起動します:
pnpm run serve:mcp別のターミナルで以下を実行します:
cloudflared tunnel --url http://localhost:3001
# or: pnpm run tunnelcloudflared は https://<random>.trycloudflare.com のようなURLを出力します。末尾に /mcp を追加し、それをMCPサーバーのURLとして使用します:
https://<random>.trycloudflare.com/mcpトンネルは cloudflared を終了するまで維持されます。安定したホスト名が必要な場合は、クイックトンネルではなく 名前付きCloudflareトンネル を設定してください。
Claude Desktop拡張機能(.mcpb)としてのパッケージ化
このリポジトリには、Claude Desktop用のインストール可能な MCP Bundle を生成するパッカーが同梱されています。この拡張機能はサーバーをstdio経由で実行するため、トンネルは不要です。
pnpm run pack:mcpbこれにより両方のパッケージがビルドされ、コンパイル済みのサーバー + UI HTML + プロダクション用 node_modules が build/mcpb-staging/ 配下にステージングされ、mcpb pack が呼び出されて以下が生成されます:
build/react-mcp-spa.mcpbインストールするには、Finder/エクスプローラーで .mcpb をダブルクリック(またはClaude Desktopにドラッグ)します。Claudeがマニフェストを検証してサーバーを登録します。インストール後、3つのツール(show-home、show-counter、show-profile)が利用可能になり、それぞれがインラインReact UIとしてページをレンダリングします。
バンドルマニフェストは mcpb/manifest.json にあります。新しい拡張機能をリリースする際は、そこで(および packages/mcp/package.json で)version を更新してください。
ルーティングの仕組み
SPAは window.location を読み取りません。代わりに、packages/ui/src/App.tsx が @modelcontextprotocol/ext-apps/react の useApp() を使用して以下を行います:
app.getHostContext().toolInfo.tool.nameを読み取り、ホストがどのツールを呼び出したか(これが「ルート」になります)を把握します。app.ontoolresultをサブスクライブしてサーバーからCallToolResultを受け取り、データとしてページに渡します。app.onhostcontextchangedを監視し、テーマ、セーフエリア、ロケールの更新が正しく再レンダリングされるようにします。
新しいページを追加するには、2段階の変更が必要です:
packages/mcp/src/server.ts で、
_meta.ui.resourceUriが共有リソースui://react-mcp-spa/app.htmlを指すようにツールを登録します。packages/ui/src/App.tsx 内の
renderRoute()に、そのツール名のケースを追加します。
This server cannot be deployed
Maintenance
Related MCP Connectors
The Remote MCP server acts as a standardized bridge between LLM applications (like Claude, ChatGPT, and Cursor) and external services, enabling AI agents to access external tools and resources. Its primary capability is providing a centralized search tool to discover other MCP servers and their respective tools. Unlike local implementations, it runs remotely with OAuth authentication and permission controls for security.
Unified MCP Server is a remote MCP connector for AI agents and vertical AI products that provides access to 22,000+ authorized SaaS tools across 400+ integrations and 24 categories directly inside LLMs (Claude, GPT, Gemini, Cohere). Tools operate only on explicitly authorized customer connections, enabling agents to safely read and write against live third-party systems.
Hosted MCP catalog with 30 tenant-isolated browser, RAG, AI, mail and media tools.
MCP server connecting AI agents to 100+ apps (Gmail, Slack, Notion, GitHub) via one-click OAuth.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceA Model Context Protocol (MCP) server built with the mcp-framework for developing and managing custom tools. It provides a structured foundation for building and integrating modular components like data processors and API clients into Claude Desktop.11 npm-
- AlicenseNot gradedqualityDmaintenanceAn MCP bridge server that allows AI tools to call functions and execute code directly within a web browser tab. It enables developers to register custom browser-side tools with full access to the DOM, web APIs, and local application state.14 npmApache 2.0
- FlicenseNot gradedqualityDmaintenanceA minimal todo app MCP server for ChatGPT that exposes tools for managing tasks and provides an interactive HTML widget interface. It demonstrates how to build MCP servers with React-based UIs and includes development OAuth for ChatGPT connector setup.-
- FlicenseAqualityDmaintenanceProvides interactive, React-based UI apps inside Claude Desktop for tracking workouts, planning trips, budgeting, comparing products, and making decisions with bidirectional communication.8-