Skip to content

Commit 3e8a191

Browse files
committed
fix: add debug logging to TS e2e tests
1 parent 83e8d11 commit 3e8a191

File tree

5 files changed

+65
-17
lines changed

5 files changed

+65
-17
lines changed

e2e_tests/test_questions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"Who wrote the book Pride and Prejudice?",
1111
"How do you pronounce the word 'hello'?",
1212
"Tell me the inspirational quote of the day.",
13-
"Who is Tom Cruise?"
13+
"Who is Tom Cruise? (use his Wikipedia article to answer)"
1414
]

e2e_tests/typescript/src/chat_session.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,24 @@ export class ChatSession {
1717
for (const userInput of this.userUtterances) {
1818
console.log(`\nYou: ${userInput}`);
1919
process.stdout.write("\nAssistant: ");
20-
await this.agent.invoke(userInput);
20+
21+
logger.info(`Starting agent invocation for: "${userInput}"`);
22+
const startTime = Date.now();
23+
24+
try {
25+
await this.agent.invoke(userInput);
26+
const duration = Date.now() - startTime;
27+
logger.info(`Agent invocation completed in ${duration}ms`);
28+
} catch (error) {
29+
const duration = Date.now() - startTime;
30+
logger.error(`Agent invocation failed after ${duration}ms:`, error);
31+
throw error;
32+
}
2133
}
2234
} finally {
35+
logger.info("Disconnecting MCP clients...");
2336
await Promise.all(this.mcpClients.map(client => client.disconnect()));
37+
logger.info("All MCP clients disconnected");
2438
}
2539
}
2640
}

e2e_tests/typescript/src/main.ts

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,76 @@ import {
1010
import logger from "./logger.js";
1111

1212
async function main(): Promise<void> {
13+
logger.info(`Starting e2e test with LOG_LEVEL=${process.env.LOG_LEVEL || 'info'}`);
14+
logger.info(`Node version: ${process.version}`);
15+
1316
const config = new Configuration();
1417
const serverConfig = Configuration.loadConfig("./servers_config.json");
1518

1619
const mcpClients = [];
1720

21+
logger.info("Initializing MCP clients...");
1822
for (const [name, srvConfig] of Object.entries(serverConfig.stdioServers || {})) {
19-
mcpClients.push(await createStdioClient(name, srvConfig));
23+
try {
24+
mcpClients.push(await createStdioClient(name, srvConfig));
25+
} catch (error) {
26+
logger.error(`Failed to initialize stdio server ${name}:`, error);
27+
throw error;
28+
}
2029
}
2130

2231
for (const [name, srvConfig] of Object.entries(serverConfig.lambdaFunctionServers || {})) {
23-
mcpClients.push(await createLambdaFunctionClient(name, srvConfig));
32+
try {
33+
mcpClients.push(await createLambdaFunctionClient(name, srvConfig));
34+
} catch (error) {
35+
logger.error(`Failed to initialize lambda function server ${name}:`, error);
36+
throw error;
37+
}
2438
}
2539

2640
for (const [name, srvConfig] of Object.entries(serverConfig.lambdaFunctionUrls || {})) {
27-
mcpClients.push(await createLambdaFunctionUrlClient(name, srvConfig));
41+
try {
42+
mcpClients.push(await createLambdaFunctionUrlClient(name, srvConfig));
43+
} catch (error) {
44+
logger.error(`Failed to initialize lambda function URL server ${name}:`, error);
45+
throw error;
46+
}
2847
}
2948

3049
for (const [name, srvConfig] of Object.entries(serverConfig.oAuthServers || {})) {
31-
mcpClients.push(await createAutomatedOAuthClient(name, srvConfig));
50+
try {
51+
mcpClients.push(await createAutomatedOAuthClient(name, srvConfig));
52+
} catch (error) {
53+
logger.error(`Failed to initialize OAuth server ${name}:`, error);
54+
throw error;
55+
}
3256
}
3357

58+
logger.info(`Successfully initialized ${mcpClients.length} MCP clients`);
59+
3460
const userUtterances = Configuration.loadConfig("../test_questions.json") as string[];
61+
logger.info(`Loaded ${userUtterances.length} test questions`);
3562

63+
logger.info("Initializing Bedrock model...");
3664
const model = new BedrockModel({
3765
region: config.bedrockClient.config.region as string,
3866
modelId: config.modelId,
3967
});
68+
logger.info(`Using model: ${config.modelId} in region: ${config.bedrockClient.config.region}`);
4069

70+
logger.info("Creating agent...");
4171
const agent = new Agent({
4272
model,
4373
tools: mcpClients,
4474
systemPrompt: "You are a helpful assistant.",
4575
});
76+
logger.info("Agent created successfully");
4677

4778
const chatSession = new ChatSession(agent, userUtterances, mcpClients);
4879

80+
logger.info("Starting chat session...");
4981
await chatSession.start();
82+
logger.info("Chat session completed successfully");
5083
}
5184

5285
process.on("unhandledRejection", (reason, promise) => {
@@ -56,6 +89,8 @@ process.on("unhandledRejection", (reason, promise) => {
5689

5790
main().catch((error) => {
5891
logger.error("Error in main:", error);
92+
if (error.stack) {
93+
logger.error("Stack trace:", error.stack);
94+
}
5995
process.exit(1);
6096
});
61-

e2e_tests/typescript/src/mcp_clients.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import logger from "./logger.js";
1818

1919
export async function createStdioClient(name: string, config: any): Promise<McpClient> {
2020
logger.info(`Initializing stdio server: ${name}`);
21+
logger.debug(`Stdio config: ${JSON.stringify({ command: config.command, args: config.args })}`);
2122
const transport = new StdioClientTransport({
2223
command: config.command,
2324
args: config.args,
@@ -28,6 +29,7 @@ export async function createStdioClient(name: string, config: any): Promise<McpC
2829

2930
export async function createLambdaFunctionClient(name: string, config: any): Promise<McpClient> {
3031
logger.info(`Initializing lambda function server: ${name}`);
32+
logger.debug(`Lambda function config: ${JSON.stringify({ functionName: config.functionName, region: config.region })}`);
3133
const transport = new LambdaFunctionClientTransport({
3234
functionName: config.functionName,
3335
regionName: config.region,
@@ -46,9 +48,11 @@ export async function createLambdaFunctionUrlClient(name: string, config: any):
4648

4749
if (stackName) {
4850
const outputKey = config.stackUrlOutputKey || config.stack_url_output_key || "FunctionUrl";
51+
logger.debug(`Fetching function URL from CloudFormation stack: ${stackName}, output: ${outputKey}`);
4952
functionUrl = await getCloudFormationOutput(stackName, outputKey, region);
5053
}
5154

55+
logger.debug(`Lambda function URL: ${functionUrl}, region: ${region}`);
5256
const transport = new StreamableHTTPClientWithSigV4Transport(new URL(functionUrl), { region, service: "lambda" });
5357
return new McpClient({ transport });
5458
}
@@ -68,13 +72,18 @@ export async function createAutomatedOAuthClient(name: string, config: any): Pro
6872
const authStackName = config.authStackName || config.auth_stack_name || "LambdaMcpServer-Auth";
6973
const authStackRegion = config.authStackRegion || config.auth_stack_region || "us-west-2";
7074

75+
logger.debug(`Fetching server URL for ${name}...`);
7176
const serverUrl = serverStackName
7277
? await getCloudFormationOutput(serverStackName, serverStackUrlOutputKey, serverStackRegion)
7378
: await getSsmParameter(serverSsmParameterName!, serverSsmRegion);
79+
logger.debug(`Server URL: ${serverUrl}`);
7480

81+
logger.debug(`Fetching OAuth credentials from stack: ${authStackName}`);
7582
const clientId = await getCloudFormationOutput(authStackName, "AutomatedOAuthClientId", authStackRegion);
7683
const clientSecret = await getClientSecret(authStackName, authStackRegion);
84+
logger.debug(`OAuth client ID: ${clientId}`);
7785

86+
logger.debug(`Creating OAuth transport for ${name}...`);
7887
const transport = await createAutomatedOAuthTransport(serverUrl, clientId, clientSecret);
7988

8089
return new McpClient({ transport });

src/typescript/package-lock.json

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)