Skip to content

Commit 313cc32

Browse files
authored
Merge pull request #22 from gemini/custom-user-agent
Send custom User-Agent on all MCP server API calls
2 parents 7e342c7 + b2cbe13 commit 313cc32

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

packages/mcp-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gemini-mcp",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"type": "module",
55
"main": "dist/index.js",
66
"scripts": {

packages/mcp-server/src/client/http.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
import { createRequire } from 'module';
12
import JSONBig from 'json-bigint';
23
import { config } from '../config.js';
34
import { buildSignedHeaders } from '../auth/signer.js';
45

56
const REQUEST_TIMEOUT_MS = 30_000;
67

8+
const { version: PKG_VERSION } = createRequire(import.meta.url)('../../package.json') as {
9+
version: string;
10+
};
11+
const USER_AGENT = `gemini-mcp/${PKG_VERSION} (node/${process.versions.node})`;
12+
713
// Precision-preserving JSON parser. The Gemini API emits some numeric fields
814
// — most notably prediction-market `orderId` — as JSON numbers in the 17–18
915
// digit range, which exceed JavaScript's `Number.MAX_SAFE_INTEGER` (2^53 − 1,
@@ -40,6 +46,7 @@ export class GeminiHttpClient {
4046
}
4147
}
4248
const res = await fetch(url.toString(), {
49+
headers: { 'User-Agent': USER_AGENT },
4350
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
4451
});
4552
const text = await res.text();
@@ -51,7 +58,10 @@ export class GeminiHttpClient {
5158

5259
async authenticatedPost<T>(endpoint: string, body: Record<string, unknown> = {}): Promise<T> {
5360
const fullBody = config.account ? { ...body, account: config.account } : body;
54-
const headers = buildSignedHeaders(endpoint, fullBody, this.apiKey, this.apiSecret);
61+
const headers = {
62+
...buildSignedHeaders(endpoint, fullBody, this.apiKey, this.apiSecret),
63+
'User-Agent': USER_AGENT,
64+
};
5565
const res = await fetch(`${this.baseUrl}${endpoint}`, {
5666
method: 'POST',
5767
headers,

0 commit comments

Comments
 (0)