@yoonion/mimi-seed-mcp 0.3.24 → 0.3.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/facebook/api.d.ts +16 -0
- package/dist/facebook/api.js +98 -0
- package/dist/facebook/config.d.ts +9 -0
- package/dist/facebook/config.js +31 -0
- package/dist/index.js +2 -0
- package/dist/registers/facebook.d.ts +2 -0
- package/dist/registers/facebook.js +195 -0
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FacebookConfig } from './config.js';
|
|
2
|
+
export interface FacebookPage {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
category?: string;
|
|
6
|
+
followers_count?: number;
|
|
7
|
+
fan_count?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface PostResult {
|
|
10
|
+
id: string;
|
|
11
|
+
permalink?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function getPage(cfg: FacebookConfig): Promise<FacebookPage>;
|
|
14
|
+
export declare function postPhoto(cfg: FacebookConfig, imageUrl: string, caption: string): Promise<PostResult>;
|
|
15
|
+
export declare function postMultiPhoto(cfg: FacebookConfig, imageUrls: string[], caption: string): Promise<PostResult>;
|
|
16
|
+
export declare function listAccessiblePages(userAccessToken: string): Promise<FacebookPage[]>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
const BASE = 'https://graph.facebook.com/v21.0';
|
|
2
|
+
async function fbPost(pageAccessToken, endpoint, params) {
|
|
3
|
+
const body = new URLSearchParams({ ...params, access_token: pageAccessToken });
|
|
4
|
+
const res = await fetch(`${BASE}${endpoint}`, {
|
|
5
|
+
method: 'POST',
|
|
6
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
7
|
+
body: body.toString(),
|
|
8
|
+
});
|
|
9
|
+
const text = await res.text();
|
|
10
|
+
let json;
|
|
11
|
+
try {
|
|
12
|
+
json = JSON.parse(text);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
throw new Error(`HTTP ${res.status}: ${text}`);
|
|
16
|
+
}
|
|
17
|
+
if (json.error) {
|
|
18
|
+
const err = json.error;
|
|
19
|
+
throw new Error(`${err.message} (code ${err.code})`);
|
|
20
|
+
}
|
|
21
|
+
return json;
|
|
22
|
+
}
|
|
23
|
+
async function fbGet(pageAccessToken, endpoint, params = {}) {
|
|
24
|
+
const qs = new URLSearchParams({ ...params, access_token: pageAccessToken });
|
|
25
|
+
const res = await fetch(`${BASE}${endpoint}?${qs}`);
|
|
26
|
+
const json = await res.json();
|
|
27
|
+
if (json.error) {
|
|
28
|
+
const err = json.error;
|
|
29
|
+
throw new Error(`${err.message} (code ${err.code})`);
|
|
30
|
+
}
|
|
31
|
+
return json;
|
|
32
|
+
}
|
|
33
|
+
export async function getPage(cfg) {
|
|
34
|
+
const data = await fbGet(cfg.pageAccessToken, `/${cfg.pageId}`, {
|
|
35
|
+
fields: 'id,name,category,followers_count,fan_count',
|
|
36
|
+
});
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
// Step 1: upload photo as unpublished, returns photo ID
|
|
40
|
+
async function uploadUnpublishedPhoto(cfg, imageUrl) {
|
|
41
|
+
const result = await fbPost(cfg.pageAccessToken, `/${cfg.pageId}/photos`, {
|
|
42
|
+
url: imageUrl,
|
|
43
|
+
published: 'false',
|
|
44
|
+
});
|
|
45
|
+
return result.id;
|
|
46
|
+
}
|
|
47
|
+
export async function postPhoto(cfg, imageUrl, caption) {
|
|
48
|
+
const result = await fbPost(cfg.pageAccessToken, `/${cfg.pageId}/photos`, {
|
|
49
|
+
url: imageUrl,
|
|
50
|
+
message: caption,
|
|
51
|
+
published: 'true',
|
|
52
|
+
});
|
|
53
|
+
const postId = result.post_id ?? result.id;
|
|
54
|
+
let permalink;
|
|
55
|
+
try {
|
|
56
|
+
const info = await fbGet(cfg.pageAccessToken, `/${postId}`, { fields: 'permalink_url' });
|
|
57
|
+
permalink = info.permalink_url;
|
|
58
|
+
}
|
|
59
|
+
catch { /* best-effort */ }
|
|
60
|
+
return { id: postId, permalink };
|
|
61
|
+
}
|
|
62
|
+
export async function postMultiPhoto(cfg, imageUrls, caption) {
|
|
63
|
+
if (imageUrls.length < 2 || imageUrls.length > 10) {
|
|
64
|
+
throw new Error('이미지는 2~10장이어야 합니다.');
|
|
65
|
+
}
|
|
66
|
+
// Step 1: upload each as unpublished photo
|
|
67
|
+
const photoIds = [];
|
|
68
|
+
for (const url of imageUrls) {
|
|
69
|
+
const id = await uploadUnpublishedPhoto(cfg, url);
|
|
70
|
+
photoIds.push(id);
|
|
71
|
+
}
|
|
72
|
+
// Step 2: create feed post with all photos attached
|
|
73
|
+
const attachedMedia = photoIds.map(id => JSON.stringify({ media_fbid: id }));
|
|
74
|
+
const result = await fbPost(cfg.pageAccessToken, `/${cfg.pageId}/feed`, {
|
|
75
|
+
message: caption,
|
|
76
|
+
attached_media: `[${attachedMedia.join(',')}]`,
|
|
77
|
+
});
|
|
78
|
+
const postId = result.id;
|
|
79
|
+
let permalink;
|
|
80
|
+
try {
|
|
81
|
+
const info = await fbGet(cfg.pageAccessToken, `/${postId}`, { fields: 'permalink_url' });
|
|
82
|
+
permalink = info.permalink_url;
|
|
83
|
+
}
|
|
84
|
+
catch { /* best-effort */ }
|
|
85
|
+
return { id: postId, permalink };
|
|
86
|
+
}
|
|
87
|
+
// Fetch all pages accessible with a User Access Token
|
|
88
|
+
export async function listAccessiblePages(userAccessToken) {
|
|
89
|
+
const qs = new URLSearchParams({
|
|
90
|
+
fields: 'id,name,category',
|
|
91
|
+
access_token: userAccessToken,
|
|
92
|
+
});
|
|
93
|
+
const res = await fetch(`${BASE}/me/accounts?${qs}`);
|
|
94
|
+
const json = await res.json();
|
|
95
|
+
if (json.error)
|
|
96
|
+
throw new Error(`${json.error.message} (code ${json.error.code})`);
|
|
97
|
+
return json.data ?? [];
|
|
98
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface FacebookConfig {
|
|
2
|
+
pageAccessToken: string;
|
|
3
|
+
pageId: string;
|
|
4
|
+
pageName?: string;
|
|
5
|
+
expiresAt?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function loadFacebookConfig(): FacebookConfig | null;
|
|
8
|
+
export declare function saveFacebookConfig(cfg: FacebookConfig): void;
|
|
9
|
+
export declare function requireFacebookConfig(): FacebookConfig;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
const CONFIG_PATH = path.join(os.homedir(), '.mimi-seed', 'facebook.json');
|
|
5
|
+
export function loadFacebookConfig() {
|
|
6
|
+
try {
|
|
7
|
+
return JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf-8'));
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export function saveFacebookConfig(cfg) {
|
|
14
|
+
const dir = path.dirname(CONFIG_PATH);
|
|
15
|
+
if (!fs.existsSync(dir)) {
|
|
16
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
17
|
+
}
|
|
18
|
+
fs.writeFileSync(CONFIG_PATH, JSON.stringify(cfg, null, 2));
|
|
19
|
+
if (process.platform !== 'win32') {
|
|
20
|
+
fs.chmodSync(CONFIG_PATH, 0o600);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function requireFacebookConfig() {
|
|
24
|
+
const cfg = loadFacebookConfig();
|
|
25
|
+
if (!cfg) {
|
|
26
|
+
throw new Error('Facebook 설정이 없습니다.\n' +
|
|
27
|
+
'facebook_save_config 도구로 먼저 설정해주세요.\n' +
|
|
28
|
+
'예: facebook_save_config(pageAccessToken="EAA...", pageId="...")');
|
|
29
|
+
}
|
|
30
|
+
return cfg;
|
|
31
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import { registerBigqueryTools } from './registers/bigquery.js';
|
|
|
12
12
|
import { registerAuthTools } from './registers/auth.js';
|
|
13
13
|
import { registerCiTools } from './registers/ci.js';
|
|
14
14
|
import { registerInstagramTools } from './registers/instagram.js';
|
|
15
|
+
import { registerFacebookTools } from './registers/facebook.js';
|
|
15
16
|
import { registerPrompts } from './prompts.js';
|
|
16
17
|
import { registerResources } from './resources.js';
|
|
17
18
|
const server = new McpServer({
|
|
@@ -29,6 +30,7 @@ registerBigqueryTools(server);
|
|
|
29
30
|
registerAuthTools(server);
|
|
30
31
|
registerCiTools(server);
|
|
31
32
|
registerInstagramTools(server);
|
|
33
|
+
registerFacebookTools(server);
|
|
32
34
|
registerPrompts(server);
|
|
33
35
|
registerResources(server);
|
|
34
36
|
// `npx -y @yoonion/mimi-seed-mcp <subcommand>` 처리.
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { loadFacebookConfig, requireFacebookConfig, saveFacebookConfig } from '../facebook/config.js';
|
|
3
|
+
import * as api from '../facebook/api.js';
|
|
4
|
+
export function registerFacebookTools(server) {
|
|
5
|
+
server.tool('facebook_save_config', [
|
|
6
|
+
'Facebook 페이지 액세스 토큰을 ~/.mimi-seed/facebook.json (mode 0600)에 저장합니다.',
|
|
7
|
+
'pageAccessToken: Graph API Explorer 또는 /me/accounts로 발급한 Page Access Token (EAA...).',
|
|
8
|
+
'pageId 미입력 시 토큰으로 자동 조회 (/me → id 필드).',
|
|
9
|
+
'저장 직후 페이지 정보를 조회해 토큰 유효성도 자동 검증.',
|
|
10
|
+
].join(' '), {
|
|
11
|
+
pageAccessToken: z.string().describe('Facebook Page Access Token (EAA..., long-lived 권장)'),
|
|
12
|
+
pageId: z.string().optional().describe('Facebook Page ID (생략 시 토큰에서 자동 조회)'),
|
|
13
|
+
}, async ({ pageAccessToken, pageId }) => {
|
|
14
|
+
// Resolve pageId
|
|
15
|
+
let resolvedPageId = pageId;
|
|
16
|
+
if (!resolvedPageId) {
|
|
17
|
+
try {
|
|
18
|
+
const me = await api.listAccessiblePages(pageAccessToken);
|
|
19
|
+
if (me.length === 0) {
|
|
20
|
+
// Try /me directly (already a Page Access Token)
|
|
21
|
+
const res = await fetch(`https://graph.facebook.com/v21.0/me?fields=id,name&access_token=${pageAccessToken}`);
|
|
22
|
+
const data = await res.json();
|
|
23
|
+
if (data.error)
|
|
24
|
+
throw new Error(`${data.error.message} (code ${data.error.code})`);
|
|
25
|
+
resolvedPageId = data.id;
|
|
26
|
+
}
|
|
27
|
+
else if (me.length === 1) {
|
|
28
|
+
resolvedPageId = me[0].id;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const list = me.map(p => ` • ${p.name} (${p.id})`).join('\n');
|
|
32
|
+
return {
|
|
33
|
+
content: [{
|
|
34
|
+
type: 'text',
|
|
35
|
+
text: [
|
|
36
|
+
'여러 페이지에 접근 가능합니다. pageId를 명시해주세요:',
|
|
37
|
+
list,
|
|
38
|
+
].join('\n'),
|
|
39
|
+
}],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
return {
|
|
45
|
+
content: [{
|
|
46
|
+
type: 'text',
|
|
47
|
+
text: `❌ pageId 자동 조회 실패: ${err.message}`,
|
|
48
|
+
}],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
const cfg = { pageAccessToken, pageId: resolvedPageId };
|
|
54
|
+
const page = await api.getPage(cfg);
|
|
55
|
+
saveFacebookConfig({
|
|
56
|
+
pageAccessToken,
|
|
57
|
+
pageId: resolvedPageId,
|
|
58
|
+
pageName: page.name,
|
|
59
|
+
expiresAt: new Date(Date.now() + 60 * 24 * 60 * 60 * 1000).toISOString(),
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
content: [{
|
|
63
|
+
type: 'text',
|
|
64
|
+
text: [
|
|
65
|
+
`✅ Facebook 페이지 연결 완료`,
|
|
66
|
+
` 페이지: ${page.name}`,
|
|
67
|
+
` ID: ${page.id}`,
|
|
68
|
+
page.category ? ` 카테고리: ${page.category}` : '',
|
|
69
|
+
page.followers_count !== undefined ? ` 팔로워: ${page.followers_count.toLocaleString()}` : '',
|
|
70
|
+
page.fan_count !== undefined ? ` 좋아요: ${page.fan_count.toLocaleString()}` : '',
|
|
71
|
+
].filter(Boolean).join('\n'),
|
|
72
|
+
}],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
return {
|
|
77
|
+
content: [{
|
|
78
|
+
type: 'text',
|
|
79
|
+
text: [
|
|
80
|
+
`❌ 토큰 검증 실패`,
|
|
81
|
+
` ${err.message}`,
|
|
82
|
+
``,
|
|
83
|
+
`Page Access Token을 다시 확인하거나 facebook_list_pages로 페이지 목록을 조회하세요.`,
|
|
84
|
+
].join('\n'),
|
|
85
|
+
}],
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
server.tool('facebook_list_pages', 'User Access Token으로 접근 가능한 Facebook 페이지 목록을 조회합니다. 페이지별 Page Access Token도 함께 반환.', {
|
|
90
|
+
userAccessToken: z.string().describe('Facebook User Access Token (EAA...)'),
|
|
91
|
+
}, async ({ userAccessToken }) => {
|
|
92
|
+
const pages = await api.listAccessiblePages(userAccessToken);
|
|
93
|
+
if (pages.length === 0) {
|
|
94
|
+
return {
|
|
95
|
+
content: [{
|
|
96
|
+
type: 'text',
|
|
97
|
+
text: '접근 가능한 페이지가 없습니다. pages_show_list 권한이 있는 토큰인지 확인하세요.',
|
|
98
|
+
}],
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
content: [{
|
|
103
|
+
type: 'text',
|
|
104
|
+
text: [
|
|
105
|
+
`접근 가능한 페이지 ${pages.length}개:`,
|
|
106
|
+
...pages.map(p => ` • ${p.name} (ID: ${p.id})${p.category ? ` — ${p.category}` : ''}`),
|
|
107
|
+
].join('\n'),
|
|
108
|
+
}],
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
server.tool('facebook_get_page', 'Facebook 페이지 정보 조회 + 저장된 토큰 유효성 검증.', {}, async () => {
|
|
112
|
+
const cfg = requireFacebookConfig();
|
|
113
|
+
const page = await api.getPage(cfg);
|
|
114
|
+
const remainingDays = cfg.expiresAt
|
|
115
|
+
? Math.round((new Date(cfg.expiresAt).getTime() - Date.now()) / (24 * 60 * 60 * 1000))
|
|
116
|
+
: null;
|
|
117
|
+
return {
|
|
118
|
+
content: [{
|
|
119
|
+
type: 'text',
|
|
120
|
+
text: [
|
|
121
|
+
`${page.name} (ID: ${page.id})`,
|
|
122
|
+
page.category ? ` 카테고리: ${page.category}` : '',
|
|
123
|
+
page.followers_count !== undefined ? ` 팔로워: ${page.followers_count.toLocaleString()}` : '',
|
|
124
|
+
page.fan_count !== undefined ? ` 좋아요: ${page.fan_count.toLocaleString()}` : '',
|
|
125
|
+
remainingDays !== null
|
|
126
|
+
? remainingDays > 7
|
|
127
|
+
? ` 토큰: ${remainingDays}일 남음`
|
|
128
|
+
: remainingDays > 0
|
|
129
|
+
? ` ⚠️ 토큰 ${remainingDays}일 남음 — 갱신 필요`
|
|
130
|
+
: ` ❌ 토큰 만료 — facebook_save_config로 재저장`
|
|
131
|
+
: '',
|
|
132
|
+
].filter(Boolean).join('\n'),
|
|
133
|
+
}],
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
server.tool('facebook_post_photo', [
|
|
137
|
+
'단일 이미지를 Facebook 페이지에 게시합니다.',
|
|
138
|
+
'imageUrl은 public URL이어야 합니다.',
|
|
139
|
+
].join(' '), {
|
|
140
|
+
imageUrl: z.string().url().describe('이미지의 public URL (HTTPS 권장)'),
|
|
141
|
+
caption: z.string().describe('게시글 본문'),
|
|
142
|
+
}, async ({ imageUrl, caption }) => {
|
|
143
|
+
const cfg = requireFacebookConfig();
|
|
144
|
+
const result = await api.postPhoto(cfg, imageUrl, caption);
|
|
145
|
+
return {
|
|
146
|
+
content: [{
|
|
147
|
+
type: 'text',
|
|
148
|
+
text: [
|
|
149
|
+
`✅ 게시 완료`,
|
|
150
|
+
` post_id: ${result.id}`,
|
|
151
|
+
result.permalink ? ` URL: ${result.permalink}` : '',
|
|
152
|
+
].filter(Boolean).join('\n'),
|
|
153
|
+
}],
|
|
154
|
+
};
|
|
155
|
+
});
|
|
156
|
+
server.tool('facebook_post_multi_photo', [
|
|
157
|
+
'여러 이미지를 하나의 게시물로 Facebook 페이지에 게시합니다. 2~10장.',
|
|
158
|
+
'모든 이미지는 public URL이어야 합니다.',
|
|
159
|
+
'각 이미지를 unpublished photo로 업로드한 뒤 하나의 feed 게시물로 묶습니다.',
|
|
160
|
+
].join(' '), {
|
|
161
|
+
imageUrls: z.array(z.string().url()).min(2).max(10).describe('이미지 URL 배열 (2~10장)'),
|
|
162
|
+
caption: z.string().describe('게시글 본문'),
|
|
163
|
+
}, async ({ imageUrls, caption }) => {
|
|
164
|
+
const cfg = requireFacebookConfig();
|
|
165
|
+
const result = await api.postMultiPhoto(cfg, imageUrls, caption);
|
|
166
|
+
return {
|
|
167
|
+
content: [{
|
|
168
|
+
type: 'text',
|
|
169
|
+
text: [
|
|
170
|
+
`✅ ${imageUrls.length}장 게시 완료`,
|
|
171
|
+
` post_id: ${result.id}`,
|
|
172
|
+
result.permalink ? ` URL: ${result.permalink}` : '',
|
|
173
|
+
].filter(Boolean).join('\n'),
|
|
174
|
+
}],
|
|
175
|
+
};
|
|
176
|
+
});
|
|
177
|
+
// Config load helper
|
|
178
|
+
server.tool('facebook_current_config', '현재 저장된 Facebook 페이지 설정을 확인합니다.', {}, async () => {
|
|
179
|
+
const cfg = loadFacebookConfig();
|
|
180
|
+
if (!cfg) {
|
|
181
|
+
return {
|
|
182
|
+
content: [{ type: 'text', text: '저장된 Facebook 설정 없음. facebook_save_config로 등록하세요.' }],
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
content: [{
|
|
187
|
+
type: 'text',
|
|
188
|
+
text: [
|
|
189
|
+
`페이지: ${cfg.pageName ?? '(미확인)'} (${cfg.pageId})`,
|
|
190
|
+
cfg.expiresAt ? `토큰 만료(추정): ${cfg.expiresAt.slice(0, 10)}` : '',
|
|
191
|
+
].filter(Boolean).join('\n'),
|
|
192
|
+
}],
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
}
|
package/package.json
CHANGED