MCP
Serve speak, listen, transcribe and end_call to any MCP client, from the voiceai-sdk mcp command or from your own server with voiceTools.
MCP lets a client, such as a desktop assistant or a coding agent, call tools that run in another process. VoiceAI SDK serves its voice tools over MCP in two ways: the voiceai-sdk mcp command, which needs no code, and voiceTools(session) from voiceai-sdk/mcp, which you register on your own MCP server.
Install
npm install voiceai-sdk @modelcontextprotocol/sdkpnpm add voiceai-sdk @modelcontextprotocol/sdkyarn add voiceai-sdk @modelcontextprotocol/sdkbun add voiceai-sdk @modelcontextprotocol/sdkYou need @modelcontextprotocol/sdk only to write your own server. The mcp command runs with voiceai-sdk alone.
Quickstart
Run the server from a terminal first, to check that it starts and finds your key:
npx voiceai-sdk mcp --provider deepgramIt opens one session with the provider you name and serves the four tools over stdio. It reads the provider's key from the environment, like every adapter. The session closes when the process stops.
To use it, add it to your MCP client. Most clients read an mcpServers object from a JSON config file:
{
"mcpServers": {
"voice": {
"command": "npx",
"args": ["-y", "voiceai-sdk", "mcp", "--provider", "deepgram"],
"env": { "DEEPGRAM_API_KEY": "dg_..." }
}
}
}| Field | What it does |
|---|---|
command | The program the client starts. npx runs voiceai-sdk from your project, or downloads it. |
args | mcp starts the MCP server. --provider takes the same provider names as the other CLI commands. |
env | Variables for that process only. Put the provider's key here. |
The client starts the process when it needs the tools and stops it when it exits.
Run it in your own server
Write your own server when you want a pipeline, per-user settings, or your own tools next to the voice tools. voiceTools(session) returns MCP tool definitions, each with the name, config and handler that registerTool takes.
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { createSession } from "voiceai-sdk";
import { deepgram } from "voiceai-sdk/deepgram";
import { elevenlabs } from "voiceai-sdk/elevenlabs";
import { voiceTools } from "voiceai-sdk/mcp";
const session = await createSession({ stt: deepgram(), tts: elevenlabs() });
const server = new McpServer({ name: "voice", version: "1.0.0" });
for (const tool of voiceTools(session)) {
server.registerTool(tool.name, tool.config, tool.handler);
}
await server.connect(new StdioServerTransport());
// The client stops the server by closing stdin or sending SIGTERM.
const shutdown = async () => {
await session.close();
process.exit(0);
};
process.stdin.on("close", shutdown);
process.on("SIGTERM", shutdown);This example doesn't use await using. A stdio server lives as long as its process, and await using at the top level would close the session as soon as the module finished loading. Close it when the client stops the server instead.
Where keys stay
- With the command, the provider's key sits in the client's config file, under
env. That file is on your machine. Keep it out of version control. - With your own server, the key is read from the server's environment, like any adapter.
- The model never sees a key. Tool calls and their results carry no credentials. The client only sees the four tools.
- One process, one session. Every tool call goes to the same session, so give each user their own server process rather than sharing one.
Next steps
- Agent tools: each tool's input and output.
- CLI: the other commands, such as
doctorandvoices. - Security: what the SDK stores and what it sends.