update_assistant
Update an existing Vapi assistant by modifying its name, instructions, LLM configuration, tools, transcriber, voice, or first message. Provide the assistant ID and the fields to change.
Instructions
Updates an existing Vapi assistant
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| assistantId | Yes | ID of the assistant to update | |
| name | No | New name for the assistant | |
| instructions | No | New instructions for the assistant | |
| llm | No | New LLM configuration | |
| toolIds | No | New IDs of tools to use with this assistant | |
| transcriber | No | New transcription configuration | |
| voice | No | New voice configuration | |
| firstMessage | No | First message to say to the user | |
| firstMessageMode | No | This determines who speaks first, either assistant or user |
Implementation Reference
- src/tools/assistant.ts:63-91 (handler)The handler function that executes the 'update_assistant' tool logic. It validates the assistant exists, transforms input data, calls the Vapi API to update, and returns the transformed output.
server.tool( 'update_assistant', 'Updates an existing Vapi assistant', UpdateAssistantInputSchema.shape, createToolHandler(async (data) => { const assistantId = data.assistantId; try { // First check if the assistant exists const existingAssistant = await vapiClient.assistants.get(assistantId); if (!existingAssistant) { throw new Error(`Assistant with ID ${assistantId} not found`); } // Transform the update data const updateAssistantDto = transformUpdateAssistantInput(data); // Update the assistant const updatedAssistant = await vapiClient.assistants.update( assistantId, updateAssistantDto ); return transformAssistantOutput(updatedAssistant); } catch (error: any) { console.error(`Error updating assistant: ${error.message}`); throw error; } }) ); - src/schemas/index.ts:201-252 (schema)The Zod schema for UpdateAssistantInputSchema, defining all input fields accepted by the 'update_assistant' tool: assistantId (required), name, instructions, llm, toolIds, transcriber, voice, firstMessage, and firstMessageMode (all optional).
export const UpdateAssistantInputSchema = z.object({ assistantId: z.string().describe('ID of the assistant to update'), name: z.string().optional().describe('New name for the assistant'), instructions: z .string() .optional() .describe('New instructions for the assistant'), llm: z .union([ LLMSchema, z.string().transform((str) => { try { return JSON.parse(str); } catch (e) { throw new Error(`Invalid LLM JSON string: ${str}`); } }), ]) .optional() .describe('New LLM configuration'), toolIds: z .array(z.string()) .optional() .describe('New IDs of tools to use with this assistant'), transcriber: z .object({ provider: z.string().describe('Provider to use for transcription'), model: z.string().describe('Transcription model to use'), }) .optional() .describe('New transcription configuration'), voice: z .object({ provider: VoiceProviderSchema.describe('Provider to use for voice'), voiceId: z.string().describe('Voice ID to use'), model: z.string().optional().describe('Voice model to use'), }) .optional() .describe('New voice configuration'), firstMessage: z .string() .optional() .describe('First message to say to the user'), firstMessageMode: z .enum([ 'assistant-speaks-first', 'assistant-waits-for-user', 'assistant-speaks-first-with-model-generated-message', ]) .optional() .describe('This determines who speaks first, either assistant or user'), }); - src/transformers/index.ts:64-131 (helper)The transformUpdateAssistantInput helper function that converts user-provided input into the Vapi.UpdateAssistantDto format. It conditionally builds the DTO object based on which fields were provided by the user.
export function transformUpdateAssistantInput( input: z.infer<typeof UpdateAssistantInputSchema> ): Vapi.UpdateAssistantDto { const updateDto: any = {}; if (input.name) { updateDto.name = input.name; } if (input.llm) { updateDto.model = { provider: input.llm.provider as any, model: input.llm.model, }; if (input.toolIds && input.toolIds.length > 0) { updateDto.model.toolIds = input.toolIds; } if (input.instructions) { updateDto.model.messages = [ { role: 'system', content: input.instructions, }, ]; } } else { if (input.toolIds && input.toolIds.length > 0) { updateDto.model = { toolIds: input.toolIds }; } if (input.instructions) { if (!updateDto.model) updateDto.model = {}; updateDto.model.messages = [ { role: 'system', content: input.instructions, }, ]; } } if (input.transcriber) { updateDto.transcriber = { provider: input.transcriber.provider, ...(input.transcriber.model ? { model: input.transcriber.model } : {}), }; } if (input.voice) { updateDto.voice = { provider: input.voice.provider as any, voiceId: input.voice.voiceId, ...(input.voice.model ? { model: input.voice.model } : {}), }; } if (input.firstMessage) { updateDto.firstMessage = input.firstMessage; } if (input.firstMessageMode) { updateDto.firstMessageMode = input.firstMessageMode; } return updateDto as Vapi.UpdateAssistantDto; } - src/tools/assistant.ts:15-92 (registration)The registerAssistantTools function that registers the 'update_assistant' tool (along with list_assistants, create_assistant, get_assistant) with the MCP server via server.tool().
export const registerAssistantTools = ( server: McpServer, vapiClient: VapiClient ) => { server.tool( 'list_assistants', 'Lists all Vapi assistants', {}, createToolHandler(async () => { // console.log('list_assistants'); const assistants = await vapiClient.assistants.list({ limit: 10 }); // console.log('assistants', assistants); return assistants.map(transformAssistantOutput); }) ); server.tool( 'create_assistant', 'Creates a new Vapi assistant', CreateAssistantInputSchema.shape, createToolHandler(async (data) => { // console.log('create_assistant', data); const createAssistantDto = transformAssistantInput(data); const assistant = await vapiClient.assistants.create(createAssistantDto); return transformAssistantOutput(assistant); }) ); server.tool( 'get_assistant', 'Gets a Vapi assistant by ID', GetAssistantInputSchema.shape, createToolHandler(async (data) => { // console.log('get_assistant', data); const assistantId = data.assistantId; try { const assistant = await vapiClient.assistants.get(assistantId); if (!assistant) { throw new Error(`Assistant with ID ${assistantId} not found`); } return transformAssistantOutput(assistant); } catch (error: any) { console.error(`Error getting assistant: ${error.message}`); throw error; } }) ); server.tool( 'update_assistant', 'Updates an existing Vapi assistant', UpdateAssistantInputSchema.shape, createToolHandler(async (data) => { const assistantId = data.assistantId; try { // First check if the assistant exists const existingAssistant = await vapiClient.assistants.get(assistantId); if (!existingAssistant) { throw new Error(`Assistant with ID ${assistantId} not found`); } // Transform the update data const updateAssistantDto = transformUpdateAssistantInput(data); // Update the assistant const updatedAssistant = await vapiClient.assistants.update( assistantId, updateAssistantDto ); return transformAssistantOutput(updatedAssistant); } catch (error: any) { console.error(`Error updating assistant: ${error.message}`); throw error; } }) ); };