@cyanheads/federal-regulations-mcp-server 0.1.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 (105) hide show
  1. package/AGENTS.md +387 -0
  2. package/CLAUDE.md +387 -0
  3. package/Dockerfile +127 -0
  4. package/LICENSE +201 -0
  5. package/README.md +372 -0
  6. package/changelog/0.1.x/0.1.0.md +20 -0
  7. package/changelog/template.md +127 -0
  8. package/dist/config/server-config.d.ts +32 -0
  9. package/dist/config/server-config.d.ts.map +1 -0
  10. package/dist/config/server-config.js +64 -0
  11. package/dist/config/server-config.js.map +1 -0
  12. package/dist/index.d.ts +12 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +51 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/mcp-server/resources/definitions/cfr-section.resource.d.ts +14 -0
  17. package/dist/mcp-server/resources/definitions/cfr-section.resource.d.ts.map +1 -0
  18. package/dist/mcp-server/resources/definitions/cfr-section.resource.js +77 -0
  19. package/dist/mcp-server/resources/definitions/cfr-section.resource.js.map +1 -0
  20. package/dist/mcp-server/resources/definitions/document.resource.d.ts +12 -0
  21. package/dist/mcp-server/resources/definitions/document.resource.d.ts.map +1 -0
  22. package/dist/mcp-server/resources/definitions/document.resource.js +38 -0
  23. package/dist/mcp-server/resources/definitions/document.resource.js.map +1 -0
  24. package/dist/mcp-server/resources/definitions/index.d.ts +12 -0
  25. package/dist/mcp-server/resources/definitions/index.d.ts.map +1 -0
  26. package/dist/mcp-server/resources/definitions/index.js +8 -0
  27. package/dist/mcp-server/resources/definitions/index.js.map +1 -0
  28. package/dist/mcp-server/tools/definitions/browse-cfr.tool.d.ts +73 -0
  29. package/dist/mcp-server/tools/definitions/browse-cfr.tool.d.ts.map +1 -0
  30. package/dist/mcp-server/tools/definitions/browse-cfr.tool.js +205 -0
  31. package/dist/mcp-server/tools/definitions/browse-cfr.tool.js.map +1 -0
  32. package/dist/mcp-server/tools/definitions/find-comments.tool.d.ts +85 -0
  33. package/dist/mcp-server/tools/definitions/find-comments.tool.d.ts.map +1 -0
  34. package/dist/mcp-server/tools/definitions/find-comments.tool.js +271 -0
  35. package/dist/mcp-server/tools/definitions/find-comments.tool.js.map +1 -0
  36. package/dist/mcp-server/tools/definitions/format-utils.d.ts +7 -0
  37. package/dist/mcp-server/tools/definitions/format-utils.d.ts.map +1 -0
  38. package/dist/mcp-server/tools/definitions/format-utils.js +9 -0
  39. package/dist/mcp-server/tools/definitions/format-utils.js.map +1 -0
  40. package/dist/mcp-server/tools/definitions/get-cfr-section.tool.d.ts +50 -0
  41. package/dist/mcp-server/tools/definitions/get-cfr-section.tool.d.ts.map +1 -0
  42. package/dist/mcp-server/tools/definitions/get-cfr-section.tool.js +152 -0
  43. package/dist/mcp-server/tools/definitions/get-cfr-section.tool.js.map +1 -0
  44. package/dist/mcp-server/tools/definitions/get-docket.tool.d.ts +67 -0
  45. package/dist/mcp-server/tools/definitions/get-docket.tool.d.ts.map +1 -0
  46. package/dist/mcp-server/tools/definitions/get-docket.tool.js +154 -0
  47. package/dist/mcp-server/tools/definitions/get-docket.tool.js.map +1 -0
  48. package/dist/mcp-server/tools/definitions/get-document.tool.d.ts +51 -0
  49. package/dist/mcp-server/tools/definitions/get-document.tool.d.ts.map +1 -0
  50. package/dist/mcp-server/tools/definitions/get-document.tool.js +138 -0
  51. package/dist/mcp-server/tools/definitions/get-document.tool.js.map +1 -0
  52. package/dist/mcp-server/tools/definitions/index.d.ts +356 -0
  53. package/dist/mcp-server/tools/definitions/index.d.ts.map +1 -0
  54. package/dist/mcp-server/tools/definitions/index.js +21 -0
  55. package/dist/mcp-server/tools/definitions/index.js.map +1 -0
  56. package/dist/mcp-server/tools/definitions/list-open-comments.tool.d.ts +47 -0
  57. package/dist/mcp-server/tools/definitions/list-open-comments.tool.d.ts.map +1 -0
  58. package/dist/mcp-server/tools/definitions/list-open-comments.tool.js +179 -0
  59. package/dist/mcp-server/tools/definitions/list-open-comments.tool.js.map +1 -0
  60. package/dist/mcp-server/tools/definitions/search-rules.tool.d.ts +57 -0
  61. package/dist/mcp-server/tools/definitions/search-rules.tool.d.ts.map +1 -0
  62. package/dist/mcp-server/tools/definitions/search-rules.tool.js +185 -0
  63. package/dist/mcp-server/tools/definitions/search-rules.tool.js.map +1 -0
  64. package/dist/services/ecfr/ecfr-service.d.ts +54 -0
  65. package/dist/services/ecfr/ecfr-service.d.ts.map +1 -0
  66. package/dist/services/ecfr/ecfr-service.js +303 -0
  67. package/dist/services/ecfr/ecfr-service.js.map +1 -0
  68. package/dist/services/ecfr/types.d.ts +105 -0
  69. package/dist/services/ecfr/types.d.ts.map +1 -0
  70. package/dist/services/ecfr/types.js +7 -0
  71. package/dist/services/ecfr/types.js.map +1 -0
  72. package/dist/services/ecfr/xml.d.ts +15 -0
  73. package/dist/services/ecfr/xml.d.ts.map +1 -0
  74. package/dist/services/ecfr/xml.js +103 -0
  75. package/dist/services/ecfr/xml.js.map +1 -0
  76. package/dist/services/ecfr-mirror/ecfr-mirror.d.ts +43 -0
  77. package/dist/services/ecfr-mirror/ecfr-mirror.d.ts.map +1 -0
  78. package/dist/services/ecfr-mirror/ecfr-mirror.js +267 -0
  79. package/dist/services/ecfr-mirror/ecfr-mirror.js.map +1 -0
  80. package/dist/services/federal-register/federal-register-service.d.ts +30 -0
  81. package/dist/services/federal-register/federal-register-service.d.ts.map +1 -0
  82. package/dist/services/federal-register/federal-register-service.js +241 -0
  83. package/dist/services/federal-register/federal-register-service.js.map +1 -0
  84. package/dist/services/federal-register/types.d.ts +138 -0
  85. package/dist/services/federal-register/types.d.ts.map +1 -0
  86. package/dist/services/federal-register/types.js +8 -0
  87. package/dist/services/federal-register/types.js.map +1 -0
  88. package/dist/services/regulations-gov/regulations-gov-service.d.ts +55 -0
  89. package/dist/services/regulations-gov/regulations-gov-service.d.ts.map +1 -0
  90. package/dist/services/regulations-gov/regulations-gov-service.js +283 -0
  91. package/dist/services/regulations-gov/regulations-gov-service.js.map +1 -0
  92. package/dist/services/regulations-gov/types.d.ts +148 -0
  93. package/dist/services/regulations-gov/types.d.ts.map +1 -0
  94. package/dist/services/regulations-gov/types.js +7 -0
  95. package/dist/services/regulations-gov/types.js.map +1 -0
  96. package/dist/services/request-context.d.ts +13 -0
  97. package/dist/services/request-context.d.ts.map +1 -0
  98. package/dist/services/request-context.js +23 -0
  99. package/dist/services/request-context.js.map +1 -0
  100. package/package.json +94 -0
  101. package/scripts/_mirror-context.ts +101 -0
  102. package/scripts/ecfr-mirror-init.ts +36 -0
  103. package/scripts/ecfr-mirror-refresh.ts +29 -0
  104. package/scripts/ecfr-mirror-verify.ts +33 -0
  105. package/server.json +113 -0
package/AGENTS.md ADDED
@@ -0,0 +1,387 @@
1
+ # Developer Protocol
2
+
3
+ **Server:** federal-regulations-mcp-server
4
+ **Version:** 0.1.0
5
+ **Framework:** [@cyanheads/mcp-ts-core](https://www.npmjs.com/package/@cyanheads/mcp-ts-core) `^0.10.6`
6
+ **Engines:** Bun ≥1.3.0, Node ≥24.0.0
7
+ **MCP SDK:** `@modelcontextprotocol/sdk` ^1.29.0
8
+ **Zod:** ^4.4.3
9
+
10
+ > **Read the framework docs first:** `node_modules/@cyanheads/mcp-ts-core/CLAUDE.md` contains the full API reference — builders, Context, error codes, exports, patterns. This file covers server-specific conventions only.
11
+
12
+ ---
13
+
14
+ ## Core Rules
15
+
16
+ - **Logic throws, framework catches.** Tool/resource handlers are pure — throw on failure, no `try/catch`. Plain `Error` is fine; the framework catches, classifies, and formats. Use error factories (`notFound()`, `validationError()`, etc.) when the error code matters.
17
+ - **Use `ctx.log`** for request-scoped logging. No `console` calls.
18
+ - **Use `ctx.state`** for tenant-scoped storage. Never access persistence directly.
19
+ - **Check `ctx.elicit`** for presence before calling.
20
+ - **Secrets in env vars only** — never hardcoded.
21
+ - **Close the loop on issues.** When implementing work tracked by a GitHub issue, comment on the issue with what landed and close it. Do both — a comment without a close leaves stale issues open; a close without a comment leaves no record of what shipped. The comment is for future readers — state the concrete changes, not the conversation that produced them.
22
+
23
+ ---
24
+
25
+ ## Patterns
26
+
27
+ ### Tool
28
+
29
+ ```ts
30
+ import { tool, z } from '@cyanheads/mcp-ts-core';
31
+
32
+ export const searchItems = tool('search_items', {
33
+ description: 'Search inventory items by query.',
34
+ annotations: { readOnlyHint: true },
35
+ input: z.object({
36
+ query: z.string().describe('Search terms'),
37
+ limit: z.number().default(10).describe('Max results'),
38
+ }),
39
+ output: z.object({
40
+ items: z.array(z.object({
41
+ id: z.string().describe('Item ID'),
42
+ name: z.string().describe('Item name'),
43
+ })).describe('Matching items'),
44
+ }),
45
+ auth: ['inventory:read'],
46
+
47
+ async handler(input, ctx) {
48
+ const items = await findItems(input.query, input.limit);
49
+ ctx.log.info('Search completed', { query: input.query, count: items.length });
50
+ return { items };
51
+ },
52
+
53
+ // format() populates content[] — the markdown twin of structuredContent.
54
+ // Different clients read different surfaces (Claude Code → structuredContent,
55
+ // Claude Desktop → content[]); both must carry the same data.
56
+ // Enforced at lint time: every field in `output` must appear in the rendered text.
57
+ format: (result) => [{
58
+ type: 'text',
59
+ text: result.items.map(i => `**${i.id}**: ${i.name}`).join('\n'),
60
+ }],
61
+ });
62
+ ```
63
+
64
+ ### Resource
65
+
66
+ ```ts
67
+ import { resource, z } from '@cyanheads/mcp-ts-core';
68
+ import { notFound } from '@cyanheads/mcp-ts-core/errors';
69
+
70
+ export const itemData = resource('inventory://{itemId}', {
71
+ description: 'Fetch an inventory item by ID.',
72
+ params: z.object({ itemId: z.string().describe('Item identifier') }),
73
+ auth: ['inventory:read'],
74
+ async handler(params, ctx) {
75
+ const item = await ctx.state.get(`item:${params.itemId}`);
76
+ if (!item) throw notFound(`Item ${params.itemId} not found`, { itemId: params.itemId });
77
+ return item;
78
+ },
79
+ });
80
+ ```
81
+
82
+ ### Prompt
83
+
84
+ ```ts
85
+ import { prompt, z } from '@cyanheads/mcp-ts-core';
86
+
87
+ export const reviewCode = prompt('review_code', {
88
+ description: 'Review code for issues and best practices.',
89
+ args: z.object({
90
+ code: z.string().describe('Code to review'),
91
+ language: z.string().optional().describe('Programming language'),
92
+ }),
93
+ generate: (args) => [
94
+ { role: 'user', content: { type: 'text', text: `Review this ${args.language ?? ''} code:\n${args.code}` } },
95
+ ],
96
+ });
97
+ ```
98
+
99
+ ### Server config
100
+
101
+ ```ts
102
+ // src/config/server-config.ts — lazy-parsed, separate from framework config
103
+ import { z } from '@cyanheads/mcp-ts-core';
104
+ import { parseEnvConfig } from '@cyanheads/mcp-ts-core/config';
105
+
106
+ const ServerConfigSchema = z.object({
107
+ apiKey: z.string().describe('External API key'),
108
+ maxResults: z.coerce.number().default(100),
109
+ verboseLogging: z.stringbool().default(false).describe('Enable verbose logging'),
110
+ });
111
+
112
+ let _config: z.infer<typeof ServerConfigSchema> | undefined;
113
+ export function getServerConfig() {
114
+ _config ??= parseEnvConfig(ServerConfigSchema, {
115
+ apiKey: 'MY_API_KEY',
116
+ maxResults: 'MY_MAX_RESULTS',
117
+ verboseLogging: 'MY_VERBOSE_LOGGING',
118
+ });
119
+ return _config;
120
+ }
121
+ ```
122
+
123
+ `parseEnvConfig` maps Zod schema paths → env var names so errors name the variable (`MY_API_KEY`) not the path (`apiKey`). Throws `ConfigurationError`, which the framework prints as a clean startup banner.
124
+
125
+ For env booleans use `z.stringbool()`, never `z.coerce.boolean()` — `Boolean("false")` is `true`, so a coerced flag can't be disabled through the environment. `z.stringbool()` parses `true/false/1/0/yes/no/on/off` and rejects anything else, so `=false` actually disables.
126
+
127
+ ### Server identity and instructions
128
+
129
+ `createApp()` accepts optional identity fields forwarded to the SDK's `initialize` response and the server manifest (`/.well-known/mcp.json`):
130
+
131
+ ```ts
132
+ await createApp({
133
+ name: 'my-mcp-server',
134
+ title: 'My Server', // human-readable display name
135
+ websiteUrl: 'https://github.com/owner/repo', // canonical homepage URL
136
+ description: 'One-line description.', // wins over MCP_SERVER_DESCRIPTION
137
+ icons: [{ src: 'https://example.com/icon.png', sizes: ['48x48'], mimeType: 'image/png' }],
138
+ instructions: 'Use shortcut alpha for the most common case.', // session-level context
139
+ });
140
+ ```
141
+
142
+ `instructions` is optional server-level orientation, sent on every `initialize` as session-level context. Use it for deployment guidance (connection aliases, regional notes, scope hints) instead of repeating the same context across tool descriptions. Client adoption is uneven, but there's no downside when set.
143
+
144
+ ---
145
+
146
+ ## Context
147
+
148
+ Handlers receive a unified `ctx` object. Key properties:
149
+
150
+ | Property | Description |
151
+ |:---------|:------------|
152
+ | `ctx.log` | Request-scoped logger — `.debug()`, `.info()`, `.notice()`, `.warning()`, `.error()`. Auto-correlates requestId, traceId, tenantId. |
153
+ | `ctx.state` | Tenant-scoped KV — `.get(key)`, `.set(key, value, { ttl? })`, `.delete(key)`, `.list(prefix, { cursor, limit })`. Accepts any serializable value. |
154
+ | `ctx.elicit` | Ask user for structured input — form call `(message, schema)` or `.url(message, url)` for an external link. **Check for presence first:** `if (ctx.elicit) { ... }` |
155
+ | `ctx.signal` | `AbortSignal` for cancellation. |
156
+ | `ctx.progress` | Task progress (present when `task: true`) — `.setTotal(n)`, `.increment()`, `.update(message)`. |
157
+ | `ctx.requestId` | Unique request ID. |
158
+ | `ctx.tenantId` | Tenant ID from JWT or `'default'` for stdio. |
159
+
160
+ ---
161
+
162
+ ## Errors
163
+
164
+ Handlers throw — the framework catches, classifies, and formats.
165
+
166
+ **Recommended: typed error contract.** Declare `errors: [{ reason, code, when, recovery, retryable? }]` on `tool()` / `resource()` to receive `ctx.fail(reason, …)` typed against the reason union. TypeScript catches typos at compile time, `data.reason` is auto-populated for observability, linter enforces conformance against the handler body. `recovery` is required descriptive metadata for the agent's next move (≥ 5 words, lint-validated); for the wire `data.recovery.hint` (mirrored into `content[]` text), pass explicitly at the throw site when dynamic context matters: `ctx.fail('reason', msg, { recovery: { hint: '...' } })`. Baseline codes (`InternalError`, `ServiceUnavailable`, `Timeout`, `ValidationError`, `SerializationError`) bubble freely and don't need declaring.
167
+
168
+ ```ts
169
+ import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
170
+
171
+ errors: [
172
+ { reason: 'no_match', code: JsonRpcErrorCode.NotFound,
173
+ when: 'No item matched the query',
174
+ recovery: 'Broaden the query or check the spelling and try again.' },
175
+ ],
176
+ async handler(input, ctx) {
177
+ const item = await db.find(input.id);
178
+ if (!item) throw ctx.fail('no_match', `No item ${input.id}`);
179
+ return item;
180
+ }
181
+ ```
182
+
183
+ **Declare contracts inline on each tool.** The contract is part of the tool's public surface — one file should give the full picture. Don't extract a shared `errors[]` constant; per-tool repetition is the intended cost of locality.
184
+
185
+ **Fallback (no contract entry fits):** throw via factories or plain `Error`.
186
+
187
+ ```ts
188
+ // Error factories — explicit code
189
+ import { notFound, serviceUnavailable } from '@cyanheads/mcp-ts-core/errors';
190
+ throw notFound('Item not found', { itemId });
191
+ throw serviceUnavailable('API unavailable', { url }, { cause: err });
192
+
193
+ // Plain Error — framework auto-classifies from message patterns
194
+ throw new Error('Item not found'); // → NotFound
195
+ throw new Error('Invalid query format'); // → ValidationError
196
+
197
+ // McpError — when no factory exists for the code
198
+ import { McpError, JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
199
+ throw new McpError(JsonRpcErrorCode.DatabaseError, 'Connection failed', { pool: 'primary' });
200
+ ```
201
+
202
+ See framework CLAUDE.md and the `api-errors` skill for the full auto-classification table, all available factories, and the contract reference.
203
+
204
+ ---
205
+
206
+ ## Structure
207
+
208
+ ```text
209
+ src/
210
+ index.ts # createApp() entry point — wires the 3 services + mirror refresh cron
211
+ config/
212
+ server-config.ts # Server-specific env vars (Zod schema)
213
+ services/
214
+ federal-register/ # Federal Register API v1 client (keyless)
215
+ ecfr/ # eCFR API client (keyless) — versioner, structure, search, XML parsing
216
+ ecfr-mirror/ # eCFR codified-text mirror (MirrorService — SQLite + FTS5)
217
+ regulations-gov/ # Regulations.gov v4 client (X-Api-Key) — dockets, comments
218
+ mcp-server/
219
+ tools/definitions/ # 7 regulations_* tools (search-rules, get-document, browse-cfr,
220
+ # get-cfr-section, get-docket, find-comments, list-open-comments)
221
+ resources/definitions/ # 2 resources (document, cfr-section)
222
+ scripts/
223
+ ecfr-mirror-init.ts # out-of-band mirror lifecycle (init / refresh / verify)
224
+ ecfr-mirror-refresh.ts
225
+ ecfr-mirror-verify.ts
226
+ _mirror-context.ts # shared shim imported by the three mirror scripts
227
+ ```
228
+
229
+ No prompts in v1 — `createApp({ prompts: [] })`.
230
+
231
+ ---
232
+
233
+ ## Naming
234
+
235
+ | What | Convention | Example |
236
+ |:-----|:-----------|:--------|
237
+ | Files | kebab-case with suffix | `search-docs.tool.ts` |
238
+ | Tool/resource/prompt names | snake_case | `search_docs` |
239
+ | Directories | kebab-case | `src/services/doc-search/` |
240
+ | Descriptions | Single string or template literal, no `+` concatenation | `'Search items by query and filter.'` |
241
+
242
+ ---
243
+
244
+ ## Skills
245
+
246
+ Skills are modular instructions in `skills/` at the project root. Read them directly when a task matches — e.g., `skills/add-tool/SKILL.md` when adding a tool.
247
+
248
+ **Agent skill directory:** Copy skills into the directory your agent discovers (Claude Code: `.claude/skills/`, others: equivalent). Skills then load as context without referencing `skills/` paths. After framework updates, run the `maintenance` skill — Phase B re-syncs the agent directory.
249
+
250
+ Available skills:
251
+
252
+ | Skill | Purpose |
253
+ |:------|:--------|
254
+ | `setup` | Post-init project orientation |
255
+ | `design-mcp-server` | Design tool surface, resources, and services for a new server |
256
+ | `add-tool` | Scaffold a new tool definition |
257
+ | `add-app-tool` | Scaffold an MCP App tool + paired UI resource |
258
+ | `add-resource` | Scaffold a new resource definition |
259
+ | `add-prompt` | Scaffold a new prompt definition |
260
+ | `add-service` | Scaffold a new service integration |
261
+ | `add-test` | Scaffold test file for a tool, resource, or service |
262
+ | `field-test` | Exercise tools/resources/prompts with real inputs, verify behavior, report issues |
263
+ | `tool-defs-analysis` | Read-only audit of MCP definition language across the surface — voice, leaks, defaults, recovery hints, output descriptions |
264
+ | `security-pass` | Audit server for MCP-flavored security gaps: output injection, scope blast radius, input sinks, tenant isolation |
265
+ | `code-simplifier` | Post-session cleanup against `git diff` — modernize syntax, consolidate duplication, align with the codebase |
266
+ | `devcheck` | Lint, format, typecheck, audit |
267
+ | `polish-docs-meta` | Finalize docs, README, metadata, and agent protocol for shipping |
268
+ | `git-wrapup` | Land working-tree changes as a versioned commit + annotated tag — version bump, changelog, verify, tag. Local only. |
269
+ | `release-and-publish` | Push + npm + MCP Registry + GH Release + Docker. Picks up from `git-wrapup` |
270
+ | `maintenance` | Investigate changelogs, adopt upstream changes, sync skills to agent dirs |
271
+ | `orchestrations` | Chain task skills into a gated multi-phase pipeline — build-out, QA-fix, update-ship — when you can spawn sub-agents |
272
+ | `report-issue-framework` | File a bug or feature request against `@cyanheads/mcp-ts-core` via `gh` CLI |
273
+ | `report-issue-local` | File a bug or feature request against this server's own repo via `gh` CLI |
274
+ | `api-auth` | Auth modes, scopes, JWT/OAuth |
275
+ | `api-canvas` | DataCanvas: register tabular data, run SQL, export, plus the `spillover()` helper for big result sets — Tier 3 opt-in |
276
+ | `api-config` | AppConfig, parseConfig, env vars |
277
+ | `api-context` | Context interface, logger, state, progress |
278
+ | `api-errors` | McpError, JsonRpcErrorCode, error patterns |
279
+ | `api-linter` | Definition linter rule catalog — invoked by `bun run lint:mcp` and `devcheck` |
280
+ | `api-services` | LLM, Speech, Graph services |
281
+ | `api-testing` | createMockContext, test patterns |
282
+ | `api-utils` | Formatting, parsing, security, pagination, scheduling, telemetry helpers |
283
+ | `api-telemetry` | OTel catalog: spans, metrics, completion logs, env config, cardinality rules |
284
+ | `api-workers` | Cloudflare Workers runtime |
285
+
286
+ **Chaining skills into pipelines.** When the user wants a multi-phase effort — build this server out, QA-and-fix the surface, update-and-ship — *and you can spawn sub-agents*, `skills/orchestrations/SKILL.md` sequences the task skills above into a gated pipeline with verification at each step. Read it to drive the run. Optional: skip it if you can't orchestrate sub-agents, and ignore it entirely if you were *spawned* as one — you've already been scoped to a single phase.
287
+
288
+ When you complete a skill's checklist, check the boxes and add a completion timestamp at the end (e.g., `Completed: 2026-03-11`).
289
+
290
+ ---
291
+
292
+ ## Commands
293
+
294
+ **Runtime:** Scripts use Bun's native TypeScript execution — `bun run <cmd>` is the standard invocation. `npm run <cmd>` also works (npm delegates to bun).
295
+
296
+ | Command | Purpose |
297
+ |:--------|:--------|
298
+ | `npm run build` | Compile TypeScript |
299
+ | `npm run rebuild` | Clean + build |
300
+ | `npm run clean` | Remove build artifacts |
301
+ | `npm run devcheck` | Lint + format + typecheck + security + changelog sync |
302
+ | `bun run audit:refresh` | Delete `bun.lock`, reinstall, and re-run `bun audit`. Use when `devcheck` flags a transitive advisory — Bun's `update` is sticky on transitive resolutions, so the advisory may be a stale-lockfile false positive. If it survives the refresh, it's real. |
303
+ | `npm run tree` | Generate directory structure doc |
304
+ | `npm run format` | Auto-fix formatting (safe fixes only) |
305
+ | `npm run format:unsafe` | Also apply Biome's unsafe autofixes — review the diff; they can change behavior |
306
+ | `npm test` | Run tests |
307
+ | `npm run start:stdio` | Production mode (stdio) |
308
+ | `npm run start:http` | Production mode (HTTP) |
309
+ | `npm run changelog:build` | Regenerate `CHANGELOG.md` from `changelog/*.md` |
310
+ | `npm run changelog:check` | Verify `CHANGELOG.md` is in sync (used by devcheck) |
311
+ | `npm run bundle` | Build, pack, and clean a `.mcpb` for one-click Claude Desktop install |
312
+ | `npm run lint:mcp` | Validate MCP tool/resource definitions against the linter rule catalog |
313
+ | `npm run lint:packaging` | Verify `server.json` ↔ `manifest.json` env var names match (used by devcheck) |
314
+ | `npm run mirror:init` | Build the eCFR codified-text mirror (out-of-band, idempotent, resumable). Scope with `ECFR_MIRROR_TITLES`. |
315
+ | `npm run mirror:refresh` | Incremental refresh of the eCFR mirror against the latest eCFR issues |
316
+ | `npm run mirror:verify` | Report mirror row counts and the last-synced issue date |
317
+ | `npm run list-skills` | List the project skills and their paths |
318
+
319
+ ---
320
+
321
+ ## Bundling
322
+
323
+ `npm run bundle` produces a `.mcpb` extension bundle for one-click install in Claude Desktop. The pack step is followed by `scripts/clean-mcpb.ts`, which prunes dev dependencies (`mcpb clean`) and strips dependency-shipped agent docs (`node_modules/**` `skills/`, `.claude/`, `.agents/`, `SKILL.md`) that root-anchored `.mcpbignore` patterns cannot reach. MCPB is stdio-only — HTTP and Cloudflare Workers deployments are unaffected. Consumers who don't need it can delete `manifest.json` and `.mcpbignore`; `lint:packaging` skips cleanly.
324
+
325
+ **Adding an env var requires both files:** `server.json` (registry discovery, `environmentVariables[]`) and `manifest.json` (bundle install UX, `mcp_config.env` + `user_config`). `lint:packaging` (run by `devcheck`) verifies the env var names match.
326
+
327
+ **README install badges** (Claude Desktop `.mcpb`, Cursor, VS Code) and the `base64` / `encodeURIComponent` config-generation commands are ship-time concerns — run the `polish-docs-meta` skill, which carries the badge format, layout, and generation snippets in `skills/polish-docs-meta/references/readme.md`.
328
+
329
+ ---
330
+
331
+ ## Changelog
332
+
333
+ Directory-based, grouped by minor series via the `.x` semver-wildcard convention. Source of truth: `changelog/<major.minor>.x/<version>.md` (e.g. `changelog/0.1.x/0.1.0.md`) — one file per release, shipped in the npm package. At release, author the per-version file with a concrete version and date, then run `npm run changelog:build` to regenerate the rollup. `changelog/template.md` is a **pristine format reference** — never edited or moved; read it for the frontmatter + section layout when scaffolding. `CHANGELOG.md` is a **navigation index** (header + link + summary per version), regenerated by `npm run changelog:build` — devcheck hard-fails on drift; never hand-edit it.
334
+
335
+ Each per-version file opens with YAML frontmatter:
336
+
337
+ ```markdown
338
+ ---
339
+ summary: "One-line headline, ≤350 chars" # required — powers the rollup index
340
+ breaking: false # optional — true flags breaking changes
341
+ security: false # optional — true flags security fixes
342
+ ---
343
+
344
+ # 0.1.0 — YYYY-MM-DD
345
+ ...
346
+ ```
347
+
348
+ `breaking: true` renders a `· ⚠️ Breaking` badge — use it when consumers must update code on upgrade (signature changes, removed APIs, config renames). `security: true` renders a `· 🛡️ Security` badge and pairs with a `## Security` body section. When both are set, badges render `· ⚠️ Breaking · 🛡️ Security`.
349
+
350
+ `agent-notes` is an optional free-form field for maintenance agents processing the release downstream. Content here won't appear in the rendered CHANGELOG — it's consumed by agents running the `maintenance` skill. Use it for adoption instructions that don't fit the human-facing sections: new files to create, fields to populate, one-time migration steps. Omit entirely when there's nothing to say.
351
+
352
+ **Section order** (Keep a Changelog): Added, Changed, Deprecated, Removed, Fixed, Security. Include only sections with entries — don't ship empty headers.
353
+
354
+ **Tag annotations** render as GitHub Release bodies via `--notes-from-tag`. They must be structured markdown — never a flat comma-separated string. Subject omits the version number (GitHub prepends it). See `changelog/template.md` for the full format reference.
355
+
356
+ ---
357
+
358
+ ## Imports
359
+
360
+ ```ts
361
+ // Framework — z is re-exported, no separate zod import needed
362
+ import { tool, z } from '@cyanheads/mcp-ts-core';
363
+ import { McpError, JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
364
+
365
+ // Server's own code — via path alias
366
+ import { getMyService } from '@/services/my-domain/my-service.js';
367
+ ```
368
+
369
+ ---
370
+
371
+ ## Checklist
372
+
373
+ - [ ] Zod schemas: all fields have `.describe()`, only JSON-Schema-serializable types (no `z.custom()`, `z.date()`, `z.transform()`, `z.bigint()`, `z.symbol()`, `z.void()`, `z.map()`, `z.set()`, `z.function()`, `z.nan()`)
374
+ - [ ] Optional nested objects: handler guards for empty inner values from form-based clients (`if (input.obj?.field && ...)`, not just `if (input.obj)`). When regex/length constraints matter, use `z.union([z.literal(''), z.string().regex(...).describe(...)])` — literal variants are exempt from `describe-on-fields`.
375
+ - [ ] JSDoc `@fileoverview` + `@module` on every file
376
+ - [ ] `ctx.log` for logging, `ctx.state` for storage
377
+ - [ ] Handlers throw on failure — error factories or plain `Error`, no try/catch
378
+ - [ ] `format()` renders all data the LLM needs — different clients forward different surfaces (Claude Code → `structuredContent`, Claude Desktop → `content[]`); both must carry the same data
379
+ - [ ] If wrapping external API: raw/domain/output schemas reviewed against real upstream sparsity/nullability before finalizing required vs optional fields
380
+ - [ ] If wrapping external API: normalization and `format()` preserve uncertainty; do not fabricate facts from missing upstream data
381
+ - [ ] If wrapping external API: tests include at least one sparse payload case with omitted upstream fields
382
+ - [ ] Registered in `createApp()` arrays (directly or via barrel exports)
383
+ - [ ] Tests use `createMockContext()` from `@cyanheads/mcp-ts-core/testing`
384
+ - [ ] `.codex-plugin/plugin.json` populated — `name`, `version`, `description`, `repository`, `license` from `package.json`; `interface.displayName` = package name; `interface.shortDescription` from `package.json` description
385
+ - [ ] `.codex-plugin/mcp.json` updated — server name key matches `package.json` name; env vars added for any required API keys
386
+ - [ ] `.claude-plugin/plugin.json` populated — `name`, `version`, `description`, `repository`, `license` from `package.json`; inline `mcpServers` entry with server name key, env vars for any required API keys
387
+ - [ ] `npm run devcheck` passes