update_segment
Modify an existing email segment's name or query criteria in SendGrid to refine contact targeting and improve campaign personalization.
Instructions
Update an existing segment's name or query criteria
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| segment_id | Yes | ID of the segment to update | |
| name | No | New name for the segment | |
| query_dsl | No | New query criteria for the segment (JSON string) |
Implementation Reference
- src/tools/contacts.ts:494-520 (handler)Handler function that performs the PATCH request to update the segment name or query DSL via SendGrid API, with readonly check and input validation.handler: async ({ segment_id, name, query_dsl }: { segment_id: string; name?: string; query_dsl?: string }): Promise<ToolResult> => { const readOnlyCheck = checkReadOnlyMode(); if (readOnlyCheck.blocked) { return { content: [{ type: "text", text: readOnlyCheck.message! }] }; } const updateData: any = {}; if (name) updateData.name = name; if (query_dsl) { try { updateData.query_dsl = JSON.parse(query_dsl); } catch (error) { return { content: [{ type: "text", text: "Error: query_dsl must be valid JSON. Please provide a properly formatted query." }] }; } } if (Object.keys(updateData).length === 0) { return { content: [{ type: "text", text: "Error: Please provide either 'name' or 'query_dsl' to update." }] }; } const result = await makeRequest(`https://api.sendgrid.com/v3/marketing/segments/2.0/${segment_id}`, { method: "PATCH", body: JSON.stringify(updateData), }); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; }, },
- src/tools/contacts.ts:485-493 (schema)Configuration including Zod input schema for the update_segment tool parameters.config: { title: "Update Segment", description: "Update an existing segment's name or query criteria", inputSchema: { segment_id: z.string().describe("ID of the segment to update"), name: z.string().optional().describe("New name for the segment"), query_dsl: z.string().optional().describe("New query criteria for the segment (JSON string)"), }, },
- src/index.ts:21-23 (registration)MCP server registration loop that registers all tools from allTools, including update_segment.for (const [name, tool] of Object.entries(allTools)) { server.registerTool(name, tool.config as any, tool.handler as any); }
- src/tools/index.ts:9-12 (registration)Aggregation of all tool sets into allTools, including contactTools which contains update_segment.export const allTools = { ...automationTools, ...campaignTools, ...contactTools,