modelcontextprotocol / modelcontextprotocol/go-sdk

Proposal: add `ModifyRequest func(*http.Request)` to HTTP client transports

Open
#533 9 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

needs community feedback
Dominant language
Go
Stars
5.1k
Forks
543
Avg merge
1d 17h
Merged PRs (30d)
37

Description

Following up on #522, where we discussed making it easier to modify HTTP client transport requests, for example by adding headers, we propose the following two new options:

type StreamableClientTransport struct {
  ...
  // If set, ModifyRequest is called before each outgoing HTTP request made by the client
  // connection. It can be use to, for example, add headers to outgoing requests.
  ModifyRequest func(*http.Request)
}

type SSEClientTransport struct {
  ...
  // <ditto>
  ModifyRequest func(*http.Request)
}

We believe these options will make it easier to do things like add auth headers. Currently, this can be achieved using the HTTPClient field, but only in the roundtripper, which requires cloning the request.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the StreamableClientTransport and SSEClientTransport definitions, then trace how each creates outgoing HTTP requests. Check the existing HTTPClient and roundtripper behavior before deciding where the callbacks belong. Done means both transports expose ModifyRequest and invoke it before each outgoing request, with tests covering the callback behavior and header modification.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.