create_contact
Add new contacts to your SendGrid account with email addresses, names, and custom fields for email marketing campaigns and contact management.
Instructions
Create new contacts in your SendGrid account
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contacts | Yes | Array of contact objects |
Input Schema (JSON Schema)
{
"properties": {
"contacts": {
"description": "Array of contact objects",
"items": {
"additionalProperties": false,
"properties": {
"custom_fields": {
"additionalProperties": {},
"description": "Custom field values",
"type": "object"
},
"email": {
"description": "Contact email address",
"type": "string"
},
"first_name": {
"description": "First name",
"type": "string"
},
"last_name": {
"description": "Last name",
"type": "string"
}
},
"required": [
"email"
],
"type": "object"
},
"type": "array"
}
},
"required": [
"contacts"
],
"type": "object"
}
Implementation Reference
- src/tools/contacts.ts:123-134 (handler)The handler function that performs the actual logic: checks read-only mode and sends a PUT request to SendGrid API to create the contacts.handler: async ({ contacts }: { contacts: any[] }): 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/contacts", { method: "PUT", body: JSON.stringify({ contacts }), }); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; },
- src/tools/contacts.ts:116-122 (schema)Tool configuration including title, description, and input schema defining 'contacts' as array of ContactSchema.config: { title: "Create Contact", description: "Create new contacts in your SendGrid account", inputSchema: { contacts: z.array(ContactSchema).describe("Array of contact objects"), }, },
- src/shared/types.ts:6-11 (schema)Zod schema defining the structure of a contact object used in create_contact input.export const ContactSchema = z.object({ email: z.string().describe("Contact email address"), first_name: z.string().optional().describe("First name"), last_name: z.string().optional().describe("Last name"), custom_fields: z.record(z.any()).optional().describe("Custom field values"), });
- src/tools/contacts.ts:115-135 (registration)Full tool definition object for 'create_contact' exported as part of contactTools, which is then aggregated into allTools.create_contact: { config: { title: "Create Contact", description: "Create new contacts in your SendGrid account", inputSchema: { contacts: z.array(ContactSchema).describe("Array of contact objects"), }, }, handler: async ({ contacts }: { contacts: any[] }): 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/contacts", { method: "PUT", body: JSON.stringify({ contacts }), }); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; }, },
- src/index.ts:21-23 (registration)Generic registration loop that registers all tools from allTools, including create_contact, to the MCP server.for (const [name, tool] of Object.entries(allTools)) { server.registerTool(name, tool.config as any, tool.handler as any); }