Cloudflare Worker that serves inline JS/CSS as hosted resources for Home Assistant AI integrations.
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.
https://ha-mcp-resources.rapid-math-bbad.workers.dev/{base64_content}?type=module|js|css
// 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`;| Type | Content-Type | Use Case |
|---|---|---|
module |
application/javascript |
ES6 modules (default) |
js |
application/javascript |
Plain JavaScript |
css |
text/css |
Stylesheets |
- 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
- 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
# Install dependencies
pnpm install
# Run locally (http://localhost:8787)
pnpm dev
# Run tests
pnpm test
# Type check
pnpm typecheck
# Deploy
pnpm publish:workerAutomatic deployment on push to main via GitHub Actions.
| Secret | Description |
|---|---|
CLOUDFLARE_API_TOKEN |
API token with Workers edit permission |
CLOUDFLARE_ACCOUNT_ID |
Your Cloudflare account ID |
- ha-mcp - Home Assistant MCP server
- Issue #266 - Feature request