Skip to content

VITE_runtime_var and mcp-protocol-version header - #157

Merged
iFurySt merged 4 commits into
AmoyLab:mainfrom
boston008:VITE_runtime_varables
Jun 26, 2025
Merged

iFurySt merged 4 commits into
AmoyLab:mainfrom
boston008:VITE_runtime_varables

Conversation

@boston008

@boston008 boston008 commented Jun 24, 2025 •

Copy link
Copy Markdown
Contributor

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:

  • Serve frontend runtime configuration via /api/runtime-config endpoint and expose it on window.RUNTIME_CONFIG
  • Load and apply runtime config at startup to replace build-time VITE_* env usage

Enhancements:

  • Use getGatewayBaseUrl helper to resolve gateway URLs from runtime config
  • Change GatewayManager default view mode from 'card' to 'table'
  • Add TypeScript declarations for importing image files
  • Include 'mcp-protocol-version' header in CORS allow/expose lists across configs and UI components

Build:

  • Remove static VITE_* environment variable ARG/ENV declarations from Docker build stage

VITE_runtime_var and mcp-protocol-version header
@sourcery-ai

sourcery-ai Bot commented Jun 24, 2025 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This 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 initialization

sequenceDiagram
    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
Loading

Class diagram for runtime config and service usage

classDiagram
    class Window {
        +any RUNTIME_CONFIG
    }
    class MCPService {
        +connect(prefix)
    }
    class APIService {
        +axiosInstance
    }
    Window <.. MCPService : uses RUNTIME_CONFIG
    Window <.. APIService : uses RUNTIME_CONFIG
Loading

Class diagram for CORS config changes with mcp-protocol-version header

classDiagram
    class CORSConfig {
        +string[] AllowHeaders
        +string[] ExposeHeaders
        +bool AllowCredentials
    }
    CORSConfig : +AllowHeaders includes mcp-protocol-version
    CORSConfig : +ExposeHeaders includes mcp-protocol-version
Loading

File-Level Changes

Change Details Files
Introduce runtime configuration loading
  • Replaced direct ReactDOM render with async fetchRuntimeConfig loader
  • Declared global window.RUNTIME_CONFIG before use
  • Added /api/runtime-config route and handler returning env vars
web/src/main.tsx
cmd/apiserver/main.go
internal/apiserver/handler/runtime_config.go
Migrate to runtime config variables in frontend
  • Updated Router basename to use window.RUNTIME_CONFIG.VITE_BASE_URL
  • Set axios baseURL from window.RUNTIME_CONFIG.VITE_API_BASE_URL
  • Built MCP service URL from window.RUNTIME_CONFIG.VITE_MCP_GATEWAY_BASE_URL
  • Removed VITE_* ARGs and ENV in Dockerfile
web/src/App.tsx
web/src/services/api.ts
web/src/services/mcp.ts
deploy/docker/multi/web/Dockerfile
Refactor GatewayManager for dynamic gateway base URL
  • Added getGatewayBaseUrl helper reading RUNTIME_CONFIG
  • Replaced import.meta.env references with helper calls
  • Changed default viewMode state from 'card' to 'table'
web/src/pages/gateway/gateway-manager.tsx
Add mcp-protocol-version header support in CORS and UI
  • Included mcp-protocol-version in allowHeaders and exposeHeaders in YAML configs
  • Augmented default converter CORS settings with the new header
  • Added mcp-protocol-version option in RouterConfig datalists and CORS defaults
configs/proxy-mcp-exp.yaml
configs/proxy-mock-server.yaml
configs/mcp-gateway.yaml
pkg/openapi/converter.go
web/src/pages/gateway/components/RouterConfig.tsx
Add static asset type declarations
  • Declared module types for png, jpg, jpeg, svg, and gif imports
web/src/types/images.d.ts

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @boston008 - I've reviewed your changes - here's some feedback:

  • 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
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>
Kris Rane added 2 commits June 24, 2025 20:49
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.
@boston008

Copy link
Copy Markdown
Contributor Author

Hey @boston008 - I've reviewed your changes - here's some feedback:

  • 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.

Prompt for AI Agents
Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Updated code

@iFurySt iFurySt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@iFurySt
iFurySt merged commit 5669fb7 into AmoyLab:main Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants