-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvite.config.ts
More file actions
137 lines (134 loc) · 4.22 KB
/
Copy pathvite.config.ts
File metadata and controls
137 lines (134 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import tailwindcss from "@tailwindcss/vite";
import react from "@vitejs/plugin-react";
import { readFileSync } from "node:fs";
import path from "node:path";
import { defineConfig } from "vite";
import { hasNoOpenFlag, parsePortFromArgs } from "./src/server/utils.js";
import { inspectorDevApiPlugin } from "./src/server/vite-dev-api-plugin.js";
import { getDevCallbackRedirect } from "./src/server/dev-callback-redirect.js";
// Read version from package.json
const packageJson = JSON.parse(
readFileSync(path.resolve(__dirname, "package.json"), "utf-8")
);
const clientPackageJson = JSON.parse(
readFileSync(path.resolve(__dirname, "../client/package.json"), "utf-8")
);
const devPort =
parsePortFromArgs() ?? (Number(process.env.INSPECTOR_PORT) || 3000);
export default defineConfig({
base: "/inspector",
plugins: [
react(),
tailwindcss(),
inspectorDevApiPlugin(),
{
name: "inspector-dev-banner",
configureServer(server) {
server.httpServer?.once("listening", () => {
const addr = server.httpServer?.address();
const port = typeof addr === "object" && addr ? addr.port : devPort;
console.log(
`\n🚀 MCP Inspector running on http://localhost:${port}/inspector`
);
console.log(
"📡 Proxy request logs appear below when you connect to an MCP server\n"
);
});
},
},
// Custom plugin to inject version into HTML
{
name: "inject-version",
transformIndexHtml(html) {
return html.replace(
"</head>",
` <script>window.__INSPECTOR_VERSION__ = "${packageJson.version}";</script>\n <script>window.__MCP_INSPECTOR_MODE__ = "development";</script>\n </head>`
);
},
},
// Mirror MCP_USE_ANONYMIZED_TELEMETRY=false into a per-page window flag so
// the env-var opt-out works in pure-Vite dev mode too (the inspector
// backend's `injectRuntimeConfig` never runs when Vite serves directly).
{
name: "inject-telemetry-opt-out",
transformIndexHtml() {
if (process.env.MCP_USE_ANONYMIZED_TELEMETRY !== "false") return [];
return [
{
tag: "script",
children: "window.__MCP_USE_ANONYMIZED_TELEMETRY__ = false;",
injectTo: "head-prepend",
},
];
},
},
// Mirror MANUFACT_CHAT_URL / VITE_MANUFACT_CHAT_URL into window for parity
// with the packaged Inspector shell (cli.ts injects the same flag at runtime).
{
name: "inject-manufact-chat-url",
transformIndexHtml() {
const url =
process.env.MANUFACT_CHAT_URL ?? process.env.VITE_MANUFACT_CHAT_URL;
if (!url) return [];
return [
{
tag: "script",
children: `window.__MANUFACT_CHAT_URL__ = ${JSON.stringify(url)};`,
injectTo: "head-prepend",
},
];
},
},
// Custom plugin to handle OAuth callback redirects in dev mode
{
name: "oauth-callback-redirect",
configureServer(server) {
server.middlewares.use((req, res, next) => {
const redirect = getDevCallbackRedirect(req.url ?? "");
if (redirect) {
res.writeHead(302, { Location: redirect });
res.end();
return;
}
next();
});
},
},
],
resolve: {
// Ensure a single React instance even when deps resolve to different minor versions.
dedupe: ["react", "react-dom"],
alias: {
"@": path.resolve(__dirname, "./src"),
},
conditions: ["browser", "module", "import", "default"],
},
define: {
"process.env": "{}",
"process.platform": '"browser"',
__MCP_USE_PACKAGE_VERSION__: JSON.stringify(clientPackageJson.version),
// Ensure global is defined
global: "globalThis",
},
optimizeDeps: {
include: ["@mcp-use/client", "@mcp-use/client/react", "@mcp-use/agent"],
},
build: {
minify: true,
outDir: "dist/web",
rolldownOptions: {
external: [
"langfuse-langchain",
"langfuse",
"@e2b/code-interpreter",
"os",
],
},
},
server: {
port: devPort,
strictPort: true,
host: true,
open: hasNoOpenFlag() ? false : "/inspector",
},
});