Connect Custom Agent (AI SDK)
to the live web.
Building your own agent? Use the AI SDK's experimental MCP client to load NeuroAPI's tools into any `streamText` or `generateText` call. Works on the edge, in serverless, or in a long-running Node process.
Setup in 5 min
- 1Install
Add `ai` and `@ai-sdk/mcp` to your project.
- 2Create the client
Open an HTTP MCP client pointed at the NeuroAPI endpoint. No auth provider needed — the URL is the credential.
- 3Pass tools to streamText
Spread `await client.tools()` into your `tools` map. Close the client when the stream ends.
npm install ai @ai-sdk/mcp zod
import { streamText, stepCountIs } from "ai";
import { createMCPClient } from "@ai-sdk/mcp";
import { createLovableAiGatewayProvider } from "./lib/ai-gateway";
const gateway = createLovableAiGatewayProvider(process.env.LOVABLE_API_KEY!);
export async function runAgent(messages: any[]) {
const mcp = await createMCPClient({
transport: {
type: "http",
url: "https://neuroapi.me/api/nk_live_YOUR_KEY/mcp",
},
});
try {
const tools = await mcp.tools();
const result = streamText({
model: gateway("google/gemini-3-flash-preview"),
system: "You are a research agent with live web access.",
messages,
tools,
stopWhen: stepCountIs(50),
});
return result.toUIMessageStreamResponse({
onFinish: () => mcp.close(),
});
} catch (err) {
await mcp.close();
throw err;
}
}curl -X POST https://neuroapi.me/api/nk_live_YOUR_KEY/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'First prompts to try
Wire neuroapi_scrape and neuroapi_search into a research agent that always cites sources.
Troubleshooting
The Accept header must include both application/json and text/event-stream. Most SDKs set this automatically — only relevant if you're calling JSON-RPC by hand.
Don't close the MCP client before streamText finishes. Use the onFinish hook.
More clients
Ship an agent that sees the web
100 free credits, no card. Your MCP URL is ready the moment you sign up.