Skip to content

Commit dde5bd4

Browse files
committed
fix(worker): gate mcp discovery collector diagnostics
Signed-off-by: zebbern <185730623+zebbern@users.noreply.github.com>
1 parent 83d6f8f commit dde5bd4

2 files changed

Lines changed: 72 additions & 21 deletions

File tree

worker/src/temporal/activities/__tests__/mcp-discovery.activity.test.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@ import { afterEach, beforeAll, beforeEach, describe, expect, mock, test, vi } fr
33
const redisSetex = vi.fn(async (_key: string, _ttlSeconds: number, _value: string) => 'OK');
44
const redisGet = vi.fn(async (_key: string): Promise<string | null> => null);
55
const mockHeartbeat = vi.fn();
6-
const mockStartMcpDockerServer = vi.fn(async () => ({
6+
7+
interface MockMcpDockerServerInput {
8+
context: {
9+
logger: {
10+
debug: (...args: unknown[]) => void;
11+
info: (...args: unknown[]) => void;
12+
};
13+
};
14+
}
15+
16+
const mockStartMcpDockerServer = vi.fn(async (_input: MockMcpDockerServerInput) => ({
717
endpoint: 'http://localhost:4100/mcp',
818
containerId: 'mcp-container-1',
919
}));
@@ -166,4 +176,49 @@ describe('MCP discovery activity diagnostics', () => {
166176
consoleLogSpy.mockRestore();
167177
}
168178
});
179+
180+
test('discoverMcpGroupToolsActivity does not mirror docker info/debug collector logs to console by default', async () => {
181+
mockStartMcpDockerServer.mockImplementationOnce(async (input: MockMcpDockerServerInput) => {
182+
input.context.logger.info('stdio proxy started');
183+
input.context.logger.debug('stdio proxy details');
184+
return {
185+
endpoint: 'http://localhost:4100/mcp',
186+
containerId: 'mcp-container-1',
187+
};
188+
});
189+
globalThis.fetch = vi.fn(async (url: Parameters<typeof fetch>[0]) => {
190+
const href = String(url);
191+
if (href.endsWith('/health')) {
192+
return createJsonResponse({
193+
status: 'ok',
194+
servers: [{ ready: true }],
195+
});
196+
}
197+
return createJsonResponse({
198+
result: {
199+
tools: [{ name: 'list_buckets', description: 'List storage buckets' }],
200+
},
201+
});
202+
}) as unknown as typeof fetch;
203+
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
204+
const consoleDebugSpy = vi.spyOn(console, 'debug').mockImplementation(() => {});
205+
206+
try {
207+
await discoverMcpGroupToolsActivity({
208+
servers: [
209+
{
210+
name: 'storage',
211+
transport: 'stdio',
212+
command: 'storage-mcp',
213+
},
214+
],
215+
});
216+
217+
expect(consoleLogSpy).not.toHaveBeenCalled();
218+
expect(consoleDebugSpy).not.toHaveBeenCalled();
219+
} finally {
220+
consoleLogSpy.mockRestore();
221+
consoleDebugSpy.mockRestore();
222+
}
223+
});
169224
});

worker/src/temporal/activities/mcp-discovery.activity.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { startMcpDockerServer } from '../../components/core/mcp-runtime';
22
import { Context } from '@temporalio/activity';
3-
import { createExecutionContext } from '@sentris/component-sdk';
3+
import { createExecutionContext, type LogEventInput } from '@sentris/component-sdk';
44
import { existsSync } from 'node:fs';
55
import { homedir } from 'node:os';
66
import { join } from 'node:path';
@@ -20,6 +20,19 @@ const redisUrl =
2020
process.env.REDIS_URL || process.env.TERMINAL_REDIS_URL || 'redis://localhost:6379';
2121
const redis = new Redis(redisUrl);
2222

23+
function logMcpDiscoveryEntry(prefix: string, entry: LogEventInput): void {
24+
const message = `[${prefix}] ${entry.message}`;
25+
if (entry.level === 'error') {
26+
console.error(message);
27+
return;
28+
}
29+
if (entry.level === 'warn') {
30+
console.warn(message);
31+
return;
32+
}
33+
workflowDiagnosticLog(message);
34+
}
35+
2336
/**
2437
* Cache discovery results in Redis
2538
*/
@@ -218,16 +231,7 @@ async function spawnStdioContainer(input: {
218231
runId: `mcp-discovery-${Date.now()}`,
219232
componentRef: 'mcp-discovery',
220233
logCollector: (entry) => {
221-
// Log to console for discovery activity
222-
const logMethod =
223-
entry.level === 'error'
224-
? console.error
225-
: entry.level === 'warn'
226-
? console.warn
227-
: entry.level === 'debug'
228-
? console.debug
229-
: console.log;
230-
logMethod(`[MCP Discovery] ${entry.message}`);
234+
logMcpDiscoveryEntry('MCP Discovery', entry);
231235
},
232236
});
233237

@@ -270,15 +274,7 @@ async function spawnNamedServersContainer(input: {
270274
runId: `mcp-group-discovery-${Date.now()}`,
271275
componentRef: 'mcp-group-discovery',
272276
logCollector: (entry) => {
273-
const logMethod =
274-
entry.level === 'error'
275-
? console.error
276-
: entry.level === 'warn'
277-
? console.warn
278-
: entry.level === 'debug'
279-
? console.debug
280-
: console.log;
281-
logMethod(`[MCP Group Discovery] ${entry.message}`);
277+
logMcpDiscoveryEntry('MCP Group Discovery', entry);
282278
},
283279
});
284280

0 commit comments

Comments
 (0)