Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@ import { afterEach, beforeAll, beforeEach, describe, expect, mock, test, vi } fr
const redisSetex = vi.fn(async (_key: string, _ttlSeconds: number, _value: string) => 'OK');
const redisGet = vi.fn(async (_key: string): Promise<string | null> => null);
const mockHeartbeat = vi.fn();
const mockStartMcpDockerServer = vi.fn(async () => ({

interface MockMcpDockerServerInput {
context: {
logger: {
debug: (...args: unknown[]) => void;
info: (...args: unknown[]) => void;
};
};
}

const mockStartMcpDockerServer = vi.fn(async (_input: MockMcpDockerServerInput) => ({
endpoint: 'http://localhost:4100/mcp',
containerId: 'mcp-container-1',
}));
Expand Down Expand Up @@ -166,4 +176,49 @@ describe('MCP discovery activity diagnostics', () => {
consoleLogSpy.mockRestore();
}
});

test('discoverMcpGroupToolsActivity does not mirror docker info/debug collector logs to console by default', async () => {
mockStartMcpDockerServer.mockImplementationOnce(async (input: MockMcpDockerServerInput) => {
input.context.logger.info('stdio proxy started');
input.context.logger.debug('stdio proxy details');
return {
endpoint: 'http://localhost:4100/mcp',
containerId: 'mcp-container-1',
};
});
globalThis.fetch = vi.fn(async (url: Parameters<typeof fetch>[0]) => {
const href = String(url);
if (href.endsWith('/health')) {
return createJsonResponse({
status: 'ok',
servers: [{ ready: true }],
});
}
return createJsonResponse({
result: {
tools: [{ name: 'list_buckets', description: 'List storage buckets' }],
},
});
}) as unknown as typeof fetch;
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
const consoleDebugSpy = vi.spyOn(console, 'debug').mockImplementation(() => {});

try {
await discoverMcpGroupToolsActivity({
servers: [
{
name: 'storage',
transport: 'stdio',
command: 'storage-mcp',
},
],
});

expect(consoleLogSpy).not.toHaveBeenCalled();
expect(consoleDebugSpy).not.toHaveBeenCalled();
} finally {
consoleLogSpy.mockRestore();
consoleDebugSpy.mockRestore();
}
Comment on lines +203 to +222
});
});
36 changes: 16 additions & 20 deletions worker/src/temporal/activities/mcp-discovery.activity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { startMcpDockerServer } from '../../components/core/mcp-runtime';
import { Context } from '@temporalio/activity';
import { createExecutionContext } from '@sentris/component-sdk';
import { createExecutionContext, type LogEventInput } from '@sentris/component-sdk';
import { existsSync } from 'node:fs';
import { homedir } from 'node:os';
import { join } from 'node:path';
Expand All @@ -20,6 +20,19 @@ const redisUrl =
process.env.REDIS_URL || process.env.TERMINAL_REDIS_URL || 'redis://localhost:6379';
const redis = new Redis(redisUrl);

function logMcpDiscoveryEntry(prefix: string, entry: LogEventInput): void {
const message = `[${prefix}] ${entry.message}`;
if (entry.level === 'error') {
console.error(message);
return;
}
if (entry.level === 'warn') {
console.warn(message);
return;
}
workflowDiagnosticLog(message);
}

/**
* Cache discovery results in Redis
*/
Expand Down Expand Up @@ -218,16 +231,7 @@ async function spawnStdioContainer(input: {
runId: `mcp-discovery-${Date.now()}`,
componentRef: 'mcp-discovery',
logCollector: (entry) => {
// Log to console for discovery activity
const logMethod =
entry.level === 'error'
? console.error
: entry.level === 'warn'
? console.warn
: entry.level === 'debug'
? console.debug
: console.log;
logMethod(`[MCP Discovery] ${entry.message}`);
logMcpDiscoveryEntry('MCP Discovery', entry);
},
});

Expand Down Expand Up @@ -270,15 +274,7 @@ async function spawnNamedServersContainer(input: {
runId: `mcp-group-discovery-${Date.now()}`,
componentRef: 'mcp-group-discovery',
logCollector: (entry) => {
const logMethod =
entry.level === 'error'
? console.error
: entry.level === 'warn'
? console.warn
: entry.level === 'debug'
? console.debug
: console.log;
logMethod(`[MCP Group Discovery] ${entry.message}`);
logMcpDiscoveryEntry('MCP Group Discovery', entry);
},
});

Expand Down
Loading