From df63442c3c99f1b793b9555061401d163027cd65 Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Sun, 2 Feb 2025 15:01:16 +0000 Subject: [PATCH] Include meaningful `User-Agent` header in requests to the GitHub UI 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 --- src/github/common/utils.ts | 7 ++++++- src/github/common/version.ts | 1 + src/github/index.ts | 3 ++- src/github/package.json | 3 ++- 4 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 src/github/common/version.ts diff --git a/src/github/common/utils.ts b/src/github/common/utils.ts index 21c8aa71a..e85691a0b 100644 --- a/src/github/common/utils.ts +++ b/src/github/common/utils.ts @@ -1,10 +1,12 @@ +import { getUserAgent } from "universal-user-agent"; import { createGitHubError } from "./errors.js"; +import { VERSION } from "./version.js"; type RequestOptions = { method?: string; body?: unknown; headers?: Record; -}; +} async function parseResponseBody(response: Response): Promise { const contentType = response.headers.get("content-type"); @@ -24,6 +26,8 @@ export function buildUrl(baseUrl: string, params: Record = { "Accept": "application/vnd.github.v3+json", "Content-Type": "application/json", + "User-Agent": USER_AGENT, ...options.headers, }; diff --git a/src/github/common/version.ts b/src/github/common/version.ts new file mode 100644 index 000000000..00b8a6918 --- /dev/null +++ b/src/github/common/version.ts @@ -0,0 +1 @@ +export const VERSION = "0.6.2"; \ No newline at end of file diff --git a/src/github/index.ts b/src/github/index.ts index 3d60e8faf..88b236894 100644 --- a/src/github/index.ts +++ b/src/github/index.ts @@ -25,11 +25,12 @@ import { GitHubConflictError, isGitHubError, } from './common/errors.js'; +import { VERSION } from "./common/version.js"; const server = new Server( { name: "github-mcp-server", - version: "0.1.0", + version: VERSION, }, { capabilities: { diff --git a/src/github/package.json b/src/github/package.json index 46d24ccd6..29f5296b6 100644 --- a/src/github/package.json +++ b/src/github/package.json @@ -23,6 +23,7 @@ "@types/node": "^22", "@types/node-fetch": "^2.6.12", "node-fetch": "^3.3.2", + "universal-user-agent": "^7.0.2", "zod": "^3.22.4", "zod-to-json-schema": "^3.23.5" }, @@ -30,4 +31,4 @@ "shx": "^0.3.4", "typescript": "^5.6.2" } -} \ No newline at end of file +}