Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(mcp): stop logging the tool count on every request
Yudhi Armyndharisb45612761de3
diff --git a/src/modules/mcp/mcp.server.spec.ts b/src/modules/mcp/mcp.server.spec.tsindex 74cc709ea..e066e6d66 100644--- a/src/modules/mcp/mcp.server.spec.ts+++ b/src/modules/mcp/mcp.server.spec.ts@@ -9,6 +9,7 @@ import type { AnyToolDescriptor } from '../../core/agent-tools/tool-descriptor';import type { ToolRegistryService } from '../../core/agent-tools/tool-registry.service';import type { AuthService } from '../auth/auth.service';import type { AuditService } from '../audit/audit.service';+import { LoggerService } from '../../common/services/logger.service';// The request-handling path news up an McpServer + StreamableHTTPServerTransport per POST. Both SDK// classes are mocked so tests can observe the per-request transport (handleRequest args) and invoke@@ -511,6 +512,20 @@ describe('mountMcpServer (raw-Express request-handling path)', () => {expect(res.status).not.toHaveBeenCalled(); // no error fallback});+ it('logs the tool count once at mount, not on every request', async () => {+ const info = jest.spyOn(LoggerService.prototype, 'log');+ try {+ const h = mount();+ expect(info).toHaveBeenCalledTimes(1);+ await post(h, { jsonrpc: '2.0', id: 1, method: 'tools/list' }, { 'x-api-key': 'good-key' });+ await post(h, { jsonrpc: '2.0', id: 2, method: 'tools/list' }, { 'x-api-key': 'good-key' });+ expect(mockServerConnect).toHaveBeenCalledTimes(2);+ expect(info).toHaveBeenCalledTimes(1);+ } finally {+ info.mockRestore();+ }+ });+it('refuses an invalid API key inside the dispatch: tool error result, tool handler never runs', async () => {const h = mount();h.authService.validateApiKey.mockRejectedValue(new UnauthorizedException('API key is invalid'));diff --git a/src/modules/mcp/mcp.server.ts b/src/modules/mcp/mcp.server.tsindex 72a4d8a0d..1a6d654d8 100644--- a/src/modules/mcp/mcp.server.ts+++ b/src/modules/mcp/mcp.server.ts@@ -150,7 +150,6 @@ function buildServer();}- logger.log(`MCP server built with ${tools.length} tools (readOnly=${readOnly})`);return server;}@@ -259,7 +258,7 @@ export function mountMcpServer(// and to emit the log line once. The actual McpServer is re-created per request to// avoid the SDK's single-transport-at-a-time constraint under concurrent load.const tools = registry.list({ readOnly });- logger.log(`MCP server mounted at POST ${basePath} (${tools.length} tools)`);+ logger.log(`MCP server mounted at POST ${basePath} (${tools.length} tools, readOnly=${readOnly})`);const handler: RequestHandler = async (req: Request, res: Response) => {const server = buildServer(