Skip to content

Use runtime direct gateway modifier (#1) - #199

Merged
iFurySt merged 1 commit into
AmoyLab:mainfrom
Divyanshubansaldb:main
Jul 16, 2025
Merged

iFurySt merged 1 commit into
AmoyLab:mainfrom
Divyanshubansaldb:main

Conversation

@Divyanshubansaldb

@Divyanshubansaldb Divyanshubansaldb commented Jul 14, 2025 •

Copy link
Copy Markdown
Contributor
  • Simplify direct gateway URL builder

  • Fix direct gateway base URL helper to use window.RUNTIME_CONFIG for modifier

  • Updated getDirectGatewayBaseUrl to read VITE_DIRECT_MCP_GATEWAY_MODIFIER from window.RUNTIME_CONFIG
image

Summary by Sourcery

Introduce a runtime-configurable modifier for direct MCP gateway URLs by centralizing URL construction logic, exposing the new modifier in the API server’s runtime config, and updating environment types and deployment settings accordingly.

New Features:

  • Add getDirectGatewayBaseUrl helper to build direct gateway URLs using a runtime-provided modifier.

Enhancements:

  • Expose VITE_DIRECT_MCP_GATEWAY_MODIFIER in the API server’s runtime config and TypeScript definitions.
  • Fetch and default the direct gateway modifier in main.tsx runtime config loader.
  • Replace manual direct gateway URL constructions in GatewayManager with the new helper.

Deployment:

  • Add direct_mcp_gateway_modifier to apiserver.yaml defaults and Helm values/configMap.

* Simplify direct gateway URL builder

* Fix direct gateway base URL helper to use window.RUNTIME_CONFIG for modifier

- Updated getDirectGatewayBaseUrl to read VITE_DIRECT_MCP_GATEWAY_MODIFIER from window.RUNTIME_CONFIG for
@sourcery-ai

sourcery-ai Bot commented Jul 14, 2025 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This PR centralizes and configures the direct gateway URL logic by introducing a runtime-config-driven modifier. It replaces hardcoded port suffixes in the UI with a reusable helper that reads an env var, and propagates the new VITE_DIRECT_MCP_GATEWAY_MODIFIER through backend handlers, frontend initialization, and deployment templates.

Sequence diagram for runtime config propagation of VITE_DIRECT_MCP_GATEWAY_MODIFIER

sequenceDiagram
    participant User
    participant Frontend
    participant Backend
    participant ConfigStore

    User->>Frontend: Loads app
    Frontend->>Backend: GET /runtime-config
    Backend->>ConfigStore: Read DirectMCPGatewayModifier
    ConfigStore-->>Backend: Return value
    Backend-->>Frontend: JSON { VITE_DIRECT_MCP_GATEWAY_MODIFIER: value }
    Frontend->>Frontend: Store in window.RUNTIME_CONFIG
    Frontend->>Frontend: Use getDirectGatewayBaseUrl() with modifier
Loading

File-Level Changes

Change Details Files
Extract and apply a direct gateway URL builder helper
  • Add getDirectGatewayBaseUrl to derive base URL from runtime config or default
  • Replace all inline port-replacement expressions in GatewayManager with helper calls
web/src/pages/gateway/gateway-manager.tsx
Expose DirectMCPGatewayModifier in server runtime config
  • Add DirectMCPGatewayModifier to WebConfig struct
  • Include VITE_DIRECT_MCP_GATEWAY_MODIFIER in JSON response alongside existing fields
internal/common/config/apiserver.go
internal/apiserver/handler/runtime_config.go
Support the new modifier in frontend initialization
  • Extend RuntimeConfig interface and defaultRuntimeConfig
  • Update fetchRuntimeConfig to read VITE_DIRECT_MCP_GATEWAY_MODIFIER with fallback
web/src/main.tsx
web/src/env.d.ts
Propagate modifier into deployment and default configs
  • Add direct_mcp_gateway_modifier to apiserver.yaml
  • Include VITE_DIRECT_MCP_GATEWAY_MODIFIER in Helm ConfigMap and values.yaml
configs/apiserver.yaml
deploy/helm/templates/mcp-gateway-configmap.yaml
deploy/helm/values.yaml

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 @Divyanshubansaldb - I've reviewed your changes - here's some feedback:

  • Extract getDirectGatewayBaseUrl into a standalone utility module to reduce component bloat and make it easier to unit test the URL-building logic.
  • Consider using the native URL API (or URLPattern) instead of manual regex/substring operations to handle ports and paths more robustly when composing the gateway URL.
  • Ensure that window.RUNTIME_CONFIG.VITE_DIRECT_MCP_GATEWAY_MODIFIER is loaded before rendering so you don’t accidentally fall back to the default port if the runtime config isn’t yet available.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Extract getDirectGatewayBaseUrl into a standalone utility module to reduce component bloat and make it easier to unit test the URL-building logic.
- Consider using the native URL API (or URLPattern) instead of manual regex/substring operations to handle ports and paths more robustly when composing the gateway URL.
- Ensure that window.RUNTIME_CONFIG.VITE_DIRECT_MCP_GATEWAY_MODIFIER is loaded before rendering so you don’t accidentally fall back to the default port if the runtime config isn’t yet available.

## Individual Comments

### Comment 1
<location> `web/src/pages/gateway/gateway-manager.tsx:104` </location>
<code_context>
+    modifier = '/' + modifier;
+  }
+
+  const originWithoutPort = origin.replace(/:\d+$/, '');
+  return `${originWithoutPort}${modifier}`.replace(/\/+$/, '');
+};
</code_context>

<issue_to_address>
Removing the port from origin may break for IPv6 addresses.

The current regex may not handle IPv6 addresses correctly. Use a URL parsing utility to reliably extract the host and port.
</issue_to_address>

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.

modifier = '/' + modifier;
}

const originWithoutPort = origin.replace(/:\d+$/, '');

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.

issue (bug_risk): Removing the port from origin may break for IPv6 addresses.

The current regex may not handle IPv6 addresses correctly. Use a URL parsing utility to reliably extract the host and port.

@iFurySt
iFurySt force-pushed the main branch 3 times, most recently from a6483bd to 35748c4 Compare July 16, 2025 06:35

@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 834d845 into AmoyLab:main Jul 16, 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