Skip to content

Commit 1ca55c6

Browse files
committed
Remove no telemetry flag, add unit tests
1 parent 873e507 commit 1ca55c6

6 files changed

Lines changed: 159 additions & 13 deletions

File tree

packages/b2c-dx-mcp/README.md

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ npm install -g @salesforce/b2c-dx-mcp
2020

2121
#### MCP-Specific Flags
2222

23-
| Flag | Description |
24-
|------|-------------|
25-
| `--toolsets` | Comma-separated toolsets to enable (case-insensitive) |
26-
| `--tools` | Comma-separated individual tools to enable (case-insensitive) |
27-
| `--allow-non-ga-tools` | Enable experimental (non-GA) tools |
23+
| Flag | Env Variable | Description |
24+
|------|--------------|-------------|
25+
| `--toolsets` | `SFCC_TOOLSETS` | Comma-separated toolsets to enable (case-insensitive) |
26+
| `--tools` | `SFCC_TOOLS` | Comma-separated individual tools to enable (case-insensitive) |
27+
| `--allow-non-ga-tools` | `SFCC_ALLOW_NON_GA_TOOLS` | Enable experimental (non-GA) tools |
2828

2929
#### MRT Flags (inherited from MrtCommand)
3030

@@ -521,6 +521,39 @@ When `--config` is not provided, the MCP server searches upward from `~/` for a
521521

522522
> **Note:** Flags override environment variables, and environment variables override `dw.json`. You can mix sources (e.g., secrets via env vars, other settings via dw.json).
523523
524+
## Telemetry
525+
526+
The MCP server collects anonymous usage telemetry to help improve the developer experience. Telemetry is enabled by default and can be disabled by setting the `SFCC_TELEMETRY` environment variable to `false`.
527+
528+
### What We Collect
529+
530+
- **Server lifecycle events**: When the server starts, stops, or encounters errors
531+
- **Tool usage**: Which tools are called and their execution time (not the arguments or results)
532+
- **Environment info**: Platform, architecture, Node.js version, and package version
533+
534+
### What We Don't Collect
535+
536+
- **No credentials**: No API keys, passwords, or secrets
537+
- **No business data**: No product data, customer information, or site content
538+
- **No tool arguments**: No input parameters or output results from tool calls
539+
- **No file contents**: No source code, configuration files, or project data
540+
541+
### Disabling Telemetry
542+
543+
Set the `SFCC_TELEMETRY` environment variable to `false`:
544+
545+
```json
546+
{
547+
"mcpServers": {
548+
"b2c-dx": {
549+
"command": "/path/to/packages/b2c-dx-mcp/bin/dev.js",
550+
"args": ["--toolsets", "all"],
551+
"env": { "SFCC_TELEMETRY": "false" }
552+
}
553+
}
554+
}
555+
```
556+
524557
## License
525558

526559
Apache-2.0

packages/b2c-dx-mcp/src/commands/mcp.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
* | `--toolsets` | `SFCC_TOOLSETS` | Comma-separated toolsets to enable (case-insensitive) |
2020
* | `--tools` | `SFCC_TOOLS` | Comma-separated individual tools to enable (case-insensitive) |
2121
* | `--allow-non-ga-tools` | `SFCC_ALLOW_NON_GA_TOOLS` | Enable experimental/non-GA tools |
22-
* | `--no-telemetry` | `SFCC_NO_TELEMETRY` | Disable telemetry collection |
22+
*
23+
* ### Environment Variables (no flag equivalent)
24+
* | Env Variable | Description |
25+
* |--------------|-------------|
26+
* | `SFCC_TELEMETRY` | Set to `false` to disable telemetry collection |
2327
*
2428
* ### MRT Flags (from MrtCommand.baseFlags)
2529
* | Flag | Env Variable | Description |
@@ -202,11 +206,6 @@ export default class McpServerCommand extends BaseCommand<typeof McpServerComman
202206
env: 'SFCC_ALLOW_NON_GA_TOOLS',
203207
default: false,
204208
}),
205-
'no-telemetry': Flags.boolean({
206-
description: 'Disable telemetry collection',
207-
env: 'SFCC_NO_TELEMETRY',
208-
default: false,
209-
}),
210209
};
211210

212211
/**
@@ -247,9 +246,9 @@ export default class McpServerCommand extends BaseCommand<typeof McpServerComman
247246
workingDirectory: this.flags['working-directory'],
248247
};
249248

250-
// Initialize telemetry unless disabled
249+
// Initialize telemetry unless disabled via SFCC_TELEMETRY=false
251250
let telemetry: Telemetry | undefined;
252-
if (!this.flags['no-telemetry']) {
251+
if (process.env.SFCC_TELEMETRY !== 'false') {
253252
telemetry = createTelemetry({
254253
project: 'b2c-dx-mcp',
255254
appInsightsKey: loadAppInsightsKey(),

packages/b2c-dx-mcp/test/commands/mcp.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ describe('McpServerCommand', () => {
3535
expect(flag.default).to.equal(false);
3636
});
3737

38+
it('should not have a no-telemetry flag (telemetry controlled via SFCC_TELEMETRY env var only)', () => {
39+
// Telemetry is disabled via SFCC_TELEMETRY=false env var, not a CLI flag
40+
// This keeps the CLI cleaner and prevents accidental disabling
41+
const flags = McpServerCommand.flags as Record<string, unknown>;
42+
expect(flags['no-telemetry']).to.be.undefined;
43+
});
44+
3845
it('should inherit config flag from BaseCommand', () => {
3946
// config flag is inherited from BaseCommand.baseFlags
4047
const flag = McpServerCommand.baseFlags.config;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2025, Salesforce, Inc.
3+
* SPDX-License-Identifier: Apache-2
4+
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
7+
import {expect} from 'chai';
8+
import {APPLICATION_INSIGHTS_CONNECTION_STRING} from '../src/config.js';
9+
10+
describe('config', () => {
11+
describe('APPLICATION_INSIGHTS_CONNECTION_STRING', () => {
12+
it('should export a non-empty connection string', () => {
13+
expect(APPLICATION_INSIGHTS_CONNECTION_STRING).to.be.a('string');
14+
expect(APPLICATION_INSIGHTS_CONNECTION_STRING.length).to.be.greaterThan(0);
15+
});
16+
17+
it('should contain InstrumentationKey', () => {
18+
expect(APPLICATION_INSIGHTS_CONNECTION_STRING).to.include('InstrumentationKey=');
19+
});
20+
21+
it('should contain IngestionEndpoint', () => {
22+
expect(APPLICATION_INSIGHTS_CONNECTION_STRING).to.include('IngestionEndpoint=');
23+
});
24+
});
25+
});

packages/b2c-dx-mcp/test/server.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,33 @@
77
import {expect} from 'chai';
88
import {z} from 'zod';
99
import {B2CDxMcpServer} from '../src/server.js';
10+
import type {Telemetry} from '@salesforce/b2c-tooling-sdk/telemetry';
11+
12+
/**
13+
* Mock telemetry for testing.
14+
*/
15+
class MockTelemetry {
16+
public attributes: Record<string, unknown> = {};
17+
public events: Array<{name: string; attributes: Record<string, unknown>}> = [];
18+
public started = false;
19+
public stopped = false;
20+
21+
addAttributes(attrs: Record<string, unknown>): void {
22+
this.attributes = {...this.attributes, ...attrs};
23+
}
24+
25+
sendEvent(name: string, attributes: Record<string, unknown> = {}): void {
26+
this.events.push({name, attributes});
27+
}
28+
29+
async start(): Promise<void> {
30+
this.started = true;
31+
}
32+
33+
stop(): void {
34+
this.stopped = true;
35+
}
36+
}
1037

1138
// Handlers extracted to module scope to reduce callback nesting depth
1239
const simpleHandler = async () => ({content: [{type: 'text' as const, text: 'ok'}]});
@@ -79,4 +106,30 @@ describe('B2CDxMcpServer', () => {
79106
expect(server.isConnected()).to.be.false;
80107
});
81108
});
109+
110+
describe('telemetry integration', () => {
111+
it('should accept telemetry in options', () => {
112+
const mockTelemetry = new MockTelemetry();
113+
114+
const server = new B2CDxMcpServer(
115+
{name: 'test-server', version: '1.0.0'},
116+
{telemetry: mockTelemetry as unknown as Telemetry},
117+
);
118+
119+
expect(server).to.be.instanceOf(B2CDxMcpServer);
120+
});
121+
122+
it('should work without telemetry (telemetry disabled)', () => {
123+
// When telemetry is undefined, server should still work
124+
const server = new B2CDxMcpServer({name: 'test-server', version: '1.0.0'}, {telemetry: undefined});
125+
126+
expect(server).to.be.instanceOf(B2CDxMcpServer);
127+
});
128+
129+
it('should create server without options (no telemetry)', () => {
130+
const server = new B2CDxMcpServer({name: 'test-server', version: '1.0.0'});
131+
132+
expect(server).to.be.instanceOf(B2CDxMcpServer);
133+
});
134+
});
82135
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2025, Salesforce, Inc.
3+
* SPDX-License-Identifier: Apache-2
4+
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
7+
import {expect} from 'chai';
8+
import {loadAppInsightsKey} from '../../src/utils/index.js';
9+
10+
describe('utils', () => {
11+
describe('loadAppInsightsKey', () => {
12+
it('should return a connection string', () => {
13+
const key = loadAppInsightsKey();
14+
expect(key).to.be.a('string');
15+
});
16+
17+
it('should return a string containing InstrumentationKey', () => {
18+
const key = loadAppInsightsKey();
19+
expect(key).to.include('InstrumentationKey=');
20+
});
21+
22+
it('should return a valid Application Insights connection string format', () => {
23+
const key = loadAppInsightsKey();
24+
// Connection string should have key=value pairs separated by semicolons
25+
expect(key).to.match(/InstrumentationKey=[^;]+/);
26+
expect(key).to.match(/IngestionEndpoint=[^;]+/);
27+
});
28+
});
29+
});

0 commit comments

Comments
 (0)