First running version
This commit is contained in:
60
reference_impl/mcplets/media-pool/sns/index.ts
Normal file
60
reference_impl/mcplets/media-pool/sns/index.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* SNS MCPlet
|
||||
* pool: media-pool | mcpletType: action | visibility: [app] | auth: passkey workflow
|
||||
*/
|
||||
import { MCPletServer } from '../../mcplet-server.js';
|
||||
|
||||
const MOCK_SERVICE_URL = process.env.MOCK_SERVICE_URL ?? 'http://localhost:5100';
|
||||
|
||||
const server = new MCPletServer('sns-mcplet');
|
||||
|
||||
server.registerTool({
|
||||
name: 'post_sns',
|
||||
description: 'SNSプラットフォームに投稿します。承認済みキャンペーン告知の拡散に使用します。',
|
||||
inputSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
platform: {
|
||||
type: 'string',
|
||||
enum: ['twitter', 'instagram', 'line'],
|
||||
description: '投稿するSNSプラットフォーム',
|
||||
},
|
||||
content: {
|
||||
type: 'string',
|
||||
description: '投稿内容',
|
||||
},
|
||||
scheduleAt: {
|
||||
type: 'string',
|
||||
description: '予約投稿日時 (ISO 8601形式、任意)',
|
||||
},
|
||||
},
|
||||
required: ['platform', 'content'],
|
||||
},
|
||||
mcpletType: 'action',
|
||||
pool: 'media-pool',
|
||||
visibility: ['app'],
|
||||
auth: {
|
||||
required: 'passkey',
|
||||
enforcement: 'workflow',
|
||||
promptMessage: 'このキャンペーンのSNS投稿を承認してください',
|
||||
},
|
||||
handler: async (args, authPayload) => {
|
||||
if (authPayload) {
|
||||
console.error(`[sns-mcplet] Auth verified (challenge: ${authPayload['challenge'] ?? 'n/a'})`);
|
||||
}
|
||||
|
||||
const res = await fetch(`${MOCK_SERVICE_URL}/sns/post`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
platform: args['platform'],
|
||||
content: args['content'],
|
||||
scheduleAt: args['scheduleAt'],
|
||||
}),
|
||||
});
|
||||
if (!res.ok) throw new Error(`SNS service returned ${res.status}`);
|
||||
return res.json();
|
||||
},
|
||||
});
|
||||
|
||||
await server.listen();
|
||||
Reference in New Issue
Block a user