Skip to main content
Glama
deyikong

SendGrid MCP Server

by deyikong

update_segment

Modify an existing segment's name or query criteria to refine audience targeting and contact organization in SendGrid email marketing campaigns.

Instructions

Update an existing segment's name or query criteria

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameNoNew name for the segment
query_dslNoNew query criteria for the segment (JSON string)
segment_idYesID of the segment to update

Implementation Reference

  • The main handler function that implements the update_segment tool logic: checks read-only mode, prepares update data for name and/or query_dsl, parses JSON if provided, makes PATCH request to SendGrid API to update the segment.
    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) }] }; }, },
  • Zod input schema defining parameters for update_segment: segment_id (required string), optional name and query_dsl (strings).
    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)"), },
  • The registration of the update_segment tool as part of the contactTools object export, including config and handler.
    update_segment: { 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)"), }, }, 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) }] }; }, },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/deyikong/sendgrid-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server