mcpField
B
blink-backend

blink-backend

github.com/blink-newDevelopment441 installsUpdated 2w ago
Repository

About blink-backend

blink-backend is a skill for building and deploying Blink backend endpoints. It covers Hono app structure, secrets, JWT verification, frontend calls, and deployment checks for server-side tasks such as webhooks and callbacks.

Key features

  1. 01Guidance for Hono backend structure
  2. 02Backend eligibility checks
  3. 03Secret handling guidance
  4. 04JWT token verification
  5. 05Frontend endpoint calling patterns
  6. 06Deployment and error troubleshooting

Use cases

  1. 01Implement webhook endpoints
  2. 02Handle third-party callbacks
  3. 03Keep server-side keys out of frontend code
  4. 04Deploy a Blink backend

MCP support

The skill lists MCP tools for checking backend status, deploying a backend, and viewing logs: `blink_backend_status`, `blink_backend_deploy`, and `blink_backend_logs`.

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/blink-new/blink-plugin --skill blink-backend

After installing, type/blink-backendin Claude Code to confirm it loaded.

Details

From the project README

MCP Tools

blink_backend_status · blink_backend_deploy · blink_backend_logs

When to Use

  • Prefer SDK for auth, db, storage, AI (~95% of cases)
  • Use backend for: webhooks, server-side secrets, third-party callbacks, heavy processing
  • Never create a backend just for CRUD — use blink.db instead

Getting Started

# Check backend eligibility (Pro/Max/Team)
blink backend status

# Create the entry point
mkdir -p backend
# Write backend/index.ts (see below)

# Deploy
blink backend deploy

# View logs
blink backend logs

Structure

backend/
├── index.ts          ← REQUIRED: export default Hono app
├── routes/
│   ├── stripe.ts
│   └── webhooks.ts
└── lib/
    └── auth.ts

backend/index.ts (Required Entry Point)

import { Hono } from "hono"
import { cors } from "hono/cors"
import { createClient } from "@blinkdotnew/sdk"

const app = new Hono()
app.use("*", cors())

const getBlink = (env: Record<string, string>) =>
  createClient({
    projectId: env.BLINK_PROJECT_ID,
    secretKey: env.BLINK_SECRET_KEY,  // server key, not publishableKey
  })

app.get("/health", (c) => c.json({ ok: true }))

app.post("/api/example", async (c) => {
  const blink = getBlink(c.env as Record<string, string>)
  const body = await c.req.json()
  return c.json({ success: true })
})

export default app

Secrets

Auto-injected (never hardcode): BLINK_PROJECT_ID, BLINK_SECRET_KEY, BLINK_PUBLISHABLE_KEY

User secrets (third-party keys): Add via project settings or CLI, access as c.env.MY_SECRET.

JWT Verification

app.post("/api/protected", async (c) => {
  const blink = getBlink(c.env as Record<string, string>)
  const auth = await blink.auth.verifyToken(c.req.header("Authorization"))
  if (!auth.valid) return c.json({ error: auth.error }, 401)
  return c.json({ userId: auth.userId })
})

Calling from Frontend

// Direct fetch
const res = await fetch("https://{projectId8}.backend.blink.new/api/example", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ key: "value" }),
})

// Via SDK
const data = await blink.functions.invoke("api/example", { body: { key: "value" } })

projectId8 = last 8 chars of the full project ID.

Deployment Flow

# 1. Check eligibility
blink backend status

# 2. Write backend/index.ts

# 3. Deploy (reads all backend/ files, bundles with esbuild, deploys to CF Workers)
blink backend deploy

# 4. URL is printed: https://{projectId8}.backend.blink.new

Common Errors

ErrorCauseFix
BACKEND_REQUIRES_PROFree/Starter workspaceUpgrade to Pro+
MISSING_ENTRYPOINTNo backend/index.tsCreate with export default app
CORS errorMissing middlewareAdd app.use("*", cors())
401 on blink-apisWrong keyUse secretKey, not publishableKey

Checklist

  • backend/index.ts exports default app
  • app.use("*", cors()) present
  • Uses secretKey in createClient (not publishableKey)
  • Deployed with blink backend deploy
  • AbortController timeout on all external fetch() calls

Comments

Markdown supported