ext-apps/examples/basic-host
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Olivier Chafik 741b1d3925
feat(basic-host): improve host UI with collapsible panels and SDK types (#244)
* refactor(basic-host): use SDK types for ModelContext and AppMessage

- Import McpUiUpdateModelContextRequest and McpUiMessageRequest from SDK
- Replace custom ModelContext with McpUiUpdateModelContextRequest['params']
- Replace custom AppMessage with McpUiMessageRequest['params']
- Pass full message params instead of extracting text
- Format messages by extracting text from content blocks in display

* feat(basic-host): handle non-text content blocks in display

- Add formatContentBlock helper for text, image, audio, resource types
- Show placeholders like <image: image/png> for non-text content
- Apply to both messages and model context display

* test: update shadertoy screenshot

* test: update screenshots from CI (linux x64)
2026-01-12 19:42:11 +00:00
..
src feat(basic-host): improve host UI with collapsible panels and SDK types (#244) 2026-01-12 19:42:11 +00:00
index.html Add color-scheme meta tag to all example apps 2025-12-15 11:42:18 -08:00
package.json Fix build errors in examples (#180) 2025-12-18 11:17:23 +00:00
README.md Smoothen the process of getting started (#103) 2025-12-09 16:15:32 +01:00
sandbox.html fix: proper CSP handling in basic-host sandboxing (HTTP headers, worker-src, document.write) (#234) 2026-01-11 14:32:48 +00:00
serve.ts fix: proper CSP handling in basic-host sandboxing (HTTP headers, worker-src, document.write) (#234) 2026-01-11 14:32:48 +00:00
tsconfig.json Add basic-host and basic-server-react examples 2025-12-04 14:28:27 -06:00
vite.config.ts Add basic-host and basic-server-react examples 2025-12-04 14:28:27 -06:00

Example: Basic Host

A reference implementation showing how to build an MCP host application that connects to MCP servers and renders tool UIs in a secure sandbox.

This basic host can also be used to test MCP Apps during local development.

Key Files

Getting Started

npm install
npm run start
# Open http://localhost:8080

By default, the host application will try to connect to an MCP server at http://localhost:3001/mcp. You can configure this behavior by setting the SERVERS environment variable with a JSON array of server URLs:

SERVERS='["http://localhost:1234/mcp", "http://localhost:5678/mcp"]' npm run start

Architecture

This example uses a double-iframe sandbox pattern for secure UI isolation:

Host (port 8080)
  └── Outer iframe (port 8081) - sandbox proxy
        └── Inner iframe (srcdoc) - untrusted tool UI

Why two iframes?

  • The outer iframe runs on a separate origin (port 8081) preventing direct access to the host
  • The inner iframe receives HTML via srcdoc and is restricted by sandbox attributes
  • Messages flow through the outer iframe which validates and relays them bidirectionally

This architecture ensures that even if tool UI code is malicious, it cannot access the host application's DOM, cookies, or JavaScript context.