Skip to content

Commit

Permalink
Merge pull request #592 from timrogers/timrogers/github-user-agent
Browse files Browse the repository at this point in the history
Include meaningful `User-Agent` header in requests to the GitHub UI
  • Loading branch information
dsp-ant authored Feb 4, 2025
2 parents 8d54d44 + df63442 commit c5968be
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/github/common/utils.ts
Original file line number Diff line number Diff line change
@@ -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<string, string>;
};
}

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

const USER_AGENT = `modelcontextprotocol/servers/github/v${VERSION} ${getUserAgent()}`;

export async function githubRequest(
url: string,
options: RequestOptions = {}
): Promise<unknown> {
const headers: Record<string, string> = {
"Accept": "application/vnd.github.v3+json",
"Content-Type": "application/json",
"User-Agent": USER_AGENT,
...options.headers,
};

Expand Down
1 change: 1 addition & 0 deletions src/github/common/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const VERSION = "0.6.2";
3 changes: 2 additions & 1 deletion src/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion src/github/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
"@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"
},
"devDependencies": {
"shx": "^0.3.4",
"typescript": "^5.6.2"
}
}
}

0 comments on commit c5968be

Please sign in to comment.