Skip to content

feat: add User-Agent header to MCP HTTP requests#6988

Merged
aharvard merged 2 commits intomainfrom
aharvard/user-agent-header
Feb 5, 2026
Merged

feat: add User-Agent header to MCP HTTP requests#6988
aharvard merged 2 commits intomainfrom
aharvard/user-agent-header

Conversation

@aharvard
Copy link
Collaborator

@aharvard aharvard commented Feb 5, 2026

Summary

Adds a goose/{version} User-Agent header to all HTTP requests sent to MCP servers via streamable HTTP transport.

Why

MCP server operators need visibility into which clients are connecting to their servers. A User-Agent header enables:

  • Analytics - Understanding client distribution and usage patterns
  • Debugging - Correlating server-side issues with specific client versions
  • Compatibility - Detecting outdated clients that may need different handling
  • Security - Identifying and blocking problematic client versions if needed

This is standard practice for HTTP clients and aligns with how other MCP clients identify themselves.

Changes

  • Added goose_user_agent() helper function that returns goose/{CARGO_PKG_VERSION}
  • Added User-Agent header to initial HTTP client in create_streamable_http_client()
  • Added User-Agent header to OAuth retry flow HTTP client

Format

The header follows the standard format:

User-Agent: goose/1.23.0

Testing

  • All 17 extension_manager tests pass
  • cargo clippy passes
  • cargo fmt applied

Adds a 'goose/{version}' User-Agent header to all HTTP requests sent to
MCP servers via streamable HTTP transport. This applies to both initial
connections and OAuth retry flows.

The header follows the standard format: goose/1.23.0 (or current version)
@aharvard aharvard marked this pull request as ready for review February 5, 2026 17:48
Copilot AI review requested due to automatic review settings February 5, 2026 17:48
Copy link
Contributor

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 a User-Agent header to HTTP requests made to MCP servers, enabling server operators to identify client versions for analytics, debugging, and compatibility purposes.

Changes:

  • Added goose_user_agent() helper function that generates the User-Agent string from the package version
  • Added User-Agent header to HTTP clients in the initial connection flow
  • Added User-Agent header to HTTP clients in the OAuth retry flow

reqwest::header::USER_AGENT,
goose_user_agent()
.parse()
.expect("valid user agent header value"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't think we can to panic on this. Maybe have a regex check on the pkg version, and otherwise just send goose/?

reqwest::header::USER_AGENT,
goose_user_agent()
.parse()
.expect("valid user agent header value"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

and here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes

goose_user_agent()
.parse()
.expect("valid user agent header value"),
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this feels odd, goose_user_agent could be done at compile time I think and even though parse will never fail, it would kill the agent if it did.

can we something like:

const GOOSE_USER_AGENT = HeaderValue::from_static(concat!("goose/", env!("CARGO_PKG_VERSION")));

and then here insert that?

reqwest::header::USER_AGENT,
goose_user_agent()
.parse()
.expect("valid user agent header value"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

yes

Replace runtime goose_user_agent() function with GOOSE_USER_AGENT const
using HeaderValue::from_static(). This eliminates potential runtime panics
from .expect() calls by validating the header value at compile time.
@aharvard
Copy link
Collaborator Author

aharvard commented Feb 5, 2026

Hey @DOsinga @katzdave — good catch! Updated to use a compile-time constant with HeaderValue::from_static(concat!(...)). No more runtime parsing or potential panics. 👍

@aharvard aharvard added this pull request to the merge queue Feb 5, 2026
Merged via the queue into main with commit 66aa728 Feb 5, 2026
18 checks passed
@aharvard aharvard deleted the aharvard/user-agent-header branch February 5, 2026 20:27
katzdave added a commit that referenced this pull request Feb 6, 2026
…webtoken-10.3.0

* origin/main: (54 commits)
  Switch tetrate tool filtering back to supports_computer_use (#7024)
  feat(ui): add inline rename for chat sessions in sidebar (#6995)
  fix: handle toolnames without underscores (#7015)
  feat(claude-code): use stream-json protocol for persistent sessions (#7029)
  test(providers): add model listing to live provider suite (#7038)
  Agent added too much (#7036)
  fix(deps): bump tree-sitter to 0.26 and set sqlx default-features=false to fix RUSTSEC advisories (#7031)
  feat: add image support and improve error resilience for Codex (#7033)
  fix(providers): Azure OpenAI model listing 404 during configure (#7034)
  fix(deps): bump bat to 0.26.1 to resolve RUSTSEC-2026-0008 (#7021)
  Don't swallow Tetrate errors  (#6998)
  docs: remove hardcoded_stuff links (#7016)
  fix(ui): keep Hub chat input from overlapping SessionInsights on paste (#6719)
  Clean up css (#6944)
  docs: aws bedrock bearer token auth (#6990)
  docs: extended custom provider headers support (#7012)
  feat(cli): add type-to-search filtering to select/multiselect dialogs (#6862)
  feat(ci): add cargo-audit workflow for scanning rust vulnerabilities (#6351)
  feat: add User-Agent header to MCP HTTP requests (#6988)
  chore(deps-dev): bump webpack from 5.102.1 to 5.105.0 in /ui/desktop (#6996)
  ...

# Conflicts:
#	Cargo.lock
kuccello pushed a commit to kuccello/goose that referenced this pull request Feb 7, 2026
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