MCP servers
Model Context Protocol manager tracking context-token budget across local/remote servers with connect/pause and per-tool toggles.
pnpm dlx shadcn@latest add @haze/mcp-servers---
import { Check, ChevronDown, Plug, Plus, Server } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface McpServer {
id: string;
name: string;
transport: "Remote HTTP" | "Local stdio";
status: "Connected" | "Paused" | "Auth error";
tokens: number;
tools: { name: string; enabled: boolean }[];
}
interface Props {
id?: string;
heading?: string;
budgetTokens?: number;
servers?: McpServer[];
class?: string;
}
const {
id = "haze-mcp-servers",
heading = "MCP servers & tools",
budgetTokens = 16000,
servers = [
{ id: "gh", name: "GitHub", transport: "Remote HTTP", status: "Connected", tokens: 3400, tools: [{ name: "list_pull_requests", enabled: true }, { name: "get_file_contents", enabled: true }, { name: "create_issue", enabled: false }] },
{ id: "pg", name: "PostgreSQL", transport: "Local stdio", status: "Connected", tokens: 2100, tools: [{ name: "query_readonly", enabled: true }, { name: "describe_schema", enabled: true }] },
{ id: "lin", name: "Linear", transport: "Remote HTTP", status: "Paused", tokens: 0, tools: [{ name: "search_issues", enabled: false }, { name: "update_issue", enabled: false }] },
{ id: "st", name: "Stripe", transport: "Remote HTTP", status: "Auth error", tokens: 0, tools: [{ name: "list_invoices", enabled: false }] },
],
class: className,
} = Astro.props;
const usedTokens = servers.reduce((sum, s) => sum + s.tokens, 0);
const pct = Math.min(100, Math.round((usedTokens / budgetTokens) * 100));
---
<section aria-labelledby={`${id}-title`} data-haze-mcp-servers data-budget={budgetTokens} class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
<div class="mx-auto max-w-3xl rounded-2xl border border-border bg-card p-5 sm:p-6">
<header class="flex flex-wrap items-center justify-between gap-3 border-b border-border pb-4">
<div class="flex items-center gap-2.5">
<span class="grid size-8 place-items-center rounded-lg border border-frame bg-muted text-muted-foreground" aria-hidden="true">
<Server class="size-4" />
</span>
<div>
<h2 id={`${id}-title`} class="text-base/6 font-semibold tracking-tight text-foreground">{heading}</h2>
<p class="text-xs/5 text-muted-foreground">Manage tool schemas and context-token budget.</p>
</div>
</div>
<button type="button" data-mcp-add class="inline-flex h-8 cursor-pointer items-center gap-1.5 rounded-lg border border-frame bg-field px-3 text-xs font-medium text-foreground hover:border-frame-strong hover:bg-accent focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
<Plus class="size-3.5" aria-hidden="true" />
Add server
</button>
</header>
<div class="mt-4 rounded-xl border border-border bg-muted/40 p-3.5">
<div class="flex items-center justify-between gap-2 text-xs">
<span class="font-medium text-foreground">Context-token budget</span>
<span data-mcp-budget class="font-mono text-muted-foreground tabular-nums">{usedTokens.toLocaleString()} / {budgetTokens.toLocaleString()} tokens ({pct}%)</span>
</div>
<div class="mt-2 h-1.5 w-full overflow-hidden rounded-full bg-muted">
<div data-mcp-bar class="h-full rounded-full bg-primary transition-[width] duration-200 ease-snappy" style={`width: ${pct}%`}></div>
</div>
</div>
<ul role="list" class="mt-4 space-y-2.5">
{
servers.map((srv) => (
<li data-mcp-srv={srv.id} data-tokens={srv.tokens || 1800} class="rounded-xl border border-border bg-muted/40 p-3.5">
<div class="flex flex-wrap items-center justify-between gap-2">
<div class="flex flex-wrap items-center gap-2">
<Plug class="size-4 text-muted-foreground" aria-hidden="true" />
<span class="text-sm/5 font-semibold text-foreground">{srv.name}</span>
<span class="font-mono text-[0.6875rem] text-muted-foreground">{srv.transport}</span>
<span data-mcp-state class={cn(
"rounded-md border px-2 py-0.5 text-[0.6875rem]/4 font-medium",
srv.status === "Connected" ? "border-frame-success bg-success/10 text-success" :
srv.status === "Auth error" ? "border-frame-destructive bg-destructive/10 text-destructive" :
"border-frame bg-card text-muted-foreground",
)}>{srv.status}</span>
</div>
<button
type="button"
data-mcp-toggle={srv.name}
aria-pressed={srv.status === "Connected" ? "true" : "false"}
class="inline-flex h-7 cursor-pointer items-center rounded-md border border-frame bg-field px-2.5 text-xs font-medium text-foreground hover:border-frame-strong hover:bg-accent focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75"
>
{srv.status === "Connected" ? "Pause" : srv.status === "Auth error" ? "Reconnect" : "Connect"}
</button>
</div>
<details class="group mt-2.5 border-t border-border pt-2">
<summary class="flex cursor-pointer list-none items-center gap-1 text-xs font-medium text-muted-foreground hover:text-foreground select-none focus-visible:outline-2 focus-visible:outline-ring [&::-webkit-details-marker]:hidden">
<span>{srv.tools.length} tools</span>
<ChevronDown class="size-3.5 transition-transform duration-150 ease-snappy group-open:rotate-180" aria-hidden="true" />
</summary>
<div class="mt-2 flex flex-wrap gap-2">
{
srv.tools.map((tool) => (
<label class="inline-flex cursor-pointer items-center gap-1.5 rounded-lg border border-frame bg-field px-2.5 py-1 font-mono text-[0.6875rem] text-foreground">
<span class="relative inline-grid size-4 shrink-0 place-items-center"><input type="checkbox" checked={tool.enabled} class="peer col-start-1 row-start-1 size-4 shrink-0 cursor-pointer appearance-none rounded-sm border border-border-strong bg-field transition-[background-color,border-color,scale] duration-150 ease-snappy hover:border-foreground active:scale-90 checked:border-primary checked:bg-primary focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring forced-colors:appearance-auto" /><Check class="pointer-events-none col-start-1 row-start-1 size-3 scale-50 text-primary-foreground opacity-0 transition-[opacity,scale] duration-200 ease-spring peer-checked:scale-100 peer-checked:opacity-100 forced-colors:hidden" stroke-width={3} aria-hidden="true" /></span>
{tool.name}
</label>
))
}
</div>
</details>
</li>
))
}
</ul>
<p data-mcp-status role="status" class="mt-3 min-h-4 text-xs/4 text-muted-foreground"></p>
</div>
</section>
<script>
function initMcpServers() {
document.querySelectorAll<HTMLElement>("[data-haze-mcp-servers]").forEach((root) => {
if (root.hasAttribute("data-enhanced")) return;
root.setAttribute("data-enhanced", "");
const budget = Number(root.dataset.budget ?? 16000);
const budgetEl = root.querySelector<HTMLElement>("[data-mcp-budget]");
const bar = root.querySelector<HTMLElement>("[data-mcp-bar]");
const status = root.querySelector<HTMLElement>("[data-mcp-status]");
const recalc = () => {
let used = 0;
root.querySelectorAll<HTMLElement>("[data-mcp-srv]").forEach((row) => {
const btn = row.querySelector<HTMLButtonElement>("[data-mcp-toggle]");
if (btn?.getAttribute("aria-pressed") === "true") used += Number(row.dataset.tokens ?? 1800);
});
const pct = Math.min(100, Math.round((used / budget) * 100));
if (budgetEl) budgetEl.textContent = `${used.toLocaleString()} / ${budget.toLocaleString()} tokens (${pct}%)`;
if (bar) bar.style.width = `${pct}%`;
};
root.querySelectorAll<HTMLButtonElement>("[data-mcp-toggle]").forEach((btn) => {
btn.addEventListener("click", () => {
const next = btn.getAttribute("aria-pressed") !== "true";
btn.setAttribute("aria-pressed", String(next));
btn.textContent = next ? "Pause" : "Connect";
const badge = btn.closest("[data-mcp-srv]")?.querySelector<HTMLElement>("[data-mcp-state]");
if (badge) {
badge.textContent = next ? "Connected" : "Paused";
badge.className = next
? "rounded-md border border-frame-success bg-success/10 px-2 py-0.5 text-[0.6875rem]/4 font-medium text-success"
: "rounded-md border border-border bg-card px-2 py-0.5 text-[0.6875rem]/4 font-medium text-muted-foreground";
}
recalc();
if (status) status.textContent = `${btn.dataset.mcpToggle} ${next ? "connected" : "paused"}.`;
});
});
root.querySelector<HTMLButtonElement>("[data-mcp-add]")?.addEventListener("click", () => {
if (status) status.textContent = "Ready to register a new MCP server endpoint.";
});
});
}
initMcpServers();
document.addEventListener("astro:page-load", initMcpServers);
</script>When to use
- Managing connected MCP servers, auth errors and per-tool enablement in an agent workspace
- Showing live context-token budget usage as servers are connected or paused
When not to use
- Listing generic third-party marketing integrations without tool toggles; use integrations-card-grid
Installation
Add the Haze registry to components.json once, then install MCP servers with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/mcp-serversnpx shadcn@latest add @haze/mcp-serversyarn dlx shadcn@latest add @haze/mcp-serversbunx --bun shadcn@latest add @haze/mcp-serversFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | "haze-mcp-servers" | Unique prefix for section heading IDs. |
| heading | string | "MCP servers & tools" | Manager card heading. |
| budgetTokens | number | 16000 | Maximum tool-schema token budget. |
| servers | McpServer[] | 4 demo MCP servers | Servers with transport, status, token footprint and tools. |
| class | string | – | Extra classes on the outer section. |
Keyboard interactions
- Tab
- Move across Add server, Connect/Pause buttons, tool disclosures and tool checkboxes
- EnterSpace
- Connect or pause a server, expand its tool list or toggle individual tools
Accessibility
- Server connect/pause buttons expose aria-pressed and recalculate the visible token budget bar immediately.
- Per-tool lists expand via native details/summary disclosures with labelled checkboxes.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI block "MCP servers" with `npx shadcn@latest add @haze/mcp-servers`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import McpServers from "@/components/haze/blocks/mcp-servers.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/blocks/mcp-servers.md
Customize with real content
Adapt the Haze mcp-servers block for our product. Replace the demo values of these props with our real content: id, heading, budgetTokens, servers, class. Keep the layout, the heading level rules and these accessibility details: Server connect/pause buttons expose aria-pressed and recalculate the visible token budget bar immediately. Per-tool lists expand via native details/summary disclosures with labelled checkboxes. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using mcp-servers, check it fits: use it when managing connected mcp servers, auth errors and per-tool enablement in an agent workspace; showing live context-token budget usage as servers are connected or paused. Avoid it when listing generic third-party marketing integrations without tool toggles; use integrations-card-grid. Alternatives: @haze/integrations-card-grid, @haze/usage-meter.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.