get_messages
Retrieve messages from your Sprout Social inbox, including both received and sent messages. Supports cursor-based pagination for efficient browsing.
Instructions
Retrieve messages from your Sprout Social inbox. Supports cursor-based pagination. Messages include those received by and sent from your profiles.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| profile_ids | Yes | Array of customer_profile_id values to filter messages by. | |
| created_time_start | No | Filter messages created after this ISO 8601 datetime. | |
| created_time_end | No | Filter messages created before this ISO 8601 datetime. | |
| fields | No | Fields to return. Refer to Sprout API docs for valid message fields. | |
| sort | No | Sort order, e.g. ['created_time:desc']. | |
| limit | No | Maximum number of messages to return per page. |
Implementation Reference
- src/index.ts:276-326 (registration)Registers the 'get_messages' tool on the McpServer with Zod schema for parameters (profile_ids, created_time_start, created_time_end, fields, sort, limit) and a handler that sends a POST request to the Sprout Social /messages API endpoint.
server.tool( "get_messages", "Retrieve messages from your Sprout Social inbox. Supports cursor-based pagination. " + "Messages include those received by and sent from your profiles.", { profile_ids: z .array(z.string()) .describe("Array of customer_profile_id values to filter messages by."), created_time_start: z .string() .optional() .describe("Filter messages created after this ISO 8601 datetime."), created_time_end: z .string() .optional() .describe("Filter messages created before this ISO 8601 datetime."), fields: z .array(z.string()) .optional() .describe( "Fields to return. Refer to Sprout API docs for valid message fields." ), sort: z .array(z.string()) .optional() .describe("Sort order, e.g. ['created_time:desc']."), limit: z .number() .optional() .describe("Maximum number of messages to return per page."), }, async ({ profile_ids, created_time_start, created_time_end, fields, sort, limit }) => { const filters: string[] = [ `customer_profile_id.eq(${profile_ids.join(", ")})`, ]; if (created_time_start && created_time_end) { filters.push( `created_time.in(${created_time_start}..${created_time_end})` ); } const body: Record<string, unknown> = { filters }; if (fields) body.fields = fields; if (sort) body.sort = sort; if (limit) body.limit = limit; const data = await sproutRequest("POST", "/messages", body); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } ); - src/index.ts:307-325 (handler)The async handler function for the 'get_messages' tool. It builds a filter array with customer_profile_id.eq and optionally created_time.in, constructs the request body with optional fields/sort/limit, calls sproutRequest('POST', '/messages', body), and returns the result as text content.
async ({ profile_ids, created_time_start, created_time_end, fields, sort, limit }) => { const filters: string[] = [ `customer_profile_id.eq(${profile_ids.join(", ")})`, ]; if (created_time_start && created_time_end) { filters.push( `created_time.in(${created_time_start}..${created_time_end})` ); } const body: Record<string, unknown> = { filters }; if (fields) body.fields = fields; if (sort) body.sort = sort; if (limit) body.limit = limit; const data = await sproutRequest("POST", "/messages", body); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } - src/index.ts:280-306 (schema)Zod schema definitions for the 'get_messages' tool parameters: profile_ids (required array of strings), created_time_start/created_time_end (optional ISO 8601 strings), fields (optional array of strings), sort (optional array of strings), limit (optional number).
{ profile_ids: z .array(z.string()) .describe("Array of customer_profile_id values to filter messages by."), created_time_start: z .string() .optional() .describe("Filter messages created after this ISO 8601 datetime."), created_time_end: z .string() .optional() .describe("Filter messages created before this ISO 8601 datetime."), fields: z .array(z.string()) .optional() .describe( "Fields to return. Refer to Sprout API docs for valid message fields." ), sort: z .array(z.string()) .optional() .describe("Sort order, e.g. ['created_time:desc']."), limit: z .number() .optional() .describe("Maximum number of messages to return per page."), },