From 4474afde7f8e43244b5a7aa9954879ebfd08e013 Mon Sep 17 00:00:00 2001 From: Nevo David Date: Tue, 15 Apr 2025 11:46:42 +0700 Subject: [PATCH] feat: mcps --- apps/backend/src/mcp/main.mcp.ts | 45 +++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/apps/backend/src/mcp/main.mcp.ts b/apps/backend/src/mcp/main.mcp.ts index d6c0da23..385031d8 100644 --- a/apps/backend/src/mcp/main.mcp.ts +++ b/apps/backend/src/mcp/main.mcp.ts @@ -1,21 +1,28 @@ import { Injectable } from '@nestjs/common'; import { McpTool } from '@gitroom/nestjs-libraries/mcp/mcp.tool'; import { IntegrationService } from '@gitroom/nestjs-libraries/database/prisma/integrations/integration.service'; -import { string, array, enum as eenum, object } from 'zod'; +import { string, array, enum as eenum, object, boolean } from 'zod'; import { PostsService } from '@gitroom/nestjs-libraries/database/prisma/posts/posts.service'; import { makeId } from '@gitroom/nestjs-libraries/services/make.is'; import dayjs from 'dayjs'; +import { OpenaiService } from '@gitroom/nestjs-libraries/openai/openai.service'; @Injectable() export class MainMcp { constructor( private _integrationService: IntegrationService, - private _postsService: PostsService + private _postsService: PostsService, + private _openAiService: OpenaiService ) {} - @McpTool({ toolName: 'POSTIZ_CONFIGURATION_PRERUN' }) + @McpTool({ toolName: 'POSTIZ_GET_CONFIG_ID' }) async preRun() { - return [{type: 'text', text: `Today date is ${dayjs.utc().format()}`}]; + return [ + { + type: 'text', + text: `id: ${makeId(10)} Today date is ${dayjs.utc().format()}`, + }, + ]; } @McpTool({ toolName: 'POSTIZ_PROVIDERS_LIST' }) @@ -44,6 +51,8 @@ export class MainMcp { toolName: 'POSTIZ_SCHEDULE_POST', zod: { type: eenum(['draft', 'scheduled']), + configId: string(), + generatePictures: boolean(), date: string().describe('UTC TIME'), providerId: string().describe('Use POSTIZ_PROVIDERS_LIST to get the id'), posts: array(object({ text: string(), images: array(string()) })), @@ -53,9 +62,10 @@ export class MainMcp { organization: string, obj: { type: 'draft' | 'schedule'; + generatePictures: boolean; date: string; providerId: string; - posts: { text: string; images: string[] }[]; + posts: { text: string }[]; } ) { const create = await this._postsService.createPost(organization, { @@ -65,14 +75,23 @@ export class MainMcp { posts: [ { group: makeId(10), - value: obj.posts.map((post) => ({ - content: post.text, - id: makeId(10), - image: post.images.map((image) => ({ - id: image, - path: image, - })), - })), + value: await Promise.all( + obj.posts.map(async (post) => ({ + content: post.text, + id: makeId(10), + image: !obj.generatePictures + ? [] + : [ + { + id: makeId(10), + path: await this._openAiService.generateImage( + post.text, + true + ), + }, + ], + })) + ), // @ts-ignore settings: {}, integration: {