xmcp 0.7.0 → 0.7.1

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 (155) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/index.js +1 -1
  3. package/package.json +2 -3
  4. package/src/auth/api-key.ts +0 -120
  5. package/src/auth/jwt.ts +0 -52
  6. package/src/cli/commands/create/__tests__/create.test.ts +0 -99
  7. package/src/cli/commands/create/index.ts +0 -74
  8. package/src/cli/commands/create/templates/index.ts +0 -4
  9. package/src/cli/commands/create/templates/prompt.ts +0 -30
  10. package/src/cli/commands/create/templates/resource.ts +0 -20
  11. package/src/cli/commands/create/templates/tool.ts +0 -34
  12. package/src/cli/commands/create/templates/widget.ts +0 -33
  13. package/src/cli/utils/naming.ts +0 -39
  14. package/src/cli.ts +0 -125
  15. package/src/client/headers.ts +0 -61
  16. package/src/client/index.ts +0 -180
  17. package/src/client/types.ts +0 -122
  18. package/src/client/utils.ts +0 -133
  19. package/src/cloudflare.ts +0 -6
  20. package/src/compiler/build-telemetry.ts +0 -88
  21. package/src/compiler/client/component-compiler.ts +0 -250
  22. package/src/compiler/client/transpile.ts +0 -21
  23. package/src/compiler/compiler-context.ts +0 -61
  24. package/src/compiler/config/__tests__/config.test.ts +0 -459
  25. package/src/compiler/config/index.ts +0 -62
  26. package/src/compiler/config/injection.ts +0 -210
  27. package/src/compiler/config/schemas/bundler.ts +0 -12
  28. package/src/compiler/config/schemas/experimental/index.ts +0 -22
  29. package/src/compiler/config/schemas/index.ts +0 -20
  30. package/src/compiler/config/schemas/paths.ts +0 -35
  31. package/src/compiler/config/schemas/template.ts +0 -80
  32. package/src/compiler/config/schemas/transport/http.ts +0 -116
  33. package/src/compiler/config/schemas/transport/stdio.ts +0 -31
  34. package/src/compiler/config/schemas/typescript.ts +0 -26
  35. package/src/compiler/config/utils.ts +0 -168
  36. package/src/compiler/generate-env-code.ts +0 -5
  37. package/src/compiler/generate-import-code.ts +0 -187
  38. package/src/compiler/generate-tools-code.ts +0 -174
  39. package/src/compiler/get-bundler-config/get-entries.ts +0 -44
  40. package/src/compiler/get-bundler-config/get-externals.ts +0 -114
  41. package/src/compiler/get-bundler-config/get-injected-variables.ts +0 -46
  42. package/src/compiler/get-bundler-config/index.ts +0 -288
  43. package/src/compiler/get-bundler-config/plugins/index.ts +0 -140
  44. package/src/compiler/get-bundler-config/plugins/types/express.ts +0 -3
  45. package/src/compiler/get-bundler-config/plugins/types/fastify.ts +0 -4
  46. package/src/compiler/get-bundler-config/plugins/types/index.ts +0 -5
  47. package/src/compiler/get-bundler-config/plugins/types/nest.ts +0 -65
  48. package/src/compiler/get-bundler-config/plugins/types/next.ts +0 -52
  49. package/src/compiler/get-bundler-config/resolve-tsconfig-paths.ts +0 -51
  50. package/src/compiler/index.ts +0 -484
  51. package/src/compiler/on-first-build.ts +0 -54
  52. package/src/compiler/parse-xmcp-config.ts +0 -200
  53. package/src/compiler/start-http-server.ts +0 -42
  54. package/src/compiler/utils/__tests__/config-detection.test.ts +0 -307
  55. package/src/compiler/utils/__tests__/path-utils.test.ts +0 -137
  56. package/src/compiler/utils/config-detection.ts +0 -34
  57. package/src/compiler/utils/path-utils.ts +0 -22
  58. package/src/compiler/watcher-recovery.ts +0 -72
  59. package/src/host-bridge.ts +0 -36
  60. package/src/index.ts +0 -94
  61. package/src/platforms/build-cloudflare-output.ts +0 -116
  62. package/src/platforms/build-vercel-output.ts +0 -131
  63. package/src/plugins/index.ts +0 -1
  64. package/src/plugins/x402/index.ts +0 -24
  65. package/src/runtime/adapters/express/index.ts +0 -75
  66. package/src/runtime/adapters/fastify/__tests__/fastify.test.ts +0 -115
  67. package/src/runtime/adapters/fastify/index.ts +0 -78
  68. package/src/runtime/adapters/nestjs/index.ts +0 -16
  69. package/src/runtime/adapters/nestjs/xmcp.controller.ts +0 -34
  70. package/src/runtime/adapters/nestjs/xmcp.guard.ts +0 -101
  71. package/src/runtime/adapters/nestjs/xmcp.oauth.controller.ts +0 -36
  72. package/src/runtime/adapters/nestjs/xmcp.oauth.module.ts +0 -21
  73. package/src/runtime/adapters/nestjs/xmcp.oauth.service.ts +0 -36
  74. package/src/runtime/adapters/nestjs/xmcp.service.ts +0 -96
  75. package/src/runtime/adapters/nestjs/xmcp.utils.ts +0 -11
  76. package/src/runtime/adapters/nextjs/auth.ts +0 -265
  77. package/src/runtime/adapters/nextjs/handler/error-handler.ts +0 -67
  78. package/src/runtime/adapters/nextjs/handler/node-to-web-adapter.ts +0 -143
  79. package/src/runtime/adapters/nextjs/handler/request-converter.ts +0 -74
  80. package/src/runtime/adapters/nextjs/handler/server-lifecycle.ts +0 -69
  81. package/src/runtime/adapters/nextjs/index.ts +0 -121
  82. package/src/runtime/contexts/client-info-context.ts +0 -16
  83. package/src/runtime/contexts/http-request-context.ts +0 -21
  84. package/src/runtime/contexts/http-transport-context.ts +0 -18
  85. package/src/runtime/headers.ts +0 -42
  86. package/src/runtime/middlewares/utils.ts +0 -72
  87. package/src/runtime/platforms/cloudflare/cors.ts +0 -44
  88. package/src/runtime/platforms/cloudflare/middlewares/api-key.ts +0 -102
  89. package/src/runtime/platforms/cloudflare/middlewares/jwt.ts +0 -127
  90. package/src/runtime/platforms/cloudflare/types.ts +0 -23
  91. package/src/runtime/platforms/cloudflare/worker.ts +0 -270
  92. package/src/runtime/templates/home.ts +0 -746
  93. package/src/runtime/transports/http/base-streamable-http.ts +0 -46
  94. package/src/runtime/transports/http/cors/headers.ts +0 -58
  95. package/src/runtime/transports/http/cors/index.ts +0 -34
  96. package/src/runtime/transports/http/index.ts +0 -78
  97. package/src/runtime/transports/http/stateless-streamable-http.ts +0 -353
  98. package/src/runtime/transports/http/web-stateless-http.ts +0 -288
  99. package/src/runtime/transports/stdio/index.ts +0 -109
  100. package/src/runtime/utils/__tests__/client-info.test.ts +0 -146
  101. package/src/runtime/utils/__tests__/tool-extra.test.ts +0 -239
  102. package/src/runtime/utils/client-info.ts +0 -114
  103. package/src/runtime/utils/elicitation.ts +0 -396
  104. package/src/runtime/utils/ext-apps-registry.ts +0 -151
  105. package/src/runtime/utils/mcp-app-protocol.ts +0 -16
  106. package/src/runtime/utils/mcp-app-types.ts +0 -113
  107. package/src/runtime/utils/mcp-host-bridge.ts +0 -473
  108. package/src/runtime/utils/path-to-tool-name.ts +0 -69
  109. package/src/runtime/utils/prompt-loader.ts +0 -151
  110. package/src/runtime/utils/prompts.ts +0 -69
  111. package/src/runtime/utils/react/generate-html.ts +0 -69
  112. package/src/runtime/utils/react/index.ts +0 -6
  113. package/src/runtime/utils/request-tool-names.ts +0 -48
  114. package/src/runtime/utils/resource-loader.ts +0 -151
  115. package/src/runtime/utils/resources.ts +0 -331
  116. package/src/runtime/utils/server.ts +0 -107
  117. package/src/runtime/utils/tool-loader.ts +0 -149
  118. package/src/runtime/utils/tools.ts +0 -183
  119. package/src/runtime/utils/transformers/prompt.ts +0 -120
  120. package/src/runtime/utils/transformers/resource.ts +0 -196
  121. package/src/runtime/utils/transformers/tool.ts +0 -400
  122. package/src/runtime/utils/ui/__tests__/split-meta.test.ts +0 -803
  123. package/src/runtime/utils/ui/flatten-meta.ts +0 -44
  124. package/src/runtime/utils/ui/split-meta.ts +0 -78
  125. package/src/runtime/utils/utils/resource-uri-composer.ts +0 -204
  126. package/src/runtime/utils/validators/index.ts +0 -138
  127. package/src/telemetry/ci-info.ts +0 -6
  128. package/src/telemetry/debug.ts +0 -8
  129. package/src/telemetry/events/definitions.ts +0 -52
  130. package/src/telemetry/events/detached-flush.ts +0 -83
  131. package/src/telemetry/events/post-payload.ts +0 -141
  132. package/src/telemetry/events/tracker.ts +0 -281
  133. package/src/telemetry/index.ts +0 -7
  134. package/src/telemetry/metadata.ts +0 -49
  135. package/src/telemetry/project-id.ts +0 -35
  136. package/src/telemetry/storage.ts +0 -218
  137. package/src/types/adapter.d.ts +0 -5
  138. package/src/types/client-info.ts +0 -20
  139. package/src/types/declarations.ts +0 -37
  140. package/src/types/injected.d.ts +0 -62
  141. package/src/types/middleware.ts +0 -19
  142. package/src/types/prompt.ts +0 -6
  143. package/src/types/resource.ts +0 -15
  144. package/src/types/tool.ts +0 -192
  145. package/src/types/ui-meta.ts +0 -42
  146. package/src/utils/cli-icons.ts +0 -5
  147. package/src/utils/constants.ts +0 -31
  148. package/src/utils/context.ts +0 -105
  149. package/src/utils/detect-package-manager.ts +0 -46
  150. package/src/utils/file-watcher.ts +0 -66
  151. package/src/utils/fs-utils.ts +0 -16
  152. package/src/utils/path-validation.ts +0 -66
  153. package/src/utils/port-utils.ts +0 -43
  154. package/src/utils/spawn-process.ts +0 -49
  155. package/src/utils/subscribable.ts +0 -62
@@ -1,44 +0,0 @@
1
- /**
2
- * Flattens nested metadata object into a flat structure with "/" delimited keys.
3
- */
4
- export function flattenMeta(meta: Record<string, any>): Record<string, any> {
5
- const result: Record<string, any> = {};
6
-
7
- function flatten(obj: any, prefix = ""): void {
8
- if (!obj || typeof obj !== "object") {
9
- return;
10
- }
11
-
12
- for (const [key, value] of Object.entries(obj)) {
13
- const newKey = prefix ? `${prefix}/${key}` : key;
14
-
15
- if (
16
- value &&
17
- typeof value === "object" &&
18
- !Array.isArray(value) &&
19
- !(value instanceof Date) &&
20
- !(value instanceof RegExp)
21
- ) {
22
- flatten(value, newKey);
23
- } else {
24
- result[newKey] = value;
25
- }
26
- }
27
- }
28
-
29
- flatten(meta);
30
- return result;
31
- }
32
-
33
- /** Checks if metadata contains UI-specific keys.*/
34
- export function hasUIMeta(meta?: Record<string, any>): boolean {
35
- if (!meta || typeof meta !== "object") {
36
- return false;
37
- }
38
-
39
- if ("ui" in meta && typeof meta.ui === "object") {
40
- return true;
41
- }
42
-
43
- return false;
44
- }
@@ -1,78 +0,0 @@
1
- /**
2
- * Splits UI metadata into tool-specific and resource-specific properties.
3
- */
4
-
5
- export interface SplitMetadata {
6
- toolMeta: Record<string, any>;
7
- resourceMeta: Record<string, any>;
8
- }
9
-
10
- /**
11
- * Tool-specific metadata keys in nested format
12
- */
13
- const TOOL_META_KEYS_NESTED = ["ui/resourceUri", "resourceUri", "visibility"];
14
-
15
- /**
16
- * Resource-specific metadata keys in nested format
17
- */
18
- const RESOURCE_META_KEYS_NESTED = [
19
- "prefersBorder",
20
- "domain",
21
- "csp",
22
- "permissions",
23
- "connectDomains",
24
- "resourceDomains",
25
- "frameDomains",
26
- "baseUriDomains",
27
- ];
28
-
29
- /**
30
- * Splits nested UI metadata into tool and resource metadata.
31
- * Keeps metadata in nested format (no flattening).
32
- *
33
- * @param meta - The metadata object (nested format with 'ui' key)
34
- * @returns Object containing toolMeta and resourceMeta in nested format
35
- */
36
- export function splitUIMetaNested(meta: Record<string, any>): SplitMetadata {
37
- const toolMeta: Record<string, any> = {};
38
- const resourceMeta: Record<string, any> = {};
39
-
40
- if (meta.ui && typeof meta.ui === "object") {
41
- const uiMeta = meta.ui;
42
- const toolUI: Record<string, any> = {};
43
- const resourceUI: Record<string, any> = {};
44
-
45
- for (const [key, value] of Object.entries(uiMeta)) {
46
- if (TOOL_META_KEYS_NESTED.includes(key)) {
47
- toolUI[key] = value;
48
- } else if (RESOURCE_META_KEYS_NESTED.includes(key)) {
49
- resourceUI[key] = value;
50
- } else {
51
- toolUI[key] = value;
52
- }
53
- }
54
-
55
- if (Object.keys(toolUI).length > 0) {
56
- toolMeta.ui = toolUI;
57
- }
58
- if (Object.keys(resourceUI).length > 0) {
59
- resourceMeta.ui = resourceUI;
60
- }
61
- }
62
-
63
- for (const [key, value] of Object.entries(meta)) {
64
- if (key !== "ui") {
65
- toolMeta[key] = value;
66
- }
67
- }
68
-
69
- return { toolMeta, resourceMeta };
70
- }
71
-
72
- export function isToolMetaKeyNested(key: string): boolean {
73
- return TOOL_META_KEYS_NESTED.includes(key);
74
- }
75
-
76
- export function isResourceMetaKeyNested(key: string): boolean {
77
- return RESOURCE_META_KEYS_NESTED.includes(key);
78
- }
@@ -1,204 +0,0 @@
1
- /**
2
- * Utilities for composing URIs from resource file paths following the convention:
3
- * - (scheme) folders become URI schemes
4
- * - [param] folders become dynamic parameters
5
- * - static folders become literal path segments
6
- * - file names become endpoints
7
- */
8
-
9
- export type ResourceType = "direct" | "template";
10
-
11
- export interface ResourceInfo {
12
- /** The original file path */
13
- filePath: string;
14
- /** The composed URI template */
15
- uriTemplate: string;
16
- /** The URI scheme extracted from (scheme) folder */
17
- scheme: string;
18
- /** Dynamic parameters extracted from [param] folders */
19
- parameters: string[];
20
- /** Static path segments */
21
- pathSegments: string[];
22
- /** Whether this is a direct resource or template resource */
23
- type: ResourceType;
24
- }
25
-
26
- /**
27
- * Compose a URI template from a resource file path
28
- *
29
- * @param filePath - The file path relative to resources folder
30
- * @returns ResourceInfo with composed URI and metadata
31
- *
32
- * @example
33
- * // Static resource
34
- * composeUriFromPath('(config)/app.ts')
35
- * // Returns: { uriTemplate: 'config://app', parameters: [], ... }
36
- *
37
- * // Dynamic parameter as file
38
- * composeUriFromPath('(users)/[id].ts')
39
- * // Returns: { uriTemplate: 'users://{id}', parameters: ['id'], ... }
40
- *
41
- * // Dynamic parameter as folder with index
42
- * composeUriFromPath('(users)/[id]/index.ts')
43
- * // Returns: { uriTemplate: 'users://{id}', parameters: ['id'], ... }
44
- *
45
- * // Complex nested
46
- * composeUriFromPath('(github)/repos/[owner]/[repo]/index.ts')
47
- * // Returns: { uriTemplate: 'github://repos/{owner}/{repo}', parameters: ['owner', 'repo'], ... }
48
- */
49
- export function composeUriFromPath(filePath: string): ResourceInfo | null {
50
- const parts = filePath.split("/").filter((part) => part !== "");
51
-
52
- // find the scheme anchor: (scheme)
53
- const schemeIndex = parts.findIndex((part) => part.match(/^\(.+\)$/));
54
-
55
- if (schemeIndex === -1) {
56
- // no scheme found, skip this file
57
- return null;
58
- }
59
-
60
- // FOLDER-ONLY CONVENTION: reject [param].ts files (only allow [param]/index.ts)
61
- const fileName = parts[parts.length - 1];
62
- if (fileName && fileName.match(/^\[.+\]\.ts$/)) {
63
- // this is a [param].ts file, which violates folder-only convention
64
- // makes it difficult to scale when you can have subsegments of the same param and an index file for each
65
- return null;
66
- }
67
-
68
- const scheme = parts[schemeIndex].slice(1, -1); // (github) → github
69
-
70
- // process only parts AFTER the scheme
71
- const pathParts = parts.slice(schemeIndex + 1);
72
-
73
- // remove file extensions (.ts, .js, etc.)
74
- const lastPart = pathParts[pathParts.length - 1];
75
- if (lastPart && lastPart.includes(".")) {
76
- const fileName = lastPart.split(".")[0];
77
- // don't include 'index' in the URI path
78
- if (fileName !== "index") {
79
- pathParts[pathParts.length - 1] = fileName;
80
- } else {
81
- pathParts.pop();
82
- }
83
- }
84
-
85
- const parameters: string[] = [];
86
- const pathSegments: string[] = [];
87
-
88
- // process each path part
89
- const uriPathParts = pathParts.map((part) => {
90
- if (part.match(/^\[.+\]$/)) {
91
- // dynamic parameter: [owner] → {owner}
92
- const paramName = part.slice(1, -1);
93
- parameters.push(paramName);
94
- return `{${paramName}}`;
95
- } else {
96
- // static segment
97
- pathSegments.push(part);
98
- return part;
99
- }
100
- });
101
-
102
- const uriTemplate = `${scheme}://${uriPathParts.join("/")}`;
103
-
104
- // determine resource type based on parameters
105
- const type: ResourceType = parameters.length > 0 ? "template" : "direct";
106
-
107
- return {
108
- filePath,
109
- uriTemplate,
110
- scheme,
111
- parameters,
112
- pathSegments,
113
- type,
114
- };
115
- }
116
-
117
- /**
118
- * Get all resource URIs from a set of file paths
119
- */
120
- export function getResourceUris(
121
- resourcePaths: Set<string>,
122
- basePath: string
123
- ): ResourceInfo[] {
124
- const resourceInfos: ResourceInfo[] = [];
125
-
126
- for (const fullPath of resourcePaths) {
127
- const relativePath = fullPath.replace(basePath + "/", "");
128
-
129
- const resourceInfo = composeUriFromPath(relativePath);
130
- if (resourceInfo) {
131
- resourceInfos.push(resourceInfo);
132
- }
133
- }
134
-
135
- return resourceInfos;
136
- }
137
-
138
- /** separate resources by type for different handling when injecting into the server */
139
- export function categorizeResources(resourceInfos: ResourceInfo[]): {
140
- directResources: ResourceInfo[];
141
- templateResources: ResourceInfo[];
142
- } {
143
- const directResources: ResourceInfo[] = [];
144
- const templateResources: ResourceInfo[] = [];
145
-
146
- resourceInfos.forEach((resource) => {
147
- if (resource.type === "direct") {
148
- directResources.push(resource);
149
- } else {
150
- templateResources.push(resource);
151
- }
152
- });
153
-
154
- return { directResources, templateResources };
155
- }
156
-
157
- /** validate resource URI against MCP standards */
158
- export function validateResourceUri(resourceInfo: ResourceInfo): {
159
- valid: boolean;
160
- errors: string[];
161
- } {
162
- const errors: string[] = [];
163
-
164
- // validate scheme format (lowercase alphanumeric + hyphens)
165
- // perhaps validate against RFC 6570 for extensibility?
166
- if (!resourceInfo.scheme.match(/^[a-z0-9-]+$/)) {
167
- errors.push(
168
- `Invalid scheme format: "${resourceInfo.scheme}". Use lowercase alphanumeric characters and hyphens only.`
169
- );
170
- }
171
-
172
- // validate parameter names (alphanumeric + underscores)
173
- resourceInfo.parameters.forEach((param) => {
174
- if (!param.match(/^[a-zA-Z0-9_]+$/)) {
175
- errors.push(
176
- `Invalid parameter name: "${param}". Use alphanumeric characters and underscores only.`
177
- );
178
- }
179
- });
180
-
181
- // validate path segments (no special characters that could break URIs)
182
- resourceInfo.pathSegments.forEach((segment) => {
183
- if (!segment.match(/^[a-zA-Z0-9_-]+$/)) {
184
- errors.push(
185
- `Invalid path segment: "${segment}". Use alphanumeric characters, underscores, and hyphens only.`
186
- );
187
- }
188
- });
189
-
190
- // ensure URI doesn't end with slash (unless it's just the scheme)
191
- if (
192
- resourceInfo.uriTemplate.endsWith("/") &&
193
- resourceInfo.uriTemplate !== `${resourceInfo.scheme}://`
194
- ) {
195
- errors.push(
196
- `URI template should not end with trailing slash: "${resourceInfo.uriTemplate}"`
197
- );
198
- }
199
-
200
- return {
201
- valid: errors.length === 0,
202
- errors,
203
- };
204
- }
@@ -1,138 +0,0 @@
1
- export type ContentValidator = (content: any) => {
2
- valid: boolean;
3
- error?: string;
4
- };
5
-
6
- export const contentValidators: Record<string, ContentValidator> = {
7
- text: (content) => {
8
- if (typeof content.text !== "string") {
9
- return {
10
- valid: false,
11
- error: 'Text content must have a "text" property of type string',
12
- };
13
- }
14
- return { valid: true };
15
- },
16
-
17
- image: (content) => {
18
- if (typeof content.data !== "string") {
19
- return {
20
- valid: false,
21
- error:
22
- 'Image content must have a "data" property of type string (base64-encoded image)',
23
- };
24
- }
25
- if (typeof content.mimeType !== "string") {
26
- return {
27
- valid: false,
28
- error: 'Image content must have a "mimeType" property of type string',
29
- };
30
- }
31
- return { valid: true };
32
- },
33
-
34
- audio: (content) => {
35
- if (typeof content.data !== "string") {
36
- return {
37
- valid: false,
38
- error:
39
- 'Audio content must have a "data" property of type string (base64-encoded audio)',
40
- };
41
- }
42
- if (typeof content.mimeType !== "string") {
43
- return {
44
- valid: false,
45
- error: 'Audio content must have a "mimeType" property of type string',
46
- };
47
- }
48
- return { valid: true };
49
- },
50
-
51
- resource_link: (content) => {
52
- if (typeof content.name !== "string") {
53
- return {
54
- valid: false,
55
- error:
56
- 'Resource link content must have a "name" property of type string',
57
- };
58
- }
59
- if (typeof content.uri !== "string") {
60
- return {
61
- valid: false,
62
- error:
63
- 'Resource link content must have a "uri" property of type string',
64
- };
65
- }
66
- // Optional fields validation
67
- if (content.title !== undefined && typeof content.title !== "string") {
68
- return {
69
- valid: false,
70
- error: 'Resource link "title" property must be a string if provided',
71
- };
72
- }
73
- if (
74
- content.description !== undefined &&
75
- typeof content.description !== "string"
76
- ) {
77
- return {
78
- valid: false,
79
- error:
80
- 'Resource link "description" property must be a string if provided',
81
- };
82
- }
83
- if (
84
- content.mimeType !== undefined &&
85
- typeof content.mimeType !== "string"
86
- ) {
87
- return {
88
- valid: false,
89
- error: 'Resource link "mimeType" property must be a string if provided',
90
- };
91
- }
92
- return { valid: true };
93
- },
94
- };
95
-
96
- /**
97
- * Validates content and returns a detailed error message if invalid
98
- * applies for both tools and prompts
99
- */
100
- export function validateContent(content: unknown): {
101
- valid: boolean;
102
- error?: string;
103
- } {
104
- if (!content || typeof content !== "object") {
105
- return {
106
- valid: false,
107
- error: "Content must be an object",
108
- };
109
- }
110
-
111
- const contentObj = content as any;
112
-
113
- if (typeof contentObj.type !== "string") {
114
- return {
115
- valid: false,
116
- error: 'Content must have a "type" property of type string',
117
- };
118
- }
119
-
120
- // Validate _meta field if present - this is optional tho
121
- if (
122
- contentObj._meta !== undefined &&
123
- (contentObj._meta === null || typeof contentObj._meta !== "object")
124
- ) {
125
- return {
126
- valid: false,
127
- error: 'Content "_meta" property must be an object if provided',
128
- };
129
- }
130
-
131
- const validator = contentValidators[contentObj.type];
132
- if (validator) {
133
- return validator(contentObj);
134
- }
135
-
136
- // unknown content types are allowed (future extensibility)
137
- return { valid: true };
138
- }
@@ -1,6 +0,0 @@
1
- import ciEnvironment from "ci-info";
2
-
3
- const { isCI: _isCI, name: _name } = ciEnvironment;
4
-
5
- export const isCI = _isCI;
6
- export const name = _name;
@@ -1,8 +0,0 @@
1
- const TELEMETRY_DEBUG_ENV = "XMCP_DEBUG_TELEMETRY";
2
-
3
- export function isTelemetryDebugEnabled(): boolean {
4
- const envValue = process.env?.[
5
- TELEMETRY_DEBUG_ENV as keyof NodeJS.ProcessEnv
6
- ] as string | undefined;
7
- return typeof envValue === "string" && envValue.toLowerCase() === "true";
8
- }
@@ -1,52 +0,0 @@
1
- /**
2
- * Telemetry Event Definitions
3
- */
4
-
5
- export enum TelemetryEventName {
6
- BUILD_COMPLETED = "build:completed",
7
- BUILD_FAILED = "build:failed",
8
- }
9
-
10
- export enum TransportType {
11
- HTTP = "http",
12
- STDIO = "stdio",
13
- }
14
-
15
- export enum ErrorPhase {
16
- CONFIG = "config",
17
- COMPILE = "compile",
18
- WEBPACK = "webpack",
19
- TRANSPILE = "transpile",
20
- }
21
-
22
- export enum AdapterType {
23
- NONE = "none",
24
- EXPRESS = "express",
25
- NEXTJS = "nextjs",
26
- NESTJS = "nestjs",
27
- FASTIFY = "fastify",
28
- }
29
-
30
- type EventPayload = {
31
- success: boolean;
32
- duration: number; // milliseconds
33
- toolsCount: number;
34
- reactToolsCount: number;
35
- promptsCount: number;
36
- resourcesCount: number;
37
- transport: TransportType;
38
- adapter: AdapterType;
39
- nodeVersion: string;
40
- xmcpVersion: string;
41
- };
42
-
43
- export type BuildCompletedPayload = EventPayload & {
44
- outputSize: number; // bytes
45
- };
46
-
47
- export type BuildFailedPayload = EventPayload & {
48
- errorPhase: ErrorPhase;
49
- errorType: string;
50
- };
51
-
52
- export type TelemetryEventPayload = BuildCompletedPayload | BuildFailedPayload;
@@ -1,83 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Detached flush script
4
- */
5
-
6
- import { readFileSync, unlinkSync, existsSync } from "fs";
7
- import path from "path";
8
- import { TelemetryStorage } from "../storage";
9
- import { getAnonymousMeta } from "../metadata";
10
- import { postTelemetryPayload, createPayload } from "./post-payload";
11
- import { getProjectId } from "../project-id";
12
- import type { TelemetryEvent } from "./tracker";
13
-
14
- async function main() {
15
- const [mode, distDir] = process.argv.slice(2);
16
-
17
- if (!mode || !distDir) {
18
- console.error("Usage: detached-flush <mode> <distDir>");
19
- process.exit(1);
20
- }
21
-
22
- const eventsFile = path.join(distDir, "_events.json");
23
-
24
- if (!existsSync(eventsFile)) {
25
- return;
26
- }
27
-
28
- try {
29
- // Read events from disk
30
- const eventsData = readFileSync(eventsFile, "utf-8");
31
- const {
32
- sessionId,
33
- events,
34
- }: { sessionId: string; events: TelemetryEvent[] } = JSON.parse(eventsData);
35
-
36
- if (events.length === 0) {
37
- return;
38
- }
39
-
40
- // Initialize storage
41
- const storage = new TelemetryStorage();
42
-
43
- // Skip if telemetry is disabled
44
- if (storage.isDisabled) {
45
- try {
46
- unlinkSync(eventsFile);
47
- } catch (_) {
48
- // ignore cleanup failure
49
- }
50
- return;
51
- }
52
-
53
- // Get project ID with one-way hash
54
- const projectId = await getProjectId(storage.oneWayHash.bind(storage));
55
-
56
- // Create payload using the preserved session ID
57
- const meta = getAnonymousMeta();
58
-
59
- const payload = createPayload(
60
- {
61
- anonymousId: storage.anonymousId,
62
- projectHash: projectId,
63
- sessionId,
64
- },
65
- meta,
66
- events.map((event) => ({
67
- eventName: event.eventName,
68
- timestamp: event.timestamp ?? new Date().toISOString(),
69
- fields: event.fields,
70
- }))
71
- );
72
-
73
- await postTelemetryPayload(payload, { swallowErrors: false });
74
-
75
- // Clean up events file after successful send
76
- unlinkSync(eventsFile);
77
- } catch (error) {
78
- // Silently fail in production - don't want to spam users with errors
79
- // If we fail, the events file will remain and might be picked up next time
80
- }
81
- }
82
-
83
- main();