본문으로 건너뛰기
cccskills
무료GitHub에 공개

mcp-host-styling-integration

Integrates MCP App UI with host theming system. Applies host CSS variables, handles onhostcontextchanged, safe area insets, display mode detection, and fullscreen configuration.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(2)

  • SKILL.md10.0 KB
  • README.md2.4 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

mcp-host-styling-integration

Integrate MCP App UIs with the host application's theming system so apps look native in Claude Desktop, ChatGPT, VS Code, Goose, Postman, and other MCP-enabled hosts.

Overview

MCP Apps render in sandboxed iframes inside host applications. Each host has its own visual theme (colors, fonts, border radii, spacing). The MCP Apps SDK provides:

  • CSS variables (--color-*, --font-*, --border-radius-*) injected by the host
  • SDK helpers (applyDocumentTheme, applyHostStyleVariables, applyHostFonts) to apply them
  • React hooks (useHostStyles, useHostStyleVariables, useHostFonts) for React apps
  • onhostcontextchanged event fired when theme changes (e.g., dark mode toggle)

The key principle is: always use CSS variable fallbacks so the app looks correct both as an MCP App (host provides variables) and standalone (fallback values apply).

Capabilities

Host CSS Variable Integration

  • Apply all host CSS variables with sensible fallback values
  • Support color variables: --color-background-primary, --color-background-secondary, --color-text-primary, --color-text-secondary, --color-border-primary
  • Support font variables: --font-sans, --font-mono, --font-text-base-size, --font-text-sm-size
  • Support layout variables: --border-radius-sm, --border-radius-md, --border-radius-lg

onhostcontextchanged Handler

  • Listen for theme changes from the host
  • Reapply styling when theme changes (e.g., light to dark mode)
  • Access host context: theme, display mode, safe area insets

Safe Area Insets

  • Apply safe area padding for mobile or embedded contexts
  • Handle env(safe-area-inset-top), env(safe-area-inset-bottom), etc.

Display Mode Detection

  • Detect embedded vs fullscreen mode
  • Adapt layout based on available space
  • Configure fullscreen mode via tool metadata

SDK Helper Functions

  • applyDocumentTheme(theme) -- sets document-level theme class
  • applyHostStyleVariables(context) -- applies all CSS variables from host
  • applyHostFonts(context) -- loads and applies host fonts

React Hook Integration

  • useHostStyles() -- combined hook applying theme, variables, and fonts
  • useHostStyleVariables() -- CSS variables only
  • useHostFonts() -- font loading only

Usage

Vanilla JS: Full Host Styling

import {
  App,
  PostMessageTransport,
  applyDocumentTheme,
  applyHostStyleVariables,
  applyHostFonts,
} from '@modelcontextprotocol/ext-apps';

const app = new App({ transport: new PostMessageTransport() });

// Register handler BEFORE connect()
app.onhostcontextchanged = (params) => {
  const ctx = params.context;

  // Apply theme (light/dark)
  if (ctx.theme) {
    applyDocumentTheme(ctx.theme);
  }

  // Apply CSS variables
  applyHostStyleVariables(ctx);

  // Load and apply fonts
  applyHostFonts(ctx);
};

// THEN connect
await app.connect();

React: useHostStyles Hook

import { useApp, useHostStyles } from '@modelcontextprotocol/ext-apps/react';

function MyApp() {
  const app = useApp();
  useHostStyles();  // Handles all theme/variable/font application

  return (
    <div className="app-container">
      <h1>My MCP App</h1>
    </div>
  );
}

CSS with Fallback Values

/* Always use fallbacks so app works standalone too */
.app-container {
  background-color: var(--color-background-primary, #ffffff);
  color: var(--color-text-primary, #1a1a1a);
  font-family: var(--font-sans, system-ui, -apple-system, sans-serif);
  font-size: var(--font-text-base-size, 14px);
  border-radius: var(--border-radius-md, 8px);
}

.card {
  background-color: var(--color-background-secondary, #f5f5f5);
  border: 1px solid var(--color-border-primary, #e0e0e0);
  border-radius: var(--border-radius-sm, 4px);
  padding: 16px;
}

.label {
  color: var(--color-text-secondary, #666666);
  font-size: var(--font-text-sm-size, 12px);
}

.code {
  font-family: var(--font-mono, 'Courier New', monospace);
}

/* Safe area insets for mobile/embedded contexts */
.app-root {
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

Available Host CSS Variables

VariableCategoryDescription
--color-background-primaryColorMain background
--color-background-secondaryColorCard/section background
--color-background-tertiaryColorNested/subtle background
--color-text-primaryColorMain text
--color-text-secondaryColorSecondary/muted text
--color-text-tertiaryColorSubtle/hint text
--color-border-primaryColorMain borders
--color-border-secondaryColorSubtle borders
--color-accentColorInteractive elements
--color-errorColorError states
--color-successColorSuccess states
--color-warningColorWarning states
--font-sansFontSans-serif font family
--font-monoFontMonospace font family
--font-text-xs-sizeFontExtra small text size
--font-text-sm-sizeFontSmall text size
--font-text-base-sizeFontBase text size
--font-text-lg-sizeFontLarge text size
--font-text-xl-sizeFontExtra large text size
--border-radius-smLayoutSmall border radius
--border-radius-mdLayoutMedium border radius
--border-radius-lgLayoutLarge border radius
--border-radius-fullLayoutFull/pill border radius

Hybrid App Styling (MCP + Standalone)

/* Works in BOTH modes because of fallback values */
body {
  margin: 0;
  padding: 0;
  background-color: var(--color-background-primary, #ffffff);
  color: var(--color-text-primary, #1a1a1a);
  font-family: var(--font-sans, system-ui, -apple-system, sans-serif);
}

/* When host provides variables, they override fallbacks automatically */
/* When running standalone, fallback values apply */

Fullscreen Mode

// Configure fullscreen in the tool registration
registerAppTool(server, {
  name: 'show_dashboard',
  resourceUri: 'app:///dashboard',
  // Request fullscreen display
  displayMode: 'fullscreen',
  async handler(args) { /* ... */ },
});

Common Pitfalls

  1. Hardcoding colors/fonts: Always use CSS variables with fallbacks. Never hardcode #ffffff or Arial without a variable.
  2. Forgetting fallbacks: Without fallback values, standalone mode will have no styling.
  3. Not handling theme changes: The host can switch themes at any time. Always implement onhostcontextchanged.
  4. Ignoring safe area insets: On mobile or certain embedded contexts, content can be obscured without safe area padding.
  5. Applying styles after connect(): Register onhostcontextchanged BEFORE app.connect().

Verification Checklist

  • All colors use var(--color-*, fallback) pattern
  • All fonts use var(--font-*, fallback) pattern
  • onhostcontextchanged handler registered BEFORE app.connect()
  • applyDocumentTheme / applyHostStyleVariables / applyHostFonts called in handler
  • CSS fallback values are sensible defaults (not broken/empty)
  • Safe area insets applied to root container
  • App looks correct in both MCP mode (host variables) and standalone (fallbacks)
  • Theme switch (light/dark) handled dynamically

Task Definition

const mcpHostStylingTask = defineTask({
  name: 'mcp-host-styling-integration',
  description: 'Integrate MCP App UI with host theming system',

  inputs: {
    framework: { type: 'string', required: true },
    hybrid: { type: 'boolean', default: false },
    fullscreen: { type: 'boolean', default: false }
  },

  outputs: {
    cssFileCreated: { type: 'boolean' },
    handlerRegistered: { type: 'boolean' },
    artifacts: { type: 'array' }
  },

  async run(inputs, taskCtx) {
    return {
      kind: 'skill',
      title: `Integrate host styling (${inputs.framework})`,
      skill: {
        name: 'mcp-host-styling-integration',
        context: {
          framework: inputs.framework,
          hybrid: inputs.hybrid,
          fullscreen: inputs.fullscreen,
          instructions: [
            'Create CSS with host variable fallbacks',
            'Implement onhostcontextchanged handler',
            'Apply theme, style variables, and fonts via SDK helpers',
            'Add safe area inset padding',
            'Verify styling in both MCP and standalone modes'
          ]
        }
      },
      io: {
        inputJsonPath: `tasks/${taskCtx.effectId}/input.json`,
        outputJsonPath: `tasks/${taskCtx.effectId}/result.json`
      }
    };
  }
});

Applicable Processes

  • create-mcp-app.js
  • add-app-to-mcp-server.js
  • convert-web-app-to-mcp.js

External Dependencies

  • @modelcontextprotocol/ext-apps (applyDocumentTheme, applyHostStyleVariables, applyHostFonts)
  • @modelcontextprotocol/ext-apps/react (useHostStyles, useHostStyleVariables, useHostFonts) -- React only

References

Related Skills

  • mcp-app-scaffolding
  • mcp-tool-resource-pattern
  • mcp-app-verification
  • single-file-bundling

Related Agents

  • mcp-ui-developer
  • mcp-app-architect

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Provide implementations of advanced data structures

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

a5c-ai/babysitter1.9천2026년 9월 17일 업데이트

Fresh adversarial code review with binary PASS/FAIL verdicts, evidence citations, and anchoring bias prevention via fresh reviewer spawning.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

a5c-ai/babysitter1.9천2026년 9월 17일 업데이트

WASM-based instant code transforms for simple tasks, achieving 352x speedup over LLM inference with zero cost.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

a5c-ai/babysitter1.9천2026년 9월 17일 업데이트

Coordinate Crew (persistent) and Polecat (transient) agents using Gas Town's hook-based work distribution and GUPP principle.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

a5c-ai/babysitter1.9천2026년 9월 17일 업데이트

Generate visual representations of algorithm execution

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

a5c-ai/babysitter1.9천2026년 9월 17일 업데이트

Hierarchical coordination and drift detection with frequent checkpoints, shared memory coherence validation, role specialization enforcement, and short task cycles.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

a5c-ai/babysitter1.9천2026년 9월 17일 업데이트

a5c-ai의 스킬 모두 보기

이 스킬의 문제 신고