Skip to main content
Glama
deyikong

SendGrid MCP Server

by deyikong

delete_segment

Remove a contact segment from your SendGrid email marketing lists to maintain organized audience targeting.

Instructions

Delete an existing segment

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
segment_idYesID of the segment to delete

Implementation Reference

  • The handler function that performs the actual deletion of a segment using SendGrid's API DELETE request, with read-only mode check.
    handler: async ({ segment_id }: { segment_id: string }): Promise<ToolResult> => {
      const readOnlyCheck = checkReadOnlyMode();
      if (readOnlyCheck.blocked) {
        return { content: [{ type: "text", text: readOnlyCheck.message! }] };
      }
      
      const result = await makeRequest(`https://api.sendgrid.com/v3/marketing/segments/2.0/${segment_id}`, {
        method: "DELETE",
      });
      return { content: [{ type: "text", text: `Segment ${segment_id} deleted successfully.` }] };
    },
  • The tool's configuration including title, description, and Zod input schema validating the segment_id parameter.
    config: {
      title: "Delete Segment",
      description: "Delete an existing segment",
      inputSchema: {
        segment_id: z.string().describe("ID of the segment to delete"),
      },
    },
  • Local registration of contactTools (containing delete_segment) into the allTools object by spreading.
    import { campaignTools } from "./campaigns.js";
    import { contactTools } from "./contacts.js";
    import { mailTools } from "./mail.js";
    import { miscTools } from "./misc.js";
    import { statsTools } from "./stats.js";
    import { templateTools } from "./templates.js";
    
    export const allTools = {
      ...automationTools,
      ...campaignTools,
      ...contactTools,
      ...mailTools,
      ...miscTools,
      ...statsTools,
      ...templateTools,
    };
  • src/index.ts:5-23 (registration)
    Top-level registration loop that registers all tools from allTools (including delete_segment) with the MCP server.
    import { allTools } from "./tools/index.js";
    import { allResources } from "./resources/index.js";
    import { allPrompts } from "./prompts/index.js";
    import { validateEnvironment, getSafeEnvInfo } from "./shared/env.js";
    
    const server = new McpServer({
      name: "sendgrid-mcp",
      version: "1.0.0",
    });
    
    // Register all resources
    for (const [uri, resource] of Object.entries(allResources)) {
      server.registerResource(uri, uri, resource.config, resource.handler);
    }
    
    // Register all tools
    for (const [name, tool] of Object.entries(allTools)) {
      server.registerTool(name, tool.config as any, tool.handler as any);
    }

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