diff --git a/packages/mcp/src/index.ts b/packages/mcp/src/index.ts index 36df3a1b..b06a3271 100644 --- a/packages/mcp/src/index.ts +++ b/packages/mcp/src/index.ts @@ -153,8 +153,15 @@ You can also use special values to control access to orgs: await this.telemetry.start(); - process.stdin.on('close', (err) => { - this.telemetry?.sendEvent(err ? 'SERVER_STOPPED_ERROR' : 'SERVER_STOPPED_SUCCESS'); + process.stdin.on('close', () => { + this.telemetry?.sendEvent('SERVER_STOPPED_SUCCESS'); + this.telemetry?.stop(); + }); + + // Handle SIGTERM as a fallback to ensure telemetry is sent + // https://modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle#stdio + process.stdin.on('SIGTERM', () => { + this.telemetry?.sendEvent('SERVER_STOPPED_SUCCESS'); this.telemetry?.stop(); }); } @@ -207,6 +214,7 @@ You can also use special values to control access to orgs: await this.telemetry.start(); } + // Track startup failures such as invalid flags, missing dependencies, or initialization errors this.telemetry?.sendEvent('START_ERROR', { error: error.message, stack: error.stack, diff --git a/packages/mcp/src/sf-mcp-server.ts b/packages/mcp/src/sf-mcp-server.ts index 500eda71..fe71c289 100644 --- a/packages/mcp/src/sf-mcp-server.ts +++ b/packages/mcp/src/sf-mcp-server.ts @@ -25,7 +25,6 @@ import { import { ServerOptions } from '@modelcontextprotocol/sdk/server/index.js'; import { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js'; import { Logger } from '@salesforce/core'; -import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'; import { ZodRawShape } from 'zod'; import { Telemetry } from './telemetry.js'; import { RateLimiter, RateLimitConfig, createRateLimiter } from './utils/rate-limiter.js'; @@ -89,22 +88,6 @@ export class SfMcpServer extends McpServer implements ToolMethodSignatures { }; } - public connect: McpServer['connect'] = async (transport: Transport): Promise => { - try { - await super.connect(transport); - if (!this.isConnected()) { - this.telemetry?.sendEvent('SERVER_START_ERROR', { - error: 'Server not connected', - }); - } - } catch (error: unknown) { - this.telemetry?.sendEvent('SERVER_START_ERROR', { - error: error instanceof Error ? error.message : 'Unknown error', - stack: error instanceof Error ? error.stack : undefined, - }); - } - }; - public registerTool( name: string, config: {