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
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { XmcpConfigOutputSchema } from "@/compiler/config";
|
|
2
|
-
import { compilerContext } from "../compiler-context";
|
|
3
|
-
import {
|
|
4
|
-
injectCorsVariables,
|
|
5
|
-
InjectedVariables,
|
|
6
|
-
injectHttpVariables,
|
|
7
|
-
injectPathsVariables,
|
|
8
|
-
injectStdioVariables,
|
|
9
|
-
injectTemplateVariables,
|
|
10
|
-
injectServerInfoVariables,
|
|
11
|
-
injectAdapterVariables,
|
|
12
|
-
injectTypescriptVariables,
|
|
13
|
-
} from "../config/injection";
|
|
14
|
-
import { getResolvedHttpConfig } from "../config/utils";
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* The XMCP runtime uses variables that are not defined by default.
|
|
18
|
-
*
|
|
19
|
-
* This utility will define those variables based on the user's config.
|
|
20
|
-
*/
|
|
21
|
-
export function getInjectedVariables(
|
|
22
|
-
xmcpConfig: XmcpConfigOutputSchema
|
|
23
|
-
): InjectedVariables {
|
|
24
|
-
const { mode } = compilerContext.getContext();
|
|
25
|
-
|
|
26
|
-
const resolvedHttpConfig = getResolvedHttpConfig(xmcpConfig.http);
|
|
27
|
-
const httpVariables = injectHttpVariables(xmcpConfig.http, mode);
|
|
28
|
-
const corsVariables = injectCorsVariables(resolvedHttpConfig);
|
|
29
|
-
const pathsVariables = injectPathsVariables(xmcpConfig);
|
|
30
|
-
const stdioVariables = injectStdioVariables(xmcpConfig.stdio);
|
|
31
|
-
const templateVariables = injectTemplateVariables(xmcpConfig);
|
|
32
|
-
const serverInfoVariables = injectServerInfoVariables(xmcpConfig);
|
|
33
|
-
const adapterVariables = injectAdapterVariables(xmcpConfig);
|
|
34
|
-
const typescriptVariables = injectTypescriptVariables(xmcpConfig);
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
...httpVariables,
|
|
38
|
-
...corsVariables,
|
|
39
|
-
...pathsVariables,
|
|
40
|
-
...stdioVariables,
|
|
41
|
-
...templateVariables,
|
|
42
|
-
...serverInfoVariables,
|
|
43
|
-
...adapterVariables,
|
|
44
|
-
...typescriptVariables,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
RspackOptions,
|
|
3
|
-
ProvidePlugin,
|
|
4
|
-
DefinePlugin,
|
|
5
|
-
BannerPlugin,
|
|
6
|
-
NormalModuleReplacementPlugin,
|
|
7
|
-
IgnorePlugin,
|
|
8
|
-
type ResolveAlias,
|
|
9
|
-
} from "@rspack/core";
|
|
10
|
-
import path from "path";
|
|
11
|
-
import {
|
|
12
|
-
distOutputPath,
|
|
13
|
-
adapterOutputPath,
|
|
14
|
-
cloudflareOutputPath,
|
|
15
|
-
resolveXmcpSrcPath,
|
|
16
|
-
} from "@/utils/constants";
|
|
17
|
-
import { compilerContext } from "@/compiler/compiler-context";
|
|
18
|
-
import { XmcpConfigOutputSchema } from "@/compiler/config";
|
|
19
|
-
import { getEntries } from "./get-entries";
|
|
20
|
-
import { getInjectedVariables } from "./get-injected-variables";
|
|
21
|
-
import { resolveTsconfigPathsToAlias } from "./resolve-tsconfig-paths";
|
|
22
|
-
import {
|
|
23
|
-
CreateTypeDefinitionPlugin,
|
|
24
|
-
InjectRuntimePlugin,
|
|
25
|
-
readClientBundlesFromDisk,
|
|
26
|
-
} from "./plugins";
|
|
27
|
-
import { getExternals } from "./get-externals";
|
|
28
|
-
import { TsCheckerRspackPlugin } from "ts-checker-rspack-plugin";
|
|
29
|
-
import fs from "fs";
|
|
30
|
-
|
|
31
|
-
/** Creates the bundler configuration that xmcp will use to bundle the user's code */
|
|
32
|
-
export function getRspackConfig(
|
|
33
|
-
xmcpConfig: XmcpConfigOutputSchema
|
|
34
|
-
): RspackOptions {
|
|
35
|
-
const processFolder = process.cwd();
|
|
36
|
-
const { mode, platforms } = compilerContext.getContext();
|
|
37
|
-
|
|
38
|
-
const isCloudflare = !!platforms.cloudflare;
|
|
39
|
-
const projectZodPath = path.join(processFolder, "node_modules", "zod");
|
|
40
|
-
const zodAliases: ResolveAlias = fs.existsSync(projectZodPath)
|
|
41
|
-
? {
|
|
42
|
-
zod: projectZodPath,
|
|
43
|
-
"zod/v3": path.join(projectZodPath, "v3"),
|
|
44
|
-
"zod/v4-mini": path.join(projectZodPath, "v4-mini"),
|
|
45
|
-
}
|
|
46
|
-
: {};
|
|
47
|
-
|
|
48
|
-
const outputPath = isCloudflare
|
|
49
|
-
? cloudflareOutputPath
|
|
50
|
-
: xmcpConfig.experimental?.adapter
|
|
51
|
-
? adapterOutputPath
|
|
52
|
-
: distOutputPath;
|
|
53
|
-
|
|
54
|
-
const outputFilename = isCloudflare
|
|
55
|
-
? "worker.js"
|
|
56
|
-
: xmcpConfig.experimental?.adapter
|
|
57
|
-
? "index.js"
|
|
58
|
-
: "[name].js";
|
|
59
|
-
|
|
60
|
-
const xmcpSrcPath = isCloudflare ? resolveXmcpSrcPath() : undefined;
|
|
61
|
-
const nodeBuiltins = [
|
|
62
|
-
"assert",
|
|
63
|
-
"buffer",
|
|
64
|
-
"child_process",
|
|
65
|
-
"cluster",
|
|
66
|
-
"console",
|
|
67
|
-
"constants",
|
|
68
|
-
"crypto",
|
|
69
|
-
"dgram",
|
|
70
|
-
"dns",
|
|
71
|
-
"domain",
|
|
72
|
-
"events",
|
|
73
|
-
"fs",
|
|
74
|
-
"http",
|
|
75
|
-
"https",
|
|
76
|
-
"module",
|
|
77
|
-
"net",
|
|
78
|
-
"os",
|
|
79
|
-
"path",
|
|
80
|
-
"perf_hooks",
|
|
81
|
-
"process",
|
|
82
|
-
"punycode",
|
|
83
|
-
"querystring",
|
|
84
|
-
"readline",
|
|
85
|
-
"repl",
|
|
86
|
-
"stream",
|
|
87
|
-
"string_decoder",
|
|
88
|
-
"sys",
|
|
89
|
-
"timers",
|
|
90
|
-
"tls",
|
|
91
|
-
"tty",
|
|
92
|
-
"url",
|
|
93
|
-
"util",
|
|
94
|
-
"vm",
|
|
95
|
-
"worker_threads",
|
|
96
|
-
"zlib",
|
|
97
|
-
];
|
|
98
|
-
const nodeBuiltinAliases = nodeBuiltins.reduce<Record<string, string>>(
|
|
99
|
-
(acc, builtin) => {
|
|
100
|
-
acc[`node:${builtin}`] = builtin;
|
|
101
|
-
return acc;
|
|
102
|
-
},
|
|
103
|
-
{}
|
|
104
|
-
);
|
|
105
|
-
const nodeBuiltinFallbacks = nodeBuiltins.reduce<Record<string, false>>(
|
|
106
|
-
(acc, builtin) => {
|
|
107
|
-
acc[builtin] = false;
|
|
108
|
-
acc[`node:${builtin}`] = false;
|
|
109
|
-
return acc;
|
|
110
|
-
},
|
|
111
|
-
{}
|
|
112
|
-
);
|
|
113
|
-
const nodeBuiltinsRegex = new RegExp(
|
|
114
|
-
`^(?:node:)?(${nodeBuiltins.join("|")})$`
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
const config: RspackOptions = {
|
|
118
|
-
mode,
|
|
119
|
-
watch: mode === "development",
|
|
120
|
-
devtool: mode === "development" ? "eval-cheap-module-source-map" : false,
|
|
121
|
-
output: {
|
|
122
|
-
filename: outputFilename,
|
|
123
|
-
path: outputPath,
|
|
124
|
-
globalObject: "globalThis",
|
|
125
|
-
...(isCloudflare
|
|
126
|
-
? {
|
|
127
|
-
library: { type: "module" },
|
|
128
|
-
chunkFormat: "module",
|
|
129
|
-
module: true,
|
|
130
|
-
}
|
|
131
|
-
: {
|
|
132
|
-
libraryTarget: "commonjs2",
|
|
133
|
-
}),
|
|
134
|
-
clean: {
|
|
135
|
-
keep:
|
|
136
|
-
xmcpConfig.experimental?.adapter || isCloudflare
|
|
137
|
-
? undefined
|
|
138
|
-
: path.join(outputPath, "client"),
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
target: isCloudflare ? "webworker" : "node",
|
|
142
|
-
externals: isCloudflare ? { async_hooks: "async_hooks" } : getExternals(),
|
|
143
|
-
experiments: isCloudflare ? { outputModule: true } : undefined,
|
|
144
|
-
resolve: {
|
|
145
|
-
fallback: {
|
|
146
|
-
process: false,
|
|
147
|
-
...(isCloudflare ? nodeBuiltinFallbacks : {}),
|
|
148
|
-
},
|
|
149
|
-
alias: {
|
|
150
|
-
...nodeBuiltinAliases,
|
|
151
|
-
"xmcp/headers": path.resolve(processFolder, ".xmcp/headers.js"),
|
|
152
|
-
"xmcp/utils": path.resolve(processFolder, ".xmcp/utils.js"),
|
|
153
|
-
"xmcp/plugins/x402":
|
|
154
|
-
isCloudflare && xmcpSrcPath
|
|
155
|
-
? path.join(xmcpSrcPath, "plugins/x402/index.ts")
|
|
156
|
-
: path.resolve(processFolder, ".xmcp/x402.js"),
|
|
157
|
-
...(isCloudflare && xmcpSrcPath
|
|
158
|
-
? {
|
|
159
|
-
"@": xmcpSrcPath,
|
|
160
|
-
}
|
|
161
|
-
: {}),
|
|
162
|
-
...zodAliases,
|
|
163
|
-
...resolveTsconfigPathsToAlias(),
|
|
164
|
-
},
|
|
165
|
-
extensions: [".tsx", ".ts", ".jsx", ".js", ".json"],
|
|
166
|
-
},
|
|
167
|
-
resolveLoader: {
|
|
168
|
-
modules: [
|
|
169
|
-
"node_modules",
|
|
170
|
-
path.resolve(__dirname, "../node_modules"), // for monorepo/npm
|
|
171
|
-
path.resolve(__dirname, "../.."), // for pnpm
|
|
172
|
-
],
|
|
173
|
-
},
|
|
174
|
-
plugins: [
|
|
175
|
-
isCloudflare ? new IgnorePlugin({ resourceRegExp: nodeBuiltinsRegex }) : null,
|
|
176
|
-
isCloudflare
|
|
177
|
-
? new NormalModuleReplacementPlugin(/^node:/, (resource) => {
|
|
178
|
-
resource.request = resource.request.replace(/^node:/, "");
|
|
179
|
-
})
|
|
180
|
-
: null,
|
|
181
|
-
new InjectRuntimePlugin(),
|
|
182
|
-
new CreateTypeDefinitionPlugin(),
|
|
183
|
-
xmcpConfig.typescript?.skipTypeCheck ? null : new TsCheckerRspackPlugin(),
|
|
184
|
-
],
|
|
185
|
-
module: {
|
|
186
|
-
rules: [
|
|
187
|
-
{
|
|
188
|
-
test: /\.(ts|tsx)$/,
|
|
189
|
-
use: {
|
|
190
|
-
loader: "builtin:swc-loader",
|
|
191
|
-
options: {
|
|
192
|
-
jsc: {
|
|
193
|
-
parser: {
|
|
194
|
-
syntax: "typescript",
|
|
195
|
-
tsx: true,
|
|
196
|
-
},
|
|
197
|
-
transform: {
|
|
198
|
-
react: {
|
|
199
|
-
runtime: "automatic",
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
target: "es2020",
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
test: /\.css$/,
|
|
209
|
-
type: "asset/source",
|
|
210
|
-
},
|
|
211
|
-
],
|
|
212
|
-
},
|
|
213
|
-
optimization: {
|
|
214
|
-
minimize: mode === "production",
|
|
215
|
-
mergeDuplicateChunks: true,
|
|
216
|
-
splitChunks: false,
|
|
217
|
-
...(isCloudflare ? { runtimeChunk: false } : {}),
|
|
218
|
-
},
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
// Do not watch the adapter output folder and dist/client, avoid infinite loop
|
|
222
|
-
if (mode === "development" && !xmcpConfig.experimental?.adapter) {
|
|
223
|
-
config.watchOptions = {
|
|
224
|
-
ignored: [adapterOutputPath, path.join(processFolder, "dist/client")],
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const providedPackages = {
|
|
229
|
-
// connects the user exports with our runtime
|
|
230
|
-
INJECTED_TOOLS: [
|
|
231
|
-
path.resolve(processFolder, ".xmcp/import-map.js"),
|
|
232
|
-
"tools",
|
|
233
|
-
],
|
|
234
|
-
INJECTED_PROMPTS: [
|
|
235
|
-
path.resolve(processFolder, ".xmcp/import-map.js"),
|
|
236
|
-
"prompts",
|
|
237
|
-
],
|
|
238
|
-
INJECTED_RESOURCES: [
|
|
239
|
-
path.resolve(processFolder, ".xmcp/import-map.js"),
|
|
240
|
-
"resources",
|
|
241
|
-
],
|
|
242
|
-
INJECTED_MIDDLEWARE: [
|
|
243
|
-
path.resolve(processFolder, ".xmcp/import-map.js"),
|
|
244
|
-
"middleware",
|
|
245
|
-
],
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
// add entry points based on config
|
|
249
|
-
config.entry = getEntries(xmcpConfig);
|
|
250
|
-
|
|
251
|
-
// add injected variables to config
|
|
252
|
-
config.plugins!.push(new ProvidePlugin(providedPackages));
|
|
253
|
-
|
|
254
|
-
// add defined variables to config
|
|
255
|
-
const definedVariables: Record<string, string | undefined> =
|
|
256
|
-
getInjectedVariables(xmcpConfig);
|
|
257
|
-
definedVariables["IS_CLOUDFLARE"] = JSON.stringify(isCloudflare);
|
|
258
|
-
|
|
259
|
-
if (isCloudflare) {
|
|
260
|
-
const clientBundles = readClientBundlesFromDisk();
|
|
261
|
-
definedVariables["INJECTED_CLIENT_BUNDLES"] = JSON.stringify(clientBundles);
|
|
262
|
-
} else {
|
|
263
|
-
definedVariables["INJECTED_CLIENT_BUNDLES"] = "undefined";
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// Filter out undefined values for DefinePlugin (requires Record<string, string>)
|
|
267
|
-
const filteredVariables: Record<string, string> = {};
|
|
268
|
-
for (const [key, value] of Object.entries(definedVariables)) {
|
|
269
|
-
if (value !== undefined) {
|
|
270
|
-
filteredVariables[key] = value;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
config.plugins!.push(new DefinePlugin(filteredVariables));
|
|
275
|
-
|
|
276
|
-
// add shebang to CLI output on stdio mode
|
|
277
|
-
if (xmcpConfig.stdio) {
|
|
278
|
-
config.plugins!.push(
|
|
279
|
-
new BannerPlugin({
|
|
280
|
-
banner: "#!/usr/bin/env node",
|
|
281
|
-
raw: true,
|
|
282
|
-
include: /^stdio\.js$/,
|
|
283
|
-
})
|
|
284
|
-
);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return config;
|
|
288
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { adapterOutputPath, runtimeFolderPath } from "@/utils/constants";
|
|
2
|
-
import fs from "fs-extra";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { Compiler } from "@rspack/core";
|
|
5
|
-
import { XmcpConfigOutputSchema } from "@/compiler/config";
|
|
6
|
-
import { getXmcpConfig } from "@/compiler/compiler-context";
|
|
7
|
-
import {
|
|
8
|
-
expressTypeDefinition,
|
|
9
|
-
fastifyTypeDefinition,
|
|
10
|
-
nestJsTypeDefinition,
|
|
11
|
-
nextJsTypeDefinition,
|
|
12
|
-
} from "./types";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Read all client bundles from disk for Cloudflare injection.
|
|
16
|
-
* Returns a record mapping bundle names to their JS and CSS contents.
|
|
17
|
-
*/
|
|
18
|
-
export function readClientBundlesFromDisk(): Record<
|
|
19
|
-
string,
|
|
20
|
-
{ js: string; css?: string }
|
|
21
|
-
> {
|
|
22
|
-
const bundles: Record<string, { js: string; css?: string }> = {};
|
|
23
|
-
const clientDir = path.join(process.cwd(), "dist", "client");
|
|
24
|
-
|
|
25
|
-
if (!fs.existsSync(clientDir)) {
|
|
26
|
-
return bundles;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const files = fs.readdirSync(clientDir);
|
|
30
|
-
const jsFiles = files.filter((f) => f.endsWith(".bundle.js"));
|
|
31
|
-
|
|
32
|
-
for (const jsFile of jsFiles) {
|
|
33
|
-
const bundleName = jsFile.replace(".bundle.js", "");
|
|
34
|
-
const jsPath = path.join(clientDir, jsFile);
|
|
35
|
-
const cssPath = path.join(clientDir, `${bundleName}.bundle.css`);
|
|
36
|
-
|
|
37
|
-
const js = fs.readFileSync(jsPath, "utf-8");
|
|
38
|
-
let css: string | undefined;
|
|
39
|
-
|
|
40
|
-
if (fs.existsSync(cssPath)) {
|
|
41
|
-
css = fs.readFileSync(cssPath, "utf-8");
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
bundles[bundleName] = { js, css };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return bundles;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export const runtimeFiles = RUNTIME_FILES as Record<string, string>;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Determines which runtime files are needed based on user configuration.
|
|
54
|
-
*/
|
|
55
|
-
function getNeededRuntimeFiles(xmcpConfig: XmcpConfigOutputSchema): string[] {
|
|
56
|
-
const neededFiles: string[] = [];
|
|
57
|
-
|
|
58
|
-
// headers included if http is configured
|
|
59
|
-
if (xmcpConfig.http) {
|
|
60
|
-
neededFiles.push("headers.js");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (xmcpConfig.stdio) {
|
|
64
|
-
neededFiles.push("stdio.js");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (xmcpConfig.http) {
|
|
68
|
-
if (xmcpConfig.experimental?.adapter === "express") {
|
|
69
|
-
neededFiles.push("adapter-express.js");
|
|
70
|
-
} else if (xmcpConfig.experimental?.adapter === "nextjs") {
|
|
71
|
-
neededFiles.push("adapter-nextjs.js");
|
|
72
|
-
} else if (xmcpConfig.experimental?.adapter === "nestjs") {
|
|
73
|
-
neededFiles.push("adapter-nestjs.js");
|
|
74
|
-
} else if (xmcpConfig.experimental?.adapter === "fastify") {
|
|
75
|
-
neededFiles.push("adapter-fastify.js");
|
|
76
|
-
} else {
|
|
77
|
-
neededFiles.push("http.js");
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return neededFiles;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export class InjectRuntimePlugin {
|
|
85
|
-
apply(compiler: Compiler) {
|
|
86
|
-
let hasRun = false;
|
|
87
|
-
compiler.hooks.beforeCompile.tap(
|
|
88
|
-
"InjectRuntimePlugin",
|
|
89
|
-
(_compilationParams) => {
|
|
90
|
-
if (hasRun) return;
|
|
91
|
-
hasRun = true;
|
|
92
|
-
|
|
93
|
-
const xmcpConfig = getXmcpConfig();
|
|
94
|
-
const neededFiles = getNeededRuntimeFiles(xmcpConfig);
|
|
95
|
-
|
|
96
|
-
for (const [fileName, fileContent] of Object.entries(runtimeFiles)) {
|
|
97
|
-
if (neededFiles.includes(fileName)) {
|
|
98
|
-
fs.writeFileSync(
|
|
99
|
-
path.join(runtimeFolderPath, fileName),
|
|
100
|
-
fileContent
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export class CreateTypeDefinitionPlugin {
|
|
110
|
-
apply(compiler: Compiler) {
|
|
111
|
-
let hasRun = false;
|
|
112
|
-
compiler.hooks.afterEmit.tap(
|
|
113
|
-
"CreateTypeDefinitionPlugin",
|
|
114
|
-
(_compilationParams) => {
|
|
115
|
-
if (hasRun) return;
|
|
116
|
-
hasRun = true;
|
|
117
|
-
|
|
118
|
-
const xmcpConfig = getXmcpConfig();
|
|
119
|
-
|
|
120
|
-
// Manually type the .xmcp/adapter/index.js file using a .xmcp/adapter/index.d.ts file
|
|
121
|
-
if (xmcpConfig.experimental?.adapter) {
|
|
122
|
-
let typeDefinitionContent = "";
|
|
123
|
-
if (xmcpConfig.experimental?.adapter === "nextjs") {
|
|
124
|
-
typeDefinitionContent = nextJsTypeDefinition;
|
|
125
|
-
} else if (xmcpConfig.experimental?.adapter === "express") {
|
|
126
|
-
typeDefinitionContent = expressTypeDefinition;
|
|
127
|
-
} else if (xmcpConfig.experimental?.adapter === "nestjs") {
|
|
128
|
-
typeDefinitionContent = nestJsTypeDefinition;
|
|
129
|
-
} else if (xmcpConfig.experimental?.adapter === "fastify") {
|
|
130
|
-
typeDefinitionContent = fastifyTypeDefinition;
|
|
131
|
-
}
|
|
132
|
-
fs.writeFileSync(
|
|
133
|
-
path.join(adapterOutputPath, "index.d.ts"),
|
|
134
|
-
typeDefinitionContent
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
export const nestJsTypeDefinition = `
|
|
2
|
-
import { Request, Response } from "express";
|
|
3
|
-
import { Type, CanActivate, DynamicModule } from "@nestjs/common";
|
|
4
|
-
|
|
5
|
-
// Auth types
|
|
6
|
-
export interface AuthInfo {
|
|
7
|
-
token: string;
|
|
8
|
-
clientId: string;
|
|
9
|
-
scopes: string[];
|
|
10
|
-
expiresAt?: number;
|
|
11
|
-
extra?: Record<string, unknown>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface McpAuthConfig {
|
|
15
|
-
verifyToken: (token: string) => Promise<Omit<AuthInfo, "token">> | Omit<AuthInfo, "token">;
|
|
16
|
-
required?: boolean;
|
|
17
|
-
requiredScopes?: string[];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export declare function createMcpAuthGuard(config: McpAuthConfig): Type<CanActivate>;
|
|
21
|
-
|
|
22
|
-
// OAuth types
|
|
23
|
-
export interface OAuthConfig {
|
|
24
|
-
authorizationServers: string[];
|
|
25
|
-
scopesSupported?: string[];
|
|
26
|
-
bearerMethodsSupported?: string[];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface OAuthProtectedResourceMetadata {
|
|
30
|
-
resource: string;
|
|
31
|
-
authorizationServers: string[];
|
|
32
|
-
scopesSupported?: string[];
|
|
33
|
-
bearerMethodsSupported?: string[];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export declare class OAuthModule {
|
|
37
|
-
static forRoot(config: OAuthConfig): DynamicModule;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export declare class OAuthService {
|
|
41
|
-
getResourceMetadata(req: Request): OAuthProtectedResourceMetadata;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export declare class OAuthController {
|
|
45
|
-
constructor(oauthService: OAuthService);
|
|
46
|
-
getResourceMetadata(req: Request): OAuthProtectedResourceMetadata;
|
|
47
|
-
handleOptions(res: Response): void;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Utility functions
|
|
51
|
-
export declare function buildBaseUrl(req: Request): string;
|
|
52
|
-
export declare function buildResourceMetadataUrl(req: Request): string;
|
|
53
|
-
|
|
54
|
-
// MCP Service & Controller
|
|
55
|
-
export declare class XmcpService {
|
|
56
|
-
handleRequest(req: Request & { auth?: AuthInfo }, res: Response): Promise<void>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export declare class XmcpController {
|
|
60
|
-
constructor(xmcpService: XmcpService);
|
|
61
|
-
handleMcp(req: Request, res: Response): Promise<void>;
|
|
62
|
-
handleGet(res: Response): void;
|
|
63
|
-
handleOptions(res: Response): void;
|
|
64
|
-
}
|
|
65
|
-
`;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export const nextJsTypeDefinition = `
|
|
2
|
-
export const xmcpHandler: (req: Request) => Promise<Response>;
|
|
3
|
-
export const withAuth: (handler: (req: Request) => Promise<Response>, authConfig: AuthConfig) => (req: Request) => Promise<Response>;
|
|
4
|
-
export const resourceMetadataHandler: ({authorizationServers}: {authorizationServers: string[]}) => (req: Request) => Response;
|
|
5
|
-
export const resourceMetadataOptions: (req: Request) => Response;
|
|
6
|
-
export const tools: () => Promise<Tool[]>;
|
|
7
|
-
export const toolRegistry: () => Promise<Record<string, ToolRegistryEntry>>;
|
|
8
|
-
export type VerifyToken = (req: Request, bearerToken?: string) => Promise<AuthInfo | undefined>;
|
|
9
|
-
export type AuthConfig = {
|
|
10
|
-
verifyToken: VerifyToken;
|
|
11
|
-
required?: boolean;
|
|
12
|
-
requiredScopes?: string[];
|
|
13
|
-
};
|
|
14
|
-
export type AuthInfo = {
|
|
15
|
-
token: string;
|
|
16
|
-
clientId: string;
|
|
17
|
-
scopes: string[];
|
|
18
|
-
expiresAt?: number;
|
|
19
|
-
resource?: URL;
|
|
20
|
-
extra?: Record<string, unknown>;
|
|
21
|
-
};
|
|
22
|
-
export type OAuthProtectedResourceMetadata = {
|
|
23
|
-
resource: string;
|
|
24
|
-
authorization_servers: string[];
|
|
25
|
-
bearer_methods_supported?: string[];
|
|
26
|
-
resource_documentation?: string;
|
|
27
|
-
introspection_endpoint?: string;
|
|
28
|
-
revocation_endpoint?: string;
|
|
29
|
-
[key: string]: unknown;
|
|
30
|
-
};
|
|
31
|
-
export type Tool = {
|
|
32
|
-
path: string;
|
|
33
|
-
name: string;
|
|
34
|
-
metadata: {
|
|
35
|
-
name: string;
|
|
36
|
-
description: string;
|
|
37
|
-
annotations?: {
|
|
38
|
-
title?: string;
|
|
39
|
-
[key: string]: any;
|
|
40
|
-
};
|
|
41
|
-
[key: string]: any;
|
|
42
|
-
};
|
|
43
|
-
schema: Record<string, any>;
|
|
44
|
-
handler: (args: any) => Promise<any>;
|
|
45
|
-
};
|
|
46
|
-
export type ToolRegistryEntry = {
|
|
47
|
-
description: string;
|
|
48
|
-
inputSchema: any; // Zod schema object
|
|
49
|
-
execute: (args: any) => Promise<any>;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
`;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// Based on https://gist.github.com/nerdyman/2f97b24ab826623bff9202750013f99e
|
|
2
|
-
|
|
3
|
-
import path from "path";
|
|
4
|
-
import { readFileSync, existsSync } from "fs";
|
|
5
|
-
import { parseJson } from "@/utils/fs-utils";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Resolve tsconfig.json paths to Rspack aliases
|
|
9
|
-
* @param {string} tsconfigPath - Path to tsconfig
|
|
10
|
-
* @param {string} bundlerConfigBasePath - Path from tsconfig to bundler config to create absolute aliases
|
|
11
|
-
* @return {object} - bundler alias config
|
|
12
|
-
*/
|
|
13
|
-
export function resolveTsconfigPathsToAlias({
|
|
14
|
-
tsconfigPath = "./tsconfig.json",
|
|
15
|
-
} = {}) {
|
|
16
|
-
if (!existsSync(tsconfigPath)) {
|
|
17
|
-
return {};
|
|
18
|
-
}
|
|
19
|
-
const tsconfigContent = readFileSync(tsconfigPath, "utf-8");
|
|
20
|
-
const [parsedTsconfig, parsingError] = parseJson(tsconfigContent);
|
|
21
|
-
|
|
22
|
-
if (parsingError) {
|
|
23
|
-
console.error(
|
|
24
|
-
`Error parsing tsconfig.json: ${parsingError.message} at ${tsconfigPath}`
|
|
25
|
-
);
|
|
26
|
-
console.log(tsconfigContent);
|
|
27
|
-
return {};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
!parsedTsconfig.compilerOptions ||
|
|
32
|
-
!parsedTsconfig.compilerOptions.paths
|
|
33
|
-
) {
|
|
34
|
-
return {};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const paths = parsedTsconfig.compilerOptions.paths;
|
|
38
|
-
|
|
39
|
-
const aliases: Record<string, string> = {};
|
|
40
|
-
|
|
41
|
-
Object.keys(paths).forEach((item) => {
|
|
42
|
-
const key = item.replace("/*", "");
|
|
43
|
-
const value = path.resolve(
|
|
44
|
-
paths[item][0].replace("/*", "").replace("*", "")
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
aliases[key] = value;
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
return aliases;
|
|
51
|
-
}
|