Skybridge Documentation

repository·main·Indexed 23 days ago

https://github.com/alpic-ai/skybridge

A full-stack React framework for building Model Context Protocol (MCP) Apps and Servers. Skybridge bridges low-level MCP SDKs with type-safe, interactive user interfaces for LLM clients such as Claude and ChatGPT. It includes tooling for widget creation, OAuth authentication integration via Auth0 and Authplane, and a Hooks Conformance suite for verifying host support of web hooks.

Tokens
85.1K
Snippets
191
Records
449
Agent score
83%

What's inside Skybridge

  1. What is Skybridge?

    main

    Skybridge is a full-stack React framework designed for building Model Context Protocol (MCP) Apps and MCP Servers. It enables developers to create type-safe, interactive UI views that can be rendered within MCP-compatible clients like Claude, ChatGPT, and VSCode.

    Key features include:

    • Type-safe end-to-end: tRPC-style inference from MCP server tool definitions to React views.
    • Write once, run everywhere: Abstracts implementation differences between various MCP clients.
    • Delightful dev environment: Includes a dev server with a local emulator, HMR, and a permanent tunnel for connecting local apps to Claude and ChatGPT.
    • React-first: Provides React Query-style hooks and advanced state management.
  2. Understand Skybridge Hooks Conformance

    main

    Skybridge Hooks Conformance is a self-testing MCP app designed to verify how different hosts (such as ChatGPT, Claude, or the DevTools emulator) support various Skybridge web hooks.

    It runs a sequence of tests via a stepper. Some tests are 'silent' (automatic), while others with user-visible side effects (like opening a link or a modal) require user interaction or automated confirmation.

    Each test results in one of four verdicts:

    • supported: The hook functions correctly on the host.
    • partial: Only part of the hook works (details are provided in a results table).
    • unsupported: The host lacks the capability, but handles it gracefully (e.g., a documented no-op or a throw). This is still considered conformant.
    • error: An unexpected failure occurred.
  3. Understand the Skybridge documentation structure and user paths

    main

    Skybridge documentation is organized into specific sections designed to support different stages of the developer journey. Understanding these sections helps you find the right information based on your current goal:

    1. Get Started (High Priority)

    Focuses on initial discovery and getting a working app running in under 5 minutes.

    • Introduction: Purpose and scope of Skybridge.
    • Fundamentals: Explains MCP Apps, ChatGPT Apps, and how Skybridge maps to OpenAI Apps SDK and MCP runtimes.
    • Quickstart: Using the create command or the Skybridge Skill to scaffold an app.
    • Migrate: Using the Skybridge Skill to move existing apps.
    • Test your app: Local testing with DevTools or in clients like ChatGPT, Claude, or Cursor.
    • Build for production: Building MCP server and UI code.
    • Deploy: Publishing to MCP client stores.

    2. Core Concepts

    Provides the mental models required to understand Skybridge internals:

    • Write Once, Run Everywhere: Abstracting client differences (ChatGPT vs. Claude/Cursor).
    • Data Flow: Movement of data between host, app, and LLM.
    • LLM Context Sync: How app state stays in sync with the model's context.
    • Fast Iteration: Local development workflow and hot reloading.
    • Type Safety: Preserving types from app to client (tools, parameters, views).

    3. Guides

    Step-by-step implementation patterns for specific tasks:

    • Fetching data: Using tools vs. resources and async patterns.
    • Managing state: App-level state, persistence, and sharing state.
    • Communicating with the model: Tool invocation, resource visibility, and prompt/context boundaries.
    • Host environment context: Accessing user, session, and locale data.

    4. Developer Tools

    Focuses on the build and debug experience:

    • Skills: Scaffolding and maintaining apps via IDE/chat.
    • Local DevTools: Debugging tools and views locally.

    5. Resources

    • FAQ: Troubleshooting and common questions.
    • Telemetry: Data collection and opt-out procedures.

    6. API Reference

    Technical specifications for precision implementation:

    • CLI: Commands like create, build, and dev.
    • Server: McpServer class, registerTool, and type exports.
    • Hooks: React hooks for UI (e.g., useCallTool, useUser, useViewState).
    • Utilities: Helpers like createStore, generateHelpers, and data-llm attribute.
    • Types: Server-to-client type inference.
    • Advanced: Low-level context hooks (useAppsSdkContext, useMcpAppContext).

    7. Showcase

    Example applications categorized by type (Basic, Auth, Third-party integrations).

  4. Project structure of the Investigation Game example

    main

    The example follows this directory structure:

    • server.ts: The main server entry point.
    • src/data/: Contains game data like suspects, puzzles, and images.
    • src/views/: Contains the UI layer.
      • murder-in-the-valley.tsx: The main widget entry point.
      • screens/: Individual screen components (e.g., Start, Intro, Main, Victory).
      • components/: Shared UI components (e.g., SuspectCard, DialogueBox).
      • hooks/: Custom React hooks (e.g., useTypewriter).
    • src/index.css: Global styles.
    • vite.config.ts: Vite configuration.
    • alpic.json: Deployment configuration.
  5. Understand the Skybridge project structure

    main

    The starter template follows this directory structure:

    • src/server.ts: The main server entry point where tools are registered.
    • src/views/: Contains React components. Each file represents a single view.
    • src/components/: Shared UI components used across different views.
    • src/helpers.ts: Shared utility functions.
    • src/index.css: Global CSS styles.
    • vite.config.ts: Vite configuration.
    • alpic.json: Deployment configuration for Alpic.
    • package.json: Project dependencies and scripts.
  6. What is a deployed MCP App?

    main

    A deployed MCP App is a server hosted on a public URL. It must satisfy two requirements:

    1. Hosts connect to the /mcp endpoint to interact with the Model Context Protocol server.
    2. The built views are served alongside the MCP server.

    Deployment can be performed on any Node.js-compatible platform.

  7. Run Skybridge with Path Prefixes

    main
    Skybridge supports running under a path prefix (e.g., https://your-domain.com/v1/mcp). It determines the prefix by reading the x-forwarded-prefix header, allowing it to serve assets correctly under that path. This is useful for hosting multiple versions of an app on a single domain.
  8. Key Skybridge hooks used in the Ecommerce Example

    main

    The Ecommerce Carousel example demonstrates several core Skybridge hooks for building interactive widgets:

    • useCallTool(): Used within a widget to invoke MCP server tools (e.g., calling create-checkout or check-checkout-status).
    • useLayout(): Used to adapt the UI to light/dark modes.
    • useUser(): Used for localization, providing access to the user's locale (supports English, French, Spanish, and German).
    • useWidgetState(): Used to maintain persistent state (like a shopping cart) across re-renders.
  9. Implement Stytch OAuth authentication in Skybridge

    main

    You can implement full OAuth authentication using the stytchProvider. This provider automates several steps:

    1. Transport-Level Auth: Enforces authentication at the /mcp transport level. Unauthenticated requests receive an HTTP 401 before reaching any tool handlers.
    2. Metadata Discovery: Automatically discovers the Connected App's OAuth metadata.
    3. JWT Verification: Verifies JWTs against the project's JWKS without requiring a network round-trip per request.
    4. Branded Provider: By passing oauth: await stytchProvider(...), the server auto-mounts well-known metadata endpoints and handles Bearer verification.

    To use this, you must serve static HTML files (e.g., authorize.html, login.html, authenticate.html) from your MCP server to handle the Stytch IDP flows via @stytch/vanilla-js.

  10. Use Skybridge hooks for widget functionality

    main

    The Productivity Example demonstrates several core Skybridge hooks used to build interactive widgets:

    • useToolInfo(): Accesses tool input, output, and metadata.
    • useCallTool(): Provides a type-safe way to call backend tools directly from the widget.
    • useWidgetState(): Maintains persistent state (like selected items or chart data) across re-renders.
    • useUser(): Handles localization; automatically provides translations based on user locale (e.g., English, French, Spanish, Chinese).
    • useLayout(): Used to adapt the UI to light or dark themes.
    • useDisplayMode(): Allows switching between inline and fullscreen views.
    • useSendFollowUpMessage(): Enables the widget to send follow-up messages back to the AI.
    • useOpenExternal(): Used to open external URLs.
  11. Key technologies used in the ChatGPT Files Example

    main

    The ChatGPT Files example utilizes the following stack:

    • File Handling: Uses useFiles() (upload, selectFiles, getDownloadUrl) from the ChatGPT Apps SDK.
    • Tool Invocation: Widgets call tools directly via useCallTool() with _meta["openai/widgetAccessible"] set to enable widget access.
    • Compression: Uses fflate (zipSync) for server-side ZIP creation (Node's zlib is insufficient for the ZIP container).
    • Storage: Uses Cloudflare R2 for archive storage, with aws4fetch for signing presigned download URLs.
    • External Links: Uses useOpenExternal() to open the generated download URLs.