@cyanheads/mcp-ts-core 0.8.1 → 0.8.3
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.
- package/CLAUDE.md +8 -2
- package/README.md +1 -1
- package/changelog/0.8.x/0.8.2.md +18 -0
- package/changelog/0.8.x/0.8.3.md +43 -0
- package/dist/logs/combined.log +12 -4
- package/dist/logs/error.log +12 -4
- package/dist/mcp-server/resources/resource-registration.d.ts.map +1 -1
- package/dist/mcp-server/resources/resource-registration.js +2 -3
- package/dist/mcp-server/resources/resource-registration.js.map +1 -1
- package/dist/mcp-server/resources/utils/resourceDefinition.d.ts +3 -3
- package/dist/mcp-server/tools/tool-registration.d.ts.map +1 -1
- package/dist/mcp-server/tools/tool-registration.js +8 -12
- package/dist/mcp-server/tools/tool-registration.js.map +1 -1
- package/dist/mcp-server/tools/utils/toolDefinition.d.ts +2 -3
- package/dist/mcp-server/tools/utils/toolDefinition.d.ts.map +1 -1
- package/dist/mcp-server/tools/utils/toolDefinition.js.map +1 -1
- package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts +28 -0
- package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts.map +1 -1
- package/dist/mcp-server/tools/utils/toolHandlerFactory.js +64 -23
- package/dist/mcp-server/tools/utils/toolHandlerFactory.js.map +1 -1
- package/dist/mcp-server/transports/http/landing-page/assets/copy-script.d.ts +13 -4
- package/dist/mcp-server/transports/http/landing-page/assets/copy-script.d.ts.map +1 -1
- package/dist/mcp-server/transports/http/landing-page/assets/copy-script.js +99 -25
- package/dist/mcp-server/transports/http/landing-page/assets/copy-script.js.map +1 -1
- package/dist/mcp-server/transports/http/landing-page/assets/styles.d.ts.map +1 -1
- package/dist/mcp-server/transports/http/landing-page/assets/styles.js +318 -8
- package/dist/mcp-server/transports/http/landing-page/assets/styles.js.map +1 -1
- package/dist/mcp-server/transports/http/landing-page/sections/status-strip.d.ts.map +1 -1
- package/dist/mcp-server/transports/http/landing-page/sections/status-strip.js +20 -1
- package/dist/mcp-server/transports/http/landing-page/sections/status-strip.js.map +1 -1
- package/dist/mcp-server/transports/http/landing-page/sections/tools.d.ts +6 -5
- package/dist/mcp-server/transports/http/landing-page/sections/tools.d.ts.map +1 -1
- package/dist/mcp-server/transports/http/landing-page/sections/tools.js +114 -69
- package/dist/mcp-server/transports/http/landing-page/sections/tools.js.map +1 -1
- package/dist/types-global/errors.d.ts +3 -22
- package/dist/types-global/errors.d.ts.map +1 -1
- package/dist/types-global/errors.js +0 -19
- package/dist/types-global/errors.js.map +1 -1
- package/package.json +1 -1
- package/skills/add-app-tool/SKILL.md +24 -8
- package/skills/add-resource/SKILL.md +1 -1
- package/skills/add-tool/SKILL.md +87 -20
- package/skills/api-errors/SKILL.md +21 -7
- package/skills/api-linter/SKILL.md +1 -1
- package/skills/design-mcp-server/SKILL.md +1 -1
- package/skills/field-test/SKILL.md +15 -6
- package/skills/maintenance/SKILL.md +19 -7
- package/templates/AGENTS.md +3 -2
- package/templates/CLAUDE.md +3 -2
- package/templates/src/mcp-server/tools/definitions/echo.tool.ts +18 -1
|
@@ -1,40 +1,73 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview Tools section — responsive
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* @fileoverview Tools section — responsive card grid grouped by safety
|
|
3
|
+
* mutability (read / write / destructive). Each card carries annotation
|
|
4
|
+
* pills, a scope chip, a JSON-RPC invocation snippet, and a collapsible
|
|
5
|
+
* input-schema preview. A filter bar above the grid wires chip + search
|
|
6
|
+
* filtering through `data-mutability` / `data-name` attributes consumed
|
|
7
|
+
* by the inline filter script.
|
|
7
8
|
*
|
|
8
9
|
* @module src/mcp-server/transports/http/landing-page/sections/tools
|
|
9
10
|
*/
|
|
10
11
|
import { html } from '../../../../../utils/formatting/html.js';
|
|
11
12
|
import { renderPill, renderSectionHeading, renderSnippet } from '../primitives.js';
|
|
13
|
+
/**
|
|
14
|
+
* Mutability bucket order — safe defaults first, deliberate engagement last.
|
|
15
|
+
* Filter chips render in this order too.
|
|
16
|
+
*/
|
|
17
|
+
const MUTABILITY_ORDER = ['read', 'write', 'destructive'];
|
|
12
18
|
export function renderToolsSection(tools) {
|
|
13
19
|
if (tools.length === 0)
|
|
14
20
|
return html ``;
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
const buckets = bucketByMutability(tools);
|
|
22
|
+
const populatedBuckets = MUTABILITY_ORDER.filter((m) => buckets[m].length > 0);
|
|
23
|
+
// A single bucket is redundant with the section header — skip per-group
|
|
24
|
+
// labels in that case but keep `data-mutability` on cards so the filter
|
|
25
|
+
// chips still work.
|
|
26
|
+
const showHeadings = populatedBuckets.length > 1;
|
|
27
|
+
const groups = populatedBuckets.map((mutability) => {
|
|
28
|
+
const bucketTools = buckets[mutability];
|
|
29
|
+
const heading = showHeadings
|
|
30
|
+
? html `<h4 class="group-heading" data-group="${mutability}">${mutability} <span class="group-count">${String(bucketTools.length)}</span></h4>`
|
|
31
|
+
: html ``;
|
|
32
|
+
return html `${heading}<div class="card-grid" data-grid="${mutability}">${bucketTools.map((t) => renderToolCard(t, mutability))}</div>`;
|
|
22
33
|
});
|
|
23
34
|
return html `
|
|
24
|
-
<section aria-labelledby="section-tools">
|
|
35
|
+
<section aria-labelledby="section-tools" data-tools-section>
|
|
25
36
|
${renderSectionHeading('section-tools', 'Tools', tools.length)}
|
|
26
|
-
${
|
|
37
|
+
${renderToolFilterBar(populatedBuckets)}
|
|
38
|
+
<div class="tools-body">${groups}</div>
|
|
39
|
+
<p class="tools-empty" hidden>No tools match the current filter.</p>
|
|
27
40
|
</section>
|
|
28
41
|
`;
|
|
29
42
|
}
|
|
30
|
-
function
|
|
43
|
+
function renderToolFilterBar(populatedBuckets) {
|
|
44
|
+
const chips = [
|
|
45
|
+
html `<button type="button" class="tool-chip" data-filter-mutability="all" aria-pressed="true">all</button>`,
|
|
46
|
+
];
|
|
47
|
+
for (const m of populatedBuckets) {
|
|
48
|
+
chips.push(html `<button type="button" class="tool-chip tool-chip--${m}" data-filter-mutability="${m}" aria-pressed="false">${m}</button>`);
|
|
49
|
+
}
|
|
50
|
+
return html `
|
|
51
|
+
<div class="tool-filter-bar" role="search" aria-label="Filter tools">
|
|
52
|
+
<div class="tool-chips" role="group" aria-label="Filter by mutability">${chips}</div>
|
|
53
|
+
<label class="tool-search">
|
|
54
|
+
<span class="visually-hidden">Search tools</span>
|
|
55
|
+
<input
|
|
56
|
+
type="search"
|
|
57
|
+
data-tool-search
|
|
58
|
+
placeholder="Search tools…"
|
|
59
|
+
autocomplete="off"
|
|
60
|
+
spellcheck="false"
|
|
61
|
+
/>
|
|
62
|
+
</label>
|
|
63
|
+
</div>
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
function renderToolCard(tool, mutability) {
|
|
31
67
|
const anchor = `tool-${tool.name}`;
|
|
32
68
|
const annotations = tool.annotations;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
pills.push(renderPill('read-only', 'readonly'));
|
|
36
|
-
if (annotations?.destructiveHint === true)
|
|
37
|
-
pills.push(renderPill('destructive', 'destructive'));
|
|
69
|
+
// Mutability badge first — the safety signal readers track at a glance.
|
|
70
|
+
const pills = [renderPill(mutability, mutability)];
|
|
38
71
|
if (annotations?.openWorldHint)
|
|
39
72
|
pills.push(renderPill('open-world', 'openworld'));
|
|
40
73
|
if (tool.isTask)
|
|
@@ -42,75 +75,87 @@ function renderToolCard(tool) {
|
|
|
42
75
|
if (tool.isApp)
|
|
43
76
|
pills.push(renderPill('app', 'app'));
|
|
44
77
|
const source = tool.sourceUrl
|
|
45
|
-
? html `<a class="source-link" href="${tool.sourceUrl}" rel="noopener">view source ↗</a>`
|
|
78
|
+
? html `<a class="source-link" href="${tool.sourceUrl}" rel="noopener" aria-label="View source for ${tool.name}">view source ↗</a>`
|
|
79
|
+
: html ``;
|
|
80
|
+
const scopeChips = tool.auth && tool.auth.length > 0
|
|
81
|
+
? html `<span class="card-scope" title="${tool.auth.join(', ')}"><span class="card-meta-label">scope</span>${tool.auth.map((scope) => html ` <code class="scope-chip">${scopeAccessLevel(scope)}</code>`)}</span>`
|
|
46
82
|
: html ``;
|
|
47
83
|
const schemaPreview = tool.inputSchema
|
|
48
84
|
? html `
|
|
49
|
-
<details>
|
|
50
|
-
<summary>
|
|
85
|
+
<details class="card-detail">
|
|
86
|
+
<summary>schema</summary>
|
|
51
87
|
<pre><code>${JSON.stringify(tool.inputSchema, null, 2)}</code></pre>
|
|
52
88
|
</details>
|
|
53
89
|
`
|
|
54
90
|
: html ``;
|
|
55
91
|
const invocation = html `
|
|
56
|
-
<details>
|
|
57
|
-
<summary>
|
|
92
|
+
<details class="card-detail">
|
|
93
|
+
<summary>invocation</summary>
|
|
58
94
|
${renderSnippet(`tool-${tool.name}`, buildInvocationSnippet(tool))}
|
|
59
95
|
</details>
|
|
60
96
|
`;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
97
|
+
// Search target: name + description as a single lowercase string. Hidden
|
|
98
|
+
// attribute (not visible) so the filter script can match without parsing
|
|
99
|
+
// DOM text repeatedly. Description gets normalized whitespace so multi-line
|
|
100
|
+
// entries don't waste haystack length.
|
|
101
|
+
const searchTarget = `${tool.name} ${tool.description}`.replace(/\s+/g, ' ').toLowerCase();
|
|
64
102
|
return html `
|
|
65
|
-
<article
|
|
66
|
-
|
|
103
|
+
<article
|
|
104
|
+
class="card tool-card"
|
|
105
|
+
id="${anchor}"
|
|
106
|
+
data-tool-card
|
|
107
|
+
data-mutability="${mutability}"
|
|
108
|
+
data-name="${tool.name}"
|
|
109
|
+
data-search="${searchTarget}"
|
|
110
|
+
>
|
|
111
|
+
<header class="card-head">
|
|
67
112
|
<h3 class="card-title"><a href="#${anchor}">${tool.name}</a></h3>
|
|
68
113
|
<div class="pill-row" role="list">${pills}</div>
|
|
69
114
|
${source}
|
|
70
|
-
</
|
|
115
|
+
</header>
|
|
71
116
|
<p class="card-desc">${tool.description}</p>
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
117
|
+
<footer class="card-foot">
|
|
118
|
+
${scopeChips}
|
|
119
|
+
<div class="card-actions">
|
|
120
|
+
${invocation}
|
|
121
|
+
${schemaPreview}
|
|
122
|
+
</div>
|
|
123
|
+
</footer>
|
|
75
124
|
</article>
|
|
76
125
|
`;
|
|
77
126
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
groups.set(prefix, list);
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
other.push(tool);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
const out = [];
|
|
105
|
-
for (const [prefix, list] of groups) {
|
|
106
|
-
out.push({ label: titleCase(prefix), tools: list });
|
|
107
|
-
}
|
|
108
|
-
if (other.length > 0)
|
|
109
|
-
out.push({ label: 'Other', tools: other });
|
|
110
|
-
return out;
|
|
127
|
+
/**
|
|
128
|
+
* Map a tool to a mutability bucket using its annotations. The MCP spec
|
|
129
|
+
* defaults `destructiveHint` to `true`, but treating annotation-less tools
|
|
130
|
+
* as "destructive" surprises readers — bucket as `write` unless the
|
|
131
|
+
* destructive hint is explicitly set. Mirrors how the annotation pills
|
|
132
|
+
* render today (`pill-destructive` requires `=== true`).
|
|
133
|
+
*/
|
|
134
|
+
function classifyMutability(tool) {
|
|
135
|
+
const a = tool.annotations;
|
|
136
|
+
if (a?.readOnlyHint === true)
|
|
137
|
+
return 'read';
|
|
138
|
+
if (a?.destructiveHint === true)
|
|
139
|
+
return 'destructive';
|
|
140
|
+
return 'write';
|
|
141
|
+
}
|
|
142
|
+
function bucketByMutability(tools) {
|
|
143
|
+
const buckets = { read: [], write: [], destructive: [] };
|
|
144
|
+
for (const tool of tools)
|
|
145
|
+
buckets[classifyMutability(tool)].push(tool);
|
|
146
|
+
return buckets;
|
|
111
147
|
}
|
|
112
|
-
|
|
113
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Reduce a colon-delimited scope (`tool:foo:read`) to its trailing access
|
|
150
|
+
* level (`read`). Scopes that don't match the convention render verbatim —
|
|
151
|
+
* the linter doesn't enforce shape, so falling back is friendlier than
|
|
152
|
+
* eating the value.
|
|
153
|
+
*/
|
|
154
|
+
function scopeAccessLevel(scope) {
|
|
155
|
+
const idx = scope.lastIndexOf(':');
|
|
156
|
+
if (idx < 0 || idx === scope.length - 1)
|
|
157
|
+
return scope;
|
|
158
|
+
return scope.slice(idx + 1);
|
|
114
159
|
}
|
|
115
160
|
function buildInvocationSnippet(tool) {
|
|
116
161
|
const args = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../../../../src/mcp-server/transports/http/landing-page/sections/tools.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../../../../src/mcp-server/transports/http/landing-page/sections/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,IAAI,EAAiB,MAAM,4BAA4B,CAAC;AAEjE,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAInF;;;GAGG;AACH,MAAM,gBAAgB,GAA0B,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;AAEjF,MAAM,UAAU,kBAAkB,CAAC,KAAqB;IACtD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA,EAAE,CAAC;IAEtC,MAAM,OAAO,G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C,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvE,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,KAAa;IACrC,MAAM,GAAG,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACnC,IAAI,GAAG,GAAG,CAAC,IAAI,GAAG,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACtD,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,sBAAsB,CAAC,IAAkB;IAChD,MAAM,IAAI,GAA4B,EAAE,CAAC;IACzC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;QACxC,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,KAAK,GAAG,CAAC;IAC7B,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CACnB;QACE,OAAO,EAAE,KAAK;QACd,EAAE,EAAE,CAAC;QACL,MAAM,EAAE,YAAY;QACpB,MAAM,EAAE;YACN,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,SAAS,EAAE,IAAI;SAChB;KACF,EACD,IAAI,EACJ,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -116,13 +116,9 @@ export type ErrorResponse = z.infer<typeof ErrorSchema>;
|
|
|
116
116
|
* Lets a definition advertise what it can fail with — the JSON-RPC code, a
|
|
117
117
|
* stable machine-readable `reason`, and a human-readable `when` description.
|
|
118
118
|
*
|
|
119
|
-
* **
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
* modes alongside the input/output schema.
|
|
123
|
-
* - Validated by the startup linter — invalid codes, duplicate `reason` strings
|
|
124
|
-
* within a single definition, and (with the conformance check enabled)
|
|
125
|
-
* handler bodies that throw codes not in the contract are flagged.
|
|
119
|
+
* **Validation.** Checked by the startup linter — invalid codes, duplicate
|
|
120
|
+
* `reason` strings within a single definition, and (with the conformance check
|
|
121
|
+
* enabled) handler bodies that throw codes not in the contract are flagged.
|
|
126
122
|
*
|
|
127
123
|
* **Authoring guidance:**
|
|
128
124
|
* - Keep `reason` short, snake_case, stable. Treat it like a CSS class name
|
|
@@ -171,19 +167,4 @@ export interface ErrorContract {
|
|
|
171
167
|
*/
|
|
172
168
|
when: string;
|
|
173
169
|
}
|
|
174
|
-
/**
|
|
175
|
-
* The MCP `_meta` namespace key under which `errors[]` is published in
|
|
176
|
-
* `tools/list` and `resources/list`. Namespaced to avoid collisions with
|
|
177
|
-
* other framework or vendor extensions.
|
|
178
|
-
*/
|
|
179
|
-
export declare const ERROR_CONTRACT_META_KEY = "mcp-ts-core/errors";
|
|
180
|
-
/**
|
|
181
|
-
* Merges a tool/resource's `errors[]` contract into its `_meta` object under
|
|
182
|
-
* {@link ERROR_CONTRACT_META_KEY}. Returns `undefined` when both sides are
|
|
183
|
-
* absent so callers can spread conditionally without producing an empty
|
|
184
|
-
* `_meta` field. Used by the tool and resource registries.
|
|
185
|
-
*
|
|
186
|
-
* @internal
|
|
187
|
-
*/
|
|
188
|
-
export declare function buildMetaWithErrorContract(baseMeta: Record<string, unknown> | undefined, errors: readonly unknown[] | undefined): Record<string, unknown> | undefined;
|
|
189
170
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/types-global/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,oBAAY,gBAAgB;IAE1B,UAAU,SAAS;IACnB,cAAc,SAAS;IACvB,cAAc,SAAS;IACvB,aAAa,SAAS;IACtB,aAAa,SAAS;IAGtB,kBAAkB,SAAS;IAC3B,QAAQ,SAAS;IACjB,QAAQ,SAAS;IACjB,WAAW,SAAS;IACpB,OAAO,SAAS;IAChB,SAAS,SAA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-138,23 +138,4 @@ export const ErrorSchema = z
|
|
|
138
138
|
.describe('Optional structured data providing more context about the error'),
|
|
139
139
|
})
|
|
140
140
|
.describe('Schema for validating structured error objects, ensuring consistency in error reporting.');
|
|
141
|
-
/**
|
|
142
|
-
* The MCP `_meta` namespace key under which `errors[]` is published in
|
|
143
|
-
* `tools/list` and `resources/list`. Namespaced to avoid collisions with
|
|
144
|
-
* other framework or vendor extensions.
|
|
145
|
-
*/
|
|
146
|
-
export const ERROR_CONTRACT_META_KEY = 'mcp-ts-core/errors';
|
|
147
|
-
/**
|
|
148
|
-
* Merges a tool/resource's `errors[]` contract into its `_meta` object under
|
|
149
|
-
* {@link ERROR_CONTRACT_META_KEY}. Returns `undefined` when both sides are
|
|
150
|
-
* absent so callers can spread conditionally without producing an empty
|
|
151
|
-
* `_meta` field. Used by the tool and resource registries.
|
|
152
|
-
*
|
|
153
|
-
* @internal
|
|
154
|
-
*/
|
|
155
|
-
export function buildMetaWithErrorContract(baseMeta, errors) {
|
|
156
|
-
if (!errors || errors.length === 0)
|
|
157
|
-
return baseMeta;
|
|
158
|
-
return { ...(baseMeta ?? {}), [ERROR_CONTRACT_META_KEY]: errors };
|
|
159
|
-
}
|
|
160
141
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/types-global/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,MAAM,CAAN,IAAY,gBAsBX;AAtBD,WAAY,gBAAgB;IAC1B,+BAA+B;IAC/B,wEAAmB,CAAA;IACnB,gFAAuB,CAAA;IACvB,gFAAuB,CAAA;IACvB,8EAAsB,CAAA;IACtB,8EAAsB,CAAA;IAEtB,0DAA0D;IAC1D,wFAA2B,CAAA;IAC3B,oEAAiB,CAAA;IACjB,oEAAiB,CAAA;IACjB,0EAAoB,CAAA;IAC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QAAQ,CAAC,uCAAuC,CAAC;IACpD;;;OAGG;IACH,IAAI,EAAE,CAAC;SACJ,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;SAC/B,QAAQ,EAAE;SACV,QAAQ,CAAC,iEAAiE,CAAC;CAC/E,CAAC;KACD,QAAQ,CACP,0FAA0F,CAC3F,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyanheads/mcp-ts-core",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"mcpName": "io.github.cyanheads/mcp-ts-core",
|
|
5
5
|
"description": "Agent-native TypeScript framework for building MCP servers. Declarative definitions with auth, multi-backend storage, OpenTelemetry, and first-class support for Bun/Node/Cloudflare Workers.",
|
|
6
6
|
"main": "dist/core/index.js",
|
|
@@ -108,8 +108,10 @@ const APP_HTML = `<!DOCTYPE html>
|
|
|
108
108
|
<!-- your UI markup -->
|
|
109
109
|
|
|
110
110
|
<script type="module">
|
|
111
|
-
//
|
|
112
|
-
//
|
|
111
|
+
// PROTOTYPING ONLY — replace before shipping. Bundle via Vite +
|
|
112
|
+
// vite-plugin-singlefile or inline the SDK. Live CDN imports require
|
|
113
|
+
// CSP whitelisting, add supply-chain risk, and break offline use.
|
|
114
|
+
// See UI Notes below.
|
|
113
115
|
import {
|
|
114
116
|
App,
|
|
115
117
|
applyDocumentTheme,
|
|
@@ -186,13 +188,27 @@ export const {{RESOURCE_EXPORT}} = appResource('ui://{{tool-name}}/app.html', {
|
|
|
186
188
|
});
|
|
187
189
|
```
|
|
188
190
|
|
|
189
|
-
## UI
|
|
191
|
+
## UI Notes
|
|
190
192
|
|
|
191
|
-
- **
|
|
192
|
-
- **
|
|
193
|
-
- **
|
|
194
|
-
-
|
|
195
|
-
-
|
|
193
|
+
- **Ship self-contained HTML.** Author with Vite + `vite-plugin-singlefile` or inline the SDK. Live CDN imports in a `ui://` resource are a CSP footgun (every domain has to be whitelisted on `_meta.ui.csp.resourceDomains`), a supply-chain footgun (third-party JS executes inside the host's iframe), and a runtime footgun (every render needs network). The `unpkg` line in the template is for prototyping only.
|
|
194
|
+
- **CSP.** MCP Apps iframes run under deny-by-default CSP. With `appResource()`, put `_meta.ui.csp.resourceDomains` on the definition; the builder mirrors it into returned `resources/read` content items. With plain `resource()`, attach `_meta.ui` yourself in `format()`.
|
|
195
|
+
- **Adopt the host's visual identity, don't impose your own.** App UIs render inside the host's iframe alongside its native UI. Three host hooks layer on top of your CSS:
|
|
196
|
+
- `applyDocumentTheme(hostContext.theme)` — sets `color-scheme` and a `data-theme` attribute on `<html>`
|
|
197
|
+
- `applyHostStyleVariables(hostContext.styles.variables)` — installs host CSS custom properties on `:root` (host decides the names, e.g. `--mcp-color-bg-primary`)
|
|
198
|
+
- `applyHostFonts(hostContext.styles.css.fonts)` — installs `@font-face` rules for the host's font stack
|
|
199
|
+
|
|
200
|
+
Author CSS to *consume* these via `var(--mcp-color-bg-primary, /* fallback */ #fff)`. Don't hardcode brand colors that fight the host.
|
|
201
|
+
- **Pre-connect baseline.** `app.connect()` is async — host context arrives a frame or two after first paint. Without a baseline, the UI flashes unstyled or wrong-themed on light hosts. Ship a `prefers-color-scheme`-aware default so the first frame is sensible:
|
|
202
|
+
|
|
203
|
+
```css
|
|
204
|
+
:root { color-scheme: light dark; --bg: #fff; --fg: #111; }
|
|
205
|
+
@media (prefers-color-scheme: dark) { :root { --bg: #0c0d12; --fg: #ededef; } }
|
|
206
|
+
body { background: var(--bg); color: var(--fg); }
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Host vars override these once `onhostcontextchanged` fires.
|
|
210
|
+
- **`format()` for app tools.** The first `text` content block is typically JSON that the UI parses via `ontoolresult`. Additional blocks are the human-readable fallback that non-app hosts and LLMs consume — they must render every field the LLM needs to reason about. JSON-only payloads leave model-visible context blind.
|
|
211
|
+
- **App resource `format()`.** `appResource()` already preserves raw HTML for the default app MIME type and mirrors definition `_meta.ui` into content items. Add a custom `format()` only when you need extra per-read metadata or non-default content shaping.
|
|
196
212
|
|
|
197
213
|
## Registration
|
|
198
214
|
|
|
@@ -109,7 +109,7 @@ If the repo already uses `src/mcp-server/resources/definitions/index.ts`, update
|
|
|
109
109
|
|
|
110
110
|
### Optional: declarative `errors[]` contract
|
|
111
111
|
|
|
112
|
-
Resources can opt into the same typed error contract as tools —
|
|
112
|
+
Resources can opt into the same typed error contract as tools — bound to a typed `ctx.fail(reason, …)` keyed by the declared reason union:
|
|
113
113
|
|
|
114
114
|
```typescript
|
|
115
115
|
import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
|
package/skills/add-tool/SKILL.md
CHANGED
|
@@ -4,7 +4,7 @@ description: >
|
|
|
4
4
|
Scaffold a new MCP tool definition. Use when the user asks to add a tool, create a new tool, or implement a new capability for the server.
|
|
5
5
|
metadata:
|
|
6
6
|
author: cyanheads
|
|
7
|
-
version: "
|
|
7
|
+
version: "2.0"
|
|
8
8
|
audience: external
|
|
9
9
|
type: reference
|
|
10
10
|
---
|
|
@@ -44,6 +44,7 @@ For shape selection (Workflow or Instruction variants — standard single-action
|
|
|
44
44
|
*/
|
|
45
45
|
|
|
46
46
|
import { tool, z } from '@cyanheads/mcp-ts-core';
|
|
47
|
+
import { JsonRpcErrorCode } from '@cyanheads/mcp-ts-core/errors';
|
|
47
48
|
|
|
48
49
|
export const {{TOOL_EXPORT}} = tool('{{tool_name}}', {
|
|
49
50
|
title: '{{TOOL_TITLE}}',
|
|
@@ -58,17 +59,25 @@ export const {{TOOL_EXPORT}} = tool('{{tool_name}}', {
|
|
|
58
59
|
// All fields need .describe(). Only JSON-Schema-serializable Zod types allowed.
|
|
59
60
|
}),
|
|
60
61
|
// auth: ['tool:{{tool_name}}:read'],
|
|
61
|
-
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
//
|
|
62
|
+
|
|
63
|
+
// Each entry declares a domain-specific failure mode and types
|
|
64
|
+
// `ctx.fail(reason, …)` against the declared union. Baseline codes
|
|
65
|
+
// (InternalError, ServiceUnavailable, Timeout, ValidationError,
|
|
66
|
+
// SerializationError) bubble freely — only declare domain-specific reasons.
|
|
67
|
+
// Delete this block if no domain failures apply.
|
|
68
|
+
errors: [
|
|
69
|
+
{ reason: 'no_match', code: JsonRpcErrorCode.NotFound, when: 'No items matched the query.' },
|
|
70
|
+
{ reason: 'queue_full', code: JsonRpcErrorCode.RateLimited, when: 'Local queue at capacity.', retryable: true },
|
|
71
|
+
],
|
|
65
72
|
|
|
66
73
|
async handler(input, ctx) {
|
|
67
74
|
ctx.log.info('Processing', { /* relevant input fields */ });
|
|
68
75
|
// Pure logic — throw on failure, no try/catch.
|
|
69
76
|
// With an `errors[]` contract: `throw ctx.fail('reason_id', message?, data?)`.
|
|
70
77
|
// Without: throw via factories (`notFound`, `validationError`, …) or plain `Error`.
|
|
71
|
-
|
|
78
|
+
const items = await search(input);
|
|
79
|
+
if (items.length === 0) throw ctx.fail('no_match', `No items matched "${input.query}"`);
|
|
80
|
+
return { items };
|
|
72
81
|
},
|
|
73
82
|
|
|
74
83
|
// format() populates MCP content[] — the markdown twin of structuredContent.
|
|
@@ -186,18 +195,38 @@ Single-item tools don't need this — they either succeed or throw. The partial
|
|
|
186
195
|
|
|
187
196
|
### Empty results need context
|
|
188
197
|
|
|
189
|
-
An empty array with no explanation is a dead end. Echo back the criteria that produced zero results and, where possible, suggest how to broaden the search.
|
|
198
|
+
An empty array with no explanation is a dead end. Echo back the criteria that produced zero results and, where possible, suggest how to broaden the search. The recovery hint needs three pieces working together — schema entry, handler return, and `format()` rendering — or the `format-parity` lint will flag the missing field.
|
|
190
199
|
|
|
191
200
|
```typescript
|
|
192
|
-
//
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
+
// 1. Output schema — declare the recovery field so the linter sees it
|
|
202
|
+
output: z.object({
|
|
203
|
+
items: z.array(ItemSchema).describe('Matching items.'),
|
|
204
|
+
totalCount: z.number().describe('Total matches before pagination.'),
|
|
205
|
+
message: z.string().optional()
|
|
206
|
+
.describe('Recovery hint when results are empty — echoes filters and suggests how to broaden. Absent on successful result pages.'),
|
|
207
|
+
}),
|
|
208
|
+
|
|
209
|
+
// 2. Handler — populate `message` when the result is empty
|
|
210
|
+
async handler(input, ctx) {
|
|
211
|
+
const results = await search(input);
|
|
212
|
+
if (results.length === 0) {
|
|
213
|
+
return {
|
|
214
|
+
items: [],
|
|
215
|
+
totalCount: 0,
|
|
216
|
+
message: `No items matched status="${input.status}" in project "${input.project}". `
|
|
217
|
+
+ `Try a broader status filter or verify the project name.`,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
return { items: results, totalCount: results.length };
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
// 3. format() — render the recovery hint so content[]-only clients see it too
|
|
224
|
+
format: (result) => {
|
|
225
|
+
const lines = [`**Total:** ${result.totalCount}`];
|
|
226
|
+
if (result.message) lines.push(`\n> ${result.message}`);
|
|
227
|
+
for (const item of result.items) lines.push(`- ${item.name}`);
|
|
228
|
+
return [{ type: 'text', text: lines.join('\n') }];
|
|
229
|
+
},
|
|
201
230
|
```
|
|
202
231
|
|
|
203
232
|
### Sparse upstream data must stay honest
|
|
@@ -265,13 +294,51 @@ export const fetchArticles = tool('fetch_articles', {
|
|
|
265
294
|
});
|
|
266
295
|
```
|
|
267
296
|
|
|
268
|
-
**Baseline codes** (`InternalError`, `ServiceUnavailable`, `Timeout`, `ValidationError`, `SerializationError`) bubble freely and don't need declaring.
|
|
297
|
+
**Baseline codes** (`InternalError`, `ServiceUnavailable`, `Timeout`, `ValidationError`, `SerializationError`) bubble freely and don't need declaring. Wire-level behavior is identical when the contract is omitted, but you lose the type-checked `ctx.fail`, the `tools/list` advertisement, and conformance lint coverage — declare a contract whenever the tool has a domain-specific failure mode.
|
|
269
298
|
|
|
270
299
|
`ctx.fail` accepts an optional 4th `options` argument for ES2022 cause chaining: `throw ctx.fail('upstream_error', 'Upstream returned 500', { url }, { cause: e })`.
|
|
271
300
|
|
|
272
|
-
|
|
301
|
+
#### Service-layer throws
|
|
302
|
+
|
|
303
|
+
API-wrapping tools usually delegate to a service: `const data = await ncbi.fetch(input)`. The throw lives in the service, not the handler — and services don't receive `ctx`, so `ctx.fail` is unreachable from there. The fix is to pass `data: { reason: 'X' }` to the factory in the service. The framework's auto-classifier preserves `data` on the wire, so clients see the same `error.data.reason` they would have seen from `ctx.fail`. The handler doesn't catch — it just bubbles.
|
|
304
|
+
|
|
305
|
+
The contract entry on the tool and the `data: { reason }` on the service throw need to use the **same reason string** so the two sides line up.
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
// service — passes data.reason to match the consuming tool's contract
|
|
309
|
+
import { serviceUnavailable } from '@cyanheads/mcp-ts-core/errors';
|
|
310
|
+
|
|
311
|
+
export class NcbiService {
|
|
312
|
+
async fetch(pmids: string[]) {
|
|
313
|
+
const response = await fetchWithRetry(...);
|
|
314
|
+
if (!response.ok) {
|
|
315
|
+
throw serviceUnavailable(
|
|
316
|
+
`NCBI returned HTTP ${response.status}`,
|
|
317
|
+
{ reason: 'ncbi_unreachable', status: response.status }, // ← matches contract entry
|
|
318
|
+
{ cause: undefined },
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
return response.json();
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// tool — declares the matching contract entry, calls the service, doesn't catch
|
|
326
|
+
export const fetchArticles = tool('fetch_articles', {
|
|
327
|
+
errors: [
|
|
328
|
+
{ reason: 'ncbi_unreachable', code: JsonRpcErrorCode.ServiceUnavailable,
|
|
329
|
+
when: 'NCBI E-utilities is unreachable.', retryable: true },
|
|
330
|
+
],
|
|
331
|
+
async handler(input, ctx) {
|
|
332
|
+
return { articles: await ncbi.fetch(input.pmids) }; // throws bubble unchanged
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
See `add-service` for the full pattern.
|
|
338
|
+
|
|
339
|
+
#### Ad-hoc factory throws (fallback)
|
|
273
340
|
|
|
274
|
-
|
|
341
|
+
When no contract entry fits — prototype code, one-off throws, or service-layer fallbacks — use error factories or plain `throw new Error()`. The framework auto-classifies plain `Error` from message patterns as a last resort.
|
|
275
342
|
|
|
276
343
|
```typescript
|
|
277
344
|
// Client input error — agent can fix and retry
|
|
@@ -365,7 +432,7 @@ Large payloads burn the agent's context window. Default to curated summaries; of
|
|
|
365
432
|
- [ ] `format()` renders every field in the output schema — enforced at lint time via sentinel injection, startup fails with `format-parity` errors otherwise. Different clients forward different surfaces (Claude Code → `structuredContent`, Claude Desktop → `content[]`); both must carry the same data. Primary fix: render the missing field in `format()` (use `z.discriminatedUnion` for list/detail variants). Escape hatch: if the output schema was over-typed for a genuinely dynamic upstream API, relax it (`z.object({}).passthrough()`) rather than maintaining aspirational typing
|
|
366
433
|
- [ ] If wrapping external API: output schema and `format()` preserve uncertainty from sparse upstream payloads instead of inventing concrete values
|
|
367
434
|
- [ ] `auth` scopes declared if the tool needs authorization
|
|
368
|
-
- [ ] `errors: [...]` contract declared for
|
|
435
|
+
- [ ] `errors: [...]` contract declared for the tool's domain-specific failure modes — or block deleted if no domain failures apply (baseline codes bubble freely)
|
|
369
436
|
- [ ] `task: true` added if the tool is long-running
|
|
370
437
|
- [ ] Registered in the project's existing `createApp()` tool list (directly or via barrel)
|
|
371
438
|
- [ ] `bun run devcheck` passes
|