Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat(agent): list posts via a tool aligned with the List Posts API

Gilad Resisi80f747503db2
diff --git a/libraries/nestjs-libraries/src/chat/load.tools.service.ts b/libraries/nestjs-libraries/src/chat/load.tools.service.ts
index d252b52e5..5e2e7c8be 100644
--- a/libraries/nestjs-libraries/src/chat/load.tools.service.ts
+++ b/libraries/nestjs-libraries/src/chat/load.tools.service.ts
@@ -54,6 +54,7 @@ export class LoadToolsService {
You are an agent that helps manage and schedule social media posts for users, you can:
- Schedule posts into the future, or now, adding texts, images and videos
+ - List the posts scheduled between two dates (postsListTool)
- Generate pictures for posts
- Generate videos for posts
- Generate text for posts
@@ -76,6 +77,7 @@ export class LoadToolsService {
- In every message I will send you the list of needed social medias (id and platform), if you already have the information use it, if not, use the integrationSchema tool to get it.
- Make sure you always take the last information I give you about the socials, it might have changed.
- Before scheduling a post, always make sure you ask the user confirmation by providing all the details of the post (text, images, videos, date, time, social media platform, account).
+ - To find or inspect existing posts, use postsListTool with a UTC start and end date - it returns every post scheduled in that window. To cover "all my upcoming posts", pass a wide window starting now.
- Between tools, we will reference things like: [output:name] and [input:name] to set the information right.
- When outputting a date for the user, make sure it's human readable with time
- The content of the post, HTML, Each line must be wrapped in <p> here is the possible tags: h1, h2, h3, u, strong, li, ul, p (you can\'t have u and strong together), don't use a "code" box
diff --git a/libraries/nestjs-libraries/src/chat/tools/posts.list.tool.ts b/libraries/nestjs-libraries/src/chat/tools/posts.list.tool.ts
new file mode 100644
index 000000000..85049fccc
--- /dev/null
+++ b/libraries/nestjs-libraries/src/chat/tools/posts.list.tool.ts
@@ -0,0 +1,108 @@
+import { AgentToolInterface } from '@gitroom/nestjs-libraries/chat/agent.tool.interface';
+import { createTool } from '@mastra/core/tools';
+import { z } from 'zod';
+import { Injectable } from '@nestjs/common';
+import { PostsService } from '@gitroom/nestjs-libraries/database/prisma/posts/posts.service';
+import { checkAuth } from '@gitroom/nestjs-libraries/chat/auth.context';
+import dayjs from 'dayjs';
+import utc from 'dayjs/plugin/utc';
+
+dayjs.extend(utc);
+
+const parseSettings = (settings: string | null) => {
+ try {
+ return JSON.parse(settings || '{}');
+ } catch (err) {
+ return {};
+ }
+};
+
+@Injectable()
+export class PostsListTool implements AgentToolInterface {
+ constructor(private _postsService: PostsService) {}
+ name = 'postsListTool';
+
+ run() {
+ return createTool({
+ id: 'postsListTool',
+ mcp: {
+ annotations: {
+ title: 'List Posts',
+ readOnlyHint: true,
+ destructiveHint: false,
+ idempotentHint: true,
+ openWorldHint: false,
+ },
+ },
+ description: `
+List the organization's posts scheduled to be published between two dates (the same data as the "List Posts" API endpoint).
+Returns every post in the window whatever its state (scheduled, draft, published, errored).
+"startDate" and "endDate" are required (UTC) - to list all upcoming posts, pass a wide window (for example from now to a year ahead).
+Each item has an "id", its publish date, state, content, channel and current provider settings.
+`,
+ inputSchema: z.object({
+ startDate: z
+ .string()
+ .describe('Start of the window (UTC), for example 2026-07-20T00:00:00'),
+ endDate: z
+ .string()
+ .describe('End of the window (UTC), for example 2026-08-20T00:00:00'),
+ customer: z
+ .string()
+ .optional()
+ .describe('Optional customer (group) id to filter the channels by'),
+ }),
+ outputSchema: z.object({
+ output: z.object({
+ posts: z.array(
+ z.object({
+ id: z
+ .string()
+ .describe('The post id'),
+ publishDate: z.string().describe('UTC time'),
+ state: z.string().describe('QUEUE, DRAFT, PUBLISHED or ERROR'),
+ content: z.string(),
+ settings: z
+ .any()
+ .describe('The post current provider settings'),
+ group: z.string(),
+ integrationId: z.string(),
+ platform: z.string(),
+ integrationName: z.string(),
+ })
+ ),
+ }),
+ }),
+ execute: async (inputData, context) => {
+ checkAuth(inputData, context);
+ const organizationId = JSON.parse(
+ (context?.requestContext as any)?.get('organization') as string
+ ).id;
+
+ const posts = await this._postsService.getPosts(organizationId, {
+ startDate: inputData.startDate,
+ endDate: inputData.endDate,
+ customer: inputData.customer,
+ } as any);
+
+ return {
+ output: {
+ posts: (posts || []).map((p: any) => ({
+ id: p.id,
+ publishDate: dayjs(p.publishDate)
+ .utc()
+ .format('YYYY-MM-DDTHH:mm:ss'),
+ state: p.state,
+ content: p.content || '',
+ settings: parseSettings(p.settings),
+ group: p.group,
+ integrationId: p.integration?.id,
+ platform: p.integration?.providerIdentifier,
+ integrationName: p.integration?.name,
+ })),
+ },
+ };
+ },
+ });
+ }
+}
diff --git a/libraries/nestjs-libraries/src/chat/tools/tool.list.ts b/libraries/nestjs-libraries/src/chat/tools/tool.list.ts
index b188daee4..c95a5175b 100644
--- a/libraries/nestjs-libraries/src/chat/tools/tool.list.ts
+++ b/libraries/nestjs-libraries/src/chat/tools/tool.list.ts
@@ -8,6 +8,7 @@ import { GenerateImageTool } from '@gitroom/nestjs-libraries/chat/tools/generate
import { IntegrationListTool } from '@gitroom/nestjs-libraries/chat/tools/integration.list.tool';
import { GroupListTool } from '@gitroom/nestjs-libraries/chat/tools/group.list.tool';
import { UploadFromUrlTool } from '@gitroom/nestjs-libraries/chat/tools/upload.from.url.tool';
+import { PostsListTool } from '@gitroom/nestjs-libraries/chat/tools/posts.list.tool';
export const toolList = [
IntegrationListTool,
@@ -15,6 +16,7 @@ export const toolList = [
IntegrationValidationTool,
IntegrationTriggerTool,
IntegrationSchedulePostTool,
+ PostsListTool,
GenerateVideoOptionsTool,
VideoFunctionTool,
GenerateVideoTool,
diff --git a/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.ts b/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.ts
index 2a3b2b205..22b8347ff 100644
--- a/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.ts
+++ b/libraries/nestjs-libraries/src/database/prisma/posts/posts.repository.ts
@@ -181,6 +181,7 @@ export class PostsRepository {
intervalInDays: true,
group: true,
creationMethod: true,
+ settings: true,
tags: {
select: {
tag: true,