Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

demo.tools.ts

53 lines1.2 KB

1import { experimental_createMCPClient, tool } from 'ai'
2//import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
3import { z } from 'zod'
4​
5import guitars from '../data/example-guitars'
6​
7// Example of using an SSE MCP server
8// const mcpClient = await experimental_createMCPClient({
9// transport: {
10// type: "sse",
11// url: "http://localhost:8081/sse",
12// },
13// name: "Demo Service",
14// });
15​
16// Example of using an STDIO MCP server
17// const mcpClient = await experimental_createMCPClient({
18// transport: new StdioClientTransport({
19// command: "node",
20// args: [
21// "stdio-server.js",
22// ],
23// }),
24// });
25​
26const getGuitars = tool({
27 description: 'Get all products from the database',
28 inputSchema: z.object({}),
29 execute: async () => {
30 return Promise.resolve(guitars)
31 },
32})
33​
34const recommendGuitar = tool({
35 description: 'Use this tool to recommend a guitar to the user',
36 inputSchema: z.object({
37 id: z.string().describe('The id of the guitar to recommend'),
38 }),
39 execute: async ({ id }) => {
40 return {
41 id,
42 }
43 },
44})
45​
46export default async function getTools() {
47 // const mcpTools = await mcpCient.tools()
48 return {
49 // ...mcpTools,
50 getGuitars,
51 recommendGuitar,
52 }