Open History to see the last commit
1import { createFileRoute } from '@tanstack/react-router'
2import { MCPToolFilterError, createMCPClient } from '@tanstack/ai-mcp'
3
4/**
5 * `toolName` and the list form of `toolFilter`, against the e2e MCP server.
6 * Returns the names the model would see, and the error for a missing name.
7 */
8export const Route = createFileRoute('/api/mcp-tool-options-wire')({
9 server: {
10 handlers: {
11 POST: async ({ request }) => {
12 const url = `${new URL(request.url).origin}/api/mcp-server`
13
14 const named = await createMCPClient({
15 transport: { type: 'http', url },
16 toolName: (tool) => `mcp__store__${tool.name}`,
17 toolFilter: ['get_guitar_price'],
18 requestOptions: { timeout: 30_000 },
19 })
20 let names: Array<string> = []
21 try {
22 names = (await named.tools()).map((tool) => tool.name)
23 } finally {
24 await named.close()
25 }
26
27 const strict = await createMCPClient({
28 transport: { type: 'http', url },
29 toolFilter: ['get_guitar_price', 'no_such_tool'],
30 })
31 let missing: Array<string> = []
32 let errorName = ''
33 try {
34 await strict.tools()
35 } catch (error) {
36 if (error instanceof MCPToolFilterError) {
37 missing = error.missing
38 errorName = error.name
39 }
40 } finally {
41 await strict.close()
42 }
43
44 return Response.json({ names, missing, errorName })
45 },
46 },
47 },
48})