MCPcopy Create free account
hub / github.com/TanStack/ai / tryConnect

Function tryConnect

examples/ts-react-chat/src/routes/api.mcp-apps-chat.ts:36–49  ·  view source on GitHub ↗

Connect one MCP server, returning null (with a warning) if it's unreachable.

(
  url: string,
  prefix: string,
)

Source from the content-addressed store, hash-verified

34
35/** Connect one MCP server, returning null (with a warning) if it's unreachable. */
36async function tryConnect(
37 url: string,
38 prefix: string,
39): Promise<MCPClient | null> {
40 try {
41 return await createMCPClient({ transport: { type: 'http', url }, prefix })
42 } catch (error) {
43 console.warn(
44 `[api.mcp-apps-chat] could not connect MCP server "${prefix}" at ${url}:`,
45 error instanceof Error ? error.message : error,
46 )
47 return null
48 }
49}
50
51export const Route = createFileRoute('/api/mcp-apps-chat')({
52 server: {

Callers 1

Calls 2

createMCPClientFunction · 0.90
warnMethod · 0.65

Tested by

no test coverage detected