Skip to content

Commit c5968be

Browse files
authored
Merge pull request #592 from timrogers/timrogers/github-user-agent
Include meaningful `User-Agent` header in requests to the GitHub UI
2 parents 8d54d44 + df63442 commit c5968be

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

src/github/common/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import { getUserAgent } from "universal-user-agent";
12
import { createGitHubError } from "./errors.js";
3+
import { VERSION } from "./version.js";
24

35
type RequestOptions = {
46
method?: string;
57
body?: unknown;
68
headers?: Record<string, string>;
7-
};
9+
}
810

911
async function parseResponseBody(response: Response): Promise<unknown> {
1012
const contentType = response.headers.get("content-type");
@@ -24,13 +26,16 @@ export function buildUrl(baseUrl: string, params: Record<string, string | number
2426
return url.toString();
2527
}
2628

29+
const USER_AGENT = `modelcontextprotocol/servers/github/v${VERSION} ${getUserAgent()}`;
30+
2731
export async function githubRequest(
2832
url: string,
2933
options: RequestOptions = {}
3034
): Promise<unknown> {
3135
const headers: Record<string, string> = {
3236
"Accept": "application/vnd.github.v3+json",
3337
"Content-Type": "application/json",
38+
"User-Agent": USER_AGENT,
3439
...options.headers,
3540
};
3641

src/github/common/version.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const VERSION = "0.6.2";

src/github/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ import {
2525
GitHubConflictError,
2626
isGitHubError,
2727
} from './common/errors.js';
28+
import { VERSION } from "./common/version.js";
2829

2930
const server = new Server(
3031
{
3132
name: "github-mcp-server",
32-
version: "0.1.0",
33+
version: VERSION,
3334
},
3435
{
3536
capabilities: {

src/github/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
"@types/node": "^22",
2424
"@types/node-fetch": "^2.6.12",
2525
"node-fetch": "^3.3.2",
26+
"universal-user-agent": "^7.0.2",
2627
"zod": "^3.22.4",
2728
"zod-to-json-schema": "^3.23.5"
2829
},
2930
"devDependencies": {
3031
"shx": "^0.3.4",
3132
"typescript": "^5.6.2"
3233
}
33-
}
34+
}

0 commit comments

Comments
 (0)