xmcp 0.6.13 → 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.
- package/dist/cli.js +8 -8
- package/dist/index.js +2 -2
- package/dist/runtime/adapter-express.js +2 -2
- package/dist/runtime/adapter-fastify.js +2 -2
- package/dist/runtime/adapter-nestjs.js +7 -7
- package/dist/runtime/adapter-nextjs.js +11 -11
- package/dist/runtime/http.js +3 -3
- package/dist/runtime/stdio.js +8 -8
- package/package.json +10 -11
- package/src/auth/api-key.ts +0 -120
- package/src/auth/jwt.ts +0 -52
- package/src/cli/commands/create/__tests__/create.test.ts +0 -99
- package/src/cli/commands/create/index.ts +0 -74
- package/src/cli/commands/create/templates/index.ts +0 -4
- package/src/cli/commands/create/templates/prompt.ts +0 -30
- package/src/cli/commands/create/templates/resource.ts +0 -20
- package/src/cli/commands/create/templates/tool.ts +0 -34
- package/src/cli/commands/create/templates/widget.ts +0 -33
- package/src/cli/utils/naming.ts +0 -39
- package/src/cli.ts +0 -125
- package/src/client/headers.ts +0 -61
- package/src/client/index.ts +0 -180
- package/src/client/types.ts +0 -122
- package/src/client/utils.ts +0 -133
- package/src/cloudflare.ts +0 -6
- package/src/compiler/build-telemetry.ts +0 -88
- package/src/compiler/client/component-compiler.ts +0 -250
- package/src/compiler/client/transpile.ts +0 -21
- package/src/compiler/compiler-context.ts +0 -61
- package/src/compiler/config/__tests__/config.test.ts +0 -459
- package/src/compiler/config/index.ts +0 -62
- package/src/compiler/config/injection.ts +0 -210
- package/src/compiler/config/schemas/bundler.ts +0 -12
- package/src/compiler/config/schemas/experimental/index.ts +0 -22
- package/src/compiler/config/schemas/index.ts +0 -20
- package/src/compiler/config/schemas/paths.ts +0 -35
- package/src/compiler/config/schemas/template.ts +0 -80
- package/src/compiler/config/schemas/transport/http.ts +0 -116
- package/src/compiler/config/schemas/transport/stdio.ts +0 -31
- package/src/compiler/config/schemas/typescript.ts +0 -26
- package/src/compiler/config/utils.ts +0 -168
- package/src/compiler/generate-env-code.ts +0 -5
- package/src/compiler/generate-import-code.ts +0 -187
- package/src/compiler/generate-tools-code.ts +0 -174
- package/src/compiler/get-bundler-config/get-entries.ts +0 -44
- package/src/compiler/get-bundler-config/get-externals.ts +0 -114
- package/src/compiler/get-bundler-config/get-injected-variables.ts +0 -46
- package/src/compiler/get-bundler-config/index.ts +0 -288
- package/src/compiler/get-bundler-config/plugins/index.ts +0 -140
- package/src/compiler/get-bundler-config/plugins/types/express.ts +0 -3
- package/src/compiler/get-bundler-config/plugins/types/fastify.ts +0 -4
- package/src/compiler/get-bundler-config/plugins/types/index.ts +0 -5
- package/src/compiler/get-bundler-config/plugins/types/nest.ts +0 -65
- package/src/compiler/get-bundler-config/plugins/types/next.ts +0 -52
- package/src/compiler/get-bundler-config/resolve-tsconfig-paths.ts +0 -51
- package/src/compiler/index.ts +0 -484
- package/src/compiler/on-first-build.ts +0 -54
- package/src/compiler/parse-xmcp-config.ts +0 -200
- package/src/compiler/start-http-server.ts +0 -42
- package/src/compiler/utils/__tests__/config-detection.test.ts +0 -307
- package/src/compiler/utils/__tests__/path-utils.test.ts +0 -137
- package/src/compiler/utils/config-detection.ts +0 -34
- package/src/compiler/utils/path-utils.ts +0 -22
- package/src/compiler/watcher-recovery.ts +0 -72
- package/src/host-bridge.ts +0 -36
- package/src/index.ts +0 -94
- package/src/platforms/build-cloudflare-output.ts +0 -116
- package/src/platforms/build-vercel-output.ts +0 -131
- package/src/plugins/index.ts +0 -1
- package/src/plugins/x402/index.ts +0 -24
- package/src/runtime/adapters/express/index.ts +0 -75
- package/src/runtime/adapters/fastify/__tests__/fastify.test.ts +0 -115
- package/src/runtime/adapters/fastify/index.ts +0 -78
- package/src/runtime/adapters/nestjs/index.ts +0 -16
- package/src/runtime/adapters/nestjs/xmcp.controller.ts +0 -34
- package/src/runtime/adapters/nestjs/xmcp.guard.ts +0 -101
- package/src/runtime/adapters/nestjs/xmcp.oauth.controller.ts +0 -36
- package/src/runtime/adapters/nestjs/xmcp.oauth.module.ts +0 -21
- package/src/runtime/adapters/nestjs/xmcp.oauth.service.ts +0 -36
- package/src/runtime/adapters/nestjs/xmcp.service.ts +0 -96
- package/src/runtime/adapters/nestjs/xmcp.utils.ts +0 -11
- package/src/runtime/adapters/nextjs/auth.ts +0 -265
- package/src/runtime/adapters/nextjs/handler/error-handler.ts +0 -67
- package/src/runtime/adapters/nextjs/handler/node-to-web-adapter.ts +0 -143
- package/src/runtime/adapters/nextjs/handler/request-converter.ts +0 -74
- package/src/runtime/adapters/nextjs/handler/server-lifecycle.ts +0 -69
- package/src/runtime/adapters/nextjs/index.ts +0 -82
- package/src/runtime/contexts/client-info-context.ts +0 -16
- package/src/runtime/contexts/http-request-context.ts +0 -21
- package/src/runtime/contexts/http-transport-context.ts +0 -18
- package/src/runtime/headers.ts +0 -42
- package/src/runtime/middlewares/utils.ts +0 -72
- package/src/runtime/platforms/cloudflare/cors.ts +0 -44
- package/src/runtime/platforms/cloudflare/middlewares/api-key.ts +0 -102
- package/src/runtime/platforms/cloudflare/middlewares/jwt.ts +0 -127
- package/src/runtime/platforms/cloudflare/types.ts +0 -23
- package/src/runtime/platforms/cloudflare/worker.ts +0 -270
- package/src/runtime/templates/home.ts +0 -746
- package/src/runtime/transports/http/base-streamable-http.ts +0 -46
- package/src/runtime/transports/http/cors/headers.ts +0 -58
- package/src/runtime/transports/http/cors/index.ts +0 -34
- package/src/runtime/transports/http/index.ts +0 -78
- package/src/runtime/transports/http/stateless-streamable-http.ts +0 -311
- package/src/runtime/transports/http/web-stateless-http.ts +0 -288
- package/src/runtime/transports/stdio/index.ts +0 -109
- package/src/runtime/utils/__tests__/client-info.test.ts +0 -146
- package/src/runtime/utils/__tests__/tool-extra.test.ts +0 -239
- package/src/runtime/utils/client-info.ts +0 -114
- package/src/runtime/utils/elicitation.ts +0 -396
- package/src/runtime/utils/ext-apps-registry.ts +0 -151
- package/src/runtime/utils/mcp-app-protocol.ts +0 -16
- package/src/runtime/utils/mcp-app-types.ts +0 -113
- package/src/runtime/utils/mcp-host-bridge.ts +0 -473
- package/src/runtime/utils/path-to-tool-name.ts +0 -69
- package/src/runtime/utils/prompt-loader.ts +0 -151
- package/src/runtime/utils/prompts.ts +0 -69
- package/src/runtime/utils/react/generate-html.ts +0 -69
- package/src/runtime/utils/react/index.ts +0 -6
- package/src/runtime/utils/request-tool-names.ts +0 -48
- package/src/runtime/utils/resource-loader.ts +0 -151
- package/src/runtime/utils/resources.ts +0 -331
- package/src/runtime/utils/server.ts +0 -107
- package/src/runtime/utils/tool-loader.ts +0 -149
- package/src/runtime/utils/tools.ts +0 -183
- package/src/runtime/utils/transformers/prompt.ts +0 -120
- package/src/runtime/utils/transformers/resource.ts +0 -196
- package/src/runtime/utils/transformers/tool.ts +0 -400
- package/src/runtime/utils/ui/__tests__/split-meta.test.ts +0 -803
- package/src/runtime/utils/ui/flatten-meta.ts +0 -44
- package/src/runtime/utils/ui/split-meta.ts +0 -78
- package/src/runtime/utils/utils/resource-uri-composer.ts +0 -204
- package/src/runtime/utils/validators/index.ts +0 -138
- package/src/telemetry/ci-info.ts +0 -6
- package/src/telemetry/debug.ts +0 -8
- package/src/telemetry/events/definitions.ts +0 -52
- package/src/telemetry/events/detached-flush.ts +0 -83
- package/src/telemetry/events/post-payload.ts +0 -141
- package/src/telemetry/events/tracker.ts +0 -281
- package/src/telemetry/index.ts +0 -7
- package/src/telemetry/metadata.ts +0 -49
- package/src/telemetry/project-id.ts +0 -35
- package/src/telemetry/storage.ts +0 -218
- package/src/types/adapter.d.ts +0 -5
- package/src/types/client-info.ts +0 -20
- package/src/types/declarations.ts +0 -37
- package/src/types/injected.d.ts +0 -62
- package/src/types/middleware.ts +0 -19
- package/src/types/prompt.ts +0 -6
- package/src/types/resource.ts +0 -15
- package/src/types/tool.ts +0 -192
- package/src/types/ui-meta.ts +0 -42
- package/src/utils/cli-icons.ts +0 -5
- package/src/utils/constants.ts +0 -31
- package/src/utils/context.ts +0 -105
- package/src/utils/detect-package-manager.ts +0 -46
- package/src/utils/file-watcher.ts +0 -66
- package/src/utils/fs-utils.ts +0 -16
- package/src/utils/path-validation.ts +0 -66
- package/src/utils/port-utils.ts +0 -43
- package/src/utils/spawn-process.ts +0 -49
- package/src/utils/subscribable.ts +0 -62
package/src/client/headers.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A header with a static value (use only for non-sensitive values)
|
|
3
|
-
*/
|
|
4
|
-
export interface StaticHeader {
|
|
5
|
-
name: string;
|
|
6
|
-
value: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A header that reads its value from an environment variable at runtime.
|
|
11
|
-
* Use this for sensitive values like API keys and authorization tokens.
|
|
12
|
-
*/
|
|
13
|
-
export interface EnvHeader {
|
|
14
|
-
name: string;
|
|
15
|
-
/** The name of the environment variable to read at runtime */
|
|
16
|
-
env: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type CustomHeader = StaticHeader | EnvHeader;
|
|
20
|
-
|
|
21
|
-
export type CustomHeaders = CustomHeader[];
|
|
22
|
-
|
|
23
|
-
export const createEmptyHeader = (): StaticHeader => ({
|
|
24
|
-
name: "",
|
|
25
|
-
value: "",
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Check if a header uses an environment variable reference
|
|
30
|
-
*/
|
|
31
|
-
export const isEnvHeader = (header: CustomHeader): header is EnvHeader => {
|
|
32
|
-
return "env" in header && typeof header.env === "string";
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Converts CustomHeaders to a Record, resolving environment variables at runtime.
|
|
37
|
-
* Throws if a required env var is not set.
|
|
38
|
-
*/
|
|
39
|
-
export const headersToRecord = (
|
|
40
|
-
headers: CustomHeaders
|
|
41
|
-
): Record<string, string> => {
|
|
42
|
-
const record: Record<string, string> = {};
|
|
43
|
-
|
|
44
|
-
headers.forEach((header) => {
|
|
45
|
-
const name = header.name.trim();
|
|
46
|
-
|
|
47
|
-
if (isEnvHeader(header)) {
|
|
48
|
-
const envValue = process.env[header.env];
|
|
49
|
-
if (envValue === undefined) {
|
|
50
|
-
throw new Error(
|
|
51
|
-
`Environment variable "${header.env}" is not set (required for header "${name}")`
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
record[name] = envValue;
|
|
55
|
-
} else {
|
|
56
|
-
record[name] = header.value.trim();
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
return record;
|
|
61
|
-
};
|
package/src/client/index.ts
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
-
import {
|
|
3
|
-
StdioClientTransport,
|
|
4
|
-
type StdioServerParameters,
|
|
5
|
-
} from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
6
|
-
import {
|
|
7
|
-
StreamableHTTPClientTransport,
|
|
8
|
-
StreamableHTTPClientTransportOptions,
|
|
9
|
-
} from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
10
|
-
import {
|
|
11
|
-
Request,
|
|
12
|
-
Result,
|
|
13
|
-
Notification,
|
|
14
|
-
} from "@modelcontextprotocol/sdk/types.js";
|
|
15
|
-
import type { Buffer } from "node:buffer";
|
|
16
|
-
import { CustomHeaders, headersToRecord } from "./headers";
|
|
17
|
-
|
|
18
|
-
const packageJson = require("../../package.json");
|
|
19
|
-
|
|
20
|
-
// Client identity for MCP connections
|
|
21
|
-
export const CLIENT_IDENTITY = {
|
|
22
|
-
name: packageJson.name,
|
|
23
|
-
version: packageJson.version,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const CLIENT_CAPABILITIES = {
|
|
27
|
-
capabilities: {
|
|
28
|
-
sampling: {},
|
|
29
|
-
elicitation: {
|
|
30
|
-
form: {},
|
|
31
|
-
url: {},
|
|
32
|
-
},
|
|
33
|
-
roots: { listChanged: true },
|
|
34
|
-
},
|
|
35
|
-
} as const;
|
|
36
|
-
|
|
37
|
-
interface HttpClientOptions {
|
|
38
|
-
/** Full MCP server base URL — example: https://host.tld/mcp */
|
|
39
|
-
url: string;
|
|
40
|
-
headers?: CustomHeaders;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Pure direct HTTP MCP client (no proxy, no SSE, no stdio)
|
|
45
|
-
*/
|
|
46
|
-
export async function createHTTPClient({
|
|
47
|
-
url,
|
|
48
|
-
headers,
|
|
49
|
-
}: HttpClientOptions): Promise<Client<Request, Notification, Result>> {
|
|
50
|
-
const client = new Client<Request, Notification, Result>(
|
|
51
|
-
CLIENT_IDENTITY,
|
|
52
|
-
CLIENT_CAPABILITIES
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
// ----- headers -----
|
|
56
|
-
const headersRecord = headers
|
|
57
|
-
? headersToRecord(headers)
|
|
58
|
-
: ({} as Record<string, string>);
|
|
59
|
-
|
|
60
|
-
// ----- Build URL -----
|
|
61
|
-
const serverUrl = new URL(url);
|
|
62
|
-
|
|
63
|
-
// ----- Construct HTTP transport -----
|
|
64
|
-
const transportOptions: StreamableHTTPClientTransportOptions = {
|
|
65
|
-
...(headers ? { requestInit: { headers: headersRecord } } : {}),
|
|
66
|
-
reconnectionOptions: {
|
|
67
|
-
maxReconnectionDelay: 30000,
|
|
68
|
-
initialReconnectionDelay: 1000,
|
|
69
|
-
reconnectionDelayGrowFactor: 1.5,
|
|
70
|
-
maxRetries: 2,
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const transport = new StreamableHTTPClientTransport(
|
|
75
|
-
serverUrl,
|
|
76
|
-
transportOptions
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
await client.connect(transport);
|
|
80
|
-
|
|
81
|
-
return client;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export interface StdioClientOptions extends StdioServerParameters {
|
|
85
|
-
/**
|
|
86
|
-
* Optional hook that receives stderr chunks when the transport
|
|
87
|
-
* runs with piped stderr (defaults to logging to console.error).
|
|
88
|
-
*/
|
|
89
|
-
onStderrData?: (chunk: Buffer) => void;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export interface StdioClientConnection {
|
|
93
|
-
client: Client<Request, Notification, Result>;
|
|
94
|
-
transport: StdioClientTransport;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Spawn and connect to an MCP server via stdio transport.
|
|
99
|
-
*/
|
|
100
|
-
export async function createSTDIOClient(
|
|
101
|
-
options: StdioClientOptions
|
|
102
|
-
): Promise<StdioClientConnection> {
|
|
103
|
-
const { onStderrData, ...serverParams } = options;
|
|
104
|
-
|
|
105
|
-
const client = new Client<Request, Notification, Result>(
|
|
106
|
-
CLIENT_IDENTITY,
|
|
107
|
-
CLIENT_CAPABILITIES
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
const transport = new StdioClientTransport({
|
|
111
|
-
...serverParams,
|
|
112
|
-
stderr: serverParams.stderr ?? "pipe",
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
const stderrStream = transport.stderr;
|
|
116
|
-
if (stderrStream) {
|
|
117
|
-
const stderrHandler =
|
|
118
|
-
onStderrData ??
|
|
119
|
-
((data: Buffer) => {
|
|
120
|
-
console.error(`[STDIO MCP Server stderr]: ${data}`);
|
|
121
|
-
});
|
|
122
|
-
stderrStream.on("data", stderrHandler);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
await client.connect(transport);
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
client,
|
|
129
|
-
transport,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Convenience helper to list available tools on a stdio MCP server.
|
|
135
|
-
*/
|
|
136
|
-
export async function listSTDIOClientTools(
|
|
137
|
-
connection: StdioClientConnection
|
|
138
|
-
): Promise<string[]> {
|
|
139
|
-
try {
|
|
140
|
-
const result = await connection.client.listTools();
|
|
141
|
-
return result.tools.map((tool) => tool.name);
|
|
142
|
-
} catch (error) {
|
|
143
|
-
console.error("Failed to list stdio MCP tools:", error);
|
|
144
|
-
return [];
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Invoke a tool exposed by the connected stdio MCP server.
|
|
150
|
-
*/
|
|
151
|
-
export async function callSTDIOClientTool(
|
|
152
|
-
connection: StdioClientConnection,
|
|
153
|
-
toolName: string,
|
|
154
|
-
args: Record<string, unknown>
|
|
155
|
-
): Promise<unknown> {
|
|
156
|
-
try {
|
|
157
|
-
return await connection.client.callTool({
|
|
158
|
-
name: toolName,
|
|
159
|
-
arguments: args,
|
|
160
|
-
});
|
|
161
|
-
} catch (error) {
|
|
162
|
-
console.error(`Failed to call stdio MCP tool "${toolName}":`, error);
|
|
163
|
-
throw error;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Disconnect the stdio transport and close the client.
|
|
169
|
-
*/
|
|
170
|
-
export async function disconnectSTDIOClient(
|
|
171
|
-
connection: StdioClientConnection
|
|
172
|
-
): Promise<void> {
|
|
173
|
-
try {
|
|
174
|
-
await connection.transport.close();
|
|
175
|
-
await connection.client.close();
|
|
176
|
-
} catch (error) {
|
|
177
|
-
console.error("Error disconnecting from stdio MCP server:", error);
|
|
178
|
-
throw error;
|
|
179
|
-
}
|
|
180
|
-
}
|
package/src/client/types.ts
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import type { createHTTPClient, StdioClientConnection } from ".";
|
|
2
|
-
import { CustomHeaders } from "./headers";
|
|
3
|
-
|
|
4
|
-
export type JsonValue =
|
|
5
|
-
| string
|
|
6
|
-
| number
|
|
7
|
-
| boolean
|
|
8
|
-
| null
|
|
9
|
-
| undefined
|
|
10
|
-
| JsonValue[]
|
|
11
|
-
| { [key: string]: JsonValue };
|
|
12
|
-
|
|
13
|
-
export type JsonSchemaConst = {
|
|
14
|
-
const: JsonValue;
|
|
15
|
-
title?: string;
|
|
16
|
-
description?: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type JsonSchemaType = {
|
|
20
|
-
type?:
|
|
21
|
-
| "string"
|
|
22
|
-
| "number"
|
|
23
|
-
| "integer"
|
|
24
|
-
| "boolean"
|
|
25
|
-
| "array"
|
|
26
|
-
| "object"
|
|
27
|
-
| "null"
|
|
28
|
-
| (
|
|
29
|
-
| "string"
|
|
30
|
-
| "number"
|
|
31
|
-
| "integer"
|
|
32
|
-
| "boolean"
|
|
33
|
-
| "array"
|
|
34
|
-
| "object"
|
|
35
|
-
| "null"
|
|
36
|
-
)[];
|
|
37
|
-
title?: string;
|
|
38
|
-
description?: string;
|
|
39
|
-
required?: string[];
|
|
40
|
-
default?: JsonValue;
|
|
41
|
-
properties?: Record<string, JsonSchemaType>;
|
|
42
|
-
items?: JsonSchemaType;
|
|
43
|
-
minimum?: number;
|
|
44
|
-
maximum?: number;
|
|
45
|
-
minLength?: number;
|
|
46
|
-
maxLength?: number;
|
|
47
|
-
nullable?: boolean;
|
|
48
|
-
pattern?: string;
|
|
49
|
-
format?: string;
|
|
50
|
-
enum?: string[];
|
|
51
|
-
const?: JsonValue;
|
|
52
|
-
oneOf?: (JsonSchemaType | JsonSchemaConst)[];
|
|
53
|
-
anyOf?: (JsonSchemaType | JsonSchemaConst)[];
|
|
54
|
-
$ref?: string;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export type HttpClient = Awaited<ReturnType<typeof createHTTPClient>>;
|
|
58
|
-
export type StdioClient = StdioClientConnection["client"];
|
|
59
|
-
|
|
60
|
-
export type StdioIOStrategy = "pipe" | "inherit" | "ignore";
|
|
61
|
-
|
|
62
|
-
export type HttpClientDefinition = {
|
|
63
|
-
type: "http";
|
|
64
|
-
name: string;
|
|
65
|
-
url: string;
|
|
66
|
-
headers?: CustomHeaders;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export type StdioClientDefinition = {
|
|
70
|
-
type: "stdio";
|
|
71
|
-
name: string;
|
|
72
|
-
command: string;
|
|
73
|
-
args: string[];
|
|
74
|
-
npm?: string;
|
|
75
|
-
npmArgs?: string[];
|
|
76
|
-
env?: Record<string, string>;
|
|
77
|
-
cwd?: string;
|
|
78
|
-
stderr?: StdioIOStrategy;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export type ClientDefinition = HttpClientDefinition | StdioClientDefinition;
|
|
82
|
-
|
|
83
|
-
export type HttpClientConfig = {
|
|
84
|
-
/**
|
|
85
|
-
* Optional friendly name. When omitted, the key in the exported map is used.
|
|
86
|
-
*/
|
|
87
|
-
name?: string;
|
|
88
|
-
/**
|
|
89
|
-
* Explicit transport hint. Defaults to HTTP when a URL is present.
|
|
90
|
-
*/
|
|
91
|
-
type?: "http";
|
|
92
|
-
url: string;
|
|
93
|
-
headers?: CustomHeaders;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export type StdioClientConfig = {
|
|
97
|
-
/**
|
|
98
|
-
* Optional friendly name. When omitted, the key in the exported map is used.
|
|
99
|
-
*/
|
|
100
|
-
name?: string;
|
|
101
|
-
/**
|
|
102
|
-
* Explicit transport hint. Defaults to stdio when npm/command are provided.
|
|
103
|
-
*/
|
|
104
|
-
type?: "stdio";
|
|
105
|
-
command?: string;
|
|
106
|
-
args?: string[];
|
|
107
|
-
npm?: string;
|
|
108
|
-
npmArgs?: string[];
|
|
109
|
-
env?: Record<string, string>;
|
|
110
|
-
cwd?: string;
|
|
111
|
-
stderr?: StdioIOStrategy;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
export type ClientConnectionEntry =
|
|
115
|
-
| string
|
|
116
|
-
| HttpClientConfig
|
|
117
|
-
| StdioClientConfig
|
|
118
|
-
| ClientDefinition;
|
|
119
|
-
|
|
120
|
-
export type ClientConnections =
|
|
121
|
-
| Record<string, ClientConnectionEntry>
|
|
122
|
-
| ClientConnectionEntry[];
|
package/src/client/utils.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { JsonSchemaType } from "./types";
|
|
2
|
-
|
|
3
|
-
export function resolveRef(
|
|
4
|
-
schema: JsonSchemaType,
|
|
5
|
-
rootSchema: JsonSchemaType
|
|
6
|
-
): JsonSchemaType {
|
|
7
|
-
if (!("$ref" in schema) || !schema.$ref) {
|
|
8
|
-
return schema;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const ref = schema.$ref;
|
|
12
|
-
|
|
13
|
-
// Handle simple #/properties/name references
|
|
14
|
-
if (ref.startsWith("#/")) {
|
|
15
|
-
const path = ref.substring(2).split("/");
|
|
16
|
-
let current: unknown = rootSchema;
|
|
17
|
-
|
|
18
|
-
for (const segment of path) {
|
|
19
|
-
if (
|
|
20
|
-
current &&
|
|
21
|
-
typeof current === "object" &&
|
|
22
|
-
current !== null &&
|
|
23
|
-
segment in current
|
|
24
|
-
) {
|
|
25
|
-
current = (current as Record<string, unknown>)[segment];
|
|
26
|
-
} else {
|
|
27
|
-
// If reference cannot be resolved, return the original schema
|
|
28
|
-
console.warn(`Could not resolve $ref: ${ref}`);
|
|
29
|
-
return schema;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return current as JsonSchemaType;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// For other types of references, return the original schema
|
|
37
|
-
console.warn(`Unsupported $ref format: ${ref}`);
|
|
38
|
-
return schema;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function normalizeUnionType(schema: JsonSchemaType): JsonSchemaType {
|
|
42
|
-
// Handle anyOf with exactly string and null
|
|
43
|
-
if (
|
|
44
|
-
schema.anyOf &&
|
|
45
|
-
schema.anyOf.length === 2 &&
|
|
46
|
-
schema.anyOf.some((t) => (t as JsonSchemaType).type === "string") &&
|
|
47
|
-
schema.anyOf.some((t) => (t as JsonSchemaType).type === "null")
|
|
48
|
-
) {
|
|
49
|
-
return { ...schema, type: "string", anyOf: undefined, nullable: true };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Handle anyOf with exactly boolean and null
|
|
53
|
-
if (
|
|
54
|
-
schema.anyOf &&
|
|
55
|
-
schema.anyOf.length === 2 &&
|
|
56
|
-
schema.anyOf.some((t) => (t as JsonSchemaType).type === "boolean") &&
|
|
57
|
-
schema.anyOf.some((t) => (t as JsonSchemaType).type === "null")
|
|
58
|
-
) {
|
|
59
|
-
return { ...schema, type: "boolean", anyOf: undefined, nullable: true };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Handle anyOf with exactly number and null
|
|
63
|
-
if (
|
|
64
|
-
schema.anyOf &&
|
|
65
|
-
schema.anyOf.length === 2 &&
|
|
66
|
-
schema.anyOf.some((t) => (t as JsonSchemaType).type === "number") &&
|
|
67
|
-
schema.anyOf.some((t) => (t as JsonSchemaType).type === "null")
|
|
68
|
-
) {
|
|
69
|
-
return { ...schema, type: "number", anyOf: undefined, nullable: true };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Handle anyOf with exactly integer and null
|
|
73
|
-
if (
|
|
74
|
-
schema.anyOf &&
|
|
75
|
-
schema.anyOf.length === 2 &&
|
|
76
|
-
schema.anyOf.some((t) => (t as JsonSchemaType).type === "integer") &&
|
|
77
|
-
schema.anyOf.some((t) => (t as JsonSchemaType).type === "null")
|
|
78
|
-
) {
|
|
79
|
-
return { ...schema, type: "integer", anyOf: undefined, nullable: true };
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Handle anyOf with exactly array and null
|
|
83
|
-
if (
|
|
84
|
-
schema.anyOf &&
|
|
85
|
-
schema.anyOf.length === 2 &&
|
|
86
|
-
schema.anyOf.some((t) => (t as JsonSchemaType).type === "array") &&
|
|
87
|
-
schema.anyOf.some((t) => (t as JsonSchemaType).type === "null")
|
|
88
|
-
) {
|
|
89
|
-
return { ...schema, type: "array", anyOf: undefined, nullable: true };
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Handle array type with exactly string and null
|
|
93
|
-
if (
|
|
94
|
-
Array.isArray(schema.type) &&
|
|
95
|
-
schema.type.length === 2 &&
|
|
96
|
-
schema.type.includes("string") &&
|
|
97
|
-
schema.type.includes("null")
|
|
98
|
-
) {
|
|
99
|
-
return { ...schema, type: "string", nullable: true };
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Handle array type with exactly boolean and null
|
|
103
|
-
if (
|
|
104
|
-
Array.isArray(schema.type) &&
|
|
105
|
-
schema.type.length === 2 &&
|
|
106
|
-
schema.type.includes("boolean") &&
|
|
107
|
-
schema.type.includes("null")
|
|
108
|
-
) {
|
|
109
|
-
return { ...schema, type: "boolean", nullable: true };
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Handle array type with exactly number and null
|
|
113
|
-
if (
|
|
114
|
-
Array.isArray(schema.type) &&
|
|
115
|
-
schema.type.length === 2 &&
|
|
116
|
-
schema.type.includes("number") &&
|
|
117
|
-
schema.type.includes("null")
|
|
118
|
-
) {
|
|
119
|
-
return { ...schema, type: "number", nullable: true };
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Handle array type with exactly integer and null
|
|
123
|
-
if (
|
|
124
|
-
Array.isArray(schema.type) &&
|
|
125
|
-
schema.type.length === 2 &&
|
|
126
|
-
schema.type.includes("integer") &&
|
|
127
|
-
schema.type.includes("null")
|
|
128
|
-
) {
|
|
129
|
-
return { ...schema, type: "integer", nullable: true };
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return schema;
|
|
133
|
-
}
|
package/src/cloudflare.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { cloudflareApiKeyAuthMiddleware as apiKeyAuthMiddleware } from "./runtime/platforms/cloudflare/middlewares/api-key";
|
|
2
|
-
export {
|
|
3
|
-
cloudflareJwtAuthMiddleware as jwtAuthMiddleware,
|
|
4
|
-
type CloudflareJWTAuthMiddlewareConfig as JWTAuthMiddlewareConfig,
|
|
5
|
-
} from "./runtime/platforms/cloudflare/middlewares/jwt";
|
|
6
|
-
export type { WebMiddleware } from "./types/middleware";
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AdapterType,
|
|
3
|
-
ErrorPhase,
|
|
4
|
-
TelemetryEventName,
|
|
5
|
-
TransportType,
|
|
6
|
-
telemetry,
|
|
7
|
-
} from "../telemetry";
|
|
8
|
-
import type { BuildEventData } from "../telemetry/events/post-payload";
|
|
9
|
-
import { isTelemetryDebugEnabled } from "../telemetry/debug";
|
|
10
|
-
|
|
11
|
-
type TelemetryClient = Pick<typeof telemetry, "record" | "flushDetached">;
|
|
12
|
-
|
|
13
|
-
interface BaseTelemetryData {
|
|
14
|
-
duration: number;
|
|
15
|
-
toolsCount: number;
|
|
16
|
-
reactToolsCount: number;
|
|
17
|
-
promptsCount: number;
|
|
18
|
-
resourcesCount: number;
|
|
19
|
-
transport: TransportType;
|
|
20
|
-
adapter: AdapterType;
|
|
21
|
-
nodeVersion: string;
|
|
22
|
-
xmcpVersion: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface BuildSuccessTelemetry extends BaseTelemetryData {
|
|
26
|
-
outputSize: number;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface BuildFailureTelemetry extends BaseTelemetryData {
|
|
30
|
-
errorPhase: ErrorPhase;
|
|
31
|
-
errorType: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function enqueueTelemetryEvent(
|
|
35
|
-
client: TelemetryClient,
|
|
36
|
-
event: { eventName: TelemetryEventName; fields: BuildEventData }
|
|
37
|
-
) {
|
|
38
|
-
if (isTelemetryDebugEnabled()) {
|
|
39
|
-
console.log("[telemetry] Tracking event", event);
|
|
40
|
-
}
|
|
41
|
-
client.record(event, true);
|
|
42
|
-
client.flushDetached("build");
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function logBuildSuccess(
|
|
46
|
-
data: BuildSuccessTelemetry,
|
|
47
|
-
client: TelemetryClient = telemetry
|
|
48
|
-
) {
|
|
49
|
-
enqueueTelemetryEvent(client, {
|
|
50
|
-
eventName: TelemetryEventName.BUILD_COMPLETED,
|
|
51
|
-
fields: {
|
|
52
|
-
success: true,
|
|
53
|
-
duration: data.duration,
|
|
54
|
-
toolsCount: data.toolsCount,
|
|
55
|
-
reactToolsCount: data.reactToolsCount,
|
|
56
|
-
promptsCount: data.promptsCount,
|
|
57
|
-
resourcesCount: data.resourcesCount,
|
|
58
|
-
outputSize: data.outputSize,
|
|
59
|
-
transport: data.transport,
|
|
60
|
-
adapter: data.adapter,
|
|
61
|
-
nodeVersion: data.nodeVersion,
|
|
62
|
-
xmcpVersion: data.xmcpVersion,
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function logBuildFailure(
|
|
68
|
-
data: BuildFailureTelemetry,
|
|
69
|
-
client: TelemetryClient = telemetry
|
|
70
|
-
) {
|
|
71
|
-
enqueueTelemetryEvent(client, {
|
|
72
|
-
eventName: TelemetryEventName.BUILD_FAILED,
|
|
73
|
-
fields: {
|
|
74
|
-
success: false,
|
|
75
|
-
duration: data.duration,
|
|
76
|
-
errorPhase: data.errorPhase,
|
|
77
|
-
errorType: data.errorType,
|
|
78
|
-
toolsCount: data.toolsCount,
|
|
79
|
-
reactToolsCount: data.reactToolsCount,
|
|
80
|
-
promptsCount: data.promptsCount,
|
|
81
|
-
resourcesCount: data.resourcesCount,
|
|
82
|
-
transport: data.transport,
|
|
83
|
-
adapter: data.adapter,
|
|
84
|
-
nodeVersion: data.nodeVersion,
|
|
85
|
-
xmcpVersion: data.xmcpVersion,
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
}
|