-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmcpClient.ts
More file actions
41 lines (35 loc) · 1.14 KB
/
mcpClient.ts
File metadata and controls
41 lines (35 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { googleAI } from '@genkit-ai/google-genai';
import { createMcpHost } from '@genkit-ai/mcp';
import { genkit } from 'genkit';
import { flowlogger } from '../logger.js';
flowlogger.info('Setting up MCP client host...');
const mcpHost = createMcpHost({
name: 'myMcpClients', // A name for the host plugin itself
mcpServers: {
// Each key (e.g., 'fs', 'git') becomes a namespace for the server's tools.
fs: {
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-filesystem', process.cwd()],
},
memory: {
command: 'npx',
args: ['-y', ''],
},
},
});
const ai = genkit({
plugins: [googleAI()],
});
(async () => {
// Provide MCP tools to the model of your choice.
const { text } = await ai.generate({
model: googleAI.model('gemini-2.5-flash'),
prompt: `Analyze all files in ${process.cwd()}.`,
tools: await mcpHost.getActiveTools(ai),
resources: await mcpHost.getActiveResources(ai),
});
flowlogger.info('MCP client host setup complete.');
await mcpHost.close();
})();
// Note: In a real application, you would want to handle errors and cleanup more robustly.
export { mcpHost };