search_contacts
Find contacts in SendGrid using search queries with segment conditions to locate specific email addresses or contact groups without creating segments.
Instructions
Search for contacts using query conditions without creating a segment
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page_size | No | Number of results to return (max 100) | |
| page_token | No | Token for pagination | |
| query | Yes | Search query using segment conditions (e.g., 'email LIKE "@example.com"') |
Implementation Reference
- src/tools/contacts.ts:412-425 (handler)The handler function that implements the tool logic by constructing a request body with the query and optional pagination parameters, then sending a POST request to the SendGrid /marketing/contacts/search endpoint.handler: async ({ query, page_size, page_token }: { query: string; page_size?: number; page_token?: string }): Promise<ToolResult> => { const requestBody: any = { query: query }; if (page_size) requestBody.page_size = page_size; if (page_token) requestBody.page_token = page_token; const result = await makeRequest("https://api.sendgrid.com/v3/marketing/contacts/search", { method: "POST", body: JSON.stringify(requestBody), }); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; },
- src/tools/contacts.ts:406-410 (schema)Zod schema for input validation: required 'query' string for search conditions, optional 'page_size' (default 50), optional 'page_token' for pagination.inputSchema: { query: z.string().describe("Search query using segment conditions (e.g., 'email LIKE \"@example.com\"')"), page_size: z.number().optional().default(50).describe("Number of results to return (max 100)"), page_token: z.string().optional().describe("Token for pagination"), },
- src/index.ts:21-23 (registration)Registers all tools from allTools object with the MCP server by iterating and calling server.registerTool for each, including 'search_contacts'.for (const [name, tool] of Object.entries(allTools)) { server.registerTool(name, tool.config as any, tool.handler as any); }
- src/tools/index.ts:9-12 (registration)Combines contactTools (containing search_contacts) with other tool sets into allTools, which is then imported and registered in src/index.ts.export const allTools = { ...automationTools, ...campaignTools, ...contactTools,