create_custom_field
Add custom fields to SendGrid contacts to store additional data like text, numbers, or dates for enhanced contact management and segmentation.
Instructions
Create a new custom field for contacts
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| field_type | Yes | Type of the field | |
| name | Yes | Name of the custom field |
Input Schema (JSON Schema)
{
"properties": {
"field_type": {
"description": "Type of the field",
"enum": [
"Text",
"Number",
"Date"
],
"type": "string"
},
"name": {
"description": "Name of the custom field",
"type": "string"
}
},
"required": [
"name",
"field_type"
],
"type": "object"
}
Implementation Reference
- src/tools/contacts.ts:197-209 (handler)The handler function implements the core logic: checks if in read-only mode, then sends a POST request to SendGrid API to create the custom field with given name and type.handler: async ({ name, field_type }: { name: string; field_type: 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/field_definitions", { method: "POST", body: JSON.stringify({ name, field_type }), }); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; }, },
- src/tools/contacts.ts:189-196 (schema)Tool configuration including title, description, and Zod inputSchema for parameters 'name' (string) and 'field_type' (enum: Text, Number, Date).config: { title: "Create Custom Field", description: "Create a new custom field for contacts", inputSchema: { name: z.string().describe("Name of the custom field"), field_type: z.enum(["Text", "Number", "Date"]).describe("Type of the field"), }, },
- src/tools/index.ts:3-16 (registration)Imports contactTools (which includes create_custom_field) and spreads it into the allTools object exported for main server registration.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:21-23 (registration)Registers all tools from allTools, including create_custom_field, to the MCP server using registerTool with config and handler.for (const [name, tool] of Object.entries(allTools)) { server.registerTool(name, tool.config as any, tool.handler as any); }