{"id":101472,"plugin_id":"plugins_6af4333b6f008191806d76e5f43ec5f9","kind":"skill","collection_source":"plugin_package","comparison_source":null,"observed_at":"2026-11-17T12:11:35.625Z","digest":"94ab07d1d128f09dc373fbfaf4d0cb9c4f45c5e8bbf3e81884da7b23d0362759","against":null,"payload":{"description":"Build high-quality MCP (Model Context Protocol) servers that let an AI interact with external services through well-designed tools. Use whenever you are building an MCP server to integrate an external API or service, in either Python (FastMCP) or TypeScript (MCP SDK). When the server is deployed as a 3B workflow, put it behind the built-in `space` or `tenant` route auth and let the platform authenticate clients instead of implementing the MCP OAuth handshake in the server.","included_files":[],"name":"mcp-builder","skill_md_contents":"---\nname: mcp-builder\ndescription: Build high-quality MCP (Model Context Protocol) servers that let an AI interact with external services through well-designed tools. Use whenever you are building an MCP server to integrate an external API or service, in either Python (FastMCP) or TypeScript (MCP SDK). When the server is deployed as a 3B workflow, put it behind the built-in `space` or `tenant` route auth and let the platform authenticate clients instead of implementing the MCP OAuth handshake in the server.\nlicense: Apache-2.0\ncompatibility: Tines 3B\n---\n\n# Building an MCP server\n\nAn MCP server exposes an external service to an AI as a set of tools. Its quality is measured by one thing: how reliably an AI can use those tools to accomplish real tasks. Build for the AI that will call it, not for human readers of the API.\n\n## Phase 1 — Research and plan\n\n- **Read the service’s API docs first.** Identify the key endpoints, the auth model, rate limits, and the core data shapes. Use web search and fetch the live docs rather than guessing.\n- **Read the MCP spec and SDK docs.** Start from the sitemap at `https://modelcontextprotocol.io/sitemap.xml`, then fetch specific pages with a `.md` suffix. For the SDKs, fetch the TypeScript SDK README (`github.com/modelcontextprotocol/typescript-sdk`) or Python SDK README (`github.com/modelcontextprotocol/python-sdk`).\n- **Decide coverage vs. workflow tools.** Comprehensive endpoint coverage gives the AI flexibility to compose operations; a few higher-level workflow tools are more convenient for common tasks. When unsure, prioritize comprehensive coverage and add workflow tools for the hot paths.\n\n## Phase 2 — Implement\n\n**Recommended stack:** TypeScript with the MCP SDK. Use streamable HTTP with stateless JSON for remote servers (simple to scale), and stdio for local servers.\n\nBuild shared infrastructure once: an authenticated API client, error-handling helpers, response formatting, and pagination.\n\nFor each tool:\n\n- **Name it clearly and consistently.** Use an action-oriented, prefixed scheme — `github_create_issue`, `github_list_repos` — so the AI can find the right tool fast.\n- **Define a strict input schema** with Zod (TypeScript) or Pydantic (Python). Add constraints, clear field descriptions, and examples in the descriptions.\n- **Define an output schema** where possible and return structured content, not just text — it helps the client parse results.\n- **Return focused data.** Support filtering and pagination so a single call can’t flood the context window.\n- **Write actionable errors.** An error should tell the AI what went wrong and what to try next, not just echo a stack trace.\n- **Set annotations** — `readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint` — so clients can reason about safety.\n\n## Deploying on 3B — let the platform authenticate clients\n\nWhen the server runs as a 3B workflow (a step with a `route`, `route_type = \"api\"`), do **not** implement the MCP authorization spec — discovery, dynamic client registration, consent, or token exchange — inside the server. Set `route_auth = \"space\"` (or `\"tenant\"`) on the route: the `space` and `tenant` bars accept an OAuth access token as one of their credentials, so 3B handles the entire client-facing OAuth 2.1 handshake at the platform boundary — it serves the protected-resource and authorization-server metadata, registers clients, runs the consent screen, issues and verifies access tokens, and enforces them on every request.\n\n```toml\n# Routes are unique per space — use a /<server-name>/mcp path, never a bare \"/mcp\"\nroute = \"/github/mcp\"\nroute_type = \"api\"\nroute_auth = \"space\"\noutput = true\n```\n\nRoutes are unique within a space, and publishing a second workflow on a path that’s already live is rejected — so give the route a `/<server-name>/mcp` path (`/github/mcp`, `/slack/mcp`) rather than a bare `/mcp`. MCP clients connect to the full URL you hand them, so the path is just a name; there’s no requirement to serve at `/mcp`.\n\nFollow the `building-workflows` skill’s **Route URLs** guidance for links and callbacks generated by the workflow. Configure external MCP clients with the destination route’s URL after import.\n\nYour step then receives only authenticated requests, with the consenting user’s email in the `x-3b-authenticated-email` header and the bearer **stripped** before it reaches your code — so never read, require, or forward the `Authorization` header for the server’s own auth. Each token is bound to this one route, independently revocable, and gated on the caller’s access to the workflow’s space.\n\nTo serve an **external audience** — partner organizations or customers whose users are not 3B members — use `route_auth = \"sso\"`. When the tenant has its own SSO provider registered in SSO settings with a pinned email domain (the built-in 3B sign-in doesn’t count), the platform runs the same client-facing OAuth handshake, but consent authenticates the human against that provider instead of a 3B account: callers hold a valid token vouched for by the tenant’s provider and on its pinned domain, with no 3B user, membership, or space access involved, and `x-3b-authenticated-email` carries the email the IdP vouched for.\n\nStep code also receives verified group names in the spoof-proof `x-3b-authenticated-groups` header as a JSON array of strings. Parse it as JSON, never split on commas. It contains the IdP group snapshot for SSO callers and current 3B group names for members, and is absent when there are no verified groups. 3B strips caller-supplied values before injecting verified names.\n\nTo restrict an `sso` route to certain IdP groups, add `route_sso_groups = [\"Security Team\"]`; 3B requires membership in at least one listed group, compared case-insensitively, before the step runs. Other auth modes reject this setting. Draft previews require space access and do not enforce the SSO group restriction. The checks use the IdP groups captured at sign-in. That snapshot survives the fixed 30-day OAuth refresh chain, with up to 30 additional minutes for the final access token; refreshing does not pick up group changes. The IdP must emit the `groups` claim, and missing or oversized claims cannot satisfy a group restriction.\n\n### Every request is a run, so refuse what you don’t serve\n\n3B hands your step the raw HTTP request on stdin and turns every request into a workflow run, whatever the method (3B answers `OPTIONS` preflights itself, so your step never sees them). Streamable-HTTP clients open a `GET` on the endpoint to listen for server-to-client messages, and the spec requires you to either hold that stream open or answer `405 Method Not Allowed`. A `200` on `GET` tells the client the stream closed, so compliant clients reconnect immediately: one server that did this received a reconnect every two seconds from each connected Claude Code session, and each one was a full run. The `GET`s you must serve are the consent render, which arrives with `x-3b-consent-challenge`, and the connect screen, which arrives with `x-3b-connectors`. After those checks, answer `405` to anything but `POST` before parsing a body or touching a connector. With `method` and lowercased `headers` parsed from the request on stdin:\n\n```ts\nif (\n  !headers[\"x-3b-consent-challenge\"] &&\n  !headers[\"x-3b-connectors\"] &&\n  method !== \"POST\"\n) {\n  const body = JSON.stringify({\n    jsonrpc: \"2.0\",\n    id: null,\n    error: {\n      code: -32000,\n      message: \"Stateless MCP endpoint; send JSON-RPC over POST.\",\n    },\n  });\n  process.stdout.write(\n    `HTTP/1.1 405 Method Not Allowed\\r\\nAllow: POST\\r\\nContent-Type: application/json\\r\\nContent-Length: ${Buffer.byteLength(body)}\\r\\n\\r\\n${body}`\n  );\n} else {\n  // render consent or the connect screen when its header is present, otherwise parse the JSON-RPC body\n}\n```\n\n### Always render your own consent screen\n\nThe consent screen is the first thing a connecting user sees, so the workflow should own it — no config key, no second route. When a client signs in, 3B serves the OAuth route itself with a set of unspoofable request headers, and your step renders consent in response to them:\n\n- `x-3b-consent-challenge` — an opaque signed token; echo it back untouched. It is the only thing with any authority.\n- `x-3b-consent-decision-url` — where to send the decision; use it unchanged rather than constructing a workflow route URL.\n- `x-3b-consent-client`, `x-3b-consent-email`, `x-3b-consent-scope` — display values for the copy.\n- `x-3b-consent-connectors` — only when the route uses connectors in visitor mode, where each caller connects their own account: a JSON array of `{ id, name, connected, failed, connectUrl }`, one entry per connector, with `connectUrl` set while this caller still has to connect it.\n\nWhen your step sees `x-3b-consent-challenge`, return an HTML page (set response header `x-3b-consent: rendered` so 3B serves it) showing the requesting client, the signed-in email, and Allow/Deny buttons in your own branding. Each button submits a plain form POST to the decision URL with fields `challenge` (the echoed token) and `decision` (`approve` or `deny`); 3B verifies it and finishes the OAuth flow, so the page needs no crypto, cookies, or state. When the header is absent, serve your normal response. Every server needs this page, even a pure API server with no other UI: if the step doesn’t claim the render, sign-in fails with an error. When `x-3b-consent-connectors` is present, list each entry with its state and, while `connectUrl` is set, a plain link to it (“Connect”, or “Retry” when `failed`); the link usually goes straight to the provider and back to your consent page with the same challenge; connectors that sign in through a popup first show one 3B page with a Connect button. Keep Allow disabled until every entry is `connected` — 3B refuses an earlier approval by sending the browser back to your page.\n\nHTML-escape the display values before rendering them: `x-3b-consent-client` is chosen by the connecting client when it registers and connector names are free text, so treat both as untrusted, and the page shares the tenant’s edge origin, so an unescaped injection is not confined to this workflow.\n\nChallenges expire after ten minutes and 3B forces `Cache-Control: no-store` and denies framing on a consent render, so don’t fight those headers. Draft branches render consent the same way, so you can iterate before publishing.\n\nThis is the auth model for the MCP server _itself_. It is separate from how your tools authenticate to the external service they wrap (Phase 1) — that still uses the service’s own credentials.\n\n### When the caller hasn’t connected their own account\n\nWhen a tool calls a service through a connector in visitor mode, the connector uses the caller’s own account, which the consent screen normally collects before the first tool call. If the caller has no usable grant for the route’s space (they revoked it, it failed to refresh, or consent was skipped), 3B answers the tool’s outbound request itself with `403` and this JSON body instead of forwarding it:\n\n```json\n{\n  \"error\": \"connector_not_connected\",\n  \"connector\": \"slack\",\n  \"message\": \"The caller hasn’t connected their own slack account for this space. Open connect_url in a browser to connect, then retry.\",\n  \"connect_url\": \"https://…/mcp\"\n}\n```\n\nReturn `message` and `connect_url` verbatim as the tool result with `isError: true`, so the client shows the caller a link to connect and retry. Do not retry the request or treat it as a provider outage. `connect_url` opens this route in the caller’s browser after they sign in: draw the connect screen there as the `building-workflows` skill’s **Connect screens** section describes, and once every entry is connected, tell the caller to return to the client. A body without `connect_url` means the run had no caller identity to connect an account for, which happens on routes without authentication.\n\n## Phase 3 — Review and test\n\nReview for DRY code, consistent error handling, full type coverage, and clear tool descriptions. Build (`npm run build` / `python -m py_compile`), then exercise the server interactively with the MCP Inspector (`npx @modelcontextprotocol/inspector`).\n\n## Phase 4 — Evaluate\n\nWrite ~10 evaluation questions that prove an AI can actually use the server. Each should be independent, read-only, realistic, and complex enough to need several tool calls, with a single verifiable answer that won’t drift over time. Solve each yourself first to confirm the answer. Run the questions against the server and fix the tools that make them hard.\n\n---\n\n_Adapted by 3B from Anthropic’s “mcp-builder” skill (github.com/anthropics/skills), © Anthropic PBC, licensed under Apache-2.0. Modified for 3B._\n"},"changes":[],"summary":"First saved snapshot. No earlier version is available for comparison.","summary_kind":"deterministic","summary_metadata":{}}