-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmcpServer.ts
More file actions
77 lines (71 loc) · 1.48 KB
/
mcpServer.ts
File metadata and controls
77 lines (71 loc) · 1.48 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { googleAI } from '@genkit-ai/google-genai';
import { createMcpServer } from '@genkit-ai/mcp';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { genkit, z } from 'genkit/beta';
const ai = genkit({
plugins: [googleAI()],
});
ai.defineTool(
{
name: 'add',
description: 'add two numbers together',
inputSchema: z.object({ a: z.number(), b: z.number() }),
outputSchema: z.number(),
},
async ({ a, b }) => {
return a + b;
},
);
ai.definePrompt(
{
name: 'happy',
description: 'everybody together now',
input: {
schema: z.object({
action: z.string().default('clap your hands').optional(),
}),
},
},
`If you're happy and you know it, {{action}}.`,
);
ai.defineResource(
{
name: 'my resouces',
uri: 'my://resource',
},
async () => {
return {
content: [
{
text: 'my resource',
},
],
};
},
);
ai.defineResource(
{
name: 'file',
template: 'file://{path}',
},
async ({ uri }) => {
return {
content: [
{
text: `file contents for ${uri}`,
},
],
};
},
);
// Use createMcpServer
const server = createMcpServer(ai, {
name: 'Genkit-cards',
version: '0.0.2',
});
// Setup (async) then starts with stdio transport by default
server.setup().then(async () => {
await server.start();
const transport = new StdioServerTransport();
await server.server?.connect(transport);
});