Skip to content

Commit 3b13d1c

Browse files
committed
linter
1 parent 620e367 commit 3b13d1c

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

apps/web/src/lib/mcp-client.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,15 @@ interface Message {
1616
toolArgs?: any;
1717
}
1818

19-
type AnthropicMessage = {
20-
role: 'user' | 'assistant';
21-
content: string;
22-
}
23-
2419
export type MessageCallback = (message: Message) => void;
2520

2621
export class MCPClient {
2722
private static instance: MCPClient | null = null;
2823
private connecting: boolean = false;
29-
private anthropicClient: Anthropic;
24+
private anthropicClient!: Anthropic;
3025
private messages: Message[] = [];
31-
private mcpClient: Client;
32-
private transport: SSEClientTransport;
26+
private mcpClient!: Client;
27+
private transport!: SSEClientTransport;
3328
private tools: Tool[] = [];
3429
private isConnected = false;
3530
private firstMessage = true;
@@ -215,10 +210,16 @@ export class MCPClient {
215210
});
216211
}
217212

218-
if (toolResult.content.some(c => c.text.includes('[Error]'))) {
213+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
214+
if (toolResult.content.some((c: any) => c.type === 'text' && c.text?.includes('[Error]'))) {
219215
this.messages.push({
220216
role: 'user',
221-
content: `Error executing query. Please fix the query and try again. Error: ${toolResult.content.map(c => c.text).join('\n')}`
217+
content: `Error executing query. Please fix the query and try again. Error: ${toolResult.content
218+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
219+
.filter((c: any) => c.type === 'text')
220+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
221+
.map((c: any) => c.text)
222+
.join('\n')}`
222223
});
223224
} else {
224225
const formattedResult = JSON.stringify(toolResult.content.flatMap((c) => c.text));
@@ -229,8 +230,13 @@ export class MCPClient {
229230
}
230231

231232
try {
233+
const anthropicMessages = this.messages.map(({ role, content }) => ({
234+
role: role === 'tool' ? 'assistant' : role,
235+
content
236+
}));
237+
232238
const nextStream = await this.anthropicClient.messages.create({
233-
messages: this.messages,
239+
messages: anthropicMessages,
234240
model: 'claude-3-5-sonnet-latest',
235241
max_tokens: 8192,
236242
tools: this.tools,
@@ -312,7 +318,7 @@ export class MCPClient {
312318
}
313319
this.messages.push({ role: 'user', content: message });
314320

315-
const anthropicMessages: AnthropicMessage[] = this.messages.map(({ role, content }) => ({
321+
const anthropicMessages = this.messages.map(({ role, content }) => ({
316322
role: role === 'tool' ? 'assistant' : role,
317323
content
318324
}));

apps/web/src/lib/mcp-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface MCPClient {
88
export class MCPServer {
99
private clients: Set<MCPClient> = new Set();
1010
private isReady: boolean = false;
11-
private eventSource: EventSource;
11+
private eventSource!: EventSource;
1212
private sessionId: string | null = null;
1313

1414
async start() {

0 commit comments

Comments
 (0)