search_contacts
Search SendGrid contacts using query conditions to find specific recipients without creating segments, enabling targeted contact management.
Instructions
Search for contacts using query conditions without creating a segment
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query using segment conditions (e.g., 'email LIKE "@example.com"') | |
| page_size | No | Number of results to return (max 100) | |
| page_token | No | Token for pagination |
Implementation Reference
- src/tools/contacts.ts:412-425 (handler)The handler function that executes the search_contacts tool. It builds the request body from input parameters and sends a POST request to SendGrid's /marketing/contacts/search endpoint, returning the search results as JSON.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:403-411 (schema)The tool configuration including title, description, and Zod inputSchema defining the parameters for search_contacts: query (string), page_size (number optional default 50), page_token (string optional).config: { title: "Search Contacts", description: "Search for contacts using query conditions without creating a segment", 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)Registration of all tools via loop over allTools object, calling server.registerTool for each, including search_contacts by its name key.for (const [name, tool] of Object.entries(allTools)) { server.registerTool(name, tool.config as any, tool.handler as any); }
- src/tools/index.ts:9-17 (registration)Aggregation of all tool sets into allTools by spreading contactTools (containing search_contacts) with other tool modules.export const allTools = { ...automationTools, ...campaignTools, ...contactTools, ...mailTools, ...miscTools, ...statsTools, ...templateTools, };