← Alle Verbindungen

Mit Vercel AI SDK verbinden

Vercel AI SDK — NewAlgorithm tools loaded directly into your TypeScript agent.

Erstellen Sie vorab Ihr kostenloses Konto.Konto erstellen

Dieser Inhalt ist auf Englisch verfügbar.

Welchen MCP möchten Sie verbinden? Die Befehle unten passen sich Ihrer Auswahl an.

  1. 1

    Generate your API key

    Sign in to app.newalgorithm.io with your account, open Keys & apps and generate a key. It is shown only once: copy it and store it somewhere safe.

    Key format
    na_live_xxxxxxxxxxxxxxxxx
  2. 2

    Install the dependencies

    The AI SDK's MCP client uses the protocol's official transport:

    npm install ai @ai-sdk/anthropic @modelcontextprotocol/sdk
  3. 3

    Store the key in the environment

    In .env.local (and in the project's environment variables on Vercel). No NEXT_PUBLIC_ prefix — the key must never end up in the browser bundle.

    .env.local
    NA_API_KEY=na_live_xxxxxxxxxxxxxxxxx
  4. 4

    Connect and load the tools

    The client returns the tools already in the format that generateText and streamText expect:

    app/api/chat/route.ts
    import { anthropic } from "@ai-sdk/anthropic"
    import { experimental_createMCPClient as createMCPClient, generateText, stepCountIs } from "ai"
    import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
    
    const na = await createMCPClient({
      transport: new StreamableHTTPClientTransport(new URL("https://totvs.mcp.newalgorithm.io/mcp"), {
        requestInit: {
          headers: { Authorization: `Bearer ${process.env.NA_API_KEY}` },
        },
      }),
    })
    
    try {
      const { text } = await generateText({
        model: anthropic("claude-opus-5"),
        tools: await na.tools(),
        stopWhen: stepCountIs(5),
        system: "Query NewAlgorithm before answering about SAP. Let the Manager Agent choose the Specialist.",
        prompt: "How is cost center allocation done in SAP S/4HANA?",
      })
      console.log(text)
    } finally {
      await na.close()
    }
  5. 5

    Confirm

    Before plugging it into the agent, print the list of tools — it's the quickest test that the key and the endpoint are right.

    console.log(Object.keys(await na.tools()))

    Erwartet: [ 'na_search', 'na_route', 'na_specialists', 'na_version' ]

Close the client at the end of the request (na.close()) to avoid leaking connections in serverless environments. On AI SDK 4.x, replace stopWhen: stepCountIs(5) with maxSteps: 5.

Details zu Authentifizierung und Tools in der Dokumentation.