get_listening_topic_messages
Retrieve messages from a specific listening topic using its ID. Filter, sort, and paginate results to find relevant social media conversations.
Instructions
Get messages found within a specific listening topic. Use get_topics first to discover available topic IDs.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| topic_id | Yes | The listening topic ID. | |
| filters | No | Filter expressions for the messages query. | |
| fields | No | Fields to return for each message. | |
| sort | No | Sort order for results. | |
| limit | No | Maximum messages per page. | |
| page | No | Page number. |
Implementation Reference
- src/index.ts:385-399 (handler)The async handler function that executes the tool logic. It builds a request body from optional parameters (filters, fields, sort, limit, page) and calls sproutRequest to POST to /listening/topics/{topic_id}/messages.
async ({ topic_id, filters, fields, sort, limit, page }) => { const body: Record<string, unknown> = {}; if (filters) body.filters = filters; if (fields) body.fields = fields; if (sort) body.sort = sort; if (limit) body.limit = limit; if (page) body.page = page; const data = await sproutRequest( "POST", `/listening/topics/${topic_id}/messages`, body ); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } - src/index.ts:368-384 (schema)Zod schema defining the input parameters for the tool: topic_id (required string), filters (optional array of strings), fields (optional array of strings), sort (optional array of strings), limit (optional number), page (optional number).
{ topic_id: z.string().describe("The listening topic ID."), filters: z .array(z.string()) .optional() .describe("Filter expressions for the messages query."), fields: z .array(z.string()) .optional() .describe("Fields to return for each message."), sort: z .array(z.string()) .optional() .describe("Sort order for results."), limit: z.number().optional().describe("Maximum messages per page."), page: z.number().optional().describe("Page number."), }, - src/index.ts:364-400 (registration)Registration of the tool on the McpServer instance via server.tool() with the name 'get_listening_topic_messages' and a description.
server.tool( "get_listening_topic_messages", "Get messages found within a specific listening topic. " + "Use get_topics first to discover available topic IDs.", { topic_id: z.string().describe("The listening topic ID."), filters: z .array(z.string()) .optional() .describe("Filter expressions for the messages query."), fields: z .array(z.string()) .optional() .describe("Fields to return for each message."), sort: z .array(z.string()) .optional() .describe("Sort order for results."), limit: z.number().optional().describe("Maximum messages per page."), page: z.number().optional().describe("Page number."), }, async ({ topic_id, filters, fields, sort, limit, page }) => { const body: Record<string, unknown> = {}; if (filters) body.filters = filters; if (fields) body.fields = fields; if (sort) body.sort = sort; if (limit) body.limit = limit; if (page) body.page = page; const data = await sproutRequest( "POST", `/listening/topics/${topic_id}/messages`, body ); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } );