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

demo.tools.ts

47 lines1.2 KB

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