Skip to content

Feat merge the headers/cookies/querystring info in the first and later request#84

Merged
iFurySt merged 2 commits into
AmoyLab:mainfrom
LeoLiuYan:feat/store_querystring_in_session
May 15, 2025
Merged

Feat merge the headers/cookies/querystring info in the first and later request#84
iFurySt merged 2 commits into
AmoyLab:mainfrom
LeoLiuYan:feat/store_querystring_in_session

Conversation

@LeoLiuYan
Copy link
Copy Markdown
Contributor

@LeoLiuYan LeoLiuYan commented May 15, 2025

When execute tools/call, it lost the first request metadata include headers/cookies/querystring. In this PR, we merge the metadata in requests, and use the latest request metadata to ovrride the first request.

Summary by Sourcery

Capture and propagate HTTP request metadata across sessions and tool invocations to ensure headers, query parameters, and cookies persist and merge correctly.

New Features:

  • Store initial request headers, query parameters, and cookies in a new RequestInfo attached to session metadata.
  • Merge stored metadata with each subsequent request, overriding values with the latest request data.

Enhancements:

  • Extend PrepareTemplateContext to accept RequestInfo and merge initial and current request metadata before rendering.
  • Refactor mcpproxy fetch and invoke functions and core server handlers to pass session.Connection and propagate RequestInfo through tool execution APIs.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 15, 2025

Reviewer's Guide

This PR centralizes the capture and propagation of request metadata (headers, query parameters, cookies) by introducing a RequestInfo struct, merging first and later request data, and threading the session.Connection through all tool-fetching and invocation paths so templates can use the complete metadata.

File-Level Changes

Change Details Files
Capture initial request metadata into the session for SSE connections
  • Add RequestInfo struct to session package
  • Populate RequestInfo (headers, query, cookies) in handleSSE
  • Attach RequestInfo to session.Meta
internal/mcp/session/session.go
internal/core/sse.go
Merge stored metadata with each new request when rendering templates
  • Extend PrepareTemplateContext to accept RequestInfo
  • Preload existing headers, queries, cookies before applying the new request
  • Use merged metadata in template context
internal/template/renderer.go
Propagate session.Connection through server handlers and core tool invocations
  • Inject conn into FetchToolList and InvokeTool calls in SSE and streamable handlers
  • Update executeHTTPTool to accept conn
  • Pass conn to invokeHTTPTool in core
internal/core/sse.go
internal/core/streamable.go
internal/core/tool.go
Adapt mcpproxy transport functions to thread metadata into templates
  • Change FetchToolList and InvokeTool signatures to include conn
  • Import session package and extract Meta().Request
  • Pass RequestInfo into PrepareTemplateContext in stdio, SSE, streamable proxies
internal/core/mcpproxy/stdio.go
internal/core/mcpproxy/sse.go
internal/core/mcpproxy/streamable.go

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

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey @LeoLiuYan - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

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/sse.go
@LeoLiuYan
Copy link
Copy Markdown
Contributor Author

@iFurySt PTAL.

Copy link
Copy Markdown
Member

@iFurySt iFurySt left a comment

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 f60a0b3 into AmoyLab:main May 15, 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