@yhuan416/mcp-kit 0.0.0-stage → 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 (52) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +21 -0
  3. package/README.md +134 -2
  4. package/dist/env.cjs +114 -0
  5. package/dist/env.cjs.map +1 -0
  6. package/dist/env.d.cts +41 -0
  7. package/dist/env.d.ts +41 -0
  8. package/dist/env.js +105 -0
  9. package/dist/env.js.map +1 -0
  10. package/dist/http/index.cjs +567 -0
  11. package/dist/http/index.cjs.map +1 -0
  12. package/dist/http/index.d.cts +118 -0
  13. package/dist/http/index.d.ts +118 -0
  14. package/dist/http/index.js +555 -0
  15. package/dist/http/index.js.map +1 -0
  16. package/dist/index.cjs +460 -0
  17. package/dist/index.cjs.map +1 -0
  18. package/dist/index.d.cts +131 -0
  19. package/dist/index.d.ts +131 -0
  20. package/dist/index.js +432 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/info/index.cjs +376 -0
  23. package/dist/info/index.cjs.map +1 -0
  24. package/dist/info/index.d.cts +47 -0
  25. package/dist/info/index.d.ts +47 -0
  26. package/dist/info/index.js +363 -0
  27. package/dist/info/index.js.map +1 -0
  28. package/dist/testing/client.cjs +53 -0
  29. package/dist/testing/client.cjs.map +1 -0
  30. package/dist/testing/client.d.cts +33 -0
  31. package/dist/testing/client.d.ts +33 -0
  32. package/dist/testing/client.js +50 -0
  33. package/dist/testing/client.js.map +1 -0
  34. package/dist/testing/conformance.cjs +117 -0
  35. package/dist/testing/conformance.cjs.map +1 -0
  36. package/dist/testing/conformance.d.cts +26 -0
  37. package/dist/testing/conformance.d.ts +26 -0
  38. package/dist/testing/conformance.js +112 -0
  39. package/dist/testing/conformance.js.map +1 -0
  40. package/dist/types-D6AKhA-v.d.cts +95 -0
  41. package/dist/types-D6AKhA-v.d.ts +95 -0
  42. package/dist/types-DU3WHzhD.d.cts +76 -0
  43. package/dist/types-DU3WHzhD.d.ts +76 -0
  44. package/docs/contracts/env.md +77 -0
  45. package/docs/contracts/http.md +159 -0
  46. package/docs/contracts/info.md +133 -0
  47. package/docs/contracts/result.md +109 -0
  48. package/docs/contracts/tools.md +139 -0
  49. package/docs/migration.md +133 -0
  50. package/docs/release.md +106 -0
  51. package/docs/security.md +77 -0
  52. package/package.json +111 -4
@@ -0,0 +1,117 @@
1
+ 'use strict';
2
+
3
+ // src/testing/conformance.ts
4
+ var TOOL_NAME = /^[a-z][a-z0-9_-]{0,127}$/;
5
+ var SECRET_KEY = /^(token|password|secret|api[_-]?key|private[_-]?key)$/i;
6
+ function checkToolDefinitions(tools, options = {}) {
7
+ const issues = [];
8
+ const names = /* @__PURE__ */ new Set();
9
+ for (const tool of tools) {
10
+ if (!tool?.name) {
11
+ issues.push({ level: "error", code: "TOOL_NAME_MISSING", message: "tool has no name" });
12
+ continue;
13
+ }
14
+ if (names.has(tool.name)) {
15
+ issues.push({
16
+ level: "error",
17
+ code: "TOOL_NAME_DUPLICATE",
18
+ message: `duplicate tool name: ${tool.name}`
19
+ });
20
+ }
21
+ names.add(tool.name);
22
+ if (!TOOL_NAME.test(tool.name)) {
23
+ issues.push({
24
+ level: "warn",
25
+ code: "TOOL_NAME_FORMAT",
26
+ message: `${tool.name}: prefer lower_snake_case (A-Z, a-z, 0-9, _, -)`
27
+ });
28
+ }
29
+ if (!tool.description?.trim()) {
30
+ issues.push({
31
+ level: "error",
32
+ code: "TOOL_DESCRIPTION_MISSING",
33
+ message: `${tool.name}: description is required`
34
+ });
35
+ }
36
+ if (!tool.inputSchema?.["~standard"]) {
37
+ issues.push({
38
+ level: "error",
39
+ code: "TOOL_SCHEMA_MISSING",
40
+ message: `${tool.name}: inputSchema must be a Standard Schema`
41
+ });
42
+ }
43
+ if (!tool.annotations) {
44
+ issues.push({
45
+ level: "warn",
46
+ code: "TOOL_ANNOTATIONS_MISSING",
47
+ message: `${tool.name}: add readOnly/destructive/idempotent/openWorld annotations`
48
+ });
49
+ }
50
+ }
51
+ if (options.requireServiceInfo !== false && !names.has("service_info")) {
52
+ issues.push({
53
+ level: "warn",
54
+ code: "SERVICE_INFO_MISSING",
55
+ message: "no service_info tool registered"
56
+ });
57
+ }
58
+ return issues;
59
+ }
60
+ function checkSecretKeys(section, path, issues) {
61
+ if (!section) return;
62
+ for (const key of Object.keys(section)) {
63
+ if (SECRET_KEY.test(key)) {
64
+ issues.push({
65
+ level: "error",
66
+ code: "INFO_SECRET_KEY",
67
+ message: `${path}.${key}: /info must not expose secret fields`
68
+ });
69
+ }
70
+ }
71
+ }
72
+ function checkServiceInfo(info) {
73
+ const issues = [];
74
+ if (info.contract !== "info/1") {
75
+ issues.push({
76
+ level: "error",
77
+ code: "INFO_CONTRACT",
78
+ message: `contract must be "info/1" (got ${String(info.contract)})`
79
+ });
80
+ }
81
+ if (!info.service) {
82
+ issues.push({ level: "error", code: "INFO_SERVICE", message: "service is required" });
83
+ }
84
+ if (!info.version) {
85
+ issues.push({ level: "error", code: "INFO_VERSION", message: "version is required" });
86
+ }
87
+ const uptime = info.deployment?.uptimeSeconds;
88
+ if (uptime !== void 0 && typeof uptime !== "number") {
89
+ issues.push({
90
+ level: "error",
91
+ code: "INFO_UPTIME_TYPE",
92
+ message: "deployment.uptimeSeconds must be a number"
93
+ });
94
+ }
95
+ checkSecretKeys(info.deployment, "deployment", issues);
96
+ checkSecretKeys(info.storage, "storage", issues);
97
+ checkSecretKeys(info.limits, "limits", issues);
98
+ return issues;
99
+ }
100
+ function formatIssues(issues) {
101
+ return issues.map((issue) => `${issue.level.toUpperCase()} ${issue.code}: ${issue.message}`).join("\n");
102
+ }
103
+ function assertConformant(issues, options = {}) {
104
+ const errors = issues.filter((issue) => issue.level === "error");
105
+ const warnings = issues.filter((issue) => issue.level === "warn");
106
+ if (errors.length || !options.allowWarnings && warnings.length) {
107
+ throw new Error(`MCP conformance failed:
108
+ ${formatIssues([...errors, ...warnings])}`);
109
+ }
110
+ }
111
+
112
+ exports.assertConformant = assertConformant;
113
+ exports.checkServiceInfo = checkServiceInfo;
114
+ exports.checkToolDefinitions = checkToolDefinitions;
115
+ exports.formatIssues = formatIssues;
116
+ //# sourceMappingURL=conformance.cjs.map
117
+ //# sourceMappingURL=conformance.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/testing/conformance.ts"],"names":[],"mappings":";;;AASA,IAAM,SAAA,GAAY,0BAAA;AAClB,IAAM,UAAA,GAAa,wDAAA;AAQZ,SAAS,oBAAA,CACd,KAAA,EACA,OAAA,GAA8B,EAAC,EACX;AACpB,EAAA,MAAM,SAA6B,EAAC;AACpC,EAAA,MAAM,KAAA,uBAAY,GAAA,EAAY;AAE9B,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,IAAI,CAAC,MAAM,IAAA,EAAM;AACf,MAAA,MAAA,CAAO,IAAA,CAAK,EAAE,KAAA,EAAO,OAAA,EAAS,MAAM,mBAAA,EAAqB,OAAA,EAAS,oBAAoB,CAAA;AACtF,MAAA;AAAA,IACF;AACA,IAAA,IAAI,KAAA,CAAM,GAAA,CAAI,IAAA,CAAK,IAAI,CAAA,EAAG;AACxB,MAAA,MAAA,CAAO,IAAA,CAAK;AAAA,QACV,KAAA,EAAO,OAAA;AAAA,QACP,IAAA,EAAM,qBAAA;AAAA,QACN,OAAA,EAAS,CAAA,qBAAA,EAAwB,IAAA,CAAK,IAAI,CAAA;AAAA,OAC3C,CAAA;AAAA,IACH;AACA,IAAA,KAAA,CAAM,GAAA,CAAI,KAAK,IAAI,CAAA;AAEnB,IAAA,IAAI,CAAC,SAAA,CAAU,IAAA,CAAK,IAAA,CAAK,IAAI,CAAA,EAAG;AAC9B,MAAA,MAAA,CAAO,IAAA,CAAK;AAAA,QACV,KAAA,EAAO,MAAA;AAAA,QACP,IAAA,EAAM,kBAAA;AAAA,QACN,OAAA,EAAS,CAAA,EAAG,IAAA,CAAK,IAAI,CAAA,+CAAA;AAAA,OACtB,CAAA;AA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,EAAc,MAAM,CAAA;AACrD,EAAA,eAAA,CAAgB,IAAA,CAAK,OAAA,EAAS,SAAA,EAAW,MAAM,CAAA;AAC/C,EAAA,eAAA,CAAgB,IAAA,CAAK,MAAA,EAAQ,QAAA,EAAU,MAAM,CAAA;AAC7C,EAAA,OAAO,MAAA;AACT;AAEO,SAAS,aAAa,MAAA,EAAoC;AAC/D,EAAA,OAAO,OACJ,GAAA,CAAI,CAAC,UAAU,CAAA,EAAG,KAAA,CAAM,MAAM,WAAA,EAAa,CAAA,CAAA,EAAI,KAAA,CAAM,IAAI,CAAA,EAAA,EAAK,KAAA,CAAM,OAAO,CAAA,CAAE,CAAA,CAC7E,KAAK,IAAI,CAAA;AACd;AAGO,SAAS,gBAAA,CACd,MAAA,EACA,OAAA,GAAuC,EAAC,EAClC;AACN,EAAA,MAAM,SAAS,MAAA,CAAO,MAAA,CAAO,CAAC,KAAA,KAAU,KAAA,CAAM,UAAU,OAAO,CAAA;AAC/D,EAAA,MAAM,WAAW,MAAA,CAAO,MAAA,CAAO,CAAC,KAAA,KAAU,KAAA,CAAM,UAAU,MAAM,CAAA;AAChE,EAAA,IAAI,OAAO,MAAA,IAAW,CAAC,OAAA,CAAQ,aAAA,IAAiB,SAAS,MAAA,EAAS;AAChE,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA;AAAA,EAA4B,YAAA,CAAa,CAAC,GAAG,MAAA,EAAQ,GAAG,QAAQ,CAAC,CAAC,CAAA,CAAE,CAAA;AAAA,EACtF;AACF","file":"conformance.cjs","sourcesContent":["import type { ServiceInfo } from \"../info/types.js\";\nimport type { ToolDefinition } from \"../types.js\";\n\nexport interface ConformanceIssue {\n level: \"error\" | \"warn\";\n code: string;\n message: string;\n}\n\nconst TOOL_NAME = /^[a-z][a-z0-9_-]{0,127}$/;\nconst SECRET_KEY = /^(token|password|secret|api[_-]?key|private[_-]?key)$/i;\n\nexport interface ConformanceOptions {\n /** Require a `service_info` tool. Defaults to true. */\n requireServiceInfo?: boolean;\n}\n\n/** Check tool definitions against the kit's tool contract. */\nexport function checkToolDefinitions(\n tools: ToolDefinition<any>[],\n options: ConformanceOptions = {},\n): ConformanceIssue[] {\n const issues: ConformanceIssue[] = [];\n const names = new Set<string>();\n\n for (const tool of tools) {\n if (!tool?.name) {\n issues.push({ level: \"error\", code: \"TOOL_NAME_MISSING\", message: \"tool has no name\" });\n continue;\n }\n if (names.has(tool.name)) {\n issues.push({\n level: \"error\",\n code: \"TOOL_NAME_DUPLICATE\",\n message: `duplicate tool name: ${tool.name}`,\n });\n }\n names.add(tool.name);\n\n if (!TOOL_NAME.test(tool.name)) {\n issues.push({\n level: \"warn\",\n code: \"TOOL_NAME_FORMAT\",\n message: `${tool.name}: prefer lower_snake_case (A-Z, a-z, 0-9, _, -)`,\n });\n }\n if (!tool.description?.trim()) {\n issues.push({\n level: \"error\",\n code: \"TOOL_DESCRIPTION_MISSING\",\n message: `${tool.name}: description is required`,\n });\n }\n if (!tool.inputSchema?.[\"~standard\"]) {\n issues.push({\n level: \"error\",\n code: \"TOOL_SCHEMA_MISSING\",\n message: `${tool.name}: inputSchema must be a Standard Schema`,\n });\n }\n if (!tool.annotations) {\n issues.push({\n level: \"warn\",\n code: \"TOOL_ANNOTATIONS_MISSING\",\n message: `${tool.name}: add readOnly/destructive/idempotent/openWorld annotations`,\n });\n }\n }\n\n if (options.requireServiceInfo !== false && !names.has(\"service_info\")) {\n issues.push({\n level: \"warn\",\n code: \"SERVICE_INFO_MISSING\",\n message: \"no service_info tool registered\",\n });\n }\n\n return issues;\n}\n\nfunction checkSecretKeys(\n section: Record<string, unknown> | undefined,\n path: string,\n issues: ConformanceIssue[],\n): void {\n if (!section) return;\n for (const key of Object.keys(section)) {\n if (SECRET_KEY.test(key)) {\n issues.push({\n level: \"error\",\n code: \"INFO_SECRET_KEY\",\n message: `${path}.${key}: /info must not expose secret fields`,\n });\n }\n }\n}\n\n/** Check an `info/1` payload for the parts that must stay stable. */\nexport function checkServiceInfo(info: ServiceInfo): ConformanceIssue[] {\n const issues: ConformanceIssue[] = [];\n if (info.contract !== \"info/1\") {\n issues.push({\n level: \"error\",\n code: \"INFO_CONTRACT\",\n message: `contract must be \"info/1\" (got ${String(info.contract)})`,\n });\n }\n if (!info.service) {\n issues.push({ level: \"error\", code: \"INFO_SERVICE\", message: \"service is required\" });\n }\n if (!info.version) {\n issues.push({ level: \"error\", code: \"INFO_VERSION\", message: \"version is required\" });\n }\n const uptime = info.deployment?.uptimeSeconds;\n if (uptime !== undefined && typeof uptime !== \"number\") {\n issues.push({\n level: \"error\",\n code: \"INFO_UPTIME_TYPE\",\n message: \"deployment.uptimeSeconds must be a number\",\n });\n }\n checkSecretKeys(info.deployment, \"deployment\", issues);\n checkSecretKeys(info.storage, \"storage\", issues);\n checkSecretKeys(info.limits, \"limits\", issues);\n return issues;\n}\n\nexport function formatIssues(issues: ConformanceIssue[]): string {\n return issues\n .map((issue) => `${issue.level.toUpperCase()} ${issue.code}: ${issue.message}`)\n .join(\"\\n\");\n}\n\n/** Throw when any error-level issue is present. */\nexport function assertConformant(\n issues: ConformanceIssue[],\n options: { allowWarnings?: boolean } = {},\n): void {\n const errors = issues.filter((issue) => issue.level === \"error\");\n const warnings = issues.filter((issue) => issue.level === \"warn\");\n if (errors.length || (!options.allowWarnings && warnings.length)) {\n throw new Error(`MCP conformance failed:\\n${formatIssues([...errors, ...warnings])}`);\n }\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import { ServiceInfo } from '../info/index.cjs';
2
+ import { ToolDefinition } from '../index.cjs';
3
+ import 'node:http';
4
+ import '@modelcontextprotocol/server';
5
+
6
+ interface ConformanceIssue {
7
+ level: "error" | "warn";
8
+ code: string;
9
+ message: string;
10
+ }
11
+ interface ConformanceOptions {
12
+ /** Require a `service_info` tool. Defaults to true. */
13
+ requireServiceInfo?: boolean;
14
+ }
15
+ /** Check tool definitions against the kit's tool contract. */
16
+ declare function checkToolDefinitions(tools: ToolDefinition<any>[], options?: ConformanceOptions): ConformanceIssue[];
17
+ /** Check an `info/1` payload for the parts that must stay stable. */
18
+ declare function checkServiceInfo(info: ServiceInfo): ConformanceIssue[];
19
+ declare function formatIssues(issues: ConformanceIssue[]): string;
20
+ /** Throw when any error-level issue is present. */
21
+ declare function assertConformant(issues: ConformanceIssue[], options?: {
22
+ allowWarnings?: boolean;
23
+ }): void;
24
+
25
+ export { assertConformant, checkServiceInfo, checkToolDefinitions, formatIssues };
26
+ export type { ConformanceIssue, ConformanceOptions };
@@ -0,0 +1,26 @@
1
+ import { ServiceInfo } from '../info/index.js';
2
+ import { ToolDefinition } from '../index.js';
3
+ import 'node:http';
4
+ import '@modelcontextprotocol/server';
5
+
6
+ interface ConformanceIssue {
7
+ level: "error" | "warn";
8
+ code: string;
9
+ message: string;
10
+ }
11
+ interface ConformanceOptions {
12
+ /** Require a `service_info` tool. Defaults to true. */
13
+ requireServiceInfo?: boolean;
14
+ }
15
+ /** Check tool definitions against the kit's tool contract. */
16
+ declare function checkToolDefinitions(tools: ToolDefinition<any>[], options?: ConformanceOptions): ConformanceIssue[];
17
+ /** Check an `info/1` payload for the parts that must stay stable. */
18
+ declare function checkServiceInfo(info: ServiceInfo): ConformanceIssue[];
19
+ declare function formatIssues(issues: ConformanceIssue[]): string;
20
+ /** Throw when any error-level issue is present. */
21
+ declare function assertConformant(issues: ConformanceIssue[], options?: {
22
+ allowWarnings?: boolean;
23
+ }): void;
24
+
25
+ export { assertConformant, checkServiceInfo, checkToolDefinitions, formatIssues };
26
+ export type { ConformanceIssue, ConformanceOptions };
@@ -0,0 +1,112 @@
1
+ // src/testing/conformance.ts
2
+ var TOOL_NAME = /^[a-z][a-z0-9_-]{0,127}$/;
3
+ var SECRET_KEY = /^(token|password|secret|api[_-]?key|private[_-]?key)$/i;
4
+ function checkToolDefinitions(tools, options = {}) {
5
+ const issues = [];
6
+ const names = /* @__PURE__ */ new Set();
7
+ for (const tool of tools) {
8
+ if (!tool?.name) {
9
+ issues.push({ level: "error", code: "TOOL_NAME_MISSING", message: "tool has no name" });
10
+ continue;
11
+ }
12
+ if (names.has(tool.name)) {
13
+ issues.push({
14
+ level: "error",
15
+ code: "TOOL_NAME_DUPLICATE",
16
+ message: `duplicate tool name: ${tool.name}`
17
+ });
18
+ }
19
+ names.add(tool.name);
20
+ if (!TOOL_NAME.test(tool.name)) {
21
+ issues.push({
22
+ level: "warn",
23
+ code: "TOOL_NAME_FORMAT",
24
+ message: `${tool.name}: prefer lower_snake_case (A-Z, a-z, 0-9, _, -)`
25
+ });
26
+ }
27
+ if (!tool.description?.trim()) {
28
+ issues.push({
29
+ level: "error",
30
+ code: "TOOL_DESCRIPTION_MISSING",
31
+ message: `${tool.name}: description is required`
32
+ });
33
+ }
34
+ if (!tool.inputSchema?.["~standard"]) {
35
+ issues.push({
36
+ level: "error",
37
+ code: "TOOL_SCHEMA_MISSING",
38
+ message: `${tool.name}: inputSchema must be a Standard Schema`
39
+ });
40
+ }
41
+ if (!tool.annotations) {
42
+ issues.push({
43
+ level: "warn",
44
+ code: "TOOL_ANNOTATIONS_MISSING",
45
+ message: `${tool.name}: add readOnly/destructive/idempotent/openWorld annotations`
46
+ });
47
+ }
48
+ }
49
+ if (options.requireServiceInfo !== false && !names.has("service_info")) {
50
+ issues.push({
51
+ level: "warn",
52
+ code: "SERVICE_INFO_MISSING",
53
+ message: "no service_info tool registered"
54
+ });
55
+ }
56
+ return issues;
57
+ }
58
+ function checkSecretKeys(section, path, issues) {
59
+ if (!section) return;
60
+ for (const key of Object.keys(section)) {
61
+ if (SECRET_KEY.test(key)) {
62
+ issues.push({
63
+ level: "error",
64
+ code: "INFO_SECRET_KEY",
65
+ message: `${path}.${key}: /info must not expose secret fields`
66
+ });
67
+ }
68
+ }
69
+ }
70
+ function checkServiceInfo(info) {
71
+ const issues = [];
72
+ if (info.contract !== "info/1") {
73
+ issues.push({
74
+ level: "error",
75
+ code: "INFO_CONTRACT",
76
+ message: `contract must be "info/1" (got ${String(info.contract)})`
77
+ });
78
+ }
79
+ if (!info.service) {
80
+ issues.push({ level: "error", code: "INFO_SERVICE", message: "service is required" });
81
+ }
82
+ if (!info.version) {
83
+ issues.push({ level: "error", code: "INFO_VERSION", message: "version is required" });
84
+ }
85
+ const uptime = info.deployment?.uptimeSeconds;
86
+ if (uptime !== void 0 && typeof uptime !== "number") {
87
+ issues.push({
88
+ level: "error",
89
+ code: "INFO_UPTIME_TYPE",
90
+ message: "deployment.uptimeSeconds must be a number"
91
+ });
92
+ }
93
+ checkSecretKeys(info.deployment, "deployment", issues);
94
+ checkSecretKeys(info.storage, "storage", issues);
95
+ checkSecretKeys(info.limits, "limits", issues);
96
+ return issues;
97
+ }
98
+ function formatIssues(issues) {
99
+ return issues.map((issue) => `${issue.level.toUpperCase()} ${issue.code}: ${issue.message}`).join("\n");
100
+ }
101
+ function assertConformant(issues, options = {}) {
102
+ const errors = issues.filter((issue) => issue.level === "error");
103
+ const warnings = issues.filter((issue) => issue.level === "warn");
104
+ if (errors.length || !options.allowWarnings && warnings.length) {
105
+ throw new Error(`MCP conformance failed:
106
+ ${formatIssues([...errors, ...warnings])}`);
107
+ }
108
+ }
109
+
110
+ export { assertConformant, checkServiceInfo, checkToolDefinitions, formatIssues };
111
+ //# sourceMappingURL=conformance.js.map
112
+ //# sourceMappingURL=conformance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/testing/conformance.ts"],"names":[],"mappings":";AASA,IAAM,SAAA,GAAY,0BAAA;AAClB,IAAM,UAAA,GAAa,wDAAA;AAQZ,SAAS,oBAAA,CACd,KAAA,EACA,OAAA,GAA8B,EAAC,EACX;AACpB,EAAA,MAAM,SAA6B,EAAC;AACpC,EAAA,MAAM,KAAA,uBAAY,GAAA,EAAY;AAE9B,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,IAAI,CAAC,MAAM,IAAA,EAAM;AACf,MAAA,MAAA,CAAO,IAAA,CAAK,EAAE,KAAA,EAAO,OAAA,EAAS,MAAM,mBAAA,EAAqB,O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AAA,MAAM,WAAW,MAAA,CAAO,MAAA,CAAO,CAAC,KAAA,KAAU,KAAA,CAAM,UAAU,MAAM,CAAA;AAChE,EAAA,IAAI,OAAO,MAAA,IAAW,CAAC,OAAA,CAAQ,aAAA,IAAiB,SAAS,MAAA,EAAS;AAChE,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA;AAAA,EAA4B,YAAA,CAAa,CAAC,GAAG,MAAA,EAAQ,GAAG,QAAQ,CAAC,CAAC,CAAA,CAAE,CAAA;AAAA,EACtF;AACF","file":"conformance.js","sourcesContent":["import type { ServiceInfo } from \"../info/types.js\";\nimport type { ToolDefinition } from \"../types.js\";\n\nexport interface ConformanceIssue {\n level: \"error\" | \"warn\";\n code: string;\n message: string;\n}\n\nconst TOOL_NAME = /^[a-z][a-z0-9_-]{0,127}$/;\nconst SECRET_KEY = /^(token|password|secret|api[_-]?key|private[_-]?key)$/i;\n\nexport interface ConformanceOptions {\n /** Require a `service_info` tool. Defaults to true. */\n requireServiceInfo?: boolean;\n}\n\n/** Check tool definitions against the kit's tool contract. */\nexport function checkToolDefinitions(\n tools: ToolDefinition<any>[],\n options: ConformanceOptions = {},\n): ConformanceIssue[] {\n const issues: ConformanceIssue[] = [];\n const names = new Set<string>();\n\n for (const tool of tools) {\n if (!tool?.name) {\n issues.push({ level: \"error\", code: \"TOOL_NAME_MISSING\", message: \"tool has no name\" });\n continue;\n }\n if (names.has(tool.name)) {\n issues.push({\n level: \"error\",\n code: \"TOOL_NAME_DUPLICATE\",\n message: `duplicate tool name: ${tool.name}`,\n });\n }\n names.add(tool.name);\n\n if (!TOOL_NAME.test(tool.name)) {\n issues.push({\n level: \"warn\",\n code: \"TOOL_NAME_FORMAT\",\n message: `${tool.name}: prefer lower_snake_case (A-Z, a-z, 0-9, _, -)`,\n });\n }\n if (!tool.description?.trim()) {\n issues.push({\n level: \"error\",\n code: \"TOOL_DESCRIPTION_MISSING\",\n message: `${tool.name}: description is required`,\n });\n }\n if (!tool.inputSchema?.[\"~standard\"]) {\n issues.push({\n level: \"error\",\n code: \"TOOL_SCHEMA_MISSING\",\n message: `${tool.name}: inputSchema must be a Standard Schema`,\n });\n }\n if (!tool.annotations) {\n issues.push({\n level: \"warn\",\n code: \"TOOL_ANNOTATIONS_MISSING\",\n message: `${tool.name}: add readOnly/destructive/idempotent/openWorld annotations`,\n });\n }\n }\n\n if (options.requireServiceInfo !== false && !names.has(\"service_info\")) {\n issues.push({\n level: \"warn\",\n code: \"SERVICE_INFO_MISSING\",\n message: \"no service_info tool registered\",\n });\n }\n\n return issues;\n}\n\nfunction checkSecretKeys(\n section: Record<string, unknown> | undefined,\n path: string,\n issues: ConformanceIssue[],\n): void {\n if (!section) return;\n for (const key of Object.keys(section)) {\n if (SECRET_KEY.test(key)) {\n issues.push({\n level: \"error\",\n code: \"INFO_SECRET_KEY\",\n message: `${path}.${key}: /info must not expose secret fields`,\n });\n }\n }\n}\n\n/** Check an `info/1` payload for the parts that must stay stable. */\nexport function checkServiceInfo(info: ServiceInfo): ConformanceIssue[] {\n const issues: ConformanceIssue[] = [];\n if (info.contract !== \"info/1\") {\n issues.push({\n level: \"error\",\n code: \"INFO_CONTRACT\",\n message: `contract must be \"info/1\" (got ${String(info.contract)})`,\n });\n }\n if (!info.service) {\n issues.push({ level: \"error\", code: \"INFO_SERVICE\", message: \"service is required\" });\n }\n if (!info.version) {\n issues.push({ level: \"error\", code: \"INFO_VERSION\", message: \"version is required\" });\n }\n const uptime = info.deployment?.uptimeSeconds;\n if (uptime !== undefined && typeof uptime !== \"number\") {\n issues.push({\n level: \"error\",\n code: \"INFO_UPTIME_TYPE\",\n message: \"deployment.uptimeSeconds must be a number\",\n });\n }\n checkSecretKeys(info.deployment, \"deployment\", issues);\n checkSecretKeys(info.storage, \"storage\", issues);\n checkSecretKeys(info.limits, \"limits\", issues);\n return issues;\n}\n\nexport function formatIssues(issues: ConformanceIssue[]): string {\n return issues\n .map((issue) => `${issue.level.toUpperCase()} ${issue.code}: ${issue.message}`)\n .join(\"\\n\");\n}\n\n/** Throw when any error-level issue is present. */\nexport function assertConformant(\n issues: ConformanceIssue[],\n options: { allowWarnings?: boolean } = {},\n): void {\n const errors = issues.filter((issue) => issue.level === \"error\");\n const warnings = issues.filter((issue) => issue.level === \"warn\");\n if (errors.length || (!options.allowWarnings && warnings.length)) {\n throw new Error(`MCP conformance failed:\\n${formatIssues([...errors, ...warnings])}`);\n }\n}\n"]}
@@ -0,0 +1,95 @@
1
+ import { AuthInfo, ClientCapabilities, Implementation, StandardSchemaWithJSON, ToolAnnotations, CallToolResult, InputRequiredResult } from '@modelcontextprotocol/server';
2
+
3
+ type TransportKind = "stdio" | "http";
4
+ /** W3C trace context carried in the MCP `_meta` envelope. */
5
+ interface TraceContext {
6
+ traceparent?: string;
7
+ tracestate?: string;
8
+ baggage?: string;
9
+ }
10
+ /** Minimal structured logger. The default writes to stderr, never stdout. */
11
+ interface Logger {
12
+ debug(message: string, fields?: Record<string, unknown>): void;
13
+ info(message: string, fields?: Record<string, unknown>): void;
14
+ warn(message: string, fields?: Record<string, unknown>): void;
15
+ error(message: string, fields?: Record<string, unknown>): void;
16
+ child?(bindings: Record<string, unknown>): Logger;
17
+ }
18
+ interface ToolHttpContext {
19
+ method: string;
20
+ path: string;
21
+ headers: Headers;
22
+ }
23
+ /**
24
+ * Normalized request context passed to every tool handler.
25
+ *
26
+ * `ctx` is additive: existing handlers written as `(args) => ...` keep working.
27
+ */
28
+ interface ToolContext {
29
+ transport: TransportKind;
30
+ requestId: string;
31
+ auth?: AuthInfo;
32
+ /** Stable identity used for per-tenant queues/state. Derived from auth by default. */
33
+ principal?: string;
34
+ protocolVersion?: string;
35
+ clientCapabilities?: ClientCapabilities;
36
+ clientInfo?: Implementation;
37
+ signal?: AbortSignal;
38
+ logger: Logger;
39
+ trace?: TraceContext;
40
+ http?: ToolHttpContext;
41
+ }
42
+ interface ToolError {
43
+ code: string;
44
+ message: string;
45
+ details?: unknown;
46
+ retryable?: boolean;
47
+ }
48
+ interface AssertFailure {
49
+ path?: string;
50
+ actual?: unknown;
51
+ expected?: unknown;
52
+ }
53
+ interface AssertResult {
54
+ matched: boolean;
55
+ failures: AssertFailure[];
56
+ }
57
+ type ToolPayload = {
58
+ ok: true;
59
+ response: unknown;
60
+ meta?: Record<string, unknown>;
61
+ } | {
62
+ ok: false;
63
+ error: ToolError | {
64
+ message: string;
65
+ };
66
+ assert?: AssertResult;
67
+ meta?: Record<string, unknown>;
68
+ };
69
+ /**
70
+ * A handler may return the kit envelope, or a raw MCP result when it needs
71
+ * protocol features the kit does not wrap yet (for example MRTR).
72
+ */
73
+ type ToolReturn = ToolPayload | CallToolResult | InputRequiredResult;
74
+ interface ToolCacheHint {
75
+ ttlMs?: number;
76
+ scope?: "public" | "private";
77
+ }
78
+ interface ToolDefinition<TArgs = Record<string, unknown>> {
79
+ name: string;
80
+ title?: string;
81
+ description: string;
82
+ inputSchema: StandardSchemaWithJSON;
83
+ outputSchema?: StandardSchemaWithJSON;
84
+ annotations?: ToolAnnotations;
85
+ /** Defined but not registered with MCP; callable through `invokeTool`. */
86
+ hidden?: boolean;
87
+ cache?: ToolCacheHint;
88
+ handler: (args: TArgs, ctx: ToolContext) => ToolReturn | Promise<ToolReturn>;
89
+ }
90
+ interface Queue {
91
+ run<T>(key: string | undefined, fn: () => Promise<T> | T): Promise<T>;
92
+ }
93
+ type QueueKey<TArgs = Record<string, unknown>> = (args: TArgs, ctx: ToolContext) => string | undefined;
94
+
95
+ export type { AssertResult as A, Logger as L, Queue as Q, ToolError as T, AssertFailure as a, ToolPayload as b, ToolReturn as c, QueueKey as d, ToolDefinition as e, ToolContext as f, ToolCacheHint as g, ToolHttpContext as h, TraceContext as i, TransportKind as j };
@@ -0,0 +1,95 @@
1
+ import { AuthInfo, ClientCapabilities, Implementation, StandardSchemaWithJSON, ToolAnnotations, CallToolResult, InputRequiredResult } from '@modelcontextprotocol/server';
2
+
3
+ type TransportKind = "stdio" | "http";
4
+ /** W3C trace context carried in the MCP `_meta` envelope. */
5
+ interface TraceContext {
6
+ traceparent?: string;
7
+ tracestate?: string;
8
+ baggage?: string;
9
+ }
10
+ /** Minimal structured logger. The default writes to stderr, never stdout. */
11
+ interface Logger {
12
+ debug(message: string, fields?: Record<string, unknown>): void;
13
+ info(message: string, fields?: Record<string, unknown>): void;
14
+ warn(message: string, fields?: Record<string, unknown>): void;
15
+ error(message: string, fields?: Record<string, unknown>): void;
16
+ child?(bindings: Record<string, unknown>): Logger;
17
+ }
18
+ interface ToolHttpContext {
19
+ method: string;
20
+ path: string;
21
+ headers: Headers;
22
+ }
23
+ /**
24
+ * Normalized request context passed to every tool handler.
25
+ *
26
+ * `ctx` is additive: existing handlers written as `(args) => ...` keep working.
27
+ */
28
+ interface ToolContext {
29
+ transport: TransportKind;
30
+ requestId: string;
31
+ auth?: AuthInfo;
32
+ /** Stable identity used for per-tenant queues/state. Derived from auth by default. */
33
+ principal?: string;
34
+ protocolVersion?: string;
35
+ clientCapabilities?: ClientCapabilities;
36
+ clientInfo?: Implementation;
37
+ signal?: AbortSignal;
38
+ logger: Logger;
39
+ trace?: TraceContext;
40
+ http?: ToolHttpContext;
41
+ }
42
+ interface ToolError {
43
+ code: string;
44
+ message: string;
45
+ details?: unknown;
46
+ retryable?: boolean;
47
+ }
48
+ interface AssertFailure {
49
+ path?: string;
50
+ actual?: unknown;
51
+ expected?: unknown;
52
+ }
53
+ interface AssertResult {
54
+ matched: boolean;
55
+ failures: AssertFailure[];
56
+ }
57
+ type ToolPayload = {
58
+ ok: true;
59
+ response: unknown;
60
+ meta?: Record<string, unknown>;
61
+ } | {
62
+ ok: false;
63
+ error: ToolError | {
64
+ message: string;
65
+ };
66
+ assert?: AssertResult;
67
+ meta?: Record<string, unknown>;
68
+ };
69
+ /**
70
+ * A handler may return the kit envelope, or a raw MCP result when it needs
71
+ * protocol features the kit does not wrap yet (for example MRTR).
72
+ */
73
+ type ToolReturn = ToolPayload | CallToolResult | InputRequiredResult;
74
+ interface ToolCacheHint {
75
+ ttlMs?: number;
76
+ scope?: "public" | "private";
77
+ }
78
+ interface ToolDefinition<TArgs = Record<string, unknown>> {
79
+ name: string;
80
+ title?: string;
81
+ description: string;
82
+ inputSchema: StandardSchemaWithJSON;
83
+ outputSchema?: StandardSchemaWithJSON;
84
+ annotations?: ToolAnnotations;
85
+ /** Defined but not registered with MCP; callable through `invokeTool`. */
86
+ hidden?: boolean;
87
+ cache?: ToolCacheHint;
88
+ handler: (args: TArgs, ctx: ToolContext) => ToolReturn | Promise<ToolReturn>;
89
+ }
90
+ interface Queue {
91
+ run<T>(key: string | undefined, fn: () => Promise<T> | T): Promise<T>;
92
+ }
93
+ type QueueKey<TArgs = Record<string, unknown>> = (args: TArgs, ctx: ToolContext) => string | undefined;
94
+
95
+ export type { AssertResult as A, Logger as L, Queue as Q, ToolError as T, AssertFailure as a, ToolPayload as b, ToolReturn as c, QueueKey as d, ToolDefinition as e, ToolContext as f, ToolCacheHint as g, ToolHttpContext as h, TraceContext as i, TransportKind as j };
@@ -0,0 +1,76 @@
1
+ import * as node_http from 'node:http';
2
+
3
+ interface InfoEndpointSpec {
4
+ path?: string;
5
+ auth?: string;
6
+ desc?: string;
7
+ }
8
+ interface InfoSnippet {
9
+ title: string;
10
+ code: string;
11
+ }
12
+ interface InfoIntegration {
13
+ hint?: string;
14
+ snippets?: InfoSnippet[];
15
+ }
16
+ type InfoSection = Record<string, unknown>;
17
+ interface ServiceInfo {
18
+ contract: string;
19
+ service: string;
20
+ version: string;
21
+ summary?: string;
22
+ build?: string;
23
+ git?: string;
24
+ deployment?: InfoSection;
25
+ storage?: InfoSection;
26
+ limits?: InfoSection;
27
+ endpoints?: Record<string, string | InfoEndpointSpec>;
28
+ integration?: InfoIntegration;
29
+ changelog?: string;
30
+ changelog_path?: string;
31
+ labels?: Record<string, string>;
32
+ [key: string]: unknown;
33
+ }
34
+ interface BuildServiceInfoOptions {
35
+ service: string;
36
+ version: string;
37
+ summary?: string;
38
+ build?: string;
39
+ git?: string;
40
+ deployment?: InfoSection | (() => InfoSection);
41
+ storage?: InfoSection | (() => InfoSection);
42
+ limits?: InfoSection | (() => InfoSection);
43
+ endpoints?: Record<string, string | InfoEndpointSpec> | (() => Record<string, string | InfoEndpointSpec>);
44
+ integration?: InfoIntegration | (() => InfoIntegration);
45
+ labels?: Record<string, string>;
46
+ changelogPath?: string;
47
+ changelogLines?: number;
48
+ extra?: Record<string, unknown>;
49
+ /** Recompute dynamic sections on every call. Result is merged last. */
50
+ dynamic?: () => Record<string, unknown>;
51
+ }
52
+ interface DirStats {
53
+ files: number;
54
+ sizeBytes: number;
55
+ entries: number;
56
+ truncated: boolean;
57
+ }
58
+ type HeaderSource = {
59
+ headers: Headers;
60
+ } | {
61
+ headers: Record<string, string | string[] | undefined>;
62
+ };
63
+ interface ResolvePublicUrlOptions {
64
+ publicUrl?: string;
65
+ envUrl?: string;
66
+ req?: HeaderSource;
67
+ fallback?: string;
68
+ }
69
+ interface InfoEndpoint {
70
+ contract: string;
71
+ version: string;
72
+ build(): ServiceInfo;
73
+ handle(req: node_http.IncomingMessage, res: node_http.ServerResponse): void;
74
+ }
75
+
76
+ export type { BuildServiceInfoOptions as B, DirStats as D, HeaderSource as H, InfoEndpoint as I, ResolvePublicUrlOptions as R, ServiceInfo as S, InfoEndpointSpec as a, InfoIntegration as b, InfoSection as c, InfoSnippet as d };
@@ -0,0 +1,76 @@
1
+ import * as node_http from 'node:http';
2
+
3
+ interface InfoEndpointSpec {
4
+ path?: string;
5
+ auth?: string;
6
+ desc?: string;
7
+ }
8
+ interface InfoSnippet {
9
+ title: string;
10
+ code: string;
11
+ }
12
+ interface InfoIntegration {
13
+ hint?: string;
14
+ snippets?: InfoSnippet[];
15
+ }
16
+ type InfoSection = Record<string, unknown>;
17
+ interface ServiceInfo {
18
+ contract: string;
19
+ service: string;
20
+ version: string;
21
+ summary?: string;
22
+ build?: string;
23
+ git?: string;
24
+ deployment?: InfoSection;
25
+ storage?: InfoSection;
26
+ limits?: InfoSection;
27
+ endpoints?: Record<string, string | InfoEndpointSpec>;
28
+ integration?: InfoIntegration;
29
+ changelog?: string;
30
+ changelog_path?: string;
31
+ labels?: Record<string, string>;
32
+ [key: string]: unknown;
33
+ }
34
+ interface BuildServiceInfoOptions {
35
+ service: string;
36
+ version: string;
37
+ summary?: string;
38
+ build?: string;
39
+ git?: string;
40
+ deployment?: InfoSection | (() => InfoSection);
41
+ storage?: InfoSection | (() => InfoSection);
42
+ limits?: InfoSection | (() => InfoSection);
43
+ endpoints?: Record<string, string | InfoEndpointSpec> | (() => Record<string, string | InfoEndpointSpec>);
44
+ integration?: InfoIntegration | (() => InfoIntegration);
45
+ labels?: Record<string, string>;
46
+ changelogPath?: string;
47
+ changelogLines?: number;
48
+ extra?: Record<string, unknown>;
49
+ /** Recompute dynamic sections on every call. Result is merged last. */
50
+ dynamic?: () => Record<string, unknown>;
51
+ }
52
+ interface DirStats {
53
+ files: number;
54
+ sizeBytes: number;
55
+ entries: number;
56
+ truncated: boolean;
57
+ }
58
+ type HeaderSource = {
59
+ headers: Headers;
60
+ } | {
61
+ headers: Record<string, string | string[] | undefined>;
62
+ };
63
+ interface ResolvePublicUrlOptions {
64
+ publicUrl?: string;
65
+ envUrl?: string;
66
+ req?: HeaderSource;
67
+ fallback?: string;
68
+ }
69
+ interface InfoEndpoint {
70
+ contract: string;
71
+ version: string;
72
+ build(): ServiceInfo;
73
+ handle(req: node_http.IncomingMessage, res: node_http.ServerResponse): void;
74
+ }
75
+
76
+ export type { BuildServiceInfoOptions as B, DirStats as D, HeaderSource as H, InfoEndpoint as I, ResolvePublicUrlOptions as R, ServiceInfo as S, InfoEndpointSpec as a, InfoIntegration as b, InfoSection as c, InfoSnippet as d };