Skip to content

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

feat: better mcp for submission

Nevo David61cc2d474df5
diff --git a/chatgpt-app-submission.json b/chatgpt-app-submission.json
new file mode 100644
index 000000000..f95c38ce6
--- /dev/null
+++ b/chatgpt-app-submission.json
@@ -0,0 +1,224 @@
+{
+ "$schema": "https://developers.openai.com/apps-sdk/schemas/chatgpt-app-submission.v1.json",
+ "schema_version": 1,
+ "app_info": {
+ "display_name": "Postiz",
+ "subtitle": "Schedule social posts",
+ "description": "Postiz helps users manage social media publishing from ChatGPT. Users can list connected channels and groups, inspect platform requirements, upload or generate media, create drafts or scheduled posts, update provider settings, and review upcoming posts.",
+ "category": "PRODUCTIVITY"
+ },
+ "tools": {
+ "integrationList": {
+ "annotations": {
+ "readOnlyHint": true,
+ "openWorldHint": false,
+ "destructiveHint": false
+ },
+ "justifications": {
+ "read_only_justification": "Only retrieves connected social channels for the organization and optional group filter.",
+ "open_world_justification": "Does not write to public internet state or third-party systems.",
+ "destructive_justification": "Does not delete, overwrite, revoke access, or send content."
+ }
+ },
+ "groupList": {
+ "annotations": {
+ "readOnlyHint": true,
+ "openWorldHint": false,
+ "destructiveHint": false
+ },
+ "justifications": {
+ "read_only_justification": "Only retrieves the organization's customer groups.",
+ "open_world_justification": "Does not write to public internet state or third-party systems.",
+ "destructive_justification": "Does not delete, overwrite, revoke access, or send content."
+ }
+ },
+ "integrationSchema": {
+ "annotations": {
+ "readOnlyHint": true,
+ "openWorldHint": false,
+ "destructiveHint": false
+ },
+ "justifications": {
+ "read_only_justification": "Only returns platform rules, limits, settings schemas, and helper metadata.",
+ "open_world_justification": "Does not write to public internet state or third-party systems.",
+ "destructive_justification": "Does not delete, overwrite, revoke access, or send content."
+ }
+ },
+ "triggerTool": {
+ "annotations": {
+ "readOnlyHint": false,
+ "openWorldHint": true,
+ "destructiveHint": true
+ },
+ "justifications": {
+ "read_only_justification": "Can refresh stored integration tokens and mark channels as needing reconnect while retrieving provider details.",
+ "open_world_justification": "Calls connected provider APIs and can update integration auth state for the user's channel.",
+ "destructive_justification": "Can overwrite stored integration tokens or mark a channel as needing reconnect if refresh fails."
+ }
+ },
+ "integrationSchedulePostTool": {
+ "annotations": {
+ "readOnlyHint": false,
+ "openWorldHint": true,
+ "destructiveHint": true
+ },
+ "justifications": {
+ "read_only_justification": "Creates draft, scheduled, or immediate social posts and starts publishing workflows.",
+ "open_world_justification": "Can publish or schedule content to external social media channels.",
+ "destructive_justification": "Can send public social posts immediately or later through connected platforms."
+ }
+ },
+ "postsListTool": {
+ "annotations": {
+ "readOnlyHint": true,
+ "openWorldHint": false,
+ "destructiveHint": false
+ },
+ "justifications": {
+ "read_only_justification": "Only retrieves posts scheduled, drafted, published, or errored in a requested date window.",
+ "open_world_justification": "Does not write to public internet state or third-party systems.",
+ "destructive_justification": "Does not delete, overwrite, revoke access, or send content."
+ }
+ },
+ "postSettingsTool": {
+ "annotations": {
+ "readOnlyHint": false,
+ "openWorldHint": false,
+ "destructiveHint": false
+ },
+ "justifications": {
+ "read_only_justification": "Merges new provider settings into an existing draft or scheduled post.",
+ "open_world_justification": "Only updates settings stored on an unpublished Postiz post and does not reach any external or publicly visible system.",
+ "destructive_justification": "Does not delete posts, change content, change publish dates, revoke access, or publish content immediately."
+ }
+ },
+ "generateVideoOptions": {
+ "annotations": {
+ "readOnlyHint": true,
+ "openWorldHint": false,
+ "destructiveHint": false
+ },
+ "justifications": {
+ "read_only_justification": "Only lists available video generation types, required parameters, and helper functions.",
+ "open_world_justification": "Does not write to public internet state or third-party systems.",
+ "destructive_justification": "Does not delete, overwrite, revoke access, or send content."
+ }
+ },
+ "videoFunctionTool": {
+ "annotations": {
+ "readOnlyHint": true,
+ "openWorldHint": false,
+ "destructiveHint": false
+ },
+ "justifications": {
+ "read_only_justification": "Only retrieves helper data needed for video generation, such as available voice IDs.",
+ "open_world_justification": "Does not create public content or change third-party systems.",
+ "destructive_justification": "Does not delete, overwrite, revoke access, or send content."
+ }
+ },
+ "generateVideoTool": {
+ "annotations": {
+ "readOnlyHint": false,
+ "openWorldHint": true,
+ "destructiveHint": false
+ },
+ "justifications": {
+ "read_only_justification": "Generates a video, consumes the user's video generation credit, uploads the result, and saves it to the media library.",
+ "open_world_justification": "Calls external generation and storage services to create media for the user's workspace.",
+ "destructive_justification": "Does not delete or overwrite existing media, revoke access, or publish content."
+ }
+ },
+ "generateImageTool": {
+ "annotations": {
+ "readOnlyHint": false,
+ "openWorldHint": true,
+ "destructiveHint": false
+ },
+ "justifications": {
+ "read_only_justification": "Generates an image, consumes the user's image generation credit, uploads the result, and saves it to the media library.",
+ "open_world_justification": "Calls external generation and storage services to create media for the user's workspace.",
+ "destructive_justification": "Does not delete or overwrite existing media, revoke access, or publish content."
+ }
+ },
+ "uploadFromUrlTool": {
+ "annotations": {
+ "readOnlyHint": false,
+ "openWorldHint": true,
+ "destructiveHint": false
+ },
+ "justifications": {
+ "read_only_justification": "Fetches a public media URL, uploads the file, and saves it to the media library.",
+ "open_world_justification": "Reads from a public URL and stores the resulting media through external storage.",
+ "destructive_justification": "Does not delete or overwrite existing media, revoke access, or publish content."
+ }
+ }
+ },
+ "test_cases": [
+ {
+ "description": "List the user's Postiz groups and connected social channels.",
+ "user_prompt": "Show me my Postiz customer groups, then list the connected channels for the Acme group.",
+ "file_attachment_urls": null,
+ "tools_triggered": "groupList, integrationList",
+ "expected_output": "Returns available groups and the connected channels for the selected group with enough detail to choose where to post.",
+ "expected_output_url": null
+ },
+ {
+ "description": "Upload a remote media URL and schedule a social post.",
+ "user_prompt": "Use this public image URL for a LinkedIn post tomorrow at 9:00 UTC: https://example.com/product.png. I confirm the copy and time.",
+ "file_attachment_urls": null,
+ "tools_triggered": "integrationList, integrationSchema, uploadFromUrlTool, integrationSchedulePostTool",
+ "expected_output": "Uploads the media, validates LinkedIn requirements, and creates a scheduled Postiz post or returns clear validation errors.",
+ "expected_output_url": null
+ },
+ {
+ "description": "Resolve provider-specific settings before scheduling.",
+ "user_prompt": "Schedule a Reddit post for next Monday and use the correct subreddit flair for /r/startups. I confirm the post details.",
+ "file_attachment_urls": null,
+ "tools_triggered": "integrationList, integrationSchema, triggerTool, integrationSchedulePostTool",
+ "expected_output": "Retrieves Reddit requirements and flair options, then creates the scheduled post with the selected settings or reports validation errors.",
+ "expected_output_url": null
+ },
+ {
+ "description": "Find an existing scheduled post and update provider settings.",
+ "user_prompt": "Find my scheduled posts for next week and change the selected post's provider setting to the correct Reddit flair.",
+ "file_attachment_urls": null,
+ "tools_triggered": "postsListTool, integrationSchema, triggerTool, postSettingsTool",
+ "expected_output": "Returns matching posts, resolves valid settings, and updates only the requested provider settings on a draft or scheduled post.",
+ "expected_output_url": null
+ },
+ {
+ "description": "Generate media assets for a future social post.",
+ "user_prompt": "Generate an image for a product launch post, then create a vertical image-text-slides video with a suitable voice.",
+ "file_attachment_urls": null,
+ "tools_triggered": "generateImageTool, generateVideoOptions, videoFunctionTool, generateVideoTool",
+ "expected_output": "Creates media assets in the Postiz media library and returns hosted media URLs or actionable generation errors.",
+ "expected_output_url": null
+ }
+ ],
+ "negative_test_cases": [
+ {
+ "description": "Do not trigger for unrelated calendar management.",
+ "user_prompt": "Move my team meeting from tomorrow to Friday afternoon.",
+ "file_attachment_urls": null,
+ "tools_triggered": null,
+ "expected_output": "The app should not be invoked because calendar event management is outside Postiz social scheduling workflows.",
+ "expected_output_url": null
+ },
+ {
+ "description": "Do not trigger for unsupported deletion requests.",
+ "user_prompt": "Delete the scheduled post I made yesterday from Postiz.",
+ "file_attachment_urls": null,
+ "tools_triggered": null,
+ "expected_output": "The app should explain that deletion is unsupported through these tools and direct the user to delete the post in Postiz.",
+ "expected_output_url": null
+ },
+ {
+ "description": "Do not trigger for private direct-message workflows.",
+ "user_prompt": "Send a private Slack DM to Sarah saying the campaign draft is ready.",
+ "file_attachment_urls": null,
+ "tools_triggered": null,
+ "expected_output": "The app should not be invoked because private direct messaging is outside the supported Postiz publishing workflows.",
+ "expected_output_url": null
+ }
+ ]
+}
diff --git a/libraries/nestjs-libraries/src/chat/start.mcp.ts b/libraries/nestjs-libraries/src/chat/start.mcp.ts
index e849cf883..fcc210bde 100644
--- a/libraries/nestjs-libraries/src/chat/start.mcp.ts
+++ b/libraries/nestjs-libraries/src/chat/start.mcp.ts
@@ -35,6 +35,19 @@ export const startMcp = async (app: INestApplication) => {
const agent = mastra.getAgent('postiz');
const tools = await agent.listTools();
+ // The Claude connector directory does not accept AI media generation tools,
+ // so the directory-facing endpoint hides them. Direct connections
+ // (/mcp, /mcp/:id, /sse/:id) and the ChatGPT app keep the full toolset.
+ const claudeHiddenTools = [
+ 'generateImageTool',
+ 'generateVideoTool',
+ 'generateVideoOptions',
+ 'videoFunctionTool',
+ ];
+ const claudeTools = Object.fromEntries(
+ Object.entries(tools).filter(([name]) => !claudeHiddenTools.includes(name))
+ ) as typeof tools;
+
const serverConfig = {
name: 'Postiz MCP',
version: '1.0.0',
@@ -44,6 +57,21 @@ export const startMcp = async (app: INestApplication) => {
const server = new MCPServer(serverConfig);
+ // The directory-facing servers don't register the agent - it would be
+ // exposed as an annotation-less catch-all ask_postiz tool, which the
+ // ChatGPT and Claude directory reviews reject
+ const oauthServer = new MCPServer({
+ name: 'Postiz MCP',
+ version: '1.0.0',
+ tools,
+ });
+
+ const claudeOauthServer = new MCPServer({
+ name: 'Postiz MCP',
+ version: '1.0.0',
+ tools: claudeTools,
+ });
+
const oauthResource = new URL('/mcp-oauth', process.env.NEXT_PUBLIC_BACKEND_URL!).toString();
const oauthMiddleware = createOAuthMiddleware({
oauth: {
@@ -60,6 +88,23 @@ export const startMcp = async (app: INestApplication) => {
mcpPath: '/mcp-oauth',
});
+ // Same authorization server as /mcp-oauth, only the protected resource differs
+ const claudeOauthResource = new URL('/mcp-oauth-claude', process.env.NEXT_PUBLIC_BACKEND_URL!).toString();
+ const claudeOauthMiddleware = createOAuthMiddleware({
+ oauth: {
+ resource: claudeOauthResource,
+ authorizationServers: [oauthResource],
+ validateToken: async (token: string) => {
+ const org = await resolveAuth(token);
+ if (!org) {
+ return { valid: false, error: 'invalid_token', errorDescription: 'Invalid API Key or OAuth token' };
+ }
+ return { valid: true, subject: token };
+ },
+ },
+ mcpPath: '/mcp-oauth-claude',
+ });
+
if (process.env.OPENAI_APP_CHALLANGE) {
app.use('/.well-known/openai-apps-challenge', (req: Request, res: Response) => {
res.setHeader('Content-Type', 'text/plain');
@@ -68,16 +113,17 @@ export const startMcp = async (app: INestApplication) => {
}
app.use('/.well-known/oauth-protected-resource', async (req: Request, res: Response, next: () => void) => {
- // Only the /mcp-oauth resource is OAuth-protected. Answering discovery on
- // any other path (including the root, which clients fall back to) makes
- // them demand OAuth for /mcp/:id too
- if (req.path !== '/mcp-oauth') {
+ // Only the /mcp-oauth and /mcp-oauth-claude resources are OAuth-protected.
+ // Answering discovery on any other path (including the root, which clients
+ // fall back to) makes them demand OAuth for /mcp/:id too
+ if (req.path !== '/mcp-oauth' && req.path !== '/mcp-oauth-claude') {
next();
return;
}
const url = new URL('/.well-known/oauth-protected-resource', process.env.NEXT_PUBLIC_BACKEND_URL);
- await oauthMiddleware(req, res, url);
+ const middleware = req.path === '/mcp-oauth-claude' ? claudeOauthMiddleware : oauthMiddleware;
+ await middleware(req, res, url);
});
app.use('/.well-known/oauth-authorization-server', async (req: Request, res: Response, next: () => void) => {
@@ -130,7 +176,41 @@ export const startMcp = async (app: INestApplication) => {
fixAcceptHeader(req);
await runWithContext({ requestId: token!, auth }, async () => {
- await server.startHTTP({
+ await oauthServer.startHTTP({
+ url: url,
+ httpPath: url.pathname,
+ options: {
+ serverless: true,
+ enableJsonResponse: true,
+ },
+ req,
+ res,
+ });
+ });
+ });
+
+ app.use('/mcp-oauth-claude', async (req: Request, res: Response, next: () => void) => {
+ // Skip if this is the /mcp/:id route
+ if (req.path !== '/' && req.path !== '') {
+ next();
+ return;
+ }
+
+ const url = new URL('/mcp-oauth-claude', process.env.NEXT_PUBLIC_BACKEND_URL);
+
+ const result = await claudeOauthMiddleware(req, res, url);
+ if (!result.proceed) return;
+
+ const token = result.tokenValidation?.subject;
+ const auth = await resolveAuth(token!);
+ if (!auth) {
+ res.status(401).json({ error: 'invalid_token', error_description: 'Could not resolve organization' });
+ return;
+ }
+
+ fixAcceptHeader(req);
+ await runWithContext({ requestId: token!, auth }, async () => {
+ await claudeOauthServer.startHTTP({
url: url,
httpPath: url.pathname,
options: {
diff --git a/libraries/nestjs-libraries/src/chat/tools/integration.schedule.post.ts b/libraries/nestjs-libraries/src/chat/tools/integration.schedule.post.ts
index 19433a7fa..39d11cbd7 100644
--- a/libraries/nestjs-libraries/src/chat/tools/integration.schedule.post.ts
+++ b/libraries/nestjs-libraries/src/chat/tools/integration.schedule.post.ts
@@ -42,24 +42,25 @@ export class IntegrationSchedulePostTool implements AgentToolInterface {
annotations: {
title: 'Schedule Social Media Post',
readOnlyHint: false,
- destructiveHint: false,
+ destructiveHint: true,
idempotentHint: false,
openWorldHint: true,
},
},
description: `
-This tool allows you to schedule a post to a social media platform, based on integrationSchema tool.
-So for example:
+Use this when the user wants to create a draft, scheduled, or immediate social media post on their connected channels, based on the integrationSchema tool.
+Examples of the input shape:
-If the user want to post a post to LinkedIn with one comment
+A single LinkedIn post with one comment
- socialPost array length will be one
- postsAndComments array length will be two (one for the post, one for the comment)
-If the user want to post 20 posts for facebook each in individual days without comments
+20 Facebook posts each on individual days without comments
- socialPost array length will be 20
- postsAndComments array length will be one
-If the tools return errors, you would need to rerun it with the right parameters, don't ask again, just run it
+Do not use this to update or delete existing posts.
+If validation fails, the result contains output.errors describing what to fix; the call can be retried with corrected parameters.
`,
inputSchema: z.object({
socialPost: z
@@ -173,28 +174,36 @@ If the tools return errors, you would need to rerun it with the right parameters
if (validation.emptyContent) {
return {
- errors: `${validation.name}: Your post should have at least one character or one image.`,
+ output: {
+ errors: `${validation.name}: Your post should have at least one character or one image.`,
+ },
};
}
if (platform.type !== 'draft') {
if (!validation.valid) {
return {
- errors: `${validation.name}: ${
- validation.settingsError || 'Please fix your settings'
- }, please fix it, and try integrationSchedulePostTool again.`,
+ output: {
+ errors: `${validation.name}: ${
+ validation.settingsError || 'Please fix your settings'
+ }, please fix it, and try integrationSchedulePostTool again.`,
+ },
};
}
if (validation.errors !== true) {
return {
- errors: `${validation.name}: ${validation.errors}, please fix it, and try integrationSchedulePostTool again.`,
+ output: {
+ errors: `${validation.name}: ${validation.errors}, please fix it, and try integrationSchedulePostTool again.`,
+ },
};
}
if (validation.tooLong) {
return {
- errors: `${validation.name}: The maximum characters is ${validation.maximumCharacters}, please fix it, and try integrationSchedulePostTool again.`,
+ output: {
+ errors: `${validation.name}: The maximum characters is ${validation.maximumCharacters}, please fix it, and try integrationSchedulePostTool again.`,
+ },
};
}
}
diff --git a/libraries/nestjs-libraries/src/chat/tools/integration.trigger.tool.ts b/libraries/nestjs-libraries/src/chat/tools/integration.trigger.tool.ts
index 0415f3b09..6ab93cba1 100644
--- a/libraries/nestjs-libraries/src/chat/tools/integration.trigger.tool.ts
+++ b/libraries/nestjs-libraries/src/chat/tools/integration.trigger.tool.ts
@@ -24,13 +24,14 @@ export class IntegrationTriggerTool implements AgentToolInterface {
run() {
return createTool({
id: 'triggerTool',
- description: `After using the integrationSchema, we sometimes miss details we can\'t ask from the user, like ids.
- Sometimes this tool requires to user prompt for some settings, like a word to search for. methodName is required [input:callable-tools]`,
+ description: `Use this to call a provider helper function (a methodName from the integrationSchema callable tools) that fetches provider-specific data needed for settings, like ids or search results.
+ Some helper functions require values provided by the user, like a word to search for. methodName is required [input:callable-tools].
+ If provider auth is expired, this tool may refresh the stored integration token; if refresh fails, it marks the channel as needing reconnect and notifies the organization.`,
mcp: {
annotations: {
title: 'Trigger Integration Tool',
- readOnlyHint: true,
- destructiveHint: false,
+ readOnlyHint: false,
+ destructiveHint: true,
idempotentHint: false,
openWorldHint: true,
},
@@ -50,11 +51,14 @@ export class IntegrationTriggerTool implements AgentToolInterface {
),
}),
outputSchema: z.object({
- output: z.array(z.record(z.string(), z.any())),
+ output: z.union([
+ z.array(z.record(z.string(), z.any())),
+ z.record(z.string(), z.any()),
+ z.string(),
+ ]),
}),
execute: async (inputData, context) => {
checkAuth(inputData, context);
- console.log('triggerTool', inputData);
const organizationId = JSON.parse(
(context?.requestContext as any)?.get('organization') as string
).id;
@@ -66,9 +70,9 @@ export class IntegrationTriggerTool implements AgentToolInterface {
);
if (!getIntegration) {
- return {
- output: 'Integration not found',
- };
+ throw new Error(
+ 'Integration not found, use integrationList to get a valid integration id'
+ );
}
const integrationProvider = socialIntegrationList.find(
@@ -76,9 +80,9 @@ export class IntegrationTriggerTool implements AgentToolInterface {
)!;
if (!integrationProvider) {
- return {
- output: 'Integration not found',
- };
+ throw new Error(
+ 'Integration provider not found, use integrationList to get a valid integration id'
+ );
}
const tools = this._integrationManager.getAllTools();
@@ -90,9 +94,12 @@ export class IntegrationTriggerTool implements AgentToolInterface {
// @ts-ignore
!integrationProvider[inputData.methodName]
) {
- return { output: 'tool not found' };
+ throw new Error(
+ `Method "${inputData.methodName}" not found for this integration, use integrationSchema to get the callable tools`
+ );
}
+ let refreshed = false;
while (true) {
try {
// @ts-ignore
@@ -111,7 +118,8 @@ export class IntegrationTriggerTool implements AgentToolInterface {
return { output: load };
} catch (err) {
- if (err instanceof RefreshToken) {
+ if (err instanceof RefreshToken && !refreshed) {
+ refreshed = true;
const data = await this._refreshIntegrationService.refresh(
getIntegration
);
@@ -121,10 +129,9 @@ export class IntegrationTriggerTool implements AgentToolInterface {
organizationId,
getIntegration
);
- return {
- output:
- 'We had to disconnect the channel as the token expired',
- };
+ throw new Error(
+ 'The channel was disconnected because its token expired, the user needs to reconnect it in Postiz'
+ );
}
const { accessToken } = data;
@@ -137,10 +144,22 @@ export class IntegrationTriggerTool implements AgentToolInterface {
}
continue;
- } else {
}
}
- return { output: 'Unexpected error' };
+
+ if (err instanceof RefreshToken) {
+ throw new Error(
+ 'The provider rejected the credentials even after refreshing the token, the user needs to reconnect the channel in Postiz'
+ );
+ }
+
+ throw new Error(
+ `Provider call failed: ${
+ err instanceof Error && err.message
+ ? err.message
+ : 'unexpected error'
+ }`
+ );
}
}
},
diff --git a/libraries/nestjs-libraries/src/chat/tools/post.settings.tool.ts b/libraries/nestjs-libraries/src/chat/tools/post.settings.tool.ts
index 679d025d7..e3812b220 100644
--- a/libraries/nestjs-libraries/src/chat/tools/post.settings.tool.ts
+++ b/libraries/nestjs-libraries/src/chat/tools/post.settings.tool.ts
@@ -19,7 +19,7 @@ export class PostSettingsTool implements AgentToolInterface {
readOnlyHint: false,
destructiveHint: false,
idempotentHint: false,
- openWorldHint: true,
+ openWorldHint: false,
},
},
description: `
@@ -28,7 +28,7 @@ Only the settings change - the content and the publish date stay exactly as they
Find the post first (list your posts) and pass its "id" here.
The settings are merged into the existing ones, so only pass the keys you want to change; anything you don't pass stays as it is.
This relies on the integrationSchema tool [input:settings] to know which keys exist for the platform.
-If the tool returns errors, rerun it with the right parameters, don't ask again, just run it.
+If validation fails, the result contains output.errors describing what to fix; the call can be retried with corrected parameters.
`,
inputSchema: z.object({
id: z