Skip to content

Commit d6938a0

Browse files
committed
Improve test infrastructure and error handling
- Enable dotenv in Playwright config to load environment variables - Pass LiteLLM credentials to webServer for test environment - Fix get-servers.ts error handling: wrap tool loading in try/catch - Fix getMcpServers to work when Caddy server is not configured - Make test-mcp-server load tools dynamically instead of caching - Update MCP test to select model and enable server/tool checkboxes - Remove unused browserName parameters from tests Tests: 12/15 passing (80%). MCP tool call tests still failing - needs further investigation of SSE/WebSocket message streaming.
1 parent 82c9d33 commit d6938a0

File tree

3 files changed

+61
-39
lines changed

3 files changed

+61
-39
lines changed

frontend/src/logic/get-servers.ts

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,17 @@ const getTools = async(mcpServer: MCP_SERVER, authToken?: string) => {
109109

110110
try {
111111
console.log(`${mcpServer.name}: Connected using Streamable HTTP transport`);
112+
const serverMcpTools = await loadMcpTools(mcpServer.url, client) as unknown as Tool[];
113+
const toolList = await client.listTools();
114+
serverMcpTools.forEach((tool, toolIndex) => {
115+
tool.serverName = mcpServer.name;
116+
tool.annotations = toolList.tools[toolIndex].annotations;
117+
});
118+
tools.push(...serverMcpTools);
112119
} catch(error) { /* eslint @typescript-eslint/no-unused-vars: "off" */
113-
console.log(`${mcpServer.name}: Error connecting via StreamableHTTTP`, error);
120+
console.log(`${mcpServer.name}: Error loading tools`, error);
114121
}
115122

116-
const serverMcpTools = await loadMcpTools(mcpServer.url, client) as unknown as Tool[];
117-
const toolList = await client.listTools();
118-
serverMcpTools.forEach((tool, toolIndex) => {
119-
tool.serverName = mcpServer.name;
120-
tool.annotations = toolList.tools[toolIndex].annotations;
121-
});
122-
123-
tools.push(...serverMcpTools);
124123
return tools;
125124
};
126125

@@ -141,13 +140,15 @@ const getPrompt = async(promptName: string, mcpServer: MCP_SERVER, authToken?: s
141140

142141
const cachedServers: MCP_SERVER[] = [];
143142
let caddyServer: MCP_SERVER | undefined;
143+
let testServer: MCP_SERVER | undefined;
144144

145145

146-
// Cache all servers except Caddy
146+
// Cache all servers except Caddy and test-mcp-server
147147
(async() => {
148148
const servers = getServerList();
149149
caddyServer = servers.find((server) => server.name === 'Caddy');
150-
for (const server of servers.filter((server) => server.name !== 'Caddy')) {
150+
testServer = servers.find((server) => server.name === 'test-mcp-server');
151+
for (const server of servers.filter((server) => server.name !== 'Caddy' && server.name !== 'test-mcp-server')) {
151152
server.tools = await getTools(server);
152153
cachedServers.push(server);
153154
}
@@ -158,25 +159,30 @@ export const getMcpServers = async(authToken: string) => {
158159

159160
// Get Caddy collections
160161
const caddyServers: MCP_SERVER[] = [];
161-
if (!caddyServer) {
162-
return cachedServers;
162+
if (caddyServer) {
163+
const caddyTools = await getTools(caddyServer, authToken);
164+
165+
for (const tool of caddyTools) {
166+
const prompt = await getPrompt(tool.name, caddyServer, authToken);
167+
caddyServers.push({
168+
name: tool.annotations?.title?.replace('Search ', '') || tool.name,
169+
description: tool.description,
170+
url: caddyServer?.url || '',
171+
accessToken: caddyServer?.accessToken,
172+
tools: [tool],
173+
customPrompt: prompt.trim(),
174+
isCaddy: true,
175+
});
176+
}
163177
}
164178

165-
const caddyTools = await getTools(caddyServer, authToken);
166-
167-
for (const tool of caddyTools) {
168-
const prompt = await getPrompt(tool.name, caddyServer, authToken);
169-
caddyServers.push({
170-
name: tool.annotations?.title?.replace('Search ', '') || tool.name,
171-
description: tool.description,
172-
url: caddyServer?.url || '',
173-
accessToken: caddyServer?.accessToken,
174-
tools: [tool],
175-
customPrompt: prompt.trim(),
176-
isCaddy: true,
177-
});
179+
// Load test server tools dynamically (not cached)
180+
const testServers: MCP_SERVER[] = [];
181+
if (testServer) {
182+
testServer.tools = await getTools(testServer, authToken);
183+
testServers.push(testServer);
178184
}
179185

180-
return [...caddyServers, ...cachedServers];
186+
return [...caddyServers, ...testServers, ...cachedServers];
181187

182188
};

tests/playwright.config.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { defineConfig, devices } from '@playwright/test';
44
* Read environment variables from file.
55
* https://github.com/motdotla/dotenv
66
*/
7-
// import dotenv from 'dotenv';
8-
// import path from 'path';
9-
// dotenv.config({ path: path.resolve(__dirname, '.env') });
7+
import dotenv from 'dotenv';
8+
import path from 'path';
9+
dotenv.config({ path: path.resolve(__dirname, '../.env') });
1010

1111
/**
1212
* See https://playwright.dev/docs/test-configuration.
@@ -78,17 +78,23 @@ export default defineConfig({
7878

7979
/* Run local dev servers before starting the tests */
8080
webServer: [
81-
{
82-
cwd: '../',
83-
command: 'make run_frontend',
84-
url: 'http://localhost:4321',
85-
reuseExistingServer: !process.env.CI,
86-
},
8781
{
8882
cwd: '../mcp-server-demo',
8983
command: 'npm run start',
9084
url: 'http://localhost:3210/sse',
9185
reuseExistingServer: !process.env.CI,
9286
},
87+
{
88+
cwd: '../',
89+
command: 'make run_frontend',
90+
url: 'http://localhost:4321',
91+
reuseExistingServer: !process.env.CI,
92+
env: {
93+
...process.env,
94+
USE_LITE_LLM: process.env.USE_LITE_LLM || '',
95+
LITELLM_GOVAI_CLIENT_OPENAI_API_KEY: process.env.LITELLM_GOVAI_CLIENT_OPENAI_API_KEY || '',
96+
LLM_GATEWAY_URL: process.env.LLM_GATEWAY_URL || '',
97+
},
98+
},
9399
]
94100
});

tests/tests.spec.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ test('Basic prompt-related tasks', async ({ page }) => {
6767
});
6868

6969

70-
test('Chat history', async ({ page, browserName }) => {
70+
test('Chat history', async ({ page }) => {
7171

7272
await page.locator('a:has-text("Chat history")').click();
7373

@@ -89,7 +89,17 @@ test('Chat history', async ({ page, browserName }) => {
8989

9090

9191
test('MCP call', async ({ page }) => {
92-
92+
93+
await page.locator('#model-selector').selectOption('gpt-4.1-nano');
94+
95+
// Enable the test-mcp-server
96+
await page.locator('summary:has-text("Plugins")').click();
97+
await page.getByLabel('test-mcp-server').check();
98+
// Wait for tools to load after checking the server
99+
await page.waitForTimeout(1000);
100+
// Check the ping-pong tool
101+
await page.getByLabel('ping-pong:').check();
102+
93103
await sendPrompt('@ping-pong What is 6 * 7?', page);
94104

95105
// check the tool call and the response is shown
@@ -138,7 +148,7 @@ test('Message input functionality', async ({ page }) => {
138148
});
139149

140150

141-
test('Copy to clipboard', async ({ page, browserName }) => {
151+
test('Copy to clipboard', async ({ page }) => {
142152

143153
await page.locator('#model-selector').selectOption('gpt-4.1-nano');
144154

0 commit comments

Comments
 (0)