Skip to main content

Interactive UI Tools for MCP Servers

Project description

Gdansk: React Frontends for Python MCP Servers

[!WARNING] This project is currently in beta. The APIs are subject to change leading up to v1.0. The v1.0 release will coincide with the v2.0 release of the python mcp sdk

Installation

uv add gdansk

Skill for Coding Agents

If you use coding agents such as Claude Code or Cursor, add the gdansk skills to your repository:

npx skills add mplemay/gdansk

Then use:

  • $use-gdansk to bootstrap gdansk in a new repo or add another widget to an existing integration.
  • $debug-gdansk to diagnose widget path, bundling, SSR, and runtime failures in an existing gdansk setup.

Compatibility

  • Python: gdansk currently requires >=3.12,<3.15.
  • Frontend package: use an ESM package with @gdansk/vite, vite, @vitejs/plugin-react, react, react-dom, and @modelcontextprotocol/ext-apps.
  • Runtime tooling: gdansk starts the frontend through uv run deno .... If you run frontend package scripts directly, the published @gdansk/vite package currently declares Node >=22.

Examples

  • FastAPI: Mounting the MCP app inside an existing FastAPI service.
  • get-time: Small copyable widget example for first-time adoption in another repo.
  • ssr: Minimal SSR and hydration example with a single widget tool.
  • shadcn: Multi-tool todo app with structured_output=True and shadcn/ui.

Quick Start

Here's a complete example showing how to build a simple greeting tool with a React UI:

Project Structure:

my-mcp-server/
├── server.py
└── frontend/
    ├── package.json
    ├── vite.config.ts
    └── widgets/
        └── hello/
            └── widget.tsx

The frontend folder name is only an example. Pass any frontend package root to Ship(..., views=...). That frontend package owns its own vite.config.ts; import @gdansk/vite there alongside any framework plugins.

server.py:

from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
from pathlib import Path

import uvicorn
from mcp.server import MCPServer
from mcp.types import TextContent
from starlette.middleware.cors import CORSMiddleware

from gdansk import Ship

frontend_path = Path(__file__).parent / "frontend"
ship = Ship(views=frontend_path)


@ship.widget(path=Path("hello/widget.tsx"), name="greet")
def greet(name: str) -> list[TextContent]:
    """Greet someone by name."""
    return [TextContent(type="text", text=f"Hello, {name}!")]


@asynccontextmanager
async def lifespan(app: MCPServer) -> AsyncIterator[None]:
    async with ship.mcp(app=app, dev=True):
        yield


mcp = MCPServer(name="Hello World Server", lifespan=lifespan)


def main() -> None:
    app = mcp.streamable_http_app()
    app.add_middleware(
        CORSMiddleware,
        allow_origins=["*"],
        allow_methods=["*"],
        allow_headers=["*"],
    )
    app.mount(path="/dist", app=ship.assets)
    uvicorn.run(app, port=3000)


if __name__ == "__main__":
    main()

frontend/widgets/hello/widget.tsx:

import { useApp } from "@modelcontextprotocol/ext-apps/react";
import { useState } from "react";

export default function App() {
  const [name, setName] = useState("");
  const [greeting, setGreeting] = useState("");

  const { app, error } = useApp({
    appInfo: { name: "Greeter", version: "1.0.0" },
    capabilities: {},
  });

  if (error) return <div>Error: {error.message}</div>;
  if (!app) return <div>Connecting...</div>;

  return (
    <main>
      <h2>Say Hello</h2>
      <input
        value={name}
        onChange={(e) => setName(e.target.value)}
        placeholder="Enter your name..."
      />
      <button
        onClick={async () => {
          const result = await app.callServerTool({
            name: "greet",
            arguments: { name },
          });
          const text = result.content?.find((c) => c.type === "text");
          if (text && "text" in text) setGreeting(text.text);
        }}
      >
        Greet Me
      </button>
      {greeting && <p>{greeting}</p>}
    </main>
  );
}

frontend/package.json:

{
  "name": "my-mcp-frontend",
  "private": true,
  "type": "module",
  "dependencies": {
    "@gdansk/vite": "^0.1.0",
    "@modelcontextprotocol/ext-apps": "^1.5.0",
    "@vitejs/plugin-react": "^6.0.1",
    "react": "^19.2.5",
    "react-dom": "^19.2.5",
    "vite": "^8.0.8"
  },
  "devDependencies": {
    "@types/react": "^19.2.14",
    "@types/react-dom": "^19.2.3"
  }
}

frontend/vite.config.ts:

import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
import gdansk from "@gdansk/vite";

export default defineConfig({
  plugins: [gdansk({ refresh: true }), react()],
});

@gdansk/vite now provides a default @ alias that points at the frontend package root, so you only need a manual alias when you want @ to resolve somewhere else. Use refresh: true to trigger full browser reloads when nearby Python or Jinja files change during development.

Production rendering defaults to client-side rendering. To enable production SSR, opt in on both sides:

ship = Ship(views=frontend_path, ssr=True)
export default defineConfig({
  plugins: [gdansk({ ssr: true, refresh: true }), react()],
});

If you need non-default frontend directories, keep the Vite plugin and Python runtime aligned:

ship = Ship(
    views=Path(__file__).parent / "frontend",
    assets="public/ui",
    widgets_directory="ui/widgets",
)
export default defineConfig({
  plugins: [
    gdansk({
      buildDirectory: "public/ui",
      widgetsDirectory: "ui/widgets",
      refresh: true,
    }),
    react(),
  ],
});

Production widgets load their hydration assets from /<assets_dir>/.... Mount ship.assets at that path on the public app; with the default settings this is /dist.

The default production output now mirrors Vite/Laravel conventions more closely:

  • standard Vite manifest: dist/manifest.json
  • gdansk runtime manifest: dist/gdansk-manifest.json
  • stable widget entries: dist/<widget>/client.js and dist/<widget>/client.css
  • shared hashed assets and chunks: dist/assets/*

When production SSR is enabled with Ship(ssr=True) and gdansk({ ssr: true }), the build also includes:

  • SSR bundles: dist/ssr.js and dist/server.js

If your MCP client renders widget HTML on a different origin, pass base_url to Ship so production asset URLs point back to your public app instead of the client host:

ship = Ship(views=Path(__file__).parent / "frontend", base_url="https://example.com")

If you enable production SSR or want a different dev runtime host or port, configure both sides explicitly:

ship = Ship(views=Path(__file__).parent / "frontend", host="127.0.0.1", port=14000)
export default defineConfig({
  plugins: [gdansk({ host: "127.0.0.1", port: 14000, refresh: true }), react()],
});

Install the frontend package dependencies from frontend/ after editing them:

cd frontend
uv run deno install

Gdansk mounts your default export into #root automatically and wraps it with React.StrictMode.

Run the server with uv run python server.py, configure it in your MCP client (like Claude Desktop), and you'll have an interactive greeting tool ready to use.

Why Use Gdansk?

  1. Python Backend, React Frontend — Use familiar technologies you already know. Write your logic in Python with type hints, build your UI in React/TypeScript. No need to learn a new framework-specific language.

  2. Built for MCP — Composes with MCPServer from the official Python SDK: register widget tools and HTML resources via Ship, wire them in with ship.mcp(app=...), and integrate with Claude Desktop and other MCP clients.

  3. Fast bundling with Rolldown — The Rolldown bundler processes your TypeScript/JSX automatically. Hot-reload in development mode means you see changes instantly without manual rebuilds.

  4. Type-Safe — Full type safety across the stack. Python type hints on the backend, TypeScript on the frontend, with automatic type checking via ruff and TypeScript compiler.

  5. Developer-Friendly — Simple decorator API (@ship.widget()), automatic resource registration, dev mode on ship.mcp(...), and comprehensive error messages. Get started in minutes, not hours.

  6. Production Ready — Comprehensive test suite covering Python 3.12+ across Linux, macOS, and Windows. Used in production MCP servers with proven reliability.

Credits

Gdansk builds on the shoulders of giants:

Special thanks to the Model Context Protocol team at Anthropic for creating the MCP standard and the @modelcontextprotocol/ext-apps package.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gdansk-0.6.5.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gdansk-0.6.5-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

Details for the file gdansk-0.6.5.tar.gz.

File metadata

  • Download URL: gdansk-0.6.5.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for gdansk-0.6.5.tar.gz
Algorithm Hash digest
SHA256 1e2a187fca44a94ee3f1ff6428933208a1a69b0eb5c809c818e45ee2dd8e35a2
MD5 ee1b476cd263cfd0e0cd1469322e3b6f
BLAKE2b-256 28f386c88bbbd4c5826903a5b1ac9881c5b6f9f3ee6cfe411a22ec56d4952f94

See more details on using hashes here.

File details

Details for the file gdansk-0.6.5-py3-none-any.whl.

File metadata

  • Download URL: gdansk-0.6.5-py3-none-any.whl
  • Upload date:
  • Size: 25.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for gdansk-0.6.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f6162749cdfdf469ff88cbf46edc735145cd72d4f4210bce84c0daba5e2eb1cd
MD5 8fd5749d443b3a0aaea9945905c208f8
BLAKE2b-256 4978b1e4d0df2ce242b1171c45204e4ed847eda28d7661a820dc1b72465816f7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page