Skip to content
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

Include meaningful User-Agent header in requests to the GitHub UI #592

Merged

Conversation

timrogers
Copy link
Contributor

This adds a custom User-Agent header to requests from the GitHub server to the GitHub API, identifying the application, the version and key information about the environment.

This aligns with the recommendations in the GitHub Docs.

As part of this change, I have also moved the current version of the server into a constant, and fix the initialization of Server to use that version, taking from package.json.

Description

Include a meaningful User-Agent header in requests to GitHub from the GitHub server

Server Details

Server: GitHub
Changes to: Tools

Motivation and Context

If we, as GitHub, are making a breaking API change or an integration is running into performance problems, it is helpful to be able to identify that API integration.

This is impossible to do with open source integrations like this where users authenticate with personal access tokens (PATs), unless there is a user agent that identifies the integration.

How Has This Been Tested?

I connected this to Claude and ask it to fetch a pull request. A request to GitHub was made with the expected header.

Breaking Changes

No

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follows MCP security best practices
  • I have updated the server's README accordingly
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options

Additional context

This adds a custom `User-Agent` header to requests from the
GitHub server to the GitHub API, identifying the application,
the version and key information about the environment.

This aligns with the [recommendations][1] in the GitHub Docs.

As part of this change, I have also moved the current version of
the server into a constant, and fix the initialization of `Server`
to use that version, taking from `package.json`.

[1]: https://docs.github.com/en/rest/using-the-rest-api/getting-started-with-the-rest-api?apiVersion=2022-11-28#user-agent

const server = new Server(
{
name: "github-mcp-server",
version: "0.1.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm replacing this value with the contents of package.json, but I have also noticed that npm has a totally different package version. What should we use here?

Copy link
Member

Choose a reason for hiding this comment

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

We should use the package.json version. The version in the repo is a placeholder. Currently the CI pipeline just overwrites the package.json version automatically and pushes that version. I have to think through how we best handle this in the future so that it doesnt become to complex in the codebase to reason about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there anywhere we can update to make sure that this gets bumped when the package version does? Perhaps I could write a CI check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've proposed a CI check here: #593

@dsp-ant dsp-ant self-requested a review February 4, 2025 11:54
Copy link
Member

@dsp-ant dsp-ant left a comment

Choose a reason for hiding this comment

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

Makes sense! Thank you!

@dsp-ant dsp-ant merged commit c5968be into modelcontextprotocol:main Feb 4, 2025
9 of 23 checks passed
timrogers added a commit to timrogers/servers that referenced this pull request Feb 4, 2025
This fixes the build, after the merge of modelcontextprotocol#592, by committing an
updated `/package-lock.json` file with the new `universal-user-
agent` dependency.
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