Skip to content

Commit e5f8412

Browse files
committed
Fix test client to handle prompts properly and remove old simulated responses from before LMstudio was integrated
1 parent 290e61c commit e5f8412

File tree

2 files changed

+29
-46
lines changed

2 files changed

+29
-46
lines changed

mcp-test-client/src/generic-orchestrator.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,22 @@ export class GenericOrchestrator {
176176
result = await this.primaryClient!.readResource(request.uri!, request.parameters || {});
177177
break;
178178
case 'prompt':
179-
result = await this.primaryClient!.executePrompt(request.name!, request.parameters || {});
179+
// Get the prompt template from MCP server
180+
const promptTemplate = await this.primaryClient!.executePrompt(request.name!, request.parameters || {});
181+
182+
if (this.config.enableLogging) {
183+
console.log(chalk.cyan(` 📝 [Orchestrator] Got prompt template, sending to LLM for processing...`));
184+
}
185+
186+
// Send the prompt template to LLM for actual analysis
187+
const promptContent = promptTemplate.messages?.[0]?.content?.text || 'No prompt content available';
188+
const llmPromptResponse = await this.llm.processUserPrompt(promptContent, { tools: [], resources: [], prompts: [] });
189+
190+
result = {
191+
promptName: request.name,
192+
template: promptTemplate,
193+
analysis: llmPromptResponse.content || 'No analysis provided'
194+
};
180195
break;
181196
default:
182197
throw new Error(`Unknown request type: ${(request as any).type}`);

mcp-test-client/src/mcp-client.ts

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export class MCPClient {
229229
throw new Error(`Prompt not found: ${promptName}`);
230230
}
231231

232-
console.log(chalk.magenta(`💬 [MCP Client] Executing prompt: ${promptName}`));
232+
console.log(chalk.magenta(`💬 [MCP Client] Getting prompt template: ${promptName}`));
233233
console.log(chalk.gray(` 📋 Parameters: ${JSON.stringify(parameters)}`));
234234

235235
try {
@@ -239,16 +239,18 @@ export class MCPClient {
239239
});
240240

241241
if (response.error) {
242-
console.log(chalk.yellow(`⚠️ [MCP Client] Simulating prompt response due to error: ${response.error.message}`));
243-
return this.simulatePromptResponse(promptName, parameters);
242+
throw new Error(`Failed to get prompt template: ${response.error.message}`);
244243
}
245244

246-
const result = response.result?.messages?.[0]?.content?.text || 'Prompt response received';
247-
console.log(chalk.green(`✅ [MCP Client] Prompt executed successfully`));
248-
return result;
245+
// Return the complete prompt template structure - this should be sent to LLM
246+
const promptTemplate = response.result;
247+
console.log(chalk.green(`✅ [MCP Client] Retrieved prompt template successfully`));
248+
console.log(chalk.gray(` 📄 Template has ${promptTemplate?.messages?.length || 0} messages`));
249+
250+
return promptTemplate;
249251
} catch (error) {
250-
console.log(chalk.yellow(`⚠️ [MCP Client] Simulating prompt response due to error: ${(error as Error).message}`));
251-
return this.simulatePromptResponse(promptName, parameters);
252+
console.log(chalk.red(`❌ [MCP Client] Failed to get prompt template: ${(error as Error).message}`));
253+
throw error;
252254
}
253255
}
254256

@@ -280,8 +282,7 @@ export class MCPClient {
280282
});
281283

282284
if (response.error) {
283-
console.log(chalk.yellow(`⚠️ [MCP Client] Simulating resource response due to error: ${response.error.message}`));
284-
return this.simulateResourceResponse(resourceUri);
285+
throw new Error(`Resource read error: ${response.error.message}`);
285286
}
286287

287288
const result = response.result?.contents?.[0];
@@ -299,43 +300,10 @@ export class MCPClient {
299300
console.log(chalk.green(`✅ [MCP Client] Resource read successfully`));
300301
return result;
301302
} catch (error) {
302-
console.log(chalk.yellow(`⚠️ [MCP Client] Simulating resource response due to error: ${(error as Error).message}`));
303-
return this.simulateResourceResponse(resourceUri);
304-
}
305-
}
306-
307-
private simulatePromptResponse(promptName: string, parameters: Record<string, any>): string {
308-
if (promptName === 'fraud_analysis') {
309-
return 'Based on the payment data provided, this appears to be a legitimate utility payment. The payee "Power Company Australia" is a known utility provider, and the payment amount of $750 is within normal range for utility bills.';
310-
} else if (promptName === 'loan_recommendation') {
311-
return 'Based on the account history and current products (Complete Freedom Savings and Business Cheque), I recommend considering our Personal Loan at 6.5% APR for amounts up to $50,000, or our Home Equity Line of Credit at 4.2% APR for larger amounts.';
303+
console.log(chalk.red(`❌ [MCP Client] Resource read failed: ${(error as Error).message}`));
304+
throw error;
312305
}
313-
return `Analysis complete for ${promptName}. This is a simulated response with parameters: ${JSON.stringify(parameters)}`;
314306
}
315307

316-
private simulateResourceResponse(resourceUri: string): any {
317-
if (resourceUri.includes('products')) {
318-
return {
319-
contents: [{
320-
uri: resourceUri,
321-
mimeType: 'application/json',
322-
text: JSON.stringify({
323-
products: [
324-
{ id: 'SAV_001', name: 'Basic Savings', type: 'savings', rate: 0.5 },
325-
{ id: 'CHK_001', name: 'Premium Checking', type: 'checking', monthlyFee: 15 },
326-
{ id: 'LOAN_001', name: 'Auto Loan', type: 'loan', rate: 4.5 }
327-
]
328-
})
329-
}]
330-
};
331-
}
332308

333-
return {
334-
contents: [{
335-
uri: resourceUri,
336-
mimeType: 'application/json',
337-
text: JSON.stringify({ data: `Resource data for ${resourceUri}` })
338-
}]
339-
};
340-
}
341309
}

0 commit comments

Comments
 (0)