Repository navigation
VITE_runtime_var and mcp-protocol-version header - #157
Conversation
VITE_runtime_var and mcp-protocol-version header
Reviewer's GuideThis PR centralizes environment variable handling by exposing a backend runtime-config endpoint and fetching it before mounting the React app, then updates frontend routing and services to reference window.RUNTIME_CONFIG, removes build-time VITE_ ARGs, refactors GatewayManager URL logic with a helper and default view mode, adds support for the new mcp-protocol-version header across CORS configs and UI, and includes static image asset type declarations. Sequence diagram for frontend runtime config loading and app initializationsequenceDiagram
participant Browser
participant ReactApp
participant Backend as API Server
Browser->>Backend: GET /api/runtime-config
Backend-->>Browser: { VITE_API_BASE_URL, ... }
Browser->>ReactApp: Set window.RUNTIME_CONFIG
Browser->>ReactApp: Render App with runtime config
ReactApp->>Backend: API requests using window.RUNTIME_CONFIG values
Class diagram for runtime config and service usageclassDiagram
class Window {
+any RUNTIME_CONFIG
}
class MCPService {
+connect(prefix)
}
class APIService {
+axiosInstance
}
Window <.. MCPService : uses RUNTIME_CONFIG
Window <.. APIService : uses RUNTIME_CONFIG
Class diagram for CORS config changes with mcp-protocol-version headerclassDiagram
class CORSConfig {
+string[] AllowHeaders
+string[] ExposeHeaders
+bool AllowCredentials
}
CORSConfig : +AllowHeaders includes mcp-protocol-version
CORSConfig : +ExposeHeaders includes mcp-protocol-version
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @boston008 - I've reviewed your changes - here's some feedback:
- Consider adding a loading indicator or fallback UI while
fetchRuntimeConfigis in flight to avoid showing a blank screen before the app renders. - Remove or conditionally suppress the
console.logcalls infetchRuntimeConfigso debug output doesn’t clutter production logs. - Instead of declaring
window.RUNTIME_CONFIGasany, define and use a proper TypeScript interface for the runtime config to improve type safety.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider adding a loading indicator or fallback UI while `fetchRuntimeConfig` is in flight to avoid showing a blank screen before the app renders.
- Remove or conditionally suppress the `console.log` calls in `fetchRuntimeConfig` so debug output doesn’t clutter production logs.
- Instead of declaring `window.RUNTIME_CONFIG` as `any`, define and use a proper TypeScript interface for the runtime config to improve type safety.
## Individual Comments
### Comment 1
<location> `web/src/pages/gateway/gateway-manager.tsx:75` </location>
<code_context>
+const RUNTIME_CONFIG = window.RUNTIME_CONFIG || {};
+
+// Helper to get the gateway base URL
+const getGatewayBaseUrl = () => {
+ const base = RUNTIME_CONFIG.VITE_MCP_GATEWAY_BASE_URL;
+ if (!base) return '';
</code_context>
<issue_to_address>
getGatewayBaseUrl does not handle trailing slashes, which may cause double slashes in URLs.
Normalize the base URL and prefix to prevent double slashes when concatenating them.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
const getGatewayBaseUrl = () => {
const base = RUNTIME_CONFIG.VITE_MCP_GATEWAY_BASE_URL;
if (!base) return '';
return base.startsWith('http') ? base : `${window.location.origin}${base}`;
};
=======
const getGatewayBaseUrl = () => {
let base = RUNTIME_CONFIG.VITE_MCP_GATEWAY_BASE_URL;
if (!base) return '';
// Remove trailing slash if present
base = base.replace(/\/+$/, '');
if (base.startsWith('http')) {
return base;
}
// Remove trailing slash from window.location.origin just in case
const origin = window.location.origin.replace(/\/+$/, '');
// Ensure base starts with a slash
if (!base.startsWith('/')) {
base = '/' + base;
}
return `${origin}${base}`;
};
>>>>>>> REPLACE
</suggested_fix>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Avoid double slash Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Consider adding a loading indicator or fallback UI while fetchRuntimeConfig is in flight to avoid showing a blank screen before the app renders. Remove or conditionally suppress the console.log calls in fetchRuntimeConfig so debug output doesn’t clutter production logs. Instead of declaring window.RUNTIME_CONFIG as any, define and use a proper TypeScript interface for the runtime config to improve type safety.
Updated code |
VITE_runtime_var and mcp-protocol-version header
Summary by Sourcery
Fetch runtime config at app startup via /api/runtime-config and use window.RUNTIME_CONFIG for base URLs, remove build-time VITE_* injection, propagate mcp-protocol-version header in CORS and UI, refactor gateway URL logic, and update default view mode and asset typings.
New Features:
Enhancements:
Build: