Skip to content

Commit a36c09f

Browse files
authored
Add MCP version to telemetry (#3279)
1 parent cd9fd3e commit a36c09f

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@
391391
"test:acceptance": "yarn pretest && mocha --forbid-only \"test/**/*.acceptance.test.ts\" && node ./bin/bats-test-runner",
392392
"test:integration": "yarn pretest && mocha --forbid-only \"test/**/*.integration.test.ts\"",
393393
"test:smoke": "yarn pretest && mocha --forbid-only \"test/**/smoke.acceptance.test.ts\"",
394-
"test:unit:justTest:local": "nyc mocha \"test/**/*.unit.test.ts\"",
394+
"test:unit:justTest:local": "mocha \"test/**/*.unit.test.ts\"",
395395
"test:unit:justTest:ci": "nyc --reporter=lcov --reporter=text-summary mocha --forbid-only \"test/**/*.unit.test.ts\"",
396396
"test": "yarn pretest && yarn test:unit:justTest:ci",
397397
"test:local": "yarn pretest && yarn test:unit:justTest:local",

packages/cli/src/analytics.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export default class AnalyticsCommand {
4848

4949
async record(opts: RecordOpts) {
5050
await this.initialize
51+
const mcpMode = process.env.HEROKU_MCP_MODE === 'true'
52+
const mcpServerVersion = process.env.HEROKU_MCP_SERVER_VERSION || 'unknown'
5153
const plugin = opts.Command.plugin
5254
if (!plugin) {
5355
debug('no plugin found for analytics')
@@ -63,7 +65,7 @@ export default class AnalyticsCommand {
6365
cli: this.config.name,
6466
command: opts.Command.id,
6567
completion: await this._acAnalytics(opts.Command.id),
66-
version: this.config.version,
68+
version: `${this.config.version}${mcpMode ? ` (MCP ${mcpServerVersion})` : ''}`,
6769
plugin: plugin.name,
6870
plugin_version: plugin.version,
6971
os: this.config.platform,

packages/cli/src/global_telemetry.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ export function setupTelemetry(config: any, opts: any) {
9191
const now = new Date()
9292
const cmdStartTime = now.getTime()
9393
const isRegularCmd = Boolean(opts.Command)
94+
const mcpMode = process.env.HEROKU_MCP_MODE === 'true'
95+
const mcpServerVersion = process.env.HEROKU_MCP_SERVER_VERSION || 'unknown'
9496

9597
const irregularTelemetryObject = {
9698
command: opts.id,
9799
os: config.platform,
98-
version: config.version,
100+
version: `${config.version}${mcpMode ? ` (MCP ${mcpServerVersion})` : ''}`,
99101
exitCode: 0,
100102
exitState: 'successful',
101103
cliRunDuration: 0,

packages/cli/test/unit/analytics.unit.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,27 @@ describe('analytics (backboard has an error) with authorizationToken', function
202202
await runAnalyticsTest((d: AnalyticsInterface) => d.properties.install_id, 'abcde')
203203
})
204204

205+
it('includes MCP version in version string when in MCP mode', async function () {
206+
// Save original env vars
207+
const originalMcpMode = process.env.HEROKU_MCP_MODE
208+
const originalMcpVersion = process.env.HEROKU_MCP_SERVER_VERSION
209+
210+
// Set MCP mode and version
211+
process.env.HEROKU_MCP_MODE = 'true'
212+
process.env.HEROKU_MCP_SERVER_VERSION = '1.2.3'
213+
214+
try {
215+
await runAnalyticsTest(
216+
(d: AnalyticsInterface) => d.properties.version,
217+
'1 (MCP 1.2.3)', // '1' is the version set in runAnalyticsTest
218+
)
219+
} finally {
220+
// Restore original env vars
221+
process.env.HEROKU_MCP_MODE = originalMcpMode
222+
process.env.HEROKU_MCP_SERVER_VERSION = originalMcpVersion
223+
}
224+
})
225+
205226
after(function () {
206227
sandbox.restore()
207228
})

packages/cli/test/unit/global_telemetry.unit.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,21 @@ describe('telemetry', function () {
9696
reportCmdNotFoundTest(mockConfig)
9797
})
9898

99+
it('confirms version string includes MCP info when in MCP mode', function () {
100+
// Mock MCP mode and version
101+
const originalMcpMode = process.env.HEROKU_MCP_MODE
102+
const originalMcpVersion = process.env.HEROKU_MCP_SERVER_VERSION
103+
process.env.HEROKU_MCP_MODE = 'true'
104+
process.env.HEROKU_MCP_SERVER_VERSION = '1.2.3'
105+
106+
const result = telemetry.setupTelemetry(mockConfig, mockOpts)
107+
expect(result!.version).to.equal(`${version} (MCP 1.2.3)`)
108+
109+
// Restore original env vars
110+
process.env.HEROKU_MCP_MODE = originalMcpMode
111+
process.env.HEROKU_MCP_SERVER_VERSION = originalMcpVersion
112+
})
113+
99114
it('confirms successful request to honeycomb', async function () {
100115
const mockTelemetry = telemetry.setupTelemetry(mockConfig, mockOpts)
101116
telemetry.initializeInstrumentation()

0 commit comments

Comments
 (0)