
Mcp Ts Template
io.github.cyanheads由 GitHub 帳號 cyanheads 發布v3.0.9更新於 Oct 24, 2026
TypeScript template for building MCP servers with declarative tooling, observability, and auth.
概覽
用來建置 MCP 伺服器的 TypeScript 框架與腳手架,內建型別化工具/資源/提示詞建構器、驗證、儲存、日誌與測試。
- 可以做什麼
- 產生新的 MCP 伺服器專案,含原始碼目錄、建置與測試設定、代理說明與技能
- 以型別化 schema、宣告式錯誤與結果增強定義工具、資源、提示詞與 MCP Apps
- 在 Bun、Node.js 或 Cloudflare Workers 上以 stdio 或 HTTP 執行,支援 JWT/OAuth 範圍與租戶層級儲存
- 以模擬情境、契約測試套件、模糊測試與無頭 MCP Apps 渲染器測試定義
- 可選用 DuckDB 資料畫布、大量資料集的本地 SQLite 鏡像,以及 OpenTelemetry 日誌
- 適用情境
- 適合想用 TypeScript 自行開發或維護 MCP 伺服器,並希望直接取得周邊基礎設施、慣例與代理技能的情況。它是開發起點,而非給終端使用者使用的現成工具集。
- 執行需求
- 作為開發相依套件在本機執行:需要 Bun 或 Node.js 24+(亦支援 Cloudflare Workers),透過 npm 套件及其初始化指令安裝。DuckDB 畫布、Supabase 儲存、OpenTelemetry 與 MCP Apps 渲染為選用相依套件,渲染另需 chrome-headless-shell。設定透過 MCP_TRANSPORT_TYPE、MCP_HTTP_PORT、MCP_AUTH_MODE、STORAGE_PROVIDER_TYPE 等環境變數完成。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Mcp Ts Template,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
@cyanheads/mcp-ts-core
Agent-native TypeScript framework for building MCP servers.
Runtime infrastructure for your server, and the agent skills to build, test, and ship it.
Build AI tools for anything you can describe
Connect an API, a dataset, or a workflow to an AI agent through the Model Context Protocol (MCP). Your project holds the domain code; @cyanheads/mcp-ts-core handles the auth, storage, logging, and transports underneath it.
Agent-native. Every scaffold ships the framework reference and a set of Agent Skills: workflows for designing tools, writing tests, reviewing security, and cutting releases. You decide what the server does; your agent follows the skills to build it.
The framework stays a dependency. Infrastructure fixes arrive as package upgrades. Run the maintenance skill and your agent bumps core, syncs the latest skills, and adopts what changed.
Quick start
Servers run on Bun, Node.js 24+, or Cloudflare Workers.
The scaffold includes a source tree, build and test configuration, CLAUDE.md/AGENTS.md, Agent Skills, and plugin metadata for Claude Code and Codex. Open it in Claude Code, Codex, or another agent and describe what you want:
Build an MCP server for my team's inventory API. We need to find products, check stock across warehouses, investigate stock movements, and record adjustments and transfers. Let's get started.
Already have a TypeScript project? Run bun add @cyanheads/mcp-ts-core and register your definitions with createApp().
A tool is a schema and a function
This is a complete server that searches a three-item catalog. To try it, replace the scaffold's src/index.ts with it:
Build and run it over HTTP:
Point your MCP client at http://127.0.0.1:3010/mcp (Streamable HTTP), or have the client launch it over stdio with bun /absolute/path/to/dist/index.js.
What comes with it
Optional integrations (DuckDB, Supabase, the OpenTelemetry SDK) are peer dependencies; install them when you need them.
Give agents useful results
Two declared contracts shape what an agent gets back. enrichment carries success-path context (totals, the parsed query, empty-result notices), populated with ctx.enrich(). errors lists each expected failure with its recovery guidance, and the handler throws one with the typed ctx.fail().
runSearch(query, limit) stands in for your search backend. It returns { items, total, parsed }, or null when the index is down:
Both contracts are advertised in tools/list, so clients see them before calling, and the definition linter checks the handler against them. A failure with a declared reason reaches the client carrying that entry's recovery hint, and every tool error carries the request ID its server log records share.
Same data across client surfaces
MCP hosts differ in which part of a tool result they hand the agent: structuredContent (JSON), content[] (text), or both. The framework fills both with the same data, so the agent sees the same result on any host.
format() renders the text side; without one, content[] gets JSON. The format-parity lint rule fails lint:mcp if any output field is missing from the rendered text. Enrichment needs no format() entry, because the framework adds it to both surfaces. This formatter renders the items as a markdown list:
Resources
Resources expose data at a URI. This one reads from your own getItem() service:
Everything registers through createApp() in your entry point:
On Cloudflare Workers, createWorkerHandler() takes the same definitions from a separate entry point.
Runtime and integration details
- Auth and storage: Declare
auth: ['scope']on a definition and the scope is checked, under JWT or OAuth, before the handler runs.ctx.stateis tenant-scoped storage over in-memory, filesystem, Supabase, or Cloudflare D1/KV/R2, chosen by config. - Client interaction: Return
ctx.requestInput(...)to ask the user for input, the client's model for a sample, or the client for its roots. The handler runs again with the answers onctx.inputs. - Protocol compatibility: HTTP serves 2026-07-28 clients (per-request
_metaenvelope) and session-based 2025-era clients. The SDK's compatibility layer handles input requests for the older ones. - Server presentation:
instructionsgives the model server-wide guidance once, atinitialize, instead of in every tool description. Identity fields (title,websiteUrl,description,icons) populate the client's server info, the/.well-known/mcp.jsonserver card, and the HTTP landing page.skills: 'skills'serves the Agent Skills the server publishes in rootskills/through the SEP-2640 Skills extension (skills/list,skills/get), checked at build time bylint:packaging. - Definition checks:
lint:mcpchecks names, schemas, scopes, annotations, format parity, and JSON Schema portability. It runs at build time, never at startup, so a new rule can't break a deployed server. - DataCanvas: An optional DuckDB workspace where agents run SQL across staged API results and export CSV, Parquet, or JSON. Agents share a workspace by passing its canvas token. Enable it with
CANVAS_PROVIDER_TYPE=duckdband@duckdb/node-api(Bun or Node.js only). brapi-mcp-server walks through loading API results into a dataframe and querying it. - Mirror: The
/mirrormodule keeps a persistent local copy of a bulk upstream dataset in embedded SQLite with an optional FTS5 index, so tools query it locally instead of paging the live API on every call. You write thesyncingester and the schema; the framework handles storage, resumable initial loads, and incremental refreshes. Bun or Node.js only (better-sqlite3is an optional peer on Node). faa-aircraft-registry-mcp-server serves the full FAA registry this way.
See the framework reference for configuration and handler patterns, and the observability guide for Pino logging and OpenTelemetry traces and metrics.
Server structure
Framework infrastructure lives in node_modules; your source tree holds the server's definitions, configuration, and domain services.
Configuration
Core config comes from environment variables, validated with Zod. Server-specific variables get their own schema, parsed lazily so Workers can inject env at request time.
See CLAUDE.md/AGENTS.md for the full configuration reference.
API overview
Entry points
Builders
Context
Tool and resource handlers receive a Context. ctx.enrich and ctx.fail are typed against the definition's declared contracts:
Subpath exports
See CLAUDE.md/AGENTS.md for the complete exports reference.
Examples
examples/ holds a reference server built only on the public exports. examples/index.ts (Node/Bun) and examples/worker.ts (Cloudflare Workers) register the same definitions/index.ts barrels.
Testing
createMockContext() gives you a recording log, a signal, and a state backed by a real StorageService over an in-memory provider, so key validation, TTL expiry, and the JSON round-trip of stored values behave as they do in production: a Date reads back as its ISO string, and a value JSON cannot encode rejects. It uses tenant 'default' unless you pass { tenantId }. Pass { errors: myTool.errors } for a typed ctx.fail, { inputResponses, requestState } to start a multi-round-trip handler at its second round, or { clientCapabilities } to set what the client declared (seeded responses are then filtered to the declared kinds, as in production).
/testing also exports createMockSession() for session-bound contexts, createFetchMock() as a strict fake for upstream HTTP, and runToolContract(), which runs a definition through schema, handler, formatting, and error-envelope checks. /testing/vitest adds the mcpTest fixtures (ctx, session, fetchMock, storage) and toolContractSuite().
/testing/fuzz uses fast-check to generate valid inputs from your Zod schemas plus adversarial payloads, then checks for crashes, stack-trace leaks, and prototype pollution:
It also exports fuzzResource, fuzzPrompt, zodToArbitrary, and ADVERSARIAL_STRINGS for custom property-based tests.
/testing/apps is a headless MCP Apps host. renderAppTool connects to your server as an MCP Apps client, calls an app tool, loads its ui:// view into chrome-headless-shell inside the sandbox and CSP the MCP Apps spec prescribes, runs scripted steps against the view, and returns a report:
The report also carries every message between the view and the host, the view's rendered text, and the screenshot paths. The same run from the command line, writing report.json and the screenshots under --out:
It needs the optional peers @modelcontextprotocol/client and @modelcontextprotocol/ext-apps, and a chrome-headless-shell build: the newest one in Puppeteer's cache (npx @puppeteer/browsers install chrome-headless-shell@stable --path ~/.cache/puppeteer), or an explicit executable path through browserPath, --browser, or MCP_APPS_BROWSER_PATH. Installed Chrome, Edge, Brave, and Chromium are never searched for.
Documentation
- CLAUDE.md/AGENTS.md: the framework reference, covering exports, patterns,
Context, error codes, auth, config, and testing. It ships in the npm package, so your agent reads it fromnode_modulesafterinit. - docs/telemetry/: every span, metric, and attribute the framework emits (observability.md), plus an example Grafana dashboard and query recipes for Datadog, New Relic, and Honeycomb (dashboards.md).
- CHANGELOG.md: version history, indexing one file per release under
changelog/. Each has a summary, migration notes, and links to commits and issues; releases that need downstream changes carryagent-notesfor themaintenanceskill to act on.
Development
License
Apache 2.0 — see LICENSE.
來源:README.md,提交 3e0b367
工具
0版本歷史
1- v3.0.9最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分