Skip to content

Commit 091100c

Browse files
committed
feat: enhance MCP configuration and improve ingest candidate probing
- Added MCP configuration options in vite.config.ts for local development. - Refactored the probing function to validate ingest candidates more effectively, improving detection of valid endpoints. - Updated health probe logic to streamline the process of checking MCP availability during server operations.
1 parent 35ece85 commit 091100c

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

example/vue-vite-app/vite.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export default defineConfig({
77
plugins: [vue(), browserEcho(
88
{
99
stackMode: 'condensed',
10-
network: { enabled: true }
10+
network: { enabled: true },
11+
mcp: { url: 'http://127.0.0.1:5179', suppressTerminal: true }
1112
},
1213
)],
1314
})

packages/vite/src/index.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,23 +149,24 @@ function attachMiddleware(server: any, options: ResolvedOptions) {
149149
}
150150
}
151151

152-
async function probeIsMcp(base: string): Promise<boolean> {
152+
async function probeIngestCandidate(base: string, ingestRoute: `/${string}`): Promise<boolean> {
153+
// Validate ingest-only servers by probing the ingest route directly
154+
const url = `${base}${ingestRoute}`;
153155
try {
154-
// Expect GET to return 405 Method Not Allowed for MCP endpoint
155156
const ctrl = new AbortController();
156157
const t = setTimeout(() => ctrl.abort(), 400);
157-
const res = await fetch(`${base}/mcp`, { method: 'GET', signal: ctrl.signal as any, cache: 'no-store' as any });
158+
const res = await fetch(url, { method: 'GET', signal: ctrl.signal as any, cache: 'no-store' as any });
158159
clearTimeout(t);
159-
if (res && res.status === 405) return true;
160-
// Fallback OPTIONS 200/204
161-
const ctrl2 = new AbortController();
162-
const t2 = setTimeout(() => ctrl2.abort(), 400);
163-
const res2 = await fetch(`${base}/mcp`, { method: 'OPTIONS', signal: ctrl2.signal as any, cache: 'no-store' as any });
164-
clearTimeout(t2);
165-
return !!res2 && (res2.status === 200 || res2.status === 204);
166-
} catch {
167-
return false;
168-
}
160+
if (res && (res.status === 200 || res.status === 204)) return true;
161+
} catch {}
162+
try {
163+
const ctrl = new AbortController();
164+
const t = setTimeout(() => ctrl.abort(), 400);
165+
const res = await fetch(url, { method: 'OPTIONS', signal: ctrl.signal as any, cache: 'no-store' as any });
166+
clearTimeout(t);
167+
if (res && (res.status === 200 || res.status === 204)) return true;
168+
} catch {}
169+
return false;
169170
}
170171

171172
function startHealthProbe() {
@@ -188,8 +189,8 @@ function attachMiddleware(server: any, options: ResolvedOptions) {
188189
healthy = !!res && res.ok;
189190
} catch {}
190191
if (healthy) {
191-
const isMcp = await probeIsMcp(candidate);
192-
if (isMcp) {
192+
const okIngest = await probeIngestCandidate(candidate, options.mcp.routeLogs);
193+
if (okIngest) {
193194
resolvedBase = candidate;
194195
resolvedIngest = `${candidate}${options.mcp.routeLogs}`;
195196
isRemoteAvailable = true; // but we will not suppress unless explicit config is present

0 commit comments

Comments
 (0)