Skip to content

Repository files navigation

ha-mcp-worker

Cloudflare Worker that serves inline JS/CSS as hosted resources for Home Assistant AI integrations.

Why?

Browser CORS restrictions prevent data: URIs from working with ES6 modules. This worker provides a workaround by converting base64-encoded code to proper HTTPS URLs.

Usage

https://ha-mcp-resources.rapid-math-bbad.workers.dev/{base64_content}?type=module|js|css

Example

// Original code
const code = `export default class MyCard extends HTMLElement { }`;

// Encode to URL-safe base64
const encoded = btoa(code).replace(/\+/g, '-').replace(/\//g, '_');

// Use as module URL
const url = `https://ha-mcp-resources.rapid-math-bbad.workers.dev/${encoded}?type=module`;

Resource Types

Type Content-Type Use Case
module application/javascript ES6 modules (default)
js application/javascript Plain JavaScript
css text/css Stylesheets

Constraints

  • Max size: ~24KB of source code (32KB base64-encoded URL path limit)
  • Immutable: Content is cached for 1 year (URL = content)
  • Public: No authentication, content is accessible to anyone with the URL

Privacy

  • No logging: Worker logs and observability are disabled
  • No storage: Content is never stored - decoded on-the-fly from URL
  • No analytics: No tracking or telemetry

Local Development

# Install dependencies
pnpm install

# Run locally (http://localhost:8787)
pnpm dev

# Run tests
pnpm test

# Type check
pnpm typecheck

# Deploy
pnpm publish:worker

Deployment

Automatic deployment on push to main via GitHub Actions.

Required Secrets

Secret Description
CLOUDFLARE_API_TOKEN API token with Workers edit permission
CLOUDFLARE_ACCOUNT_ID Your Cloudflare account ID

Related

About

Cloudflare Worker for inline JS/CSS resource hosting for Home Assistant AI integrations

Resources

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages