Skip to main content
Glama
deyikong

SendGrid MCP Server

by deyikong

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
NameRequiredDescriptionDefault
segment_idYesID of the segment to update
nameNoNew name for the segment
query_dslNoNew query criteria for the segment (JSON string)

Implementation Reference

  • 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) }] }; }, },
  • 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); }
  • Aggregation of all tool sets into allTools, including contactTools which contains update_segment.
    export const allTools = { ...automationTools, ...campaignTools, ...contactTools,

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