8000 Add ctx propagation to raw api request by kerobbi · Pull Request #570 · github/github-mcp-server · GitHub
[go: up one dir, main page]

Skip to content

Add ctx propagation to raw api request #570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025

Conversation

kerobbi
Copy link
Contributor
@kerobbi kerobbi commented Jun 23, 2025

Update newRequest to accept a context.Context param and attach it to the generated http.Request using withContext.

This change ensures that trace contexts are correctly propagated, supporting distributed tracing in the remote MCP server.

@Copilot Copilot AI review requested due to automatic review settings June 23, 2025 08:42
@kerobbi kerobbi requested a review from a team as a code owner June 23, 2025 08:42
Copy link
Contributor
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds context propagation to the low-level newRequest helper, ensuring that trace and cancellation contexts flow through HTTP calls in the raw API client.

  • Extended newRequest to accept a context.Context and attach it via WithContext
  • Updated GetRawContent to pass the incoming ctx into newRequest
  • Adjusted error handling in newRequest to return early on failure before setting context
Comments suppressed due to low confidence (3)

pkg/raw/raw.go:65

  • Add or update unit tests to verify that the provided context is actually attached to the outgoing http.Request and that cancellations/timeouts are honored.
func (c *Client) GetRawContent(ctx context.Context, owner, repo, path string, opts *RawContentOpts) (*http.Response, error) {

pkg/raw/raw.go:28

  • Make sure to import the "context" package at the top of this file, otherwise context.Context will be undefined.
func (c *Client) newRequest(ctx context.Context, method string, urlStr string, body interface{}, opts ...gogithub.RequestOption) (*http.Request, error) {

pkg/raw/raw.go:67

  • Review other methods in this file (or in downstream code) that call newRequest to ensure they’ve been updated to pass ctx as the first argument, preventing build failures and ensuring consistent context propagation.
	req, err := c.newRequest(ctx, "GET", url, nil)

Copy link
Collaborator
@SamMorrowDrums SamMorrowDrums left a comment

Choose a reason for hiding this comment

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

Just to validate, does this work if you try it locally? I assume so, but an alternative is to take the current request context and then extend it and add it back to the request.

@kerobbi
Copy link
Contributor Author
kerobbi commented Jun 23, 2025

Just to validate, does this work if you try it locally? I assume so, but an alternative is to take the current request context and then extend it and add it back to the request.

I did test this locally and confirmed that ctx propagation is working as expected, trace info and parent-child spans are all showing up correctly.

I'm a bit confused about the suggested alternative. Since we are creating a new outbound request here (not working with an incoming HTTP request), I don't think there's an existing req ctx to extend? Let me know if I'm missing something.

@SamMorrowDrums SamMorrowDrums merged commit 2711384 into main Jun 23, 2025
16 checks passed
@SamMorrowDrums SamMorrowDrums deleted the kerobbi/propagate-context branch June 23, 2025 12:55
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
0