MCP Tools for a Voice Agent
@micdrop/mcp turns the tools of an MCP
server into tools any Micdrop agent can call, whatever its provider.
Installation
npm install @micdrop/mcp @modelcontextprotocol/sdkUsage
Connect a client of the MCP SDK, then hand its tools to the agent:
import { mcpTools } from '@micdrop/mcp'import { OpenaiAgent } from '@micdrop/openai'import { endCallTool } from '@micdrop/server'import { Client } from '@modelcontextprotocol/sdk/client/index.js'import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
const client = new Client({ name: 'voice-agent', version: '1.0.0' })await client.connect( new StreamableHTTPClientTransport(new URL('https://shop.example.com/mcp')))
const agent = new OpenaiAgent({ apiKey: process.env.OPENAI_API_KEY || '', systemPrompt: 'You help customers with their orders', tools: [ ...(await mcpTools(client, { exclude: ['delete_account'], confirm: ['cancel_order'], })), endCallTool(), ],})One client can serve every call of the process. mcpTools() lists the tools
when it is called: call it again to pick up tools the server added since.
The model reads the structured result of a tool when the server sends one, its
text otherwise. A result the server marks as an error reaches the model as
{ error }, so it can tell the user.
Options
| Option | Type | Description |
|---|---|---|
include | string[] | (tool) => boolean | Keeps only these tools |
exclude | string[] | (tool) => boolean | Leaves these tools out |
confirm | string[] | (tool) => boolean | true | Tools that run only once the user agreed on the call |
approve | ({ tool, input }) => boolean | Called before every call, which runs only if it returns true |
prefix | string | Put before every tool name, to tell several servers apart |
timeout | number | How long a call can take, in ms |
Confirmation before an action
A tool listed in confirm first asks the model to describe what it is about
to do and get a yes from the user. The call runs when the model calls it again
with the same arguments, after the user answered. See
confirmTool().
confirm: true picks every tool the server does not mark as read only or
harmless, through the readOnlyHint and destructiveHint annotations of
the MCP spec.
approve is the check of your application, a permission of the caller for
instance:
await mcpTools(client, { approve: ({ tool }) => caller.permissions.includes(tool.name),})Several servers
Give each server its own prefix, and combine their tools:
tools: [ ...(await mcpTools(shopClient, { prefix: 'shop_' })), ...(await mcpTools(crmClient, { prefix: 'crm_' })),]