|
| 1 | +'use client' |
| 2 | + |
| 3 | +import { useState } from 'react' |
| 4 | +import { useMastraQuery } from '@/lib/hooks/use-mastra-query' |
| 5 | + |
| 6 | +export default function McpA2APage() { |
| 7 | + const { |
| 8 | + useMcpServers, |
| 9 | + useMcpServerTools, |
| 10 | + useAgents, |
| 11 | + useA2ACard, |
| 12 | + } = useMastraQuery() |
| 13 | + |
| 14 | + const serversResult = useMcpServers({ page: 0, perPage: 50 }) |
| 15 | + const servers = serversResult.data?.servers ?? [] |
| 16 | + |
| 17 | + const [selectedServerId, setSelectedServerId] = useState<string>('') |
| 18 | + const activeServerId = selectedServerId || servers[0]?.id || '' |
| 19 | + |
| 20 | + const toolsResult = useMcpServerTools(activeServerId) |
| 21 | + const serverTools = toolsResult.data?.tools ?? [] |
| 22 | + |
| 23 | + const agentsResult = useAgents() |
| 24 | + const agents = agentsResult.data ?? [] |
| 25 | + |
| 26 | + const [selectedAgentId, setSelectedAgentId] = useState<string>('') |
| 27 | + const activeAgentId = selectedAgentId || agents[0]?.id || '' |
| 28 | + |
| 29 | + const a2aCardResult = useA2ACard(activeAgentId) |
| 30 | + const a2aCard = a2aCardResult.data |
| 31 | + |
| 32 | + return ( |
| 33 | + <div className="flex h-full min-h-0 flex-col gap-4 p-4 md:p-6"> |
| 34 | + <h1 className="text-xl font-semibold">MCP / A2A</h1> |
| 35 | + |
| 36 | + <div className="grid min-h-0 flex-1 grid-cols-1 gap-4 lg:grid-cols-2"> |
| 37 | + <section className="min-h-0 overflow-auto rounded-lg border p-4"> |
| 38 | + <div className="mb-3 flex items-center justify-between"> |
| 39 | + <h2 className="text-sm font-medium">MCP Servers & Tools</h2> |
| 40 | + <select |
| 41 | + aria-label="Select MCP server" |
| 42 | + title="Select MCP server" |
| 43 | + className="rounded-md border bg-background px-2 py-1 text-sm" |
| 44 | + value={activeServerId} |
| 45 | + onChange={(e) => setSelectedServerId(e.target.value)} |
| 46 | + > |
| 47 | + {servers.map((server: { id: string; name?: string }) => ( |
| 48 | + <option key={server.id} value={server.id}> |
| 49 | + {server.name ?? server.id} |
| 50 | + </option> |
| 51 | + ))} |
| 52 | + </select> |
| 53 | + </div> |
| 54 | + |
| 55 | + <ul className="space-y-2"> |
| 56 | + {serverTools.length === 0 ? ( |
| 57 | + <li className="text-sm text-muted-foreground">No MCP tools found.</li> |
| 58 | + ) : ( |
| 59 | + serverTools.map((tool: { id: string; description?: string }) => ( |
| 60 | + <li key={tool.id} className="rounded-md border p-2"> |
| 61 | + <div className="text-sm font-medium">{tool.id}</div> |
| 62 | + {typeof tool.description === 'string' && tool.description.trim().length > 0 ? ( |
| 63 | + <p className="mt-1 text-xs text-muted-foreground">{tool.description}</p> |
| 64 | + ) : null} |
| 65 | + </li> |
| 66 | + )) |
| 67 | + )} |
| 68 | + </ul> |
| 69 | + </section> |
| 70 | + |
| 71 | + <section className="min-h-0 overflow-auto rounded-lg border p-4"> |
| 72 | + <div className="mb-3 flex items-center justify-between"> |
| 73 | + <h2 className="text-sm font-medium">A2A Agent Card</h2> |
| 74 | + <select |
| 75 | + aria-label="Select A2A agent" |
| 76 | + title="Select A2A agent" |
| 77 | + className="rounded-md border bg-background px-2 py-1 text-sm" |
| 78 | + value={activeAgentId} |
| 79 | + onChange={(e) => setSelectedAgentId(e.target.value)} |
| 80 | + > |
| 81 | + {agents.map((agent) => ( |
| 82 | + <option key={agent.id} value={agent.id}> |
| 83 | + {agent.name} |
| 84 | + </option> |
| 85 | + ))} |
| 86 | + </select> |
| 87 | + </div> |
| 88 | + |
| 89 | + {!a2aCard ? ( |
| 90 | + <p className="text-sm text-muted-foreground">No A2A card available.</p> |
| 91 | + ) : ( |
| 92 | + <div className="space-y-3"> |
| 93 | + <div> |
| 94 | + <div className="text-xs text-muted-foreground">Agent</div> |
| 95 | + <div className="text-sm font-medium">{a2aCard.name ?? activeAgentId}</div> |
| 96 | + </div> |
| 97 | + <div> |
| 98 | + <div className="text-xs text-muted-foreground">Description</div> |
| 99 | + <div className="text-sm">{a2aCard.description ?? 'N/A'}</div> |
| 100 | + </div> |
| 101 | + <div> |
| 102 | + <div className="text-xs text-muted-foreground">Skills</div> |
| 103 | + <ul className="mt-1 list-disc pl-5 text-sm"> |
| 104 | + {(a2aCard.skills ?? []).map((skill: { id?: string; name?: string }, idx: number) => ( |
| 105 | + <li key={skill.id ?? skill.name ?? `skill-${idx}`}> |
| 106 | + {skill.name ?? skill.id ?? 'Unnamed skill'} |
| 107 | + </li> |
| 108 | + ))} |
| 109 | + </ul> |
| 110 | + </div> |
| 111 | + </div> |
| 112 | + )} |
| 113 | + </section> |
| 114 | + </div> |
| 115 | + </div> |
| 116 | + ) |
| 117 | +} |
0 commit comments