Skip to main content
Glama

skills-over-mcp-ts-server

A minimal MCP server that publishes Agent Skills over MCP (SEP-2640, io.modelcontextprotocol/skills) with the TypeScript SDK 2.4.0, plus an end-to-end smoke test that uses the SDK's own SkillsClient.

用 TypeScript SDK 2.4.0 撰寫的最小 MCP Server 範例:把 skills/ 目錄裡的 Agent Skills 透過 MCP 發布,並附一支以 SkillsClient 走完整個探索、驗證、讀取流程的整合測試。

MCP 2026-07-28 · SEP-2640 Final · Skills 擴充規格 Beta · @modelcontextprotocol/server 2.4.0 · 最後驗證 2026-11-30

功能

  • 以 loadSkills() 在啟動時掃描 skills/,建立固定快照。manifest 的 size/SHA-256 digest 與實際供應的位元組來自同一版。

  • 提供 skills/list、skills/get、resources/read,以及 SDK 內建的 resources/directory/read。

  • 用 createMcpHandler 同時服務 2026-07-28 與 2025-11-25 的 Client。

  • strict: true:超過 512 檔/16 MiB 或 frontmatter 有誤時直接啟動失敗。

  • 快取提示採 SDK 預設 ttlMs: 0、cacheScope: "private"。

  • 預設只綁 127.0.0.1。

  • 執行中在終端機輸入 r 再按 Enter,會重新掃描技能目錄並通知訂閱中的 Client。

Related MCP server: skill-mcp

快速開始

需要 Node.js 20 以上。

git clone https://github.com/stevenke1981/skills-over-mcp-ts-server
cd skills-over-mcp-ts-server
npm install
npm start          # MCP endpoint: http://127.0.0.1:3000/mcp

環境變數:PORT(預設 3000)、HOST(預設 127.0.0.1)、SKILLS_DIR(預設 ./skills)。

整合測試

npm test           # tsc 型別檢查 + scripts/smoke.ts

測試會在隨機埠啟動 Server,逐項檢查:

檢查

預期

擴充宣告

SkillsClient.supported 為 true

skills/list

兩項完整條目,沒有無效條目,resources 為固定 manifest

manifest 完整性

每個檔案的 size/digest 等於磁碟上的原始位元組

skills/get

依 URI 取得條目,cacheScope 為 private

讀主檔

通過 size、digest、frontmatter 驗證

讀附屬檔

按需讀取並通過驗證

未列出的檔案

送出請求前就以 SkillVerificationError(unlisted)拒絕

未知技能

skills/get 回 -32602

自動協商

mode: "auto" 列出相同技能

舊版 Client

2025-11-25 握手也能列出並驗證技能

用 curl 看線路格式

2026-07-28 的 HTTP 請求除了 body 內的 _meta,還須帶 MCP-Protocol-Version 與 Mcp-Method 標頭,且要與 body 一致,否則 Server 以 HTTP 400 回 -32020。讀檔的 resources/read 另須帶 Mcp-Name,值等於 params.uri。用 SDK 的 Client 時這些標頭會自動加上。

curl -s -X POST http://127.0.0.1:3000/mcp \
  -H 'content-type: application/json' \
  -H 'accept: application/json, text/event-stream' \
  -H 'mcp-protocol-version: 2026-07-28' \
  -H 'mcp-method: skills/list' \
  -d '{"jsonrpc":"2.0","id":1,"method":"skills/list","params":{"_meta":{
        "io.modelcontextprotocol/protocolVersion":"2026-07-28",
        "io.modelcontextprotocol/clientCapabilities":{},
        "io.modelcontextprotocol/clientInfo":{"name":"curl","version":"1"}}}}'

讀取檔案時加上 Mcp-Name:

curl -s -X POST http://127.0.0.1:3000/mcp   -H 'content-type: application/json'   -H 'accept: application/json, text/event-stream'   -H 'mcp-protocol-version: 2026-07-28'   -H 'mcp-method: resources/read'   -H 'mcp-name: skill://code-review/SKILL.md'   -d '{"jsonrpc":"2.0","id":2,"method":"resources/read","params":{"uri":"skill://code-review/SKILL.md","_meta":{
        "io.modelcontextprotocol/protocolVersion":"2026-07-28",
        "io.modelcontextprotocol/clientCapabilities":{}}}}'

skills/list 回應中每項技能都有 uri、原樣映射的 frontmatter,以及列出主檔與附屬檔 digest/size 的 resources。

專案結構

skills-over-mcp-ts-server/
├── src/
│   ├── app.ts            # loadSkills + createMcpHandler + Node http 轉接
│   └── server.ts         # 進入點:環境變數、重新載入、結束處理
├── scripts/
│   └── smoke.ts          # 以 SkillsClient 執行的整合測試
├── skills/               # 要發布的技能,每個資料夾一項
│   ├── code-review/
│   │   ├── SKILL.md
│   │   └── references/checklist.md
│   └── release-notes/
│       ├── SKILL.md
│       └── templates/release-notes.md
└── package.json

新增技能

  1. 在 skills/ 下建立資料夾,資料夾名稱必須等於 SKILL.md frontmatter 的 name。

  2. 寫 SKILL.md(必填 name、description),附屬檔放在子資料夾並以相對路徑連結。

  3. 重新啟動,或在執行中輸入 r。URI 會是 skill://<name>/SKILL.md。

.gitattributes 固定 LF 換行,避免 Windows 簽出時把檔案轉成 CRLF,讓 digest 與 Git 內的內容不同。

上線前要補的部分

這是本機範例,沒有身分驗證。對外部署前至少要:

  • 加上授權:在 handler.fetch(request, { authInfo }) 前驗證呼叫者,並在探索、取得條目及每次讀檔時依身分過濾技能。

  • 依身分變動的回應維持 cacheScope: "private",並確認代理與 CDN 不會跨身分共用快取。

  • 檢查 Host/Origin:若綁到 127.0.0.1 以外的位址,加上 Host 標頭驗證以防 DNS rebinding。

  • 確認目標 Host 支援 Skills 擴充:支援一般 Resources 的客戶端不一定能原生載入技能。

相關資源

授權

MIT

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Enables serving a directory of Agent Skills to MCP clients, listing available skills, delivering their instructions and bundled files, and running only the scripts each skill explicitly declares under strict execution limits.
      4
      201 npm
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables MCP hosts to discover, browse, and load Agent Skills from one or many SKILL.md libraries over the Model Context Protocol, with namespaced libraries, search/list/get tools, progressive disclosure, and a digest-verified pull client for syncing skills to disk.
      7
      1
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Serves any directory of Agent Skills (SKILL.md folders) over MCP, exposing skills/list, skills/get, and skill:// resources so clients can enumerate and retrieve each skill's frontmatter and files. Every returned file comes with a real SHA-256 digest, letting clients verify content rather than merely trust it.
      MIT