@cyanheads/mcp-ts-core 0.8.18 → 0.8.20
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 +50 -47
- package/README.md +35 -37
- package/changelog/0.8.x/0.8.19.md +33 -0
- package/changelog/0.8.x/0.8.20.md +26 -0
- package/changelog/template.md +71 -44
- package/dist/cli/init.js +12 -5
- package/dist/cli/init.js.map +1 -1
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +11 -0
- package/dist/config/index.js.map +1 -1
- package/dist/logs/combined.log +7 -12
- package/dist/logs/error.log +5 -8
- package/dist/mcp-server/transports/auth/authFactory.d.ts.map +1 -1
- package/dist/mcp-server/transports/auth/authFactory.js +4 -1
- package/dist/mcp-server/transports/auth/authFactory.js.map +1 -1
- package/dist/mcp-server/transports/auth/lib/authUtils.d.ts +3 -0
- package/dist/mcp-server/transports/auth/lib/authUtils.d.ts.map +1 -1
- package/dist/mcp-server/transports/auth/lib/authUtils.js +7 -0
- package/dist/mcp-server/transports/auth/lib/authUtils.js.map +1 -1
- package/dist/mcp-server/transports/auth/lib/checkScopes.d.ts +4 -0
- package/dist/mcp-server/transports/auth/lib/checkScopes.d.ts.map +1 -1
- package/dist/mcp-server/transports/auth/lib/checkScopes.js +7 -0
- package/dist/mcp-server/transports/auth/lib/checkScopes.js.map +1 -1
- package/dist/mcp-server/transports/auth/lib/claimParser.d.ts +5 -1
- package/dist/mcp-server/transports/auth/lib/claimParser.d.ts.map +1 -1
- package/dist/mcp-server/transports/auth/lib/claimParser.js +24 -8
- package/dist/mcp-server/transports/auth/lib/claimParser.js.map +1 -1
- package/package.json +14 -12
- package/scripts/build-changelog.ts +27 -18
- package/skills/api-auth/SKILL.md +37 -3
- package/skills/api-config/SKILL.md +2 -1
- package/skills/api-telemetry/SKILL.md +222 -0
- package/skills/api-utils/SKILL.md +3 -1
- package/skills/maintenance/SKILL.md +16 -6
- package/skills/polish-docs-meta/references/package-meta.md +1 -1
- package/skills/report-issue-framework/SKILL.md +5 -3
- package/skills/report-issue-local/SKILL.md +5 -3
- package/skills/security-pass/SKILL.md +3 -2
- package/skills/setup/SKILL.md +10 -9
- package/skills/tool-defs-analysis/SKILL.md +2 -2
- package/templates/AGENTS.md +20 -10
- package/templates/CLAUDE.md +20 -10
- package/templates/Dockerfile +2 -2
- package/templates/changelog/template.md +71 -44
- package/templates/package.json +2 -2
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
import { McpError, unauthorized } from '../../../../types-global/errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts a list of scope strings from a JWT claim value, accepting both
|
|
4
|
+
* array and space-delimited string forms. Non-string array entries cause
|
|
5
|
+
* the claim to be ignored entirely. Empty-string entries are dropped.
|
|
6
|
+
*/
|
|
7
|
+
function extractStringScopes(value) {
|
|
8
|
+
if (Array.isArray(value) && value.every((s) => typeof s === 'string')) {
|
|
9
|
+
return value.filter((s) => s.length > 0);
|
|
10
|
+
}
|
|
11
|
+
if (typeof value === 'string' && value.trim()) {
|
|
12
|
+
return value.split(' ').filter(Boolean);
|
|
13
|
+
}
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
2
16
|
/**
|
|
3
17
|
* Builds an {@link AuthInfo} from a raw token string and decoded JWT payload.
|
|
4
18
|
*
|
|
5
19
|
* Claim resolution order:
|
|
6
20
|
* - **clientId**: `cid` (Okta) → `client_id` (OAuth 2.1 standard)
|
|
7
|
-
* - **scopes**: `scp` (Okta, array)
|
|
21
|
+
* - **scopes**: union of `scp` (Okta, array), `scope` (standard, space-delimited string),
|
|
22
|
+
* and `mcp_tool_scopes` (custom claim for OIDC providers that cannot inject scopes
|
|
23
|
+
* into `scope` during the `authorization_code` flow — Authentik, Keycloak < 26.5,
|
|
24
|
+
* Zitadel). Operators add a property mapping returning
|
|
25
|
+
* `{"mcp_tool_scopes": "tool:foo:read tool:bar:write"}` (string or array form accepted).
|
|
8
26
|
* - **subject**: `sub` (standard)
|
|
9
27
|
* - **tenantId**: `tid` (Azure AD / custom)
|
|
10
28
|
* - **expiresAt**: `exp` (standard, seconds since epoch)
|
|
@@ -20,13 +38,11 @@ export function buildAuthInfoFromClaims(token, payload) {
|
|
|
20
38
|
if (!clientId) {
|
|
21
39
|
throw unauthorized("Invalid token: missing 'cid' or 'client_id' claim.");
|
|
22
40
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
scopes = payload.scope.split(' ').filter(Boolean);
|
|
29
|
-
}
|
|
41
|
+
const scopes = [
|
|
42
|
+
...extractStringScopes(payload.scp),
|
|
43
|
+
...extractStringScopes(payload.scope),
|
|
44
|
+
...extractStringScopes(payload.mcp_tool_scopes),
|
|
45
|
+
];
|
|
30
46
|
if (scopes.length === 0) {
|
|
31
47
|
throw unauthorized('Token must contain valid, non-empty scopes.');
|
|
32
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claimParser.js","sourceRoot":"","sources":["../../../../../src/mcp-server/transports/auth/lib/claimParser.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAElE
|
|
1
|
+
{"version":3,"file":"claimParser.js","sourceRoot":"","sources":["../../../../../src/mcp-server/transports/auth/lib/claimParser.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAElE;;;;GAIG;AACH,SAAS,mBAAmB,CAAC,KAAc;IACzC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,EAAE,CAAC;QACtE,OAAQ,KAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACzD,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;QAC9C,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAa,EAAE,OAAmB;IACxE,MAAM,QAAQ,GACZ,OAAO,OAAO,CAAC,GAAG,KAAK,QAAQ;QAC7B,CAAC,CAAC,OAAO,CAAC,GAAG;QACb,CAAC,CAAC,OAAO,OAAO,CAAC,SAAS,KAAK,QAAQ;YACrC,CAAC,CAAC,OAAO,CAAC,SAAS;YACnB,CAAC,CAAC,SAAS,CAAC;IAElB,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,YAAY,CAAC,oDAAoD,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,MAAM,GAAG;QACb,GAAG,mBAAmB,CAAC,OAAO,CAAC,GAAG,CAAC;QACnC,GAAG,mBAAmB,CAAC,OAAO,CAAC,KAAK,CAAC;QACrC,GAAG,mBAAmB,CAAC,OAAO,CAAC,eAAe,CAAC;KAChD,CAAC;IAEF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,YAAY,CAAC,6CAA6C,CAAC,CAAC;IACpE,CAAC;IAED,OAAO;QACL,KAAK;QACL,QAAQ;QACR,MAAM;QACN,GAAG,CAAC,OAAO,OAAO,CAAC,GAAG,KAAK,QAAQ,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;QAChE,GAAG,CAAC,OAAO,OAAO,CAAC,GAAG,KAAK,QAAQ,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;QACjE,GAAG,CAAC,OAAO,OAAO,CAAC,GAAG,KAAK,QAAQ,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;KACnE,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAc,EAAE,eAAuB;IAC3E,IAAI,KAAK,YAAY,QAAQ;QAAE,MAAM,KAAK,CAAC;IAE3C,MAAM,OAAO,GACX,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,eAAe,CAAC;IAEjG,MAAM,YAAY,CAAC,OAAO,CAAC,CAAC;AAC9B,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.20",
|
|
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",
|
|
@@ -165,10 +165,10 @@
|
|
|
165
165
|
},
|
|
166
166
|
"devDependencies": {
|
|
167
167
|
"@biomejs/biome": "2.4.14",
|
|
168
|
-
"@cloudflare/vitest-pool-workers": "^0.16.
|
|
169
|
-
"@cloudflare/workers-types": "^4.
|
|
168
|
+
"@cloudflare/vitest-pool-workers": "^0.16.3",
|
|
169
|
+
"@cloudflare/workers-types": "^4.20260509.1",
|
|
170
170
|
"@duckdb/node-api": "^1.5.2-r.1",
|
|
171
|
-
"@hono/otel": "^1.1.
|
|
171
|
+
"@hono/otel": "^1.1.2",
|
|
172
172
|
"@opentelemetry/exporter-metrics-otlp-http": "^0.217.0",
|
|
173
173
|
"@opentelemetry/exporter-trace-otlp-http": "^0.217.0",
|
|
174
174
|
"@opentelemetry/instrumentation-http": "^0.217.0",
|
|
@@ -178,10 +178,10 @@
|
|
|
178
178
|
"@opentelemetry/sdk-node": "^0.217.0",
|
|
179
179
|
"@opentelemetry/sdk-trace-node": "^2.7.1",
|
|
180
180
|
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
181
|
-
"@supabase/supabase-js": "^2.105.
|
|
181
|
+
"@supabase/supabase-js": "^2.105.4",
|
|
182
182
|
"@types/bun": "^1.3.13",
|
|
183
183
|
"@types/js-yaml": "^4.0.9",
|
|
184
|
-
"@types/node": "^25.6.
|
|
184
|
+
"@types/node": "^25.6.2",
|
|
185
185
|
"@types/papaparse": "^5.5.2",
|
|
186
186
|
"@types/sanitize-html": "^2.16.1",
|
|
187
187
|
"@types/validator": "^13.15.10",
|
|
@@ -195,11 +195,12 @@
|
|
|
195
195
|
"diff": "^9.0.0",
|
|
196
196
|
"execa": "^9.6.1",
|
|
197
197
|
"fast-check": "^4.7.0",
|
|
198
|
+
"fast-xml-parser": "^5.7.3",
|
|
198
199
|
"ignore": "^7.0.5",
|
|
199
200
|
"js-yaml": "^4.1.1",
|
|
200
201
|
"linkedom": "^0.18.12",
|
|
201
202
|
"node-cron": "^4.2.1",
|
|
202
|
-
"openai": "^6.
|
|
203
|
+
"openai": "^6.37.0",
|
|
203
204
|
"papaparse": "^5.5.3",
|
|
204
205
|
"partial-json": "^0.1.7",
|
|
205
206
|
"pdf-lib": "^1.17.1",
|
|
@@ -211,7 +212,7 @@
|
|
|
211
212
|
"typescript": "^6.0.3",
|
|
212
213
|
"unpdf": "^1.6.2",
|
|
213
214
|
"validator": "^13.15.35",
|
|
214
|
-
"vite": "8.0.
|
|
215
|
+
"vite": "8.0.11",
|
|
215
216
|
"vitest": "^4.1.5"
|
|
216
217
|
},
|
|
217
218
|
"keywords": [
|
|
@@ -219,13 +220,14 @@
|
|
|
219
220
|
"agent-native",
|
|
220
221
|
"ai",
|
|
221
222
|
"ai-agent",
|
|
223
|
+
"bun",
|
|
222
224
|
"cloudflare-workers",
|
|
223
225
|
"declarative",
|
|
224
|
-
"edge",
|
|
225
226
|
"framework",
|
|
226
227
|
"llm",
|
|
227
228
|
"mcp",
|
|
228
229
|
"mcp-server",
|
|
230
|
+
"mcp-framework",
|
|
229
231
|
"model-context-protocol",
|
|
230
232
|
"observability",
|
|
231
233
|
"opentelemetry",
|
|
@@ -246,8 +248,8 @@
|
|
|
246
248
|
],
|
|
247
249
|
"packageManager": "bun@1.3.2",
|
|
248
250
|
"engines": {
|
|
249
|
-
"bun": ">=1.
|
|
250
|
-
"node": ">=
|
|
251
|
+
"bun": ">=1.3.0",
|
|
252
|
+
"node": ">=24.0.0"
|
|
251
253
|
},
|
|
252
254
|
"depcheck": {
|
|
253
255
|
"ignores": [
|
|
@@ -264,7 +266,7 @@
|
|
|
264
266
|
},
|
|
265
267
|
"dependencies": {
|
|
266
268
|
"@hono/mcp": "^0.2.5",
|
|
267
|
-
"@hono/node-server": "^2.0.
|
|
269
|
+
"@hono/node-server": "^2.0.2",
|
|
268
270
|
"@modelcontextprotocol/ext-apps": "^1.7.1",
|
|
269
271
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
270
272
|
"@opentelemetry/api": "^1.9.1",
|
|
@@ -6,23 +6,25 @@
|
|
|
6
6
|
* YAML frontmatter declaring:
|
|
7
7
|
* • summary (required) — ≤250-char headline, no markdown, one line
|
|
8
8
|
* • breaking (optional) — `true` flags releases with breaking changes
|
|
9
|
+
* • security (optional) — `true` flags releases with security fixes
|
|
9
10
|
*
|
|
10
11
|
* The rollup is a thin **index**, not a copy of bodies — each entry is just a
|
|
11
12
|
* clickable header + one-line summary. Full content stays in the per-version files.
|
|
12
13
|
*
|
|
13
14
|
* Rendered rollup entry:
|
|
14
|
-
* ## [X.Y.Z](changelog/N.N.x/X.Y.Z.md) — YYYY-MM-DD · ⚠️ Breaking
|
|
15
|
+
* ## [X.Y.Z](changelog/N.N.x/X.Y.Z.md) — YYYY-MM-DD · ⚠️ Breaking · 🛡️ Security
|
|
15
16
|
*
|
|
16
17
|
* <summary>
|
|
17
18
|
*
|
|
18
|
-
*
|
|
19
|
+
* Badges only render when their flag is `true`. Order is fixed: Breaking before
|
|
20
|
+
* Security when both are set.
|
|
19
21
|
*
|
|
20
22
|
* Modes:
|
|
21
23
|
* • default → regenerate CHANGELOG.md
|
|
22
24
|
* • --check → exit 1 if CHANGELOG.md differs from what would be generated
|
|
23
25
|
*
|
|
24
26
|
* Missing `summary`: warning (not failure) — the entry renders header-only.
|
|
25
|
-
* Summary > 250 chars, or malformed `breaking`: hard error.
|
|
27
|
+
* Summary > 250 chars, or malformed `breaking` / `security`: hard error.
|
|
26
28
|
*
|
|
27
29
|
* @module scripts/build-changelog
|
|
28
30
|
*/
|
|
@@ -50,6 +52,7 @@ interface VersionEntry {
|
|
|
50
52
|
|
|
51
53
|
interface Frontmatter {
|
|
52
54
|
breaking: boolean;
|
|
55
|
+
security: boolean;
|
|
53
56
|
summary: string | null;
|
|
54
57
|
}
|
|
55
58
|
|
|
@@ -75,13 +78,13 @@ function compareSemverDesc(a: string, b: string): number {
|
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
/**
|
|
78
|
-
* Parse minimal YAML frontmatter. Only recognizes `summary
|
|
79
|
-
* other keys are ignored, so the format stays extensible without
|
|
80
|
-
* parser. Throws on malformed values we actually care about.
|
|
81
|
+
* Parse minimal YAML frontmatter. Only recognizes `summary`, `breaking`, and
|
|
82
|
+
* `security` — other keys are ignored, so the format stays extensible without
|
|
83
|
+
* touching the parser. Throws on malformed values we actually care about.
|
|
81
84
|
*/
|
|
82
85
|
function parseFrontmatter(content: string, fileLabel: string): Frontmatter {
|
|
83
86
|
const match = content.match(/^---\n([\s\S]*?)\n---\n?/);
|
|
84
|
-
if (!match) return { summary: null, breaking: false };
|
|
87
|
+
if (!match) return { summary: null, breaking: false, security: false };
|
|
85
88
|
|
|
86
89
|
const block = match[1] as string;
|
|
87
90
|
|
|
@@ -101,18 +104,21 @@ function parseFrontmatter(content: string, fileLabel: string): Frontmatter {
|
|
|
101
104
|
);
|
|
102
105
|
}
|
|
103
106
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const val = breakingMatch[1];
|
|
107
|
+
const parseBool = (key: string): boolean => {
|
|
108
|
+
const m = block.match(new RegExp(`^${key}:\\s*(\\S+)\\s*$`, 'm'));
|
|
109
|
+
if (!m) return false;
|
|
110
|
+
const val = m[1];
|
|
109
111
|
if (val !== 'true' && val !== 'false') {
|
|
110
|
-
throw new Error(`${fileLabel}:
|
|
112
|
+
throw new Error(`${fileLabel}: ${key} must be 'true' or 'false', got '${val}'.`);
|
|
111
113
|
}
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
+
return val === 'true';
|
|
115
|
+
};
|
|
114
116
|
|
|
115
|
-
return {
|
|
117
|
+
return {
|
|
118
|
+
summary,
|
|
119
|
+
breaking: parseBool('breaking'),
|
|
120
|
+
security: parseBool('security'),
|
|
121
|
+
};
|
|
116
122
|
}
|
|
117
123
|
|
|
118
124
|
/** Extract the release date from the H1 heading. */
|
|
@@ -128,8 +134,11 @@ function extractDate(body: string, fileLabel: string): string {
|
|
|
128
134
|
|
|
129
135
|
function renderEntry(entry: VersionEntry, fm: Frontmatter, date: string): string {
|
|
130
136
|
const link = `changelog/${entry.series}/${entry.version}.md`;
|
|
131
|
-
const
|
|
132
|
-
|
|
137
|
+
const badges = [fm.breaking ? '⚠️ Breaking' : null, fm.security ? '🛡️ Security' : null].filter(
|
|
138
|
+
(b): b is string => b !== null,
|
|
139
|
+
);
|
|
140
|
+
const badgeSuffix = badges.length > 0 ? ` · ${badges.join(' · ')}` : '';
|
|
141
|
+
const header = `## [${entry.version}](${link}) — ${date}${badgeSuffix}`;
|
|
133
142
|
if (fm.summary) {
|
|
134
143
|
return `${header}\n\n${fm.summary}\n`;
|
|
135
144
|
}
|
package/skills/api-auth/SKILL.md
CHANGED
|
@@ -4,7 +4,7 @@ description: >
|
|
|
4
4
|
Authentication, authorization, and multi-tenancy patterns for `@cyanheads/mcp-ts-core`. Use when implementing auth scopes on tools/resources, configuring auth modes (none/jwt/oauth), working with JWT/OAuth env vars, or understanding how tenantId flows through ctx.state.
|
|
5
5
|
metadata:
|
|
6
6
|
author: cyanheads
|
|
7
|
-
version: "1.
|
|
7
|
+
version: "1.1"
|
|
8
8
|
audience: external
|
|
9
9
|
type: reference
|
|
10
10
|
---
|
|
@@ -94,10 +94,44 @@ Set via `MCP_AUTH_MODE` environment variable.
|
|
|
94
94
|
| Claim | JWT Field | Purpose |
|
|
95
95
|
|:------|:----------|:--------|
|
|
96
96
|
| `clientId` | `cid` / `client_id` | Identifies the calling client |
|
|
97
|
-
| `scopes` | `scp
|
|
97
|
+
| `scopes` | union of `scp`, `scope`, `mcp_tool_scopes` | Granted scope list (see below) |
|
|
98
98
|
| `sub` | `sub` | Subject (user or service identity) |
|
|
99
99
|
| `tenantId` | `tid` | Tenant identifier — drives `ctx.state` scoping |
|
|
100
100
|
|
|
101
|
+
`scopes` is the **union** of three claims, in this order:
|
|
102
|
+
|
|
103
|
+
| Claim | Form | Source |
|
|
104
|
+
|:------|:-----|:-------|
|
|
105
|
+
| `scp` | array of strings | Okta-style |
|
|
106
|
+
| `scope` | space-delimited string | OAuth 2.1 / OIDC standard |
|
|
107
|
+
| `mcp_tool_scopes` | array of strings **or** space-delimited string | Custom claim for OIDC providers that cannot inject scopes into `scope` during the `authorization_code` flow (Authentik, Keycloak < 26.5, Zitadel) |
|
|
108
|
+
|
|
109
|
+
Auth0/Okta-style providers that already populate `scp` or `scope` need no migration. Other deployments add a property mapping returning `{"mcp_tool_scopes": "tool:foo:read tool:bar:write"}` — the framework unions it into `ctx.auth.scopes` alongside the standard claims. Hardcoded claim name; deployments whose IdP cannot emit `mcp_tool_scopes` use the bypass flag below.
|
|
110
|
+
|
|
111
|
+
### OIDC operator setup (Authentik / Keycloak / Zitadel)
|
|
112
|
+
|
|
113
|
+
Standard OIDC providers compute the JWT `scope` claim from what the OAuth client requested at the authorization endpoint and ignore property mappings that try to override `scope` in the `authorization_code` flow. Property mappings that inject **other** claim names work fine. To grant per-tool scopes to a Claude.ai or ChatGPT custom connector that doesn't expose scope customization, configure your IdP to return the per-tool scopes under `mcp_tool_scopes` instead of overriding `scope`.
|
|
114
|
+
|
|
115
|
+
| Provider | Where to configure |
|
|
116
|
+
|:---------|:--------------------|
|
|
117
|
+
| Authentik | Customization → Property Mappings → new "Scope Mapping" returning `{"mcp_tool_scopes": "tool:foo:read tool:bar:write"}`; bind to the OAuth2/OpenID provider |
|
|
118
|
+
| Keycloak (< 26.5) | Client → Client Scopes → Mappers → new "Hardcoded claim" or "Script Mapper" emitting `mcp_tool_scopes` |
|
|
119
|
+
| Zitadel | Project → Roles + Action returning `{"mcp_tool_scopes": "..."}` from a pre-token script |
|
|
120
|
+
|
|
121
|
+
Keycloak ≥ 26.5 ships native MCP integration support; check its release notes before falling back to a custom claim.
|
|
122
|
+
|
|
123
|
+
### Bypass flag
|
|
124
|
+
|
|
125
|
+
For environments where no custom claim can be injected (managed services, restricted IdPs), set `MCP_AUTH_DISABLE_SCOPE_CHECKS=true` to bypass scope enforcement entirely.
|
|
126
|
+
|
|
127
|
+
| Variable | Default | Effect |
|
|
128
|
+
|:---------|:--------|:-------|
|
|
129
|
+
| `MCP_AUTH_DISABLE_SCOPE_CHECKS` | `false` | When `true`, both `withRequiredScopes` (declared `auth: [...]`) and `checkScopes` (runtime-computed scopes inside handlers) early-return after the auth-context presence check. Token signature, audience, issuer, and expiry validation remain intact. |
|
|
130
|
+
|
|
131
|
+
The flag bypasses **both** declared `auth: [...]` enforcement and runtime `checkScopes` calls — including tenant isolation patterns like `team:${input.teamId}:write`. Naming is deliberate: this disables all scope checks, not just per-tool ones. Applies to `MCP_AUTH_MODE=jwt` and `MCP_AUTH_MODE=oauth` (no effect under `none`).
|
|
132
|
+
|
|
133
|
+
A `WARNING`-level log is emitted at startup whenever the flag is active so operators don't lose track of it. Combine with server-side ACLs (path filters, allowlists, tenant rules) — without an in-handler ACL, every authenticated user effectively has every scope.
|
|
134
|
+
|
|
101
135
|
---
|
|
102
136
|
|
|
103
137
|
## Endpoints
|
|
@@ -160,7 +194,7 @@ Available on `ctx.auth` inside handlers (when auth is enabled):
|
|
|
160
194
|
```ts
|
|
161
195
|
interface AuthContext {
|
|
162
196
|
clientId: string; // Required — 'cid' or 'client_id' JWT claim
|
|
163
|
-
scopes: string[]; // Required —
|
|
197
|
+
scopes: string[]; // Required — union of 'scp', 'scope', and 'mcp_tool_scopes' claims
|
|
164
198
|
sub: string; // Required — 'sub' claim; falls back to clientId when absent
|
|
165
199
|
token: string; // Required — raw JWT or OAuth bearer token string
|
|
166
200
|
tenantId?: string; // Optional — 'tid' claim; present only for multi-tenant tokens
|
|
@@ -4,7 +4,7 @@ description: >
|
|
|
4
4
|
Reference for core and server configuration in `@cyanheads/mcp-ts-core`. Covers env var tables with defaults, priority order, server-specific Zod schema pattern, and Workers lazy-parsing requirement.
|
|
5
5
|
metadata:
|
|
6
6
|
author: cyanheads
|
|
7
|
-
version: "1.
|
|
7
|
+
version: "1.4"
|
|
8
8
|
audience: external
|
|
9
9
|
type: reference
|
|
10
10
|
---
|
|
@@ -68,6 +68,7 @@ Managed by `@cyanheads/mcp-ts-core`. Validated via Zod from environment variable
|
|
|
68
68
|
|:--------|:-----------------|:--------|:------|
|
|
69
69
|
| `MCP_AUTH_MODE` | `mcpAuthMode` | `none` | `none` \| `jwt` \| `oauth` |
|
|
70
70
|
| `MCP_AUTH_SECRET_KEY` | `mcpAuthSecretKey` | — | Required for `jwt` mode; min 32 chars |
|
|
71
|
+
| `MCP_AUTH_DISABLE_SCOPE_CHECKS` | `mcpAuthDisableScopeChecks` | `false` | When `true`, bypasses both `withRequiredScopes` (declared `auth: [...]`) and `checkScopes` (runtime/tenant scopes). Token validation (sig/aud/iss/exp) intact. Logs a `WARNING` at startup. See `api-auth` skill. |
|
|
71
72
|
| `OAUTH_ISSUER_URL` | `oauthIssuerUrl` | — | Required for `oauth` mode |
|
|
72
73
|
| `OAUTH_AUDIENCE` | `oauthAudience` | — | Required for `oauth` mode |
|
|
73
74
|
| `OAUTH_JWKS_URI` | `oauthJwksUri` | — | Override JWKS endpoint (otherwise derived from issuer) |
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: api-telemetry
|
|
3
|
+
description: >
|
|
4
|
+
Catalog of OpenTelemetry instrumentation built into framework `@cyanheads/mcp-ts-core` — spans, metrics, completion logs, env config, runtime caveats, custom instrumentation patterns, and cardinality rules. Use when enabling OTel export, adding custom spans or metrics in services, debugging missing telemetry, looking up attribute names, or deciding what's safe to put on a metric attribute vs. a span.
|
|
5
|
+
metadata:
|
|
6
|
+
author: cyanheads
|
|
7
|
+
version: "1.0"
|
|
8
|
+
audience: external
|
|
9
|
+
type: reference
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Overview
|
|
13
|
+
|
|
14
|
+
The framework auto-instruments every tool, resource, prompt, storage, LLM, speech, and graph call — each gets its own span and the standard counters/histograms. HTTP server requests pick up spans from `HttpInstrumentation` (or `@hono/otel` on the HTTP transport). Auth checks, session lifecycle, and task lifecycle are tracked as **metrics only** — auth decorates the active HTTP span with attributes, sessions and tasks emit counters.
|
|
15
|
+
|
|
16
|
+
`requestId`, `traceId`, and `tenantId` correlate automatically across spans, metrics, and logs. Pino logs get `trace_id`/`span_id` injected when a span is active.
|
|
17
|
+
|
|
18
|
+
For the helper API surface (`withSpan`, `createCounter`, `createHistogram`, `buildTraceparent`, etc.) — see the `api-utils` skill, `Telemetry` section. This skill is the catalog of **what** is emitted; that one is the reference for **how** to emit your own.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Enabling export
|
|
23
|
+
|
|
24
|
+
OTel is **off by default**. `OTEL_ENABLED=true` alone does nothing — you also need an OTLP endpoint. Without an endpoint the SDK is configured but nothing leaves the process.
|
|
25
|
+
|
|
26
|
+
| Env var | Default | Purpose |
|
|
27
|
+
|:--------|:--------|:--------|
|
|
28
|
+
| `OTEL_ENABLED` | `false` | Master switch. Must be `true` to start the SDK. |
|
|
29
|
+
| `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` | — | OTLP/HTTP traces endpoint (e.g. `http://localhost:4318/v1/traces`). |
|
|
30
|
+
| `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT` | — | OTLP/HTTP metrics endpoint (e.g. `http://localhost:4318/v1/metrics`). |
|
|
31
|
+
| `OTEL_SERVICE_NAME` | `package.json` `name` | `service.name` resource attribute. |
|
|
32
|
+
| `OTEL_SERVICE_VERSION` | `package.json` `version` | `service.version` resource attribute. |
|
|
33
|
+
| `OTEL_TRACES_SAMPLER_ARG` | `1.0` | Trace sampling ratio (0–1) for `TraceIdRatioBasedSampler`. |
|
|
34
|
+
| `OTEL_LOG_LEVEL` | `INFO` | OTel diagnostic logger level (`NONE`/`ERROR`/`WARN`/`INFO`/`DEBUG`/`VERBOSE`/`ALL`). |
|
|
35
|
+
|
|
36
|
+
Metrics push via `PeriodicExportingMetricReader` every **15 seconds**. Traces use `BatchSpanProcessor`.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Runtime support
|
|
41
|
+
|
|
42
|
+
| Runtime | Behavior |
|
|
43
|
+
|:--------|:---------|
|
|
44
|
+
| **Node.js / Bun** | Full `NodeSDK`. Auto-instrumentations: HTTP server (Node http hooks; skips `/healthz`), Pino logs (`trace_id`/`span_id` injection). On the HTTP transport, when OTel is enabled and `@hono/otel` is installed, `httpInstrumentationMiddleware` is also wired onto the MCP endpoint — fills the gap on Bun, where the Node http auto-instrumentation silently no-ops. Manual spans, custom metrics, and OTLP export work on Bun regardless. |
|
|
45
|
+
| **Cloudflare Workers / V8 isolates** | `NodeSDK` is unavailable. SDK init no-ops silently. `createCounter`/`createHistogram`/`withSpan` calls still work via the global OTel API but produce no output unless you wire a Worker-compatible exporter and `ctx.waitUntil()` for flush. |
|
|
46
|
+
|
|
47
|
+
Cloud platform detection auto-populates resource attributes:
|
|
48
|
+
|
|
49
|
+
| Detected | Attributes set |
|
|
50
|
+
|:---------|:--------------|
|
|
51
|
+
| Cloudflare Workers | `cloud.provider=cloudflare`, `cloud.platform=cloudflare_workers` |
|
|
52
|
+
| AWS Lambda | `cloud.provider=aws`, `cloud.platform=aws_lambda`, `cloud.region` from `AWS_REGION` |
|
|
53
|
+
| GCP Cloud Run / Functions | `cloud.provider=gcp`, `cloud.platform=gcp_cloud_run` (or `gcp_cloud_functions`), `cloud.region` from `GCP_REGION` |
|
|
54
|
+
| All | `deployment.environment.name` from `config.environment` |
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Spans
|
|
59
|
+
|
|
60
|
+
Every handler call gets a span. Nested operations (storage, graph, LLM) become child spans on the same trace. All spans carry `code.function.name` and `code.namespace` for code-attribution. Errors are recorded via `span.recordException()` and `SpanStatusCode.ERROR`; `McpError` codes surface as the `*.error_code` attribute.
|
|
61
|
+
|
|
62
|
+
| Span name | Source | Key attributes |
|
|
63
|
+
|:----------|:-------|:---------------|
|
|
64
|
+
| `tool_execution:<tool>` | every tool call | `mcp.tool.input_bytes`, `mcp.tool.output_bytes`, `mcp.tool.duration_ms`, `mcp.tool.success`, `mcp.tool.error_code`, `mcp.tool.partial_success`, `mcp.tool.batch.{succeeded,failed}_count` |
|
|
65
|
+
| `resource_read:<resource>` | every resource handler | `mcp.resource.uri`, `mcp.resource.mime_type`, `mcp.resource.size_bytes`, `mcp.resource.duration_ms`, `mcp.resource.success`, `mcp.resource.error_code` |
|
|
66
|
+
| `prompt_generation:<prompt>` | every prompt handler | `mcp.prompt.input_bytes`, `mcp.prompt.output_bytes`, `mcp.prompt.message_count`, `mcp.prompt.duration_ms`, `mcp.prompt.success`, `mcp.prompt.error_code` |
|
|
67
|
+
| `storage:<op>` | `StorageService` (every call) | `mcp.storage.operation`, `mcp.storage.duration_ms`, `mcp.storage.success`, `mcp.storage.key_count` (batch ops) |
|
|
68
|
+
| `graph:<op>` | `GraphService` (every call) | `mcp.graph.operation`, `mcp.graph.duration_ms`, `mcp.graph.success` |
|
|
69
|
+
| `gen_ai.chat_completion` | OpenRouter LLM provider | `gen_ai.system=openrouter`, `gen_ai.request.model`, `gen_ai.request.{max_tokens,temperature,top_p,streaming}`, `gen_ai.response.model`, `gen_ai.usage.{input,output,total}_tokens` |
|
|
70
|
+
| `speech:tts` | ElevenLabs provider | `mcp.speech.provider`, `mcp.speech.operation`, `mcp.speech.input_bytes`, `mcp.speech.output_bytes`, `mcp.speech.duration_ms`, `mcp.speech.success` |
|
|
71
|
+
| `speech:stt` | Whisper provider | same as `speech:tts` |
|
|
72
|
+
|
|
73
|
+
Trace context propagates across boundaries via W3C `traceparent` headers. See `api-utils` → `telemetry/trace` for `withSpan`, `buildTraceparent`, `extractTraceparent`, `createContextWithParentTrace`, `injectCurrentContextInto`, `runInContext` signatures.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Metrics
|
|
78
|
+
|
|
79
|
+
All custom metrics are namespaced `mcp.*` (or `process.*` / `http.client.*` where standard semconv applies). Lazy-initialized on first emission; the universal ones are eagerly created at startup so series exist from the first export cycle.
|
|
80
|
+
|
|
81
|
+
### Tools, resources, prompts
|
|
82
|
+
|
|
83
|
+
| Metric | Type | Unit | Attributes |
|
|
84
|
+
|:-------|:-----|:-----|:-----------|
|
|
85
|
+
| `mcp.tool.calls` | counter | `{calls}` | `mcp.tool.name`, `mcp.tool.success` |
|
|
86
|
+
| `mcp.tool.duration` | histogram | `ms` | `mcp.tool.name`, `mcp.tool.success` |
|
|
87
|
+
| `mcp.tool.errors` | counter | `{errors}` | `mcp.tool.name`, `mcp.tool.error_category` (`upstream`/`server`/`client`) |
|
|
88
|
+
| `mcp.tool.input_bytes` | histogram | `bytes` | `mcp.tool.name` |
|
|
89
|
+
| `mcp.tool.output_bytes` | histogram | `bytes` | `mcp.tool.name` |
|
|
90
|
+
| `mcp.tool.param.usage` | counter | `{uses}` | `mcp.tool.name`, `mcp.tool.param` (top-level keys supplied by caller) |
|
|
91
|
+
| `mcp.resource.reads` | counter | `{reads}` | `mcp.resource.name`, `mcp.resource.success` |
|
|
92
|
+
| `mcp.resource.duration` | histogram | `ms` | `mcp.resource.name`, `mcp.resource.success` |
|
|
93
|
+
| `mcp.resource.errors` | counter | `{errors}` | `mcp.resource.name` |
|
|
94
|
+
| `mcp.resource.output_bytes` | histogram | `bytes` | `mcp.resource.name` |
|
|
95
|
+
| `mcp.prompt.generations` | counter | `{generations}` | `mcp.prompt.name`, `mcp.prompt.success` |
|
|
96
|
+
| `mcp.prompt.duration` | histogram | `ms` | `mcp.prompt.name`, `mcp.prompt.success` |
|
|
97
|
+
| `mcp.prompt.errors` | counter | `{errors}` | `mcp.prompt.name`, `mcp.prompt.error_category` |
|
|
98
|
+
| `mcp.prompt.input_bytes` | histogram | `bytes` | `mcp.prompt.name` |
|
|
99
|
+
| `mcp.prompt.output_bytes` | histogram | `bytes` | `mcp.prompt.name` |
|
|
100
|
+
| `mcp.prompt.message_count` | histogram | `{messages}` | `mcp.prompt.name` |
|
|
101
|
+
| `mcp.requests.active` | up/down counter | `{requests}` | — (in-flight handler executions, all three types) |
|
|
102
|
+
|
|
103
|
+
### Storage, LLM, speech, graph
|
|
104
|
+
|
|
105
|
+
| Metric | Type | Unit | Attributes |
|
|
106
|
+
|:-------|:-----|:-----|:-----------|
|
|
107
|
+
| `mcp.storage.operations` | counter | `{ops}` | `mcp.storage.operation`, `mcp.storage.success` |
|
|
108
|
+
| `mcp.storage.duration` | histogram | `ms` | `mcp.storage.operation`, `mcp.storage.success` |
|
|
109
|
+
| `mcp.storage.errors` | counter | `{errors}` | `mcp.storage.operation` |
|
|
110
|
+
| `mcp.llm.requests` | counter | `{requests}` | `gen_ai.system`, `gen_ai.request.model` |
|
|
111
|
+
| `mcp.llm.duration` | histogram | `ms` | `gen_ai.system`, `gen_ai.request.model` |
|
|
112
|
+
| `mcp.llm.errors` | counter | `{errors}` | `gen_ai.system`, `gen_ai.request.model` |
|
|
113
|
+
| `mcp.llm.tokens` | counter | `{tokens}` | `gen_ai.request.model`, `gen_ai.token.type` (`input`/`output`) |
|
|
114
|
+
| `mcp.speech.operations` | counter | `{ops}` | `mcp.speech.operation` (`tts`/`stt`), `mcp.speech.provider`, `mcp.speech.success` |
|
|
115
|
+
| `mcp.speech.duration` | histogram | `ms` | `mcp.speech.operation`, `mcp.speech.provider` |
|
|
116
|
+
| `mcp.speech.errors` | counter | `{errors}` | `mcp.speech.operation`, `mcp.speech.provider` |
|
|
117
|
+
| `mcp.graph.operations` | counter | `{ops}` | `mcp.graph.operation`, `mcp.graph.success` |
|
|
118
|
+
| `mcp.graph.duration` | histogram | `ms` | `mcp.graph.operation`, `mcp.graph.success` |
|
|
119
|
+
| `mcp.graph.errors` | counter | `{errors}` | `mcp.graph.operation` |
|
|
120
|
+
|
|
121
|
+
### Transport, auth, sessions, tasks
|
|
122
|
+
|
|
123
|
+
| Metric | Type | Unit | Attributes |
|
|
124
|
+
|:-------|:-----|:-----|:-----------|
|
|
125
|
+
| `mcp.auth.attempts` | counter | `{attempts}` | `mcp.auth.outcome` (`success`/`failure`/`missing`), `mcp.auth.failure_reason` |
|
|
126
|
+
| `mcp.auth.duration` | histogram | `ms` | `mcp.auth.outcome`, `mcp.auth.failure_reason` |
|
|
127
|
+
| `mcp.sessions.events` | counter | `{events}` | `mcp.session.event` (`created`/`terminated`/`rejected`/`stale_cleanup`) |
|
|
128
|
+
| `mcp.session.duration` | histogram | `s` | — |
|
|
129
|
+
| `mcp.sessions.active` | observable gauge | `{sessions}` | — |
|
|
130
|
+
| `mcp.heartbeat.failures` | counter | `{failures}` | `mcp.connection.transport` (`stdio`/`http`) |
|
|
131
|
+
| `mcp.http.close_failures` | counter | `{failures}` | `surface` (`transport`/`server`), `trigger` (`success`/`error`/`sse-abort`) — per-request close threw or timed out |
|
|
132
|
+
| `mcp.http.per_request.created` | counter | `{instances}` | `kind` (`server`/`transport`) — per-request `McpServer` and `McpSessionTransport` instances created |
|
|
133
|
+
| `mcp.http.per_request.finalized` | counter | `{instances}` | `kind` (`server`/`transport`) — per-request instances reclaimed by GC; persistent gap vs `created` indicates a leak |
|
|
134
|
+
| `mcp.tasks.created` | counter | `{tasks}` | `mcp.task.store_type` (`in-memory`/`storage`) |
|
|
135
|
+
| `mcp.tasks.status_changes` | counter | `{transitions}` | `mcp.task.status`, `mcp.task.store_type` |
|
|
136
|
+
| `mcp.tasks.active` | observable gauge | `{tasks}` | — (in-memory store only) |
|
|
137
|
+
|
|
138
|
+
### Errors, rate limits, HTTP client
|
|
139
|
+
|
|
140
|
+
| Metric | Type | Unit | Attributes |
|
|
141
|
+
|:-------|:-----|:-----|:-----------|
|
|
142
|
+
| `mcp.errors.classified` | counter | `{errors}` | `mcp.error.classified_code` (JSON-RPC code), `operation` |
|
|
143
|
+
| `mcp.ratelimit.rejections` | counter | `{rejections}` | `mcp.rate_limit.key` |
|
|
144
|
+
| `http.client.request.duration` | histogram | `s` | `http.request.method`, `server.address`, `http.response.status_code` (when > 0; absent on network errors before a response is received) |
|
|
145
|
+
|
|
146
|
+
### Process
|
|
147
|
+
|
|
148
|
+
Auto-registered when `process.memoryUsage` / `process.uptime` / `perf_hooks` are available (Node/Bun, not Workers). The three memory gauges share a single `process.memoryUsage()` snapshot per collection cycle, refreshed at most every 100 ms.
|
|
149
|
+
|
|
150
|
+
| Metric | Type | Unit | Notes |
|
|
151
|
+
|:-------|:-----|:-----|:------|
|
|
152
|
+
| `process.memory.rss` | observable gauge | `bytes` | Resident set size |
|
|
153
|
+
| `process.memory.heap_used` | observable gauge | `bytes` | V8 heap used |
|
|
154
|
+
| `process.memory.heap_total` | observable gauge | `bytes` | V8 total heap |
|
|
155
|
+
| `process.uptime` | observable gauge | `s` | Process uptime |
|
|
156
|
+
| `process.event_loop.delay` | observable gauge | `ms` | p99 delay (`monitorEventLoopDelay` resolution=20) |
|
|
157
|
+
| `process.event_loop.utilization` | observable gauge | `1` | 0 = idle, 1 = saturated |
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Logs
|
|
162
|
+
|
|
163
|
+
Pino logs are auto-instrumented by `@opentelemetry/instrumentation-pino`. When a span is active, `trace_id` and `span_id` are injected into the record. Combined with the framework logger's automatic `requestId`/`tenantId` correlation, every log line is searchable by trace.
|
|
164
|
+
|
|
165
|
+
For domain logging inside handlers, use `ctx.log` (`debug`/`info`/`notice`/`warning`/`error`) — auto-includes `requestId`, `traceId`, `tenantId`, `spanId`. The completion log emitted at the end of every handler carries a `metrics` payload, with fields tuned to each surface:
|
|
166
|
+
|
|
167
|
+
| Handler | Log message | `metrics` fields |
|
|
168
|
+
|:--------|:------------|:-----------------|
|
|
169
|
+
| Tool | `Tool execution finished.` | `durationMs`, `isSuccess`, `errorCode`, `inputBytes`, `outputBytes`, plus `partialSuccess` / `batchSucceeded` / `batchFailed` when the result is a partial-success batch |
|
|
170
|
+
| Resource | `Resource read finished.` | `durationMs`, `isSuccess`, `errorCode`, `outputBytes`, `uri`, `mimeType` |
|
|
171
|
+
| Prompt | `Prompt generation finished.` (or `failed.`) | `durationMs`, `isSuccess`, `errorCode`, `inputBytes`, `outputBytes`, `messageCount` |
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Custom instrumentation
|
|
176
|
+
|
|
177
|
+
Need a span or metric for your own service? Use the helpers from `@cyanheads/mcp-ts-core/utils` (full signatures in `api-utils` → `Telemetry`):
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
import { withSpan, createCounter, createHistogram } from '@cyanheads/mcp-ts-core/utils';
|
|
181
|
+
|
|
182
|
+
const myOps = createCounter('myservice.operations', 'My service ops', '{ops}');
|
|
183
|
+
const myDuration = createHistogram('myservice.duration', 'My service duration', 'ms');
|
|
184
|
+
|
|
185
|
+
export async function doWork() {
|
|
186
|
+
return withSpan('myservice.do_work', async (span) => {
|
|
187
|
+
const t0 = performance.now();
|
|
188
|
+
try {
|
|
189
|
+
const result = await reallyDoWork();
|
|
190
|
+
span.setAttribute('myservice.items', result.length);
|
|
191
|
+
return result;
|
|
192
|
+
} finally {
|
|
193
|
+
myDuration.record(performance.now() - t0);
|
|
194
|
+
myOps.add(1);
|
|
195
|
+
}
|
|
196
|
+
}, { 'myservice.region': 'us-west' });
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Span context propagates automatically — `withSpan` calls inside a `tool_execution:*` span appear as children. `runInContext(ctx, fn)` carries the active OTel context across async boundaries (`setTimeout`, `queueMicrotask`).
|
|
201
|
+
|
|
202
|
+
For attribute keys, prefer the `ATTR_*` constants exported from `@cyanheads/mcp-ts-core/utils` (telemetry/attributes) over hand-typed strings — keeps you in step with framework conventions and avoids typos. Standard OTel semantic conventions (HTTP, cloud, service, network, etc.) are NOT re-exported — import those directly from `@opentelemetry/semantic-conventions`.
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## Visualization
|
|
207
|
+
|
|
208
|
+
An example Grafana dashboard JSON and vendor-agnostic query recipes (Prometheus, Datadog, New Relic, Honeycomb) live at [`docs/telemetry/`](https://github.com/cyanheads/mcp-ts-core/tree/main/docs/telemetry) in the framework source — not bundled in the npm package, so consult the GitHub repo.
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## Cardinality discipline
|
|
213
|
+
|
|
214
|
+
Series are cheap to emit but expensive to store and query. The framework deliberately keeps high-cardinality identifiers off metric attributes and on spans only. Follow the same rule when adding your own metrics.
|
|
215
|
+
|
|
216
|
+
| On metrics | On spans / logs only |
|
|
217
|
+
|:-----------|:---------------------|
|
|
218
|
+
| `mcp.resource.name` (URI template) | `mcp.resource.uri` (full URI with IDs) |
|
|
219
|
+
| `gen_ai.request.model` (bounded enum) | `mcp.tenant.id`, `mcp.client.id`, `mcp.auth.subject` |
|
|
220
|
+
| Bounded enum / template strings | Per-request unique IDs, free-form user input, opaque tokens |
|
|
221
|
+
|
|
222
|
+
When in doubt: if the attribute can take more than ~100 distinct values across a fleet's runtime, it belongs on the span, not the metric.
|
|
@@ -4,7 +4,7 @@ description: >
|
|
|
4
4
|
API reference for all utilities exported from `@cyanheads/mcp-ts-core/utils`. Use when looking up utility method signatures, options, peer dependencies, or usage patterns.
|
|
5
5
|
metadata:
|
|
6
6
|
author: cyanheads
|
|
7
|
-
version: "2.
|
|
7
|
+
version: "2.2"
|
|
8
8
|
audience: external
|
|
9
9
|
type: reference
|
|
10
10
|
---
|
|
@@ -136,6 +136,8 @@ Both functions throw `McpError(InternalError)` only on unexpected heuristic fail
|
|
|
136
136
|
|
|
137
137
|
## `@cyanheads/mcp-ts-core/utils` — Telemetry
|
|
138
138
|
|
|
139
|
+
Helper API only. For the catalog of what the framework auto-emits (span names, metric names, attributes, completion log fields, env config, runtime support, cardinality rules), see the `api-telemetry` skill.
|
|
140
|
+
|
|
139
141
|
### `telemetry/instrumentation`
|
|
140
142
|
|
|
141
143
|
| Export | Signature | Notes |
|
|
@@ -4,7 +4,7 @@ description: >
|
|
|
4
4
|
Investigate, adopt, and verify dependency updates — with special handling for `@cyanheads/mcp-ts-core`. Captures what changed, understands why, cross-references against the codebase, adopts framework improvements, syncs project skills, and runs final checks. Supports two entry modes: run the full flow end-to-end, or review updates you already applied.
|
|
5
5
|
metadata:
|
|
6
6
|
author: cyanheads
|
|
7
|
-
version: "2.
|
|
7
|
+
version: "2.1"
|
|
8
8
|
audience: external
|
|
9
9
|
type: workflow
|
|
10
10
|
---
|
|
@@ -120,9 +120,11 @@ For each agent directory that exists:
|
|
|
120
120
|
|
|
121
121
|
If no agent directory exists, skip Phase B — the project hasn't opted in to per-agent skill copies.
|
|
122
122
|
|
|
123
|
-
**Phase C — Package
|
|
123
|
+
**Phase C — Package framework files → Project**
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
Two categories of framework-authored files ship into consumer projects and drift silently as the framework updates them. Both follow the same hash-compare-and-overwrite mechanic.
|
|
126
|
+
|
|
127
|
+
**Scripts** — `init` scaffolds a fixed set that underpin `bun run build`, `bun run devcheck`, `bun run lint:mcp`, `bun run tree`, and the changelog build. Iterate the package's shipped scripts directory:
|
|
126
128
|
|
|
127
129
|
```bash
|
|
128
130
|
for src in node_modules/@cyanheads/mcp-ts-core/scripts/*.ts; do
|
|
@@ -140,9 +142,17 @@ done
|
|
|
140
142
|
|
|
141
143
|
Scripts in `scripts/` that aren't present in the package directory are project-specific (custom deploy, codegen, etc.) — leave them alone. The package's `files:` field gates what ships into `node_modules/.../scripts/`, so enumerating that directory is the canonical "shipped scripts" set.
|
|
142
144
|
|
|
143
|
-
|
|
145
|
+
**Pristine reference files** — files explicitly documented as "never edit, rename, or move." The framework keeps the authoritative copy under `templates/`; the consumer's copy must track upstream as the format evolves (new frontmatter fields, section reorderings, etc.). Fixed src→dst mapping:
|
|
146
|
+
|
|
147
|
+
| Source (in package) | Destination (in project) |
|
|
148
|
+
|:--|:--|
|
|
149
|
+
| `templates/changelog/template.md` | `changelog/template.md` |
|
|
150
|
+
|
|
151
|
+
Apply the same compare-and-overwrite logic. Add new entries here only when a template is explicitly documented as pristine in the framework's CLAUDE.md or its own header.
|
|
152
|
+
|
|
153
|
+
If the consumer customized a framework script or pristine reference (against guidance), the overwrite discards those changes. After the sync runs, diff `scripts/` and the affected template paths to surface replacements — review before committing. If a specific local customization needs to be preserved, revert that file using your git tools.
|
|
144
154
|
|
|
145
|
-
**Report** which skills were added/updated in Phase A (with version deltas), which agent directories were refreshed in Phase B, and which scripts were resynced in Phase C. The user needs to know what new guidance and tooling is now in play.
|
|
155
|
+
**Report** which skills were added/updated in Phase A (with version deltas), which agent directories were refreshed in Phase B, and which scripts and pristine reference files were resynced in Phase C. The user needs to know what new guidance and tooling is now in play.
|
|
146
156
|
|
|
147
157
|
### 6. Adopt changes in the codebase
|
|
148
158
|
|
|
@@ -212,7 +222,7 @@ Present a concise numbered summary to the user:
|
|
|
212
222
|
- [ ] Every applicable framework adoption opportunity applied in this pass — no scope/effort/marginal-benefit deferrals; third-party adoptions evaluated on cost/benefit
|
|
213
223
|
- [ ] Project `skills/` synced from package (Phase A), with a change report
|
|
214
224
|
- [ ] Agent skill directories (`.claude/skills/`, `.agents/skills/`, etc.) refreshed from project `skills/` (Phase B)
|
|
215
|
-
- [ ] Framework `scripts/` resynced from package via content-hash compare (Phase C), with a change report;
|
|
225
|
+
- [ ] Framework `scripts/` and pristine reference files resynced from package via content-hash compare (Phase C), with a change report; diffs reviewed before committing
|
|
216
226
|
- [ ] `bun run rebuild` succeeds
|
|
217
227
|
- [ ] `bun run devcheck` passes (includes audit + outdated)
|
|
218
228
|
- [ ] `bun run test` passes
|