> ## Documentation Index
> Fetch the complete documentation index at: https://nuntly.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Use Nuntly from the AI SDK

> Connect the Vercel AI SDK to the Nuntly MCP server over stdio, pass its tools to a model, and let the model send email from your own code.

The AI SDK connects to the Nuntly MCP server through its MCP client and passes the tools to the model. Check the [prerequisites](https://nuntly.com/docs/guides/ai-agents.md#prerequisites) first: an API key and Node.js 20 or later.

## Install

Install `ai`, `@ai-sdk/mcp` and a provider such as `@ai-sdk/anthropic`.

## Call the tools from a model

```typescript agent.ts theme={null}
import { anthropic } from '@ai-sdk/anthropic';
import { createMCPClient } from '@ai-sdk/mcp';
import { Experimental_StdioMCPTransport } from '@ai-sdk/mcp/mcp-stdio';
import { generateText, isStepCount } from 'ai';

const apiKey = process.env.NUNTLY_API_KEY;
if (!apiKey) throw new Error('Set NUNTLY_API_KEY before you start the agent.');

const nuntly = await createMCPClient({
  transport: new Experimental_StdioMCPTransport({
    command: 'npx',
    args: ['-y', '@nuntly/sdk-mcp@2'],
    env: { NUNTLY_API_KEY: apiKey },
  }),
});

try {
  const { text } = await generateText({
    model: anthropic('claude-sonnet-5-5'),
    tools: await nuntly.tools(),
    stopWhen: isStepCount(5),
    prompt: 'Send a one-line status email from hello@yourdomain.com to you@example.com.',
  });
  console.log(text);
} finally {
  await nuntly.close();
}
```

The stdio transport runs on Node.js only. The sample uses `ai` 7, where `isStepCount` limits the number of tool-calling steps. See the [AI SDK MCP documentation](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) for other transports.

When a tool fails, see [Troubleshooting](https://nuntly.com/docs/guides/ai-agents-troubleshooting.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.