I'm pretty addicted to the Last Of Us series. Sorry for the cover.
シリーズのカバーについて申し訳ありません。
😉MCPはどこにでもあり、良い理由で、アプリの進化の次のステップです。
Being able to use everything from a single chat without accessing any app. It feels native for Postiz to schedule all your social posts from the chat! So, I started to dig into the Postiz code and added to it!
Postiz
The MCP Repository Is a Bit Weird
Each MCP has a transport, which is the method the LLMs use to talk to our system.
すべてのMCPには輸送があります。
現時点で2つの主な方法があります: 基本的にコマンドラインであるStdio、およびSSE。現時点で2つの主な方法があります
I don't really understand why they chose SSE — it's basically a long request that never ends and streams events to the client.
彼らがなぜSSEを選んだのか、私は本当に理解していない――それは基本的に決して終わらない長いリクエストであり、イベントをクライアントにストリーミングします。
この方法の問題は、サーバーに情報を送信するには、別のメールリクエストを送信する必要があります(SSEは一方的なコミュニケーションであるため)、つまり、状態を保持する必要があります。
彼らの例では、彼らはアプリのメモリに状態を保持し、何を推測しますか? 多くの人がメモリの漏洩について文句を言います。
I would use WebSockets. They have a built-in sleep mode, and you don't have to maintain a state for it.
彼らには組み込まれた睡眠モードがあり、あなたはそれを維持する必要はありません。「hr」
Digging In
I digged into Anthropic typcript SDK and was not amazed. It feels clunky. 多くのものが「リソース」のような生産に使用されていない。 彼らがあなたに世界中ですべてを記憶に保つことを要求する方法は、起こるのを待っている災害です。
また、認証を実装し、ユーザーを文脈から引き出すことは難しいので、彼らの詳細を得ることができます。
import EventEmitter from 'events';
import { finalize, fromEvent, startWith } from 'rxjs';
@Injectable()
export class McpService {
static event = new EventEmitter();
constructor(
private _mainMcp: MainMcp
) {
}
async runServer(apiKey: string, organization: string) {
const server = McpSettings.load(organization, this._mainMcp).server();
const transport = new McpTransport(organization);
const observer = fromEvent(
McpService.event,
`organization-${organization}`
).pipe(
startWith({
type: 'endpoint',
data: process.env.NEXT_PUBLIC_BACKEND_URL + '/mcp/' + apiKey + '/messages',
}),
finalize(() => {
transport.close();
})
);
console.log('MCP transport started');
await server.connect(transport);
return observer;
}
async processPostBody(organization: string, body: object) {
const server = McpSettings.load(organization, this._mainMcp).server();
const message = JSONRPCMessageSchema.parse(body);
const transport = new McpTransport(organization);
await server.connect(transport);
transport.handlePostMessage(message);
return {};
}
}
デコレーション FTW ️
これは、あなたがNestJS/Laravel/SpringのようなOOPフレームワークの大ファンである場合のあなたのためにあります. I created a cool decorator to create tools like API "endpoints."
平成30年4月1日(日) 平成30年1月1日(日) 平成30年1月1日(日) 平成30年1月1日(日) 平成30年1月1日(日) 平成30年1月1日(日) 平成30年1月1日(日) 平成30年1月1日(日) 平成30年1月1日(日) 平成30年1月1日(日) 平成30年1月1日(日) 平成30年1月1日(日) 平成30年1月1日(日) 平成30年1月1日(日) 平成30年1月1日(日) 平成30年1月1日(日) 平成30年1月1日(日) 平成30年1月1日(日) @McpTool({ toolName: 'POSTIZ_GET_CONFIG_ID' })
async preRun() {
return [
{
type: 'text',
text: `id: ${makeId(10)} Today date is ${dayjs.utc().format()}`,
},
];
}
@McpTool({ toolName: 'POSTIZ_PROVIDERS_LIST' })
async listOfProviders(organization: string) {
const list = (
await this._integrationService.getIntegrationsList(organization)
).map((org) => ({
id: org.id,
name: org.name,
identifier: org.providerIdentifier,
picture: org.picture,
disabled: org.disabled,
profile: org.profile,
customer: org.customer
? {
id: org.customer.id,
name: org.customer.name,
}
: undefined,
}));
return [{ type: 'text', text: JSON.stringify(list) }];
}
@McpTool({
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()) })),
},
})
async schedulePost(
organization: string,
obj: {
type: 'draft' | 'schedule';
generatePictures: boolean;
date: string;
providerId: string;
posts: { text: string }[];
}
) {
const create = await this._postsService.createPost(organization, {
date: obj.date,
type: obj.type,
tags: [],
posts: [
{
group: makeId(10),
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: {
id: obj.providerId,
},
},
],
});
return [
{
type: 'text',
text: `Post created successfully, check it here: ${process.env.FRONTEND_URL}/p/${create[0].postId}`,
},
];
}
All the code can be found in Postiz here: https://github.com/gitroomhq/postiz-app/tree/main/libraries/nestjs-libraries/src/mcp
https://github.com/gitroomhq/postiz-app/tree/main/libraries/nestjs-libraries/src/mcp
And here: https://github.com/gitroomhq/postiz-app/tree/main/apps/backend/src/mcp
https://github.com/gitroomhq/postiz-app/tree/main/apps/backend/src/mcp「hr」Force the LLM to Do Stuff 🏻
それは私たちのものにアクセスする前に、LLMが異なることをするように強制する組み込まれたオプションを持っていることは良いでしょう。
I faced some interesting problems. Whenever I told Cursor to schedule a post for me, it tried to schedule it for 2024. これはモデルがトレーニングされた最後の時です。
I needed to pass some config details, so I created the POSTIZ_CONFIGURATION_PRERUN
tool. Hopefully, the LLM will always call it before doing stuff.
POSTIZ_CONFIGURATION_PRERUN
But it ignored it many times (typical), so I had to be creative. In my POSTIZ_SCHEDULE_POST
, I added a new property called configId
and changed the config tool name to POSTIZ_GET_CONFIG_ID.
The output of the config is:id: ${makeId(10)} Today date is ${day.jsutc().format()}
POSTIZ_SCHEDULE_POST
configId
POSTIZ_GET_CONFIG_ID.
id: ${makeId(10)} Today date is ${dayjs.utc().format()}
それはLLMが常にそれを前に呼ぶことを強要し、日付が定められました! :)
それは今からUTCの日付を送信することを知っていたので、私にとってはさらに良いことでした。「hr」
使用例
I think it works best when it is combined with multiple sets of tools, for example:
- Connect it to Cursor and ask it to schedule a post about your work today.
- Connect it to Notion and ask to schedule all the team's latest work on social media - check out Composio MCPs.
- Connect it to any SaaS that has CopilotKit and schedule posts based on the app.
Postiz MCP
Postiz is the most robust open-source social media scheduling tool - and now the only scheduler that offers MCP (natively, not with Zapier or something like that)
Postiz
新しいMCPを使用すると、Cursor/Windsurf および Anthropic クライアントからすべての投稿をスケジュールできます。
Everything is 100% free, of course. :)
If you like it, please don't forget to star us ⭐️https://github.com/gitroomhq/postiz-app