ultra-mcp-toolkit 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (290) hide show
  1. package/.claude/skills/ultra-mcp-toolkit/SKILL.md +65 -0
  2. package/.claude/skills/ultra-mcp-toolkit/references/dispatcher.md +144 -0
  3. package/.claude/skills/ultra-mcp-toolkit/references/manifest.md +100 -0
  4. package/.claude/skills/ultra-mcp-toolkit/references/server-boot.md +260 -0
  5. package/.claude/skills/ultra-mcp-toolkit/references/skills.md +94 -0
  6. package/.claude/skills/ultra-mcp-toolkit/references/trim.md +115 -0
  7. package/LICENSE +21 -0
  8. package/README.md +271 -0
  9. package/build/agent-safety/index.d.ts +3 -0
  10. package/build/agent-safety/index.d.ts.map +1 -0
  11. package/build/agent-safety/index.js +3 -0
  12. package/build/agent-safety/index.js.map +1 -0
  13. package/build/agent-safety/safe-path.d.ts +67 -0
  14. package/build/agent-safety/safe-path.d.ts.map +1 -0
  15. package/build/agent-safety/safe-path.js +157 -0
  16. package/build/agent-safety/safe-path.js.map +1 -0
  17. package/build/agent-safety/safe-path.test.d.ts +2 -0
  18. package/build/agent-safety/safe-path.test.d.ts.map +1 -0
  19. package/build/agent-safety/safe-path.test.js +134 -0
  20. package/build/agent-safety/safe-path.test.js.map +1 -0
  21. package/build/agent-safety/safety-checker.d.ts +52 -0
  22. package/build/agent-safety/safety-checker.d.ts.map +1 -0
  23. package/build/agent-safety/safety-checker.js +218 -0
  24. package/build/agent-safety/safety-checker.js.map +1 -0
  25. package/build/agent-safety/safety-checker.test.d.ts +2 -0
  26. package/build/agent-safety/safety-checker.test.d.ts.map +1 -0
  27. package/build/agent-safety/safety-checker.test.js +138 -0
  28. package/build/agent-safety/safety-checker.test.js.map +1 -0
  29. package/build/agent-tools/file-tools.d.ts +93 -0
  30. package/build/agent-tools/file-tools.d.ts.map +1 -0
  31. package/build/agent-tools/file-tools.js +164 -0
  32. package/build/agent-tools/file-tools.js.map +1 -0
  33. package/build/agent-tools/file-tools.test.d.ts +2 -0
  34. package/build/agent-tools/file-tools.test.d.ts.map +1 -0
  35. package/build/agent-tools/file-tools.test.js +186 -0
  36. package/build/agent-tools/file-tools.test.js.map +1 -0
  37. package/build/agent-tools/git-tools.d.ts +106 -0
  38. package/build/agent-tools/git-tools.d.ts.map +1 -0
  39. package/build/agent-tools/git-tools.js +202 -0
  40. package/build/agent-tools/git-tools.js.map +1 -0
  41. package/build/agent-tools/github-tools.d.ts +151 -0
  42. package/build/agent-tools/github-tools.d.ts.map +1 -0
  43. package/build/agent-tools/github-tools.js +293 -0
  44. package/build/agent-tools/github-tools.js.map +1 -0
  45. package/build/agent-tools/index.d.ts +5 -0
  46. package/build/agent-tools/index.d.ts.map +1 -0
  47. package/build/agent-tools/index.js +5 -0
  48. package/build/agent-tools/index.js.map +1 -0
  49. package/build/agent-tools/test-tools.d.ts +79 -0
  50. package/build/agent-tools/test-tools.d.ts.map +1 -0
  51. package/build/agent-tools/test-tools.js +113 -0
  52. package/build/agent-tools/test-tools.js.map +1 -0
  53. package/build/boot/http.d.ts +31 -0
  54. package/build/boot/http.d.ts.map +1 -0
  55. package/build/boot/http.js +301 -0
  56. package/build/boot/http.js.map +1 -0
  57. package/build/boot/http.test.d.ts +2 -0
  58. package/build/boot/http.test.d.ts.map +1 -0
  59. package/build/boot/http.test.js +514 -0
  60. package/build/boot/http.test.js.map +1 -0
  61. package/build/boot/stdio.d.ts +14 -0
  62. package/build/boot/stdio.d.ts.map +1 -0
  63. package/build/boot/stdio.js +48 -0
  64. package/build/boot/stdio.js.map +1 -0
  65. package/build/bridge/client.d.ts +10 -0
  66. package/build/bridge/client.d.ts.map +1 -0
  67. package/build/bridge/client.js +85 -0
  68. package/build/bridge/client.js.map +1 -0
  69. package/build/bridge/discovery.d.ts +29 -0
  70. package/build/bridge/discovery.d.ts.map +1 -0
  71. package/build/bridge/discovery.js +202 -0
  72. package/build/bridge/discovery.js.map +1 -0
  73. package/build/bridge/discovery.test.d.ts +2 -0
  74. package/build/bridge/discovery.test.d.ts.map +1 -0
  75. package/build/bridge/discovery.test.js +140 -0
  76. package/build/bridge/discovery.test.js.map +1 -0
  77. package/build/bridge/index.d.ts +6 -0
  78. package/build/bridge/index.d.ts.map +1 -0
  79. package/build/bridge/index.js +10 -0
  80. package/build/bridge/index.js.map +1 -0
  81. package/build/bridge/resolve.d.ts +14 -0
  82. package/build/bridge/resolve.d.ts.map +1 -0
  83. package/build/bridge/resolve.js +22 -0
  84. package/build/bridge/resolve.js.map +1 -0
  85. package/build/bridge/server.d.ts +39 -0
  86. package/build/bridge/server.d.ts.map +1 -0
  87. package/build/bridge/server.js +237 -0
  88. package/build/bridge/server.js.map +1 -0
  89. package/build/bridge/wire.d.ts +23 -0
  90. package/build/bridge/wire.d.ts.map +1 -0
  91. package/build/bridge/wire.js +17 -0
  92. package/build/bridge/wire.js.map +1 -0
  93. package/build/cli/help-select.test.d.ts +2 -0
  94. package/build/cli/help-select.test.d.ts.map +1 -0
  95. package/build/cli/help-select.test.js +215 -0
  96. package/build/cli/help-select.test.js.map +1 -0
  97. package/build/cli/help.d.ts +17 -0
  98. package/build/cli/help.d.ts.map +1 -0
  99. package/build/cli/help.js +91 -0
  100. package/build/cli/help.js.map +1 -0
  101. package/build/cli/index.d.ts +31 -0
  102. package/build/cli/index.d.ts.map +1 -0
  103. package/build/cli/index.js +387 -0
  104. package/build/cli/index.js.map +1 -0
  105. package/build/cli/install-skill.d.ts +20 -0
  106. package/build/cli/install-skill.d.ts.map +1 -0
  107. package/build/cli/install-skill.js +98 -0
  108. package/build/cli/install-skill.js.map +1 -0
  109. package/build/cli/install-skill.test.d.ts +2 -0
  110. package/build/cli/install-skill.test.d.ts.map +1 -0
  111. package/build/cli/install-skill.test.js +159 -0
  112. package/build/cli/install-skill.test.js.map +1 -0
  113. package/build/cli/parse-argv.d.ts +10 -0
  114. package/build/cli/parse-argv.d.ts.map +1 -0
  115. package/build/cli/parse-argv.js +95 -0
  116. package/build/cli/parse-argv.js.map +1 -0
  117. package/build/cli/select.d.ts +4 -0
  118. package/build/cli/select.d.ts.map +1 -0
  119. package/build/cli/select.js +53 -0
  120. package/build/cli/select.js.map +1 -0
  121. package/build/client/http.d.ts +32 -0
  122. package/build/client/http.d.ts.map +1 -0
  123. package/build/client/http.js +183 -0
  124. package/build/client/http.js.map +1 -0
  125. package/build/client/http.test.d.ts +2 -0
  126. package/build/client/http.test.d.ts.map +1 -0
  127. package/build/client/http.test.js +76 -0
  128. package/build/client/http.test.js.map +1 -0
  129. package/build/client/index.d.ts +9 -0
  130. package/build/client/index.d.ts.map +1 -0
  131. package/build/client/index.js +19 -0
  132. package/build/client/index.js.map +1 -0
  133. package/build/client/streaming.d.ts +29 -0
  134. package/build/client/streaming.d.ts.map +1 -0
  135. package/build/client/streaming.js +133 -0
  136. package/build/client/streaming.js.map +1 -0
  137. package/build/client/streaming.test.d.ts +2 -0
  138. package/build/client/streaming.test.d.ts.map +1 -0
  139. package/build/client/streaming.test.js +139 -0
  140. package/build/client/streaming.test.js.map +1 -0
  141. package/build/client/transport.d.ts +24 -0
  142. package/build/client/transport.d.ts.map +1 -0
  143. package/build/client/transport.js +119 -0
  144. package/build/client/transport.js.map +1 -0
  145. package/build/client/transport.test.d.ts +2 -0
  146. package/build/client/transport.test.d.ts.map +1 -0
  147. package/build/client/transport.test.js +145 -0
  148. package/build/client/transport.test.js.map +1 -0
  149. package/build/code-api/boot.d.ts +28 -0
  150. package/build/code-api/boot.d.ts.map +1 -0
  151. package/build/code-api/boot.js +57 -0
  152. package/build/code-api/boot.js.map +1 -0
  153. package/build/code-api/index.d.ts +4 -0
  154. package/build/code-api/index.d.ts.map +1 -0
  155. package/build/code-api/index.js +5 -0
  156. package/build/code-api/index.js.map +1 -0
  157. package/build/code-api/script.d.ts +17 -0
  158. package/build/code-api/script.d.ts.map +1 -0
  159. package/build/code-api/script.js +57 -0
  160. package/build/code-api/script.js.map +1 -0
  161. package/build/code-api/tool.d.ts +36 -0
  162. package/build/code-api/tool.d.ts.map +1 -0
  163. package/build/code-api/tool.js +91 -0
  164. package/build/code-api/tool.js.map +1 -0
  165. package/build/config/index.d.ts +23 -0
  166. package/build/config/index.d.ts.map +1 -0
  167. package/build/config/index.js +55 -0
  168. package/build/config/index.js.map +1 -0
  169. package/build/config/index.test.d.ts +2 -0
  170. package/build/config/index.test.d.ts.map +1 -0
  171. package/build/config/index.test.js +84 -0
  172. package/build/config/index.test.js.map +1 -0
  173. package/build/confirm/index.d.ts +57 -0
  174. package/build/confirm/index.d.ts.map +1 -0
  175. package/build/confirm/index.js +198 -0
  176. package/build/confirm/index.js.map +1 -0
  177. package/build/core/disk-cache.d.ts +8 -0
  178. package/build/core/disk-cache.d.ts.map +1 -0
  179. package/build/core/disk-cache.js +70 -0
  180. package/build/core/disk-cache.js.map +1 -0
  181. package/build/core/disk-cache.test.d.ts +2 -0
  182. package/build/core/disk-cache.test.d.ts.map +1 -0
  183. package/build/core/disk-cache.test.js +62 -0
  184. package/build/core/disk-cache.test.js.map +1 -0
  185. package/build/core/lru.d.ts +18 -0
  186. package/build/core/lru.d.ts.map +1 -0
  187. package/build/core/lru.js +57 -0
  188. package/build/core/lru.js.map +1 -0
  189. package/build/core/lru.test.d.ts +2 -0
  190. package/build/core/lru.test.d.ts.map +1 -0
  191. package/build/core/lru.test.js +86 -0
  192. package/build/core/lru.test.js.map +1 -0
  193. package/build/core/manifest.d.ts +63 -0
  194. package/build/core/manifest.d.ts.map +1 -0
  195. package/build/core/manifest.js +193 -0
  196. package/build/core/manifest.js.map +1 -0
  197. package/build/core/manifest.test.d.ts +2 -0
  198. package/build/core/manifest.test.d.ts.map +1 -0
  199. package/build/core/manifest.test.js +234 -0
  200. package/build/core/manifest.test.js.map +1 -0
  201. package/build/core/page-cache.d.ts +21 -0
  202. package/build/core/page-cache.d.ts.map +1 -0
  203. package/build/core/page-cache.js +152 -0
  204. package/build/core/page-cache.js.map +1 -0
  205. package/build/core/page-cache.test.d.ts +2 -0
  206. package/build/core/page-cache.test.d.ts.map +1 -0
  207. package/build/core/page-cache.test.js +93 -0
  208. package/build/core/page-cache.test.js.map +1 -0
  209. package/build/core/sandbox.d.ts +26 -0
  210. package/build/core/sandbox.d.ts.map +1 -0
  211. package/build/core/sandbox.js +150 -0
  212. package/build/core/sandbox.js.map +1 -0
  213. package/build/core/sandbox.test.d.ts +2 -0
  214. package/build/core/sandbox.test.d.ts.map +1 -0
  215. package/build/core/sandbox.test.js +80 -0
  216. package/build/core/sandbox.test.js.map +1 -0
  217. package/build/core/trim-registry.d.ts +5 -0
  218. package/build/core/trim-registry.d.ts.map +1 -0
  219. package/build/core/trim-registry.js +27 -0
  220. package/build/core/trim-registry.js.map +1 -0
  221. package/build/core/trim.d.ts +26 -0
  222. package/build/core/trim.d.ts.map +1 -0
  223. package/build/core/trim.js +99 -0
  224. package/build/core/trim.js.map +1 -0
  225. package/build/core/trim.test.d.ts +2 -0
  226. package/build/core/trim.test.d.ts.map +1 -0
  227. package/build/core/trim.test.js +131 -0
  228. package/build/core/trim.test.js.map +1 -0
  229. package/build/index.d.ts +25 -0
  230. package/build/index.d.ts.map +1 -0
  231. package/build/index.js +49 -0
  232. package/build/index.js.map +1 -0
  233. package/build/schemas/index.d.ts +6 -0
  234. package/build/schemas/index.d.ts.map +1 -0
  235. package/build/schemas/index.js +20 -0
  236. package/build/schemas/index.js.map +1 -0
  237. package/build/schemas/index.test.d.ts +2 -0
  238. package/build/schemas/index.test.d.ts.map +1 -0
  239. package/build/schemas/index.test.js +48 -0
  240. package/build/schemas/index.test.js.map +1 -0
  241. package/build/skills/drift.d.ts +18 -0
  242. package/build/skills/drift.d.ts.map +1 -0
  243. package/build/skills/drift.js +158 -0
  244. package/build/skills/drift.js.map +1 -0
  245. package/build/skills/drift.test.d.ts +2 -0
  246. package/build/skills/drift.test.d.ts.map +1 -0
  247. package/build/skills/drift.test.js +126 -0
  248. package/build/skills/drift.test.js.map +1 -0
  249. package/build/skills/files.d.ts +14 -0
  250. package/build/skills/files.d.ts.map +1 -0
  251. package/build/skills/files.js +80 -0
  252. package/build/skills/files.js.map +1 -0
  253. package/build/skills/files.test.d.ts +2 -0
  254. package/build/skills/files.test.d.ts.map +1 -0
  255. package/build/skills/files.test.js +54 -0
  256. package/build/skills/files.test.js.map +1 -0
  257. package/build/skills/index.d.ts +3 -0
  258. package/build/skills/index.d.ts.map +1 -0
  259. package/build/skills/index.js +8 -0
  260. package/build/skills/index.js.map +1 -0
  261. package/build/skills/serve.test.d.ts +2 -0
  262. package/build/skills/serve.test.d.ts.map +1 -0
  263. package/build/skills/serve.test.js +67 -0
  264. package/build/skills/serve.test.js.map +1 -0
  265. package/build/tool/dispatcher.d.ts +48 -0
  266. package/build/tool/dispatcher.d.ts.map +1 -0
  267. package/build/tool/dispatcher.js +219 -0
  268. package/build/tool/dispatcher.js.map +1 -0
  269. package/build/tool/dispatcher.test.d.ts +2 -0
  270. package/build/tool/dispatcher.test.d.ts.map +1 -0
  271. package/build/tool/dispatcher.test.js +269 -0
  272. package/build/tool/dispatcher.test.js.map +1 -0
  273. package/build/tool/schema-validation.test.d.ts +2 -0
  274. package/build/tool/schema-validation.test.d.ts.map +1 -0
  275. package/build/tool/schema-validation.test.js +56 -0
  276. package/build/tool/schema-validation.test.js.map +1 -0
  277. package/build/trim/mutation-ack.d.ts +11 -0
  278. package/build/trim/mutation-ack.d.ts.map +1 -0
  279. package/build/trim/mutation-ack.js +52 -0
  280. package/build/trim/mutation-ack.js.map +1 -0
  281. package/build/trim/mutation-ack.test.d.ts +2 -0
  282. package/build/trim/mutation-ack.test.d.ts.map +1 -0
  283. package/build/trim/mutation-ack.test.js +67 -0
  284. package/build/trim/mutation-ack.test.js.map +1 -0
  285. package/build/types/refs.d.ts +14 -0
  286. package/build/types/refs.d.ts.map +1 -0
  287. package/build/types/refs.js +9 -0
  288. package/build/types/refs.js.map +1 -0
  289. package/package.json +181 -0
  290. package/scripts/install-skill.mjs +128 -0
@@ -0,0 +1,65 @@
1
+ ---
2
+ name: ultra-mcp-toolkit
3
+ description: Use when building, extending, or debugging an MCP (Model Context Protocol) server with ultra-mcp-toolkit. Triggers include adding a new operation, writing a trim function, wiring a consolidated tool, booting stdio or code-api mode, or asking how the toolkit's manifest / trim / dispatcher patterns work. Skip for generic MCP questions unrelated to this toolkit.
4
+ ---
5
+
6
+ # Building MCP servers with `ultra-mcp-toolkit`
7
+
8
+ This skill is the entry point for working with `ultra-mcp-toolkit` — the shared infrastructure that powers `jira-mcp`, `confluence-mcp`, and `bitbucket-mcp`. It optimizes for **token efficiency**: the server does deterministic filtering/chunking; the model never receives raw API blobs.
9
+
10
+ Load a topic reference (below) before writing code in that area — each one has the exact shapes, gotchas, and patterns the toolkit expects.
11
+
12
+ ## Mental model — 5 things to internalize
13
+
14
+ 1. **One manifest is the source of truth.** Every operation the server exposes is declared once as data (`{ name, verb, pathTemplate, params, trim }`). Tools, CLI, and dispatcher all read it.
15
+ 2. **Trim functions are allowlists.** They declare what to *keep*, never what to drop. They produce the compact projection the model sees.
16
+ 3. **Full responses live on disk, not in context.** A content-addressed sandbox stores the raw JSON; the model gets `{ summary, ref }`. The `ref` is how the agent fetches the rest if it needs to.
17
+ 4. **Two runtime modes per server.** Classic (consolidated MCP tools, e.g. `jira_issue`) and code-api (single MCP tool + bundled CLI binary — ~76× tool-list reduction).
18
+ 5. **Consolidated tools dispatch by `action`.** A single MCP tool exposes N actions; the dispatcher peels off `action`, validates per-action Zod schema, routes to the manifest op or a custom handler.
19
+
20
+ ## Topic references — load on demand
21
+
22
+ | You're working on... | Load |
23
+ |---|---|
24
+ | Declaring operations, `pathTemplate`, `ParamSpec`, `ExecuteFn`, multi-API routing | [references/manifest.md](references/manifest.md) |
25
+ | Writing trim projections, registering them, sandbox+ref envelope, list summarizers | [references/trim.md](references/trim.md) |
26
+ | Building a consolidated MCP tool with `action`-discriminated input, Zod schemas, `full: true` escape hatch, `DispatchError`/`ToolError` | [references/dispatcher.md](references/dispatcher.md) |
27
+ | Wiring server startup — `Client` impl, `createSandbox`, `startStdioServer`, `startHttpServer`, `bootCodeApi`, `createCli`, install-skill subcommand | [references/server-boot.md](references/server-boot.md) |
28
+ | Shipping a skill with your server — SDK `loadSkills` + `attach`, `install-skill --check` fallback, manifest drift test | [references/skills.md](references/skills.md) |
29
+
30
+ ## Common starter tasks
31
+
32
+ - **"Add a new API operation"** — load `manifest.md` and `trim.md`. Declare the operation, register a trim, expose it via a consolidated tool (`dispatcher.md`) or directly as a CLI op.
33
+ - **"Add a new consolidated tool"** — load `dispatcher.md`. Define `ConsolidatedToolDef`, per-action Zod schemas, register in the server's tool list.
34
+ - **"Start a new server from scratch"** — load `server-boot.md` first, then `manifest.md`. Boot pattern, Client impl, two runtime modes.
35
+ - **"My trimmed response drops a field the model needs"** — `trim.md` (extend the projection) or `dispatcher.md` (use `full: true` for raw response on a per-call basis).
36
+ - **"Bump the toolkit version in my server"** — check `npm view ultra-mcp-toolkit version`; consult release notes for breaking changes in `DispatchError`/manifest shape.
37
+
38
+ ## Design principles (do not violate)
39
+
40
+ - **No model-side chunking.** If a response needs paging or filtering, the server does it.
41
+ - **Field allowlists in trim, never denylists.** New API fields default to dropped, not included.
42
+ - **The manifest is pure data.** No closures, no functions — it must round-trip through JSON for the CLI bridge.
43
+ - **`Client` is generic.** Auth-specific construction stays in the server; the toolkit consumes `get/post/put/delete`.
44
+ - **Stderr for banners, stdout is reserved for the MCP transport** when running stdio mode.
45
+
46
+ ## Quick package-export map
47
+
48
+ ```
49
+ ultra-mcp-toolkit/manifest — Operation, ParamSpec, invokeOperation
50
+ ultra-mcp-toolkit/trim — pick, paginatedListSummary, helpers
51
+ ultra-mcp-toolkit/trim-registry — createTrimRegistry
52
+ ultra-mcp-toolkit/sandbox — createSandbox (content-addressed)
53
+ ultra-mcp-toolkit/page-cache — versioned-id disk cache
54
+ ultra-mcp-toolkit/tool — dispatch, buildInputSchema, DispatchError
55
+ ultra-mcp-toolkit/stdio — startStdioServer
56
+ ultra-mcp-toolkit/http — startHttpServer (one process, many clients)
57
+ ultra-mcp-toolkit/code-api — bootCodeApi, createCodeApiTool
58
+ ultra-mcp-toolkit/bridge — startBridge, callBridge
59
+ ultra-mcp-toolkit/cli — createCli (CLI scaffolding)
60
+ ultra-mcp-toolkit/client — Client interface
61
+ ultra-mcp-toolkit/http-client — createHttpClient
62
+ ultra-mcp-toolkit/schemas — shared Zod helpers (positiveInt, etc.)
63
+ ```
64
+
65
+ Prefer the subpath imports over the umbrella `ultra-mcp-toolkit` import — better tree-shaking and clearer dependency intent.
@@ -0,0 +1,144 @@
1
+ # Consolidated tools — the dispatcher
2
+
3
+ A consolidated tool exposes N actions through a single MCP tool with an `action` discriminator on its input. Reduces the tool-listing surface the model sees by 10×–30× vs one MCP tool per operation.
4
+
5
+ Example: instead of `issue_get`, `issue_list`, `issue_create`, `issue_comment` (4 tools), expose `jira_issue` with `action: "get" | "list" | "create" | "comment"`.
6
+
7
+ ## Defining a consolidated tool
8
+
9
+ ```ts
10
+ import { z } from "zod";
11
+ import type { ConsolidatedToolDef } from "ultra-mcp-toolkit/tool";
12
+
13
+ export const jiraIssueTool: ConsolidatedToolDef = {
14
+ name: "jira_issue",
15
+ description: "Read, list, and mutate Jira issues",
16
+ actions: {
17
+ get: {
18
+ operation: "issue.get", // manifest op name
19
+ schema: z.object({
20
+ issueIdOrKey: z.string(),
21
+ fields: z.string().optional(),
22
+ }),
23
+ description: "Fetch a single issue",
24
+ },
25
+ list: {
26
+ operation: "issue.list",
27
+ schema: z.object({
28
+ jql: z.string(),
29
+ maxResults: z.number().int().positive().optional(),
30
+ }),
31
+ description: "JQL search",
32
+ },
33
+ summarize: {
34
+ // No `operation` → uses a custom handler instead of the manifest.
35
+ schema: z.object({ jql: z.string() }),
36
+ description: "LLM-side summary across many issues",
37
+ handler: async (args, ctx) => {
38
+ // Free to call invokeOperation directly, read the sandbox,
39
+ // hit a different client, return any shape.
40
+ return { summarized: true, count: 0 };
41
+ },
42
+ },
43
+ },
44
+ };
45
+ ```
46
+
47
+ ## Wiring into an MCP server
48
+
49
+ ```ts
50
+ import { fromJsonSchema, McpServer } from "@modelcontextprotocol/server";
51
+ import { buildInputSchema, dispatch } from "ultra-mcp-toolkit/tool";
52
+
53
+ mcp.registerTool(
54
+ jiraIssueTool.name,
55
+ { description: jiraIssueTool.description, inputSchema: fromJsonSchema(buildInputSchema(jiraIssueTool)) },
56
+ async (args) => {
57
+ const { result } = await dispatch(jiraIssueTool, args, {
58
+ manifest, client, trimRegistry, invokeOptions: { execute },
59
+ });
60
+ return { content: [{ type: "text", text: JSON.stringify(result) }] };
61
+ },
62
+ );
63
+ ```
64
+
65
+ `buildInputSchema` produces a flat JSON Schema (not `oneOf`): every action's fields are hoisted to the top level with `(used by: get, list)` annotations, because MCP clients render flat schemas reliably and unions less so.
66
+
67
+ When actions disagree on a field's type, for example `fields` as a string for `get` but an object for `create`, the field becomes an `anyOf` of each shape. This matters because SDK v2's `McpServer` validates arguments against the listed schema: with only one shape, it would reject valid calls for the other actions.
68
+
69
+ ## The `dispatch` flow
70
+
71
+ 1. Validate that `rawArgs` is an object with a string `action`.
72
+ 2. Look up the action; reject unknowns with the valid-action list in the error.
73
+ 3. Peel off the `full` meta-arg (boolean), strip the `action` discriminator.
74
+ 4. Validate the remaining args with `action.schema.safeParse`. On failure, throws `DispatchError` with a `prettifyError`-formatted detail.
75
+ 5. Apply `ctx.preprocess(operation, args)` if provided (inject workspace defaults, normalize keys, etc.).
76
+ 6. If `action.handler` present → call it, return.
77
+ 7. If `action.operation` present → `invokeOperation(...)` (or `invokeOperationRaw` when `full: true` on a GET op).
78
+
79
+ ## The `full: true` escape hatch
80
+
81
+ ```json
82
+ { "action": "get", "issueIdOrKey": "PROJ-1", "full": true }
83
+ ```
84
+
85
+ Skips the trim projection on a per-call basis; returns the raw API response. Only valid on **read-shaped (GET) actions** routed through the manifest. Rejected for:
86
+ - Custom handlers (bypass the manifest already).
87
+ - Non-GET ops (mutation-ack already carries everything).
88
+ - Non-boolean values.
89
+
90
+ Use it as an escape hatch when a trim drops a field a one-off agent task needs.
91
+
92
+ ## Errors — `DispatchError` and `ToolError`
93
+
94
+ ```ts
95
+ import { DispatchError, ToolError } from "ultra-mcp-toolkit/tool";
96
+ ```
97
+
98
+ - `DispatchError(message, action, tool?)` — thrown for missing/invalid action, Zod failures, type errors on `full`, missing operation+handler, etc.
99
+ - `ToolError extends DispatchError` — same shape; just a name alias for catch sites that prefer `ToolError`. `instanceof DispatchError` is true.
100
+
101
+ Fields (since v0.4.0):
102
+ - `.action: string` — the action name, or `""` if rejected before action resolution.
103
+ - `.tool?: string` — the consolidated tool name (`"jira_issue"`). Populated for every throw inside `dispatch()`.
104
+ - `.message: string` — always prefixed with `${tool.name}.${actionName}: ...`.
105
+
106
+ Catch sites:
107
+ ```ts
108
+ try {
109
+ await dispatch(tool, args, ctx);
110
+ } catch (err) {
111
+ if (err instanceof DispatchError) {
112
+ log.warn({ tool: err.tool, action: err.action }, err.message);
113
+ return errorEnvelope(err);
114
+ }
115
+ throw err; // OperationError, network errors, etc.
116
+ }
117
+ ```
118
+
119
+ `OperationError` (thrown by `invokeOperation` itself — manifest layer) does **not** carry `tool`. The manifest layer has no notion of which consolidated tool initiated the call. If you need `tool` on those, wrap and rethrow in the catch site.
120
+
121
+ ## The `DispatcherContext`
122
+
123
+ ```ts
124
+ interface DispatcherContext {
125
+ manifest: Manifest;
126
+ client: Client;
127
+ trimRegistry: TrimRegistry;
128
+ invokeOptions?: InvokeOptions; // execute, sandbox overrides
129
+ preprocess?: (op: string, args: Record<string, unknown>)
130
+ => Record<string, unknown>; // inject defaults post-validation
131
+ }
132
+ ```
133
+
134
+ `preprocess` runs *after* Zod validation, *before* dispatch. Common uses:
135
+ - Inject default `workspace` from env.
136
+ - Coerce `issueIdOrKey` casing.
137
+ - Resolve a short alias to a full ID.
138
+
139
+ ## Conventions
140
+
141
+ - Action names are short verbs (`get`, `list`, `create`, `comment`) — never `getIssue`. The tool name already carries the noun.
142
+ - Per-action schemas use `z.object({...})` flat, not nested. The merged JSON Schema flattens regardless.
143
+ - Custom handlers should still register a `schema` — the merged input schema needs it for the LLM-facing menu.
144
+ - One consolidated tool per resource. `jira_issue`, `jira_project`, `jira_user` — not one mega-tool.
@@ -0,0 +1,100 @@
1
+ # Manifest — declaring operations
2
+
3
+ The manifest is the single source of truth for every API operation a server exposes. It's pure data, JSON-serializable, and read at runtime by the tool dispatcher, the CLI, and the code-api bridge.
4
+
5
+ ## Operation shape
6
+
7
+ ```ts
8
+ import type { Manifest, Operation } from "ultra-mcp-toolkit/manifest";
9
+
10
+ const issueGet: Operation = {
11
+ name: "issue.get", // stable id, used by CLI + dispatcher
12
+ description: "Fetch a single issue",
13
+ verb: "GET", // GET | POST | PUT | DELETE
14
+ pathTemplate: "/rest/api/3/issue/{issueIdOrKey}",
15
+ params: [
16
+ { name: "issueIdOrKey", role: "path", required: true },
17
+ { name: "fields", role: "query", required: false,
18
+ description: "Comma-separated list of field names" },
19
+ ],
20
+ trim: "issue", // key into the trim registry
21
+ // Optional:
22
+ // bodyShape: "object" | "rawString" — defaults to "object"
23
+ // meta: { ...arbitrary } — per-server routing hint, read by ExecuteFn
24
+ };
25
+
26
+ export const manifest: Manifest = [issueGet, /* ... */];
27
+ ```
28
+
29
+ ### `ParamSpec.role`
30
+
31
+ - `path` — interpolated into `pathTemplate` (`{name}` placeholders).
32
+ - `query` — appended as `?name=...`.
33
+ - `body` — bundled into the request body (`{ paramA, paramB }` by default).
34
+
35
+ `required: true` fails fast at the dispatcher; missing optional params are dropped from the request.
36
+
37
+ ### `bodyShape: "rawString"`
38
+
39
+ For the rare endpoint that takes a bare JSON scalar (e.g. `"acc-123"` with quotes) instead of an object. Declare exactly one body param; its value is sent as the raw stringified JSON body.
40
+
41
+ ### `meta`
42
+
43
+ Opaque to the SDK. Servers attach routing hints here — e.g. jira-mcp uses `meta: { isAgile: true }` to pick the agile API base URL inside its `ExecuteFn`.
44
+
45
+ ## Dispatching against the manifest
46
+
47
+ ```ts
48
+ import { invokeOperation } from "ultra-mcp-toolkit/manifest";
49
+
50
+ const result = await invokeOperation(
51
+ manifest,
52
+ client,
53
+ "issue.get",
54
+ { issueIdOrKey: "PROJ-123", fields: "summary,status" },
55
+ trimRegistry,
56
+ { /* InvokeOptions: execute?, sandbox?, ... */ },
57
+ );
58
+ // → { summary, ref }
59
+ ```
60
+
61
+ What it does, in order:
62
+ 1. Find the op by `name`.
63
+ 2. Validate required params present.
64
+ 3. Interpolate `pathTemplate` with path params; collect query and body params per their role.
65
+ 4. Call `client[verb](path, ...)` (or your `ExecuteFn` if you passed one).
66
+ 5. Run the trim projection registered under `op.trim`.
67
+ 6. Hand the raw response to `sandbox()`, return `{ summary, ref }`.
68
+
69
+ Use `invokeOperationRaw` to bypass the trim step and return the raw response — the dispatcher's `full: true` escape hatch routes through this.
70
+
71
+ ## Multi-API routing — `ExecuteFn`
72
+
73
+ Default behavior: `client[verb](path, body, queryParams)`. To route based on `meta` (e.g. agile vs cloud APIs):
74
+
75
+ ```ts
76
+ await invokeOperation(manifest, client, "sprint.list", args, trimRegistry, {
77
+ execute: async ({ op, path, body, query }) => {
78
+ const c = op.meta?.isAgile ? agileClient : cloudClient;
79
+ return c[op.verb.toLowerCase()](path, body, query);
80
+ },
81
+ });
82
+ ```
83
+
84
+ ## Conventions
85
+
86
+ - Name pattern: `<resource>.<action>` (`issue.get`, `pullrequest.list`, `page.create`). The CLI parses this same syntax verbatim.
87
+ - One op = one API call. Don't fold "get + transform" into a single op; do that in the trim.
88
+ - `trim: "issue"` keys must match a key registered in `createTrimRegistry({ issue: ... })`. Mismatches throw at dispatch time, not boot.
89
+ - Keep `description` to one line — it surfaces in `--help` lists and consolidated-tool action enums.
90
+
91
+ ## Validating the manifest
92
+
93
+ `src/core/manifest.ts` exposes a typed `Manifest = readonly Operation[]`. There's no runtime validator helper; rely on TS for shape, and on tests for behavior (use the manifest tests as a template — see `src/core/manifest.test.ts`).
94
+
95
+ ## Common pitfalls
96
+
97
+ - **`pathTemplate` placeholder name must match `ParamSpec.name`.** A typo here surfaces as "missing path param" at runtime.
98
+ - **Required body params and required path params are both `required: true`** — the role determines wiring, not the requiredness.
99
+ - **Don't put closures in `meta`.** The manifest must JSON-serialize; the CLI bridge transfers it across processes.
100
+ - **`trim: "..."` is a *string key*, not a function.** Register the function in the trim registry — see [trim.md](trim.md).
@@ -0,0 +1,260 @@
1
+ # Server boot — wiring it all up
2
+
3
+ Every consumer server (jira-mcp, confluence-mcp, bitbucket-mcp) follows the same shape: build a `Client`, build a `sandbox`, build a `trimRegistry`, then boot in one of three modes.
4
+
5
+ ## The three modes
6
+
7
+ | Mode | What runs | When to use |
8
+ |---|---|---|
9
+ | **Classic stdio** | N consolidated MCP tools (`jira_issue`, `jira_project`, …) over stdio | Default. Best when the tool list fits comfortably. |
10
+ | **Code-api** | Single MCP tool (`<server>_code_api`) that dispatches to a bundled CLI over a Unix-socket bridge | Use when the consolidated tool list is still too noisy for the host. ~76× tool-list reduction. |
11
+ | **Shared HTTP** | The classic tools over streamable HTTP; one process serves many clients | Use when many clients on one machine should share one server process instead of one each. |
12
+
13
+ The same manifest, trims, and operations power all three. Only the *surface* and *transport* differ.
14
+
15
+ ## Building the `Client`
16
+
17
+ `Client` is an interface:
18
+
19
+ ```ts
20
+ import type { Client } from "ultra-mcp-toolkit/client";
21
+
22
+ // Most servers use the bundled HTTP client:
23
+ import { createHttpClient } from "ultra-mcp-toolkit/http-client";
24
+
25
+ const client: Client = createHttpClient({
26
+ baseUrl: "https://your.atlassian.net",
27
+ auth: { type: "basic", username, password: apiToken },
28
+ // or: { type: "bearer", token }
29
+ // or: { type: "custom", header: "X-API-Key", value: key }
30
+ retry: true, // opt into the pooled retry-aware transport
31
+ });
32
+ ```
33
+
34
+ `createHttpClient` handles redirects, auth, 204→`{}`, and (opt-in) retries via the pooled `undici.Agent`. Multi-base servers (jira-mcp routes between cloud + agile) instantiate two clients and pick inside `ExecuteFn`.
35
+
36
+ ## Building the sandbox + registry
37
+
38
+ ```ts
39
+ import { createSandbox } from "ultra-mcp-toolkit/sandbox";
40
+ import { createTrimRegistry } from "ultra-mcp-toolkit/trim-registry";
41
+
42
+ const sandbox = createSandbox({ rootName: "my-server-mcp" });
43
+ const trimRegistry = createTrimRegistry({
44
+ issue: issueSummary,
45
+ /* one entry per `op.trim` key in your manifest */
46
+ });
47
+ ```
48
+
49
+ `rootName` becomes a directory under the OS temp area (e.g. `/tmp/my-server-mcp/<session>/`). Refs the model sees (`refs:abc...`) resolve back to files inside that root.
50
+
51
+ ## Classic stdio mode
52
+
53
+ The toolkit is built on the MCP TypeScript SDK v2 (`@modelcontextprotocol/server`).
54
+
55
+ ```ts
56
+ import { fromJsonSchema, McpServer } from "@modelcontextprotocol/server";
57
+ import { startStdioServer } from "ultra-mcp-toolkit/stdio";
58
+ import { buildInputSchema, dispatch } from "ultra-mcp-toolkit/tool";
59
+
60
+ function buildServer(): McpServer {
61
+ const mcp = new McpServer({ name: "my-server-mcp", version: "1.0.0" });
62
+ for (const tool of tools) {
63
+ mcp.registerTool(
64
+ tool.name,
65
+ { description: tool.description, inputSchema: fromJsonSchema(buildInputSchema(tool)) },
66
+ async (args) => {
67
+ const { result } = await dispatch(tool, args, { manifest, client, trimRegistry });
68
+ return { content: [{ type: "text", text: JSON.stringify(result) }] };
69
+ },
70
+ );
71
+ }
72
+ return mcp;
73
+ }
74
+
75
+ await startStdioServer({
76
+ createServer: () => buildServer(),
77
+ banner: "my-server-mcp ready",
78
+ onShutdown: async () => { /* cleanup */ },
79
+ });
80
+ // Do NOT call process.exit() — stdio keeps the event loop alive.
81
+ ```
82
+
83
+ - **`createServer` is a factory.** The SDK builds one server per connection, plus one for a `server/discover` probe that it discards, so build a new server per call and keep shared state (clients, caches) outside the factory.
84
+ - **Both protocol revisions are served:** 2025-11-25 (`initialize`) and the stateless 2026-07-28. The factory's `ctx.era` says which one an instance serves.
85
+ - **Arguments are validated against the schema.** `McpServer` checks them against `inputSchema` before your handler runs, and answers unknown tools with `-32602`. `buildInputSchema` emits `anyOf` for a field whose type differs between actions, so every action passes.
86
+ - **Footguns handled:** `startStdioServer` doesn't exit after startup, and installs SIGINT/SIGTERM handlers.
87
+
88
+ ## Shared HTTP mode
89
+
90
+ Stdio gives every MCP client its own server process. When many clients
91
+ (for example many agent sessions on one machine) should share one
92
+ process, boot over streamable HTTP instead. The helper asks a factory for
93
+ a server. A 2025-11-25 client gets one per session (on its `initialize`);
94
+ a 2026-07-28 client, which has no session, gets one per request:
95
+
96
+ ```ts
97
+ import { HttpSessionRejected, startHttpServer } from "ultra-mcp-toolkit/http";
98
+
99
+ await startHttpServer({
100
+ host: "127.0.0.1",
101
+ port: 18001,
102
+ // Per 2025 session (on initialize) and per 2026-07-28 request.
103
+ createServer: ({ headers }) => {
104
+ const token = headers["my-server-token"];
105
+ if (typeof token !== "string") throw new HttpSessionRejected("my-server-token header required");
106
+ return buildServer(createHttpClient({ baseUrl, auth: { type: "bearer", token } }));
107
+ },
108
+ // Every later request in a 2025 session must repeat these headers.
109
+ bindHeaders: ["my-server-token"],
110
+ banner: "my-server-mcp ready",
111
+ });
112
+ ```
113
+
114
+ - Credentials come from request headers (per session for 2025 clients,
115
+ per request for 2026-07-28 clients), so the shared process holds none
116
+ of its own.
117
+ - Throw `HttpSessionRejected` from the factory to answer 401.
118
+ - The Host header must match `allowedHosts` (default: loopback names at
119
+ the bound port) and any Origin header must be in `allowedOrigins`
120
+ (default: none). Both stop DNS-rebinding requests from web pages.
121
+ - Sessions are kept until the client deletes them or `idleTimeoutMs`
122
+ passes (default 0: never). A session whose client never sends
123
+ `notifications/initialized` is closed after `initTimeoutMs` (default
124
+ 30 s).
125
+ - Every POST body is capped at `maxBodyBytes` (default 4 MiB), in both
126
+ revisions.
127
+ - 2025 sessions stay stateful (not the SDK's stateless 2025 default), so
128
+ a server can still send server-to-client requests to those clients.
129
+ Their responses are SSE.
130
+ - `bindHeaders`, `initTimeoutMs`, `idleTimeoutMs`, and `sessionCount()`
131
+ apply to 2025 sessions only; 2026-07-28 requests hold no session.
132
+ - Inside a container, listen on `0.0.0.0` and publish the port on the
133
+ host's loopback only (`-p 127.0.0.1:18001:18001`). Use the same port
134
+ on both sides so the default Host allowlist matches.
135
+ - Code-api mode is per process (one bridge socket), so it does not fit a
136
+ shared server; use the classic tool surface.
137
+
138
+ ## Code-api mode
139
+
140
+ ```ts
141
+ import { bootCodeApi, createCodeApiTool } from "ultra-mcp-toolkit/code-api";
142
+
143
+ const { bridge, ctx } = await bootCodeApi({
144
+ manifest, client, sandbox, trimRegistry,
145
+ cliPath: path.resolve("dist/cli/index.js"), // bundled CLI binary
146
+ socketEnvVar: "MY_SERVER_MCP_SOCKET",
147
+ });
148
+
149
+ const codeApiTool = createCodeApiTool({
150
+ toolName: "my_server_code_api",
151
+ cliBinaryName: "my-server-cli",
152
+ socketEnvVar: "MY_SERVER_MCP_SOCKET",
153
+ });
154
+
155
+ // In the server factory: register the single code-api tool.
156
+ mcp.registerTool(
157
+ codeApiTool.definition.name,
158
+ { description: codeApiTool.definition.description, inputSchema: fromJsonSchema(codeApiTool.definition.inputSchema) },
159
+ async () => ({ content: [{ type: "text", text: JSON.stringify(codeApiTool.buildResponse(ctx)) }] }),
160
+ );
161
+ // Boot the bridge once, outside the factory: it is per process.
162
+ ```
163
+
164
+ How it works:
165
+ 1. `bootCodeApi` opens a Unix-socket bridge (loopback TCP on Windows), sets `MY_SERVER_MCP_SOCKET` in the server's own env, and publishes the address for discovery.
166
+ 2. The MCP host sees one tool (`my_server_code_api`).
167
+ 3. The model writes shell snippets that invoke `my-server-cli issue.get --issueIdOrKey PROJ-1`.
168
+ 4. The CLI finds the bridge, dispatches over it into the running server, and returns `{ summary, ref }`.
169
+
170
+ ### How the CLI finds the bridge
171
+
172
+ Host shells are siblings of the MCP server, not children. Claude Code's Bash tool, for example, starts its own shells. So they don't inherit `MY_SERVER_MCP_SOCKET`. The CLI resolves the address in this order:
173
+
174
+ 1. **`MY_SERVER_MCP_SOCKET`, while its socket exists.**
175
+ 2. **Discovery.**
176
+ - `bootCodeApi` writes a record for its bridge into a private per-user directory under tmpdir. It's keyed by the host session id (`CLAUDE_CODE_SESSION_ID` by default; configurable with `discovery.sessionEnvVars`) and by the server's working directory.
177
+ - The CLI looks up its own session first, then walks up from its cwd. It uses only records whose server process is alive.
178
+ - A stale env var (the server restarted) falls through to discovery, and the CLI prints a one-line note.
179
+ 3. **Direct mode** (`callDirect`), if the server provides it.
180
+
181
+ Agents therefore don't need the env var prefix. Pass `codeApiToolName: "my_server_code_api"` to `createCli` so its errors tell the agent what to call when nothing is reachable. `my-server-cli status` shows which path it would take, without calling the API.
182
+
183
+ Set `ULTRA_MCP_DISCOVERY=0` in your CLI test suite. Otherwise a CLI under test, run inside a developer's Claude Code session, can find and call their real running server. `discovery: false` on `bootCodeApi` or `createCli` turns it off in code.
184
+
185
+ ## The bundled CLI
186
+
187
+ ```ts
188
+ // dist/cli/index.js
189
+ #!/usr/bin/env node
190
+ import { createCli } from "ultra-mcp-toolkit/cli";
191
+ import { manifest } from "../core/manifest.js";
192
+ import { callDirect } from "./direct.js"; // optional direct-mode hook
193
+ import { SKILL_CONTENT } from "./skill.js"; // optional install-skill body
194
+
195
+ const cli = createCli({
196
+ cliName: "my-server-cli",
197
+ socketEnvVar: "MY_SERVER_MCP_SOCKET",
198
+ manifest,
199
+ callDirect, // when no socket: build client in-process
200
+ skillContent: SKILL_CONTENT, // enables `my-server-cli install-skill`
201
+ skillSlug: "my-server",
202
+ directModeEnvVars: ["MY_SERVER_HOST", "MY_SERVER_TOKEN"],
203
+ });
204
+
205
+ process.exit(await cli.run(process.argv.slice(2)));
206
+ ```
207
+
208
+ `createCli` gives you two modes for free:
209
+ - **Bridge mode** — `MY_SERVER_MCP_SOCKET` is set (because the MCP server set it) → forward to the running server.
210
+ - **Direct mode** — no socket → call `callDirect` which builds a client in-process. Lets the CLI work standalone for debugging or scripting.
211
+
212
+ ## The `install-skill` subcommand
213
+
214
+ `createCli` adds an `install-skill` subcommand when `skillContent` + `skillSlug` are set. Writes `~/.claude/skills/<slug>/SKILL.md` so the agent picks up the server-specific skill on demand.
215
+
216
+ - `my-server-cli install-skill` — write the file.
217
+ - `--force` — overwrite an existing one.
218
+ - `--print` — dump the rendered SKILL.md to stdout instead.
219
+
220
+ The `skillContent` body should describe *this server's* tools and patterns — not toolkit internals (those are in this skill).
221
+
222
+ ## Confirming destructive operations
223
+
224
+ Hosts grant permissions per MCP tool, so allowing a consolidated tool allows every action in it, deletes included. `disabled_actions` blocks outright. A confirm list allows an operation once the user says yes.
225
+
226
+ ```ts
227
+ import { confirmGate, confirmForCodeApi, createConfirmTokens } from "ultra-mcp-toolkit/confirm";
228
+
229
+ const filter = parseToolFilterEnv({ /* ... */ confirmActionsEnv: process.env.MY_CONFIRM_ACTIONS });
230
+ const policy = { actions: filter.confirmActions ?? [], configHint: "MY_CONFIRM_ACTIONS" };
231
+
232
+ // Classic tools: gate first. The handler re-runs when the answer comes back.
233
+ mcp.registerTool(tool.name, { inputSchema }, async (args, ctx) => {
234
+ const gate = confirmGate(mcp, ctx, op, args, policy);
235
+ if (gate.kind === "ask") return gate.result; // client shows the prompt
236
+ if (gate.kind === "stop") return { content: [{ type: "text", text: gate.message }], isError: true };
237
+ // ...dispatch...
238
+ });
239
+
240
+ // Code-api: the bridge can't ask, so it refuses listed operations without a token.
241
+ const tokens = createConfirmTokens();
242
+ await bootCodeApi({ /* ... */ confirm: { actions: policy.actions, tokens, toolName: "my_code_api" } });
243
+ const codeApiTool = createCodeApiTool({ /* ... */ confirm: true });
244
+ // In its handler: if (args.confirm) return confirmForCodeApi(mcp, ctx, args.confirm, { manifest, tokens, policy });
245
+ ```
246
+
247
+ How it behaves:
248
+
249
+ - **Clients with prompt support** get one prompt (a checkbox, or "type `<value>` to confirm" when the manifest entry sets `confirm.typeToConfirm`). On 2026-07-28 the client asks and retries; on 2025 sessions the SDK pushes the prompt itself.
250
+ - **Clients without prompt support** follow `onUnsupported`: `"allow"` (the default) runs the operation as before; `"deny"` refuses it.
251
+ - **In code-api mode** the agent gets `ConfirmationRequired` from the CLI and calls the code-api tool with `{ confirm: { operation, args } }`. That asks the user and returns a token bound to the operation and arguments. The token works once and expires after 5 minutes. The agent reruns with `--confirm-token=<token>`.
252
+ - **Declines** come back as a message telling the agent not to retry unless the user asks.
253
+
254
+ ## Common pitfalls
255
+
256
+ - **`process.exit(0)` after `server.connect()`** kills the server before it handles any request. Use `startStdioServer` and don't exit.
257
+ - **Stdout writes in stdio mode** are interpreted as MCP JSON-RPC frames. Use stderr for logs/banners.
258
+ - **The manifest must be JSON-serializable.** No functions, no closures — the CLI bridge passes it across processes.
259
+ - **`cliPath` for `bootCodeApi` must be absolute.** Relative paths break under different CWDs.
260
+ - **The bridge socket lives in the session cache dir under the OS temp dir**, keyed by the server's session id (its pid by default), so a restarted server gets a new address. The CLI's discovery finds the new one; an old `<SOCKET_ENV>=...` prefix gets a note and is replaced.
@@ -0,0 +1,94 @@
1
+ # Shipping a skill with your server
2
+
3
+ Keep one skill directory in your repo. That one directory is:
4
+ - served to hosts over the MCP skills extension, by the SDK;
5
+ - installed by `<server>-cli install-skill` for hosts that can't load skills over MCP;
6
+ - checked against your manifest in CI.
7
+
8
+ ## Why skills, and what to put in them
9
+
10
+ | Where | Context cost | Holds |
11
+ |---|---|---|
12
+ | Tool schemas | Every conversation | The call surface |
13
+ | Skill `name` + `description` | Every conversation, ~50-100 tokens | When to reach for the skill |
14
+ | Skill body and `references/` | Only when used | How to do the task well |
15
+
16
+ Put knowledge that saves calls or output tokens in skills:
17
+
18
+ - Recipes for multi-step tasks, such as looking up an id and then mutating.
19
+ - Input formats the agent would otherwise get wrong, for example "markdown is accepted; don't hand-write the rich-text AST".
20
+ - Query-language cookbooks that spare a metadata dump or a guessing loop.
21
+ - How to read `ref` files: `jq` a path (or `--select`) instead of `cat`ing the whole payload.
22
+
23
+ Leave the operation list out. `<cli> --help` is generated from the manifest, so it can't drift.
24
+
25
+ ## Layout
26
+
27
+ ```
28
+ skills/
29
+ my-server/ # directory name == frontmatter name
30
+ SKILL.md # short hub: when to use, first call, output contract
31
+ references/
32
+ writing.md # loaded only when the agent needs it
33
+ ```
34
+
35
+ Ship it in the package (`"files": ["build", "skills"]`), and resolve it relative to your compiled code: `fileURLToPath(new URL("../skills", import.meta.url))`.
36
+
37
+ ## Serving (the SDK)
38
+
39
+ ```ts
40
+ import { loadSkills } from "@modelcontextprotocol/server/ext/skills/node";
41
+
42
+ // Once, at startup. Validates frontmatter and builds the digested manifest.
43
+ const skills = await loadSkills(SKILLS_DIR, { cacheHint: { ttlMs: 3_600_000, cacheScope: "public" } });
44
+
45
+ await startStdioServer({
46
+ createServer: () => {
47
+ const mcp = new McpServer({ name: "my-server", version });
48
+ // ...registerTool / registerResource...
49
+ skills.attach(mcp); // every instance, before it connects
50
+ return mcp;
51
+ },
52
+ });
53
+ ```
54
+
55
+ The same works inside `startHttpServer`'s `createServer`.
56
+
57
+ What `attach` does:
58
+ - Declares the extension (`io.modelcontextprotocol/skills`).
59
+ - Serves `skills/list`, `skills/get`, `skill://` reads, and directory reads.
60
+ - Registers its files as `McpServer` resources. Your own `registerResource` calls keep working beside them.
61
+
62
+ Cache hints reach 2026-07-28 clients only. Hosts cache files by digest, so keep skill content static for a server version: socket paths and other per-session values belong in tool responses, not skills.
63
+
64
+ ## The install-skill fallback
65
+
66
+ Some hosts don't load skills over MCP: `claude -p`, the Agent SDK, Desktop-config servers, and non-Claude agents. Point `createCli` at the skill directory:
67
+
68
+ ```ts
69
+ createCli({ cliName: "my-server-cli", socketEnvVar, manifest, skillDir: path.join(SKILLS_DIR, "my-server") });
70
+ ```
71
+
72
+ - `install-skill` writes every file to `~/.claude/skills/<name>/`.
73
+ - `install-skill --check` exits 1 when a bundled file is missing from the installed copy or differs. It also lists installed files that aren't in the bundle; those don't count as stale, and it never deletes them.
74
+ - Paths that would escape the install directory are refused. Writes do follow symlinks that already exist inside it, which suits skills kept in a dotfiles repo.
75
+ - `install-skill --print` dumps the files.
76
+ - The older `skillContent` + `skillSlug` single-string form still works.
77
+
78
+ ## Drift test
79
+
80
+ Agents copy skill examples verbatim. A renamed operation or parameter costs a failed call plus a retry, so check the examples in CI:
81
+
82
+ ```ts
83
+ import { checkSkillAgainstManifest, readSkillDir } from "ultra-mcp-toolkit/skills";
84
+
85
+ it("skill examples match the manifest", async () => {
86
+ const skill = await readSkillDir(path.join(SKILLS_DIR, "my-server"));
87
+ expect(checkSkillAgainstManifest(skill, operations, { cliName: "my-server-cli", metaCommands: ["install-skill", "status"] })).toEqual([]);
88
+ });
89
+ ```
90
+
91
+ How it checks:
92
+ - It scans fenced code blocks (joining `\` continuation lines) and inline code spans in every `.md` file.
93
+ - It checks both `<cli> <op> --flag` examples and bare `<op> --flag` examples.
94
+ - It ignores prose, placeholders (`<op>`), `--help`, meta commands, and anything after a shell operator.