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

index.tsx

68 lines2.1 KB

1import { createFileRoute } from '@tanstack/react-router'
2import { useState } from 'react'
3import { callDesk } from '@/lib/call-server'
4import type { DeskResult } from '@/lib/call-server'
5​
6function McpServerPage() {
7 const [result, setResult] = useState<DeskResult | null>(null)
8 const [error, setError] = useState('')
9 const [pending, setPending] = useState(false)
10​
11 async function onCall() {
12 setError('')
13 setPending(true)
14 try {
15 setResult(await callDesk())
16 } catch (caught) {
17 setResult(null)
18 setError(caught instanceof Error ? caught.message : 'The call failed.')
19 } finally {
20 setPending(false)
21 }
22 }
23​
24 return (
25 <main className="mx-auto max-w-2xl p-6">
26 <h1 className="mb-2 text-3xl font-bold text-white">Travel desk</h1>
27 <p className="mb-6 text-gray-300">
28 This page calls your MCP server. The server has one tool, one resource,
29 and one prompt.
30 </p>
31 <button
32 type="button"
33 className="rounded bg-white px-4 py-2 font-semibold text-gray-900 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white disabled:opacity-60"
34 disabled={pending}
35 onClick={() => {
36 void onCall()
37 }}
38 >
39 {pending ? 'The call is in progress' : 'Call the server'}
40 </button>
41 {error !== '' ? (
42 <p className="mt-4 text-red-300" role="alert">
43 {error}
44 </p>
45 ) : null}
46 {result !== null ? (
47 <div className="mt-8 space-y-6 text-gray-100">
48 <section>
49 <h2 className="text-xl font-semibold">Forecast</h2>
50 <p>{result.forecast}</p>
51 </section>
52 <section>
53 <h2 className="text-xl font-semibold">City guide</h2>
54 <pre className="whitespace-pre-wrap">{result.guide}</pre>
55 </section>
56 <section>
57 <h2 className="text-xl font-semibold">Trip brief</h2>
58 <p>{result.brief}</p>
59 </section>
60 </div>
61 ) : null}
62 </main>
63 )
65​
66export const Route = createFileRoute('/')({
67 component: McpServerPage,
68})