Skip to content

Commit 2c9fa1a

Browse files
authored
chore: attribute MCP calls to SDK [DX-197] (#12)
* chore: integration tag added to client config * fix: header added directly to client config * feat: new header added to client config * chore: origin -> tool * chore: version tracking added to config
1 parent a0eb287 commit 2c9fa1a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/config/contentful.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ClientOptions } from 'contentful-management';
22
import { env } from '../config/env.js';
3+
import { getVersion } from '../utils/getVersion.js';
34

45
/**
56
* Creates a default Contentful client configuration without actually initializing it.
@@ -13,6 +14,9 @@ export function getDefaultClientConfig(): ClientOptions {
1314
accessToken: env.data.CONTENTFUL_MANAGEMENT_ACCESS_TOKEN,
1415
host: env.data.CONTENTFUL_HOST,
1516
space: env.data.SPACE_ID,
17+
headers: {
18+
'X-Contentful-User-Agent-Tool': `contentful-mcp/${getVersion()}`, //Include user agent header for telemetry tracking
19+
},
1620
};
1721

1822
return clientConfig;

src/utils/getVersion.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { readFileSync } from 'node:fs';
2+
import { join } from 'node:path';
3+
import { fileURLToPath } from 'node:url';
4+
import { dirname } from 'node:path';
5+
6+
export const getVersion = () => {
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = dirname(__filename);
9+
const packageJsonPath = join(__dirname, '../../package.json');
10+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
11+
return packageJson.version;
12+
};

0 commit comments

Comments
 (0)