Skip to content

feat: support transparent-headers - #207

Merged
iFurySt merged 5 commits into
AmoyLab:mainfrom
qiankunli:feat/support-transparent-headers
Jul 16, 2025
Merged

iFurySt merged 5 commits into
AmoyLab:mainfrom
qiankunli:feat/support-transparent-headers

Conversation

@qiankunli

@qiankunli qiankunli commented Jul 16, 2025 •

Copy link
Copy Markdown
Contributor

Summary by Sourcery

Support transparent header forwarding in HTTP tools by introducing a configurable argument key, refactoring header processing, and augmenting logging for better visibility.

New Features:

  • Add configurable transparent header forwarding via a new transparent_headers_arg_name setting
  • Implement transferTransparentHeaderArgs to move transparentHeaders from tool arguments into outgoing HTTP requests

Enhancements:

  • Refactor prepareRequest to forward custom request headers (excluding standard ones) and honor tool-configured header overrides
  • Enhance debug logging to include outbound request headers and transparent header transfer details

Documentation:

  • Expose transparent_headers_arg_name in the server config struct and sample YAML

@sourcery-ai

sourcery-ai Bot commented Jul 16, 2025 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds support for user-defined “transparent” headers by propagating them from MCP arguments into outgoing HTTP requests, introducing a new helper for merging headers, extending server initialization and configuration to pass through a “transparentHeadersArgName,” and updating the CLI entrypoint and YAML schema accordingly.

Sequence diagram for propagating transparent headers in HTTP tool execution

sequenceDiagram
    participant Client
    participant Server
    participant HTTPTool

    Client->>Server: Call tool with args (including transparent headers)
    Server->>Server: transferTransparentHeaderArgs(args, request)
    Server->>HTTPTool: Prepare HTTP request (headers merged)
    HTTPTool-->>Server: HTTP response
    Server-->>Client: Tool result (response)
Loading

File-Level Changes

Change Details Files
Implement transparent header propagation in HTTP requests
  • Forward non-default request headers in prepareRequest
  • Invoke transferTransparentHeaderArgs before sending HTTP tool
  • Add transferTransparentHeaderArgs helper to extract headers from args
  • Log transferred headers with zap.Any in executeHTTPTool
internal/core/tool.go
Propagate transparentHeadersArgName through server setup and config
  • Add transparentHeadersArgName field to Server struct
  • Extend NewServer signature to accept transparentHeadersArgName
  • Pass transparentHeadersArgName from main.go into server
  • Add TransparentHeadersArgName to MCPGatewayConfig and YAML mapping
  • Include transparent_headers_arg_name in example config file
internal/core/server.go
internal/common/config/config.go
cmd/mcp-gateway/main.go
configs/mcp-gateway.yaml
Reorganize imports for new dependencies
  • Introduce slices import for header filtering
  • Reorder proxy and zap imports for consistency
internal/core/tool.go

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

  • Extract the hard-coded header whitelist in prepareRequest into a package-level constant or configurable variable to avoid duplicating header names.
  • Add defensive type checks and error returns in transferTransparentHeaderArgs to handle unexpected argument shapes instead of assuming map[string]any and avoid potential panics.
  • Consider refactoring the two header-setting flows (template headers and transparent headers) into a single unified helper to reduce duplication and improve maintainability.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Extract the hard-coded header whitelist in prepareRequest into a package-level constant or configurable variable to avoid duplicating header names.
- Add defensive type checks and error returns in transferTransparentHeaderArgs to handle unexpected argument shapes instead of assuming map[string]any and avoid potential panics.
- Consider refactoring the two header-setting flows (template headers and transparent headers) into a single unified helper to reduce duplication and improve maintainability.

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.

Comment thread internal/core/tool.go Fixed
@qiankunli
qiankunli force-pushed the feat/support-transparent-headers branch from 9bc9431 to ee5cd9c Compare July 16, 2025 08:48
@iFurySt
iFurySt force-pushed the feat/support-transparent-headers branch from 4c2b342 to c98e83a Compare July 16, 2025 12:41
@iFurySt
iFurySt merged commit 6f08788 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.

3 participants