postproxy-mcp 0.1.0
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/LICENSE +21 -0
- package/README.md +635 -0
- package/dist/api/client.d.ts +71 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +432 -0
- package/dist/api/client.js.map +1 -0
- package/dist/auth/credentials.d.ts +19 -0
- package/dist/auth/credentials.d.ts.map +1 -0
- package/dist/auth/credentials.js +40 -0
- package/dist/auth/credentials.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +162 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +220 -0
- package/dist/server.js.map +1 -0
- package/dist/setup-cli.d.ts +6 -0
- package/dist/setup-cli.d.ts.map +1 -0
- package/dist/setup-cli.js +10 -0
- package/dist/setup-cli.js.map +1 -0
- package/dist/setup.d.ts +8 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +143 -0
- package/dist/setup.js.map +1 -0
- package/dist/tools/accounts.d.ts +11 -0
- package/dist/tools/accounts.d.ts.map +1 -0
- package/dist/tools/accounts.js +53 -0
- package/dist/tools/accounts.js.map +1 -0
- package/dist/tools/auth.d.ts +11 -0
- package/dist/tools/auth.d.ts.map +1 -0
- package/dist/tools/auth.js +35 -0
- package/dist/tools/auth.js.map +1 -0
- package/dist/tools/history.d.ts +13 -0
- package/dist/tools/history.d.ts.map +1 -0
- package/dist/tools/history.js +79 -0
- package/dist/tools/history.js.map +1 -0
- package/dist/tools/post.d.ts +44 -0
- package/dist/tools/post.d.ts.map +1 -0
- package/dist/tools/post.js +251 -0
- package/dist/tools/post.js.map +1 -0
- package/dist/tools/profiles.d.ts +11 -0
- package/dist/tools/profiles.d.ts.map +1 -0
- package/dist/tools/profiles.js +52 -0
- package/dist/tools/profiles.js.map +1 -0
- package/dist/types/index.d.ts +147 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/errors.d.ts +21 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +33 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/idempotency.d.ts +8 -0
- package/dist/utils/idempotency.d.ts.map +1 -0
- package/dist/utils/idempotency.js +23 -0
- package/dist/utils/idempotency.js.map +1 -0
- package/dist/utils/logger.d.ts +20 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +68 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/validation.d.ts +555 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +145 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +39 -0
- package/src/api/client.ts +497 -0
- package/src/auth/credentials.ts +43 -0
- package/src/index.ts +57 -0
- package/src/server.ts +235 -0
- package/src/setup-cli.ts +11 -0
- package/src/setup.ts +187 -0
- package/src/tools/auth.ts +45 -0
- package/src/tools/history.ts +89 -0
- package/src/tools/post.ts +338 -0
- package/src/tools/profiles.ts +69 -0
- package/src/types/index.ts +161 -0
- package/src/utils/errors.ts +38 -0
- package/src/utils/idempotency.ts +31 -0
- package/src/utils/logger.ts +75 -0
- package/src/utils/validation.ts +171 -0
- package/tsconfig.json +19 -0
- package/worker/index.ts +901 -0
- package/wrangler.toml +11 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostProxy API HTTP client
|
|
3
|
+
*/
|
|
4
|
+
import type { ProfileGroup, Profile, CreatePostParams, CreatePostResponse, PostDetails, Post } from "../types/index.js";
|
|
5
|
+
export declare class PostProxyClient {
|
|
6
|
+
private apiKey;
|
|
7
|
+
private baseUrl;
|
|
8
|
+
constructor(apiKey: string, baseUrl: string);
|
|
9
|
+
/**
|
|
10
|
+
* Extract array from API response
|
|
11
|
+
* API returns either:
|
|
12
|
+
* - Direct array: [...]
|
|
13
|
+
* - Object with data field: {"data": [...]}
|
|
14
|
+
* - Paginated response: {"total": N, "data": [...]}
|
|
15
|
+
*/
|
|
16
|
+
private extractArray;
|
|
17
|
+
/**
|
|
18
|
+
* Expand ~ to home directory in file paths
|
|
19
|
+
*/
|
|
20
|
+
private expandPath;
|
|
21
|
+
/**
|
|
22
|
+
* Get MIME type based on file extension
|
|
23
|
+
*/
|
|
24
|
+
private getMimeType;
|
|
25
|
+
/**
|
|
26
|
+
* Check if any media items are file paths (vs URLs)
|
|
27
|
+
*/
|
|
28
|
+
private hasFilePaths;
|
|
29
|
+
/**
|
|
30
|
+
* Create post using multipart/form-data (for file uploads)
|
|
31
|
+
* Uses form field names with brackets: post[body], profiles[], media[]
|
|
32
|
+
*/
|
|
33
|
+
private createPostWithFiles;
|
|
34
|
+
/**
|
|
35
|
+
* Make an HTTP request to the PostProxy API
|
|
36
|
+
*/
|
|
37
|
+
private request;
|
|
38
|
+
/**
|
|
39
|
+
* Get all profile groups
|
|
40
|
+
*/
|
|
41
|
+
getProfileGroups(): Promise<ProfileGroup[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Get profiles, optionally filtered by group ID
|
|
44
|
+
*/
|
|
45
|
+
getProfiles(groupId?: string | number): Promise<Profile[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Create a new post
|
|
48
|
+
* API expects: { post: { body, scheduled_at, draft }, profiles: [...], media: [...], platforms: {...} }
|
|
49
|
+
* Note: draft parameter must be inside the post object, not at the top level
|
|
50
|
+
* If media contains file paths, uses multipart/form-data for file upload
|
|
51
|
+
*/
|
|
52
|
+
createPost(params: CreatePostParams): Promise<CreatePostResponse>;
|
|
53
|
+
/**
|
|
54
|
+
* Get post details by ID
|
|
55
|
+
*/
|
|
56
|
+
getPost(postId: string): Promise<PostDetails>;
|
|
57
|
+
/**
|
|
58
|
+
* List posts with optional pagination
|
|
59
|
+
*/
|
|
60
|
+
listPosts(limit?: number, page?: number, perPage?: number): Promise<Post[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Delete a post by ID
|
|
63
|
+
*/
|
|
64
|
+
deletePost(postId: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Publish a draft post
|
|
67
|
+
* Only posts with status "draft" can be published using this endpoint
|
|
68
|
+
*/
|
|
69
|
+
publishPost(postId: string): Promise<PostDetails>;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EACV,YAAY,EACZ,OAAO,EACP,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,IAAI,EACL,MAAM,mBAAmB,CAAC;AAK3B,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAK3C;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IAWpB;;OAEG;IACH,OAAO,CAAC,UAAU;IAOlB;;OAEG;IACH,OAAO,CAAC,WAAW;IAgBnB;;OAEG;IACH,OAAO,CAAC,YAAY;IAIpB;;;OAGG;YACW,mBAAmB;IAuIjC;;OAEG;YACW,OAAO;IA8GrB;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAKjD;;OAEG;IACG,WAAW,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAQhE;;;;;OAKG;IACG,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA+FvE;;OAEG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAInD;;OAEG;IACG,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAkBjF;;OAEG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C;;;OAGG;IACG,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAGxD"}
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostProxy API HTTP client
|
|
3
|
+
*/
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { basename } from "node:path";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { createError, ErrorCodes, formatError } from "../utils/errors.js";
|
|
8
|
+
import { log, logError } from "../utils/logger.js";
|
|
9
|
+
import { isFilePath } from "../utils/validation.js";
|
|
10
|
+
export class PostProxyClient {
|
|
11
|
+
apiKey;
|
|
12
|
+
baseUrl;
|
|
13
|
+
constructor(apiKey, baseUrl) {
|
|
14
|
+
this.apiKey = apiKey;
|
|
15
|
+
this.baseUrl = baseUrl.replace(/\/$/, ""); // Remove trailing slash
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Extract array from API response
|
|
19
|
+
* API returns either:
|
|
20
|
+
* - Direct array: [...]
|
|
21
|
+
* - Object with data field: {"data": [...]}
|
|
22
|
+
* - Paginated response: {"total": N, "data": [...]}
|
|
23
|
+
*/
|
|
24
|
+
extractArray(response) {
|
|
25
|
+
if (Array.isArray(response)) {
|
|
26
|
+
return response;
|
|
27
|
+
}
|
|
28
|
+
if (response && typeof response === "object" && Array.isArray(response.data)) {
|
|
29
|
+
return response.data;
|
|
30
|
+
}
|
|
31
|
+
// Return empty array if response is not in expected format
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Expand ~ to home directory in file paths
|
|
36
|
+
*/
|
|
37
|
+
expandPath(filePath) {
|
|
38
|
+
if (filePath.startsWith("~/")) {
|
|
39
|
+
return filePath.replace("~", homedir());
|
|
40
|
+
}
|
|
41
|
+
return filePath;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get MIME type based on file extension
|
|
45
|
+
*/
|
|
46
|
+
getMimeType(filePath) {
|
|
47
|
+
const ext = filePath.toLowerCase().split(".").pop();
|
|
48
|
+
const mimeTypes = {
|
|
49
|
+
jpg: "image/jpeg",
|
|
50
|
+
jpeg: "image/jpeg",
|
|
51
|
+
png: "image/png",
|
|
52
|
+
gif: "image/gif",
|
|
53
|
+
webp: "image/webp",
|
|
54
|
+
mp4: "video/mp4",
|
|
55
|
+
mov: "video/quicktime",
|
|
56
|
+
avi: "video/x-msvideo",
|
|
57
|
+
webm: "video/webm",
|
|
58
|
+
};
|
|
59
|
+
return mimeTypes[ext || ""] || "application/octet-stream";
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Check if any media items are file paths (vs URLs)
|
|
63
|
+
*/
|
|
64
|
+
hasFilePaths(media) {
|
|
65
|
+
return media.some((item) => isFilePath(item));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Create post using multipart/form-data (for file uploads)
|
|
69
|
+
* Uses form field names with brackets: post[body], profiles[], media[]
|
|
70
|
+
*/
|
|
71
|
+
async createPostWithFiles(params, extraHeaders) {
|
|
72
|
+
const url = `${this.baseUrl}/posts`;
|
|
73
|
+
const formData = new FormData();
|
|
74
|
+
// Add post body
|
|
75
|
+
formData.append("post[body]", params.content);
|
|
76
|
+
// Add scheduled_at if provided
|
|
77
|
+
if (params.schedule) {
|
|
78
|
+
formData.append("post[scheduled_at]", params.schedule);
|
|
79
|
+
}
|
|
80
|
+
// Add draft if provided
|
|
81
|
+
if (params.draft !== undefined) {
|
|
82
|
+
formData.append("post[draft]", String(params.draft));
|
|
83
|
+
}
|
|
84
|
+
// Add profiles (platform names)
|
|
85
|
+
for (const profile of params.profiles) {
|
|
86
|
+
formData.append("profiles[]", profile);
|
|
87
|
+
}
|
|
88
|
+
// Add media files and URLs
|
|
89
|
+
if (params.media && params.media.length > 0) {
|
|
90
|
+
for (const mediaItem of params.media) {
|
|
91
|
+
if (isFilePath(mediaItem)) {
|
|
92
|
+
// It's a file path - read and upload the file
|
|
93
|
+
const expandedPath = this.expandPath(mediaItem);
|
|
94
|
+
try {
|
|
95
|
+
const fileContent = readFileSync(expandedPath);
|
|
96
|
+
const fileName = basename(expandedPath);
|
|
97
|
+
const mimeType = this.getMimeType(expandedPath);
|
|
98
|
+
const blob = new Blob([fileContent], { type: mimeType });
|
|
99
|
+
formData.append("media[]", blob, fileName);
|
|
100
|
+
if (process.env.POSTPROXY_MCP_DEBUG === "1") {
|
|
101
|
+
log(`Adding file to upload: ${fileName} (${mimeType}, ${fileContent.length} bytes)`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
throw createError(ErrorCodes.VALIDATION_ERROR, `Failed to read file: ${mediaItem} - ${error.message}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// It's a URL - pass it as-is
|
|
110
|
+
formData.append("media[]", mediaItem);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Add platform-specific parameters as JSON
|
|
115
|
+
if (params.platforms && Object.keys(params.platforms).length > 0) {
|
|
116
|
+
formData.append("platforms", JSON.stringify(params.platforms));
|
|
117
|
+
}
|
|
118
|
+
// Build headers (no Content-Type - fetch will set it with boundary for multipart)
|
|
119
|
+
const headers = {
|
|
120
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
121
|
+
...extraHeaders,
|
|
122
|
+
};
|
|
123
|
+
if (process.env.POSTPROXY_MCP_DEBUG === "1") {
|
|
124
|
+
log(`Creating post with file upload (multipart/form-data)`);
|
|
125
|
+
log(`Profiles: ${params.profiles.join(", ")}`);
|
|
126
|
+
log(`Media count: ${params.media?.length || 0}`);
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
const response = await fetch(url, {
|
|
130
|
+
method: "POST",
|
|
131
|
+
headers,
|
|
132
|
+
body: formData,
|
|
133
|
+
signal: AbortSignal.timeout(60000), // 60 second timeout for file uploads
|
|
134
|
+
});
|
|
135
|
+
const requestId = response.headers.get("x-request-id");
|
|
136
|
+
if (!response.ok) {
|
|
137
|
+
let errorMessage = `API request failed with status ${response.status}`;
|
|
138
|
+
let errorDetails = { status: response.status, requestId };
|
|
139
|
+
try {
|
|
140
|
+
const errorBody = await response.json();
|
|
141
|
+
if (Array.isArray(errorBody.errors)) {
|
|
142
|
+
errorMessage = errorBody.errors.join("; ");
|
|
143
|
+
errorDetails = { ...errorDetails, errors: errorBody.errors };
|
|
144
|
+
}
|
|
145
|
+
else if (errorBody.message) {
|
|
146
|
+
errorMessage = errorBody.message;
|
|
147
|
+
errorDetails = { ...errorDetails, ...errorBody };
|
|
148
|
+
}
|
|
149
|
+
else if (errorBody.error) {
|
|
150
|
+
errorMessage = typeof errorBody.error === "string"
|
|
151
|
+
? errorBody.error
|
|
152
|
+
: errorBody.message || errorMessage;
|
|
153
|
+
errorDetails = { ...errorDetails, ...errorBody };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
errorMessage = response.statusText || errorMessage;
|
|
158
|
+
}
|
|
159
|
+
let errorCode = ErrorCodes.API_ERROR;
|
|
160
|
+
if (response.status === 401) {
|
|
161
|
+
errorCode = ErrorCodes.AUTH_INVALID;
|
|
162
|
+
}
|
|
163
|
+
else if (response.status === 404) {
|
|
164
|
+
errorCode = ErrorCodes.TARGET_NOT_FOUND;
|
|
165
|
+
}
|
|
166
|
+
else if (response.status >= 400 && response.status < 500) {
|
|
167
|
+
errorCode = ErrorCodes.VALIDATION_ERROR;
|
|
168
|
+
}
|
|
169
|
+
logError(createError(errorCode, errorMessage, errorDetails), `API POST /posts (multipart)`);
|
|
170
|
+
throw createError(errorCode, errorMessage, errorDetails);
|
|
171
|
+
}
|
|
172
|
+
const jsonResponse = await response.json();
|
|
173
|
+
if (process.env.POSTPROXY_MCP_DEBUG === "1") {
|
|
174
|
+
log(`Response POST /posts (multipart)`, JSON.stringify(jsonResponse, null, 2));
|
|
175
|
+
}
|
|
176
|
+
return jsonResponse;
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
if (error instanceof Error && error.name === "TimeoutError") {
|
|
180
|
+
throw createError(ErrorCodes.API_ERROR, "Request timeout - API did not respond within 60 seconds");
|
|
181
|
+
}
|
|
182
|
+
if (error instanceof Error && "code" in error) {
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
logError(error, `API POST /posts (multipart)`);
|
|
186
|
+
throw formatError(error, ErrorCodes.API_ERROR, { method: "POST", path: "/posts" });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Make an HTTP request to the PostProxy API
|
|
191
|
+
*/
|
|
192
|
+
async request(method, path, body, extraHeaders) {
|
|
193
|
+
const url = `${this.baseUrl}${path}`;
|
|
194
|
+
const headers = {
|
|
195
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
196
|
+
"Content-Type": "application/json",
|
|
197
|
+
};
|
|
198
|
+
// Merge extra headers if provided
|
|
199
|
+
if (extraHeaders) {
|
|
200
|
+
Object.assign(headers, extraHeaders);
|
|
201
|
+
}
|
|
202
|
+
const options = {
|
|
203
|
+
method,
|
|
204
|
+
headers,
|
|
205
|
+
signal: AbortSignal.timeout(30000), // 30 second timeout
|
|
206
|
+
};
|
|
207
|
+
if (body && (method === "POST" || method === "PUT" || method === "PATCH")) {
|
|
208
|
+
options.body = JSON.stringify(body);
|
|
209
|
+
// Log request payload in debug mode
|
|
210
|
+
if (process.env.POSTPROXY_MCP_DEBUG === "1") {
|
|
211
|
+
log(`Request ${method} ${path}`, JSON.stringify(body, null, 2));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
try {
|
|
215
|
+
const response = await fetch(url, options);
|
|
216
|
+
const requestId = response.headers.get("x-request-id");
|
|
217
|
+
if (!response.ok) {
|
|
218
|
+
let errorMessage = `API request failed with status ${response.status}`;
|
|
219
|
+
let errorDetails = { status: response.status, requestId };
|
|
220
|
+
try {
|
|
221
|
+
const errorBody = await response.json();
|
|
222
|
+
// Handle different error response formats
|
|
223
|
+
if (Array.isArray(errorBody.errors)) {
|
|
224
|
+
// 422 validation errors: {"errors": ["...", "..."]}
|
|
225
|
+
errorMessage = errorBody.errors.join("; ");
|
|
226
|
+
errorDetails = { ...errorDetails, errors: errorBody.errors };
|
|
227
|
+
}
|
|
228
|
+
else if (errorBody.message) {
|
|
229
|
+
// 400 errors: {"status":400,"error":"Bad Request","message":"..."}
|
|
230
|
+
errorMessage = errorBody.message;
|
|
231
|
+
errorDetails = { ...errorDetails, ...errorBody };
|
|
232
|
+
}
|
|
233
|
+
else if (errorBody.error) {
|
|
234
|
+
// Some errors use "error" field
|
|
235
|
+
errorMessage = typeof errorBody.error === "string"
|
|
236
|
+
? errorBody.error
|
|
237
|
+
: errorBody.message || errorMessage;
|
|
238
|
+
errorDetails = { ...errorDetails, ...errorBody };
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
// Fallback: use any available message field
|
|
242
|
+
errorMessage = errorBody.message || errorBody.error || errorMessage;
|
|
243
|
+
errorDetails = { ...errorDetails, ...errorBody };
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
// If response is not JSON, use status text
|
|
248
|
+
errorMessage = response.statusText || errorMessage;
|
|
249
|
+
}
|
|
250
|
+
// Map HTTP status codes to error codes
|
|
251
|
+
let errorCode = ErrorCodes.API_ERROR;
|
|
252
|
+
if (response.status === 401) {
|
|
253
|
+
errorCode = ErrorCodes.AUTH_INVALID;
|
|
254
|
+
}
|
|
255
|
+
else if (response.status === 404) {
|
|
256
|
+
errorCode = ErrorCodes.TARGET_NOT_FOUND;
|
|
257
|
+
}
|
|
258
|
+
else if (response.status >= 400 && response.status < 500) {
|
|
259
|
+
errorCode = ErrorCodes.VALIDATION_ERROR;
|
|
260
|
+
}
|
|
261
|
+
logError(createError(errorCode, errorMessage, errorDetails), `API ${method} ${path}`);
|
|
262
|
+
throw createError(errorCode, errorMessage, errorDetails);
|
|
263
|
+
}
|
|
264
|
+
// Handle empty responses
|
|
265
|
+
const contentType = response.headers.get("content-type");
|
|
266
|
+
if (contentType && contentType.includes("application/json")) {
|
|
267
|
+
const jsonResponse = await response.json();
|
|
268
|
+
// Log response in debug mode
|
|
269
|
+
if (process.env.POSTPROXY_MCP_DEBUG === "1") {
|
|
270
|
+
log(`Response ${method} ${path}`, JSON.stringify(jsonResponse, null, 2));
|
|
271
|
+
}
|
|
272
|
+
return jsonResponse;
|
|
273
|
+
}
|
|
274
|
+
return {};
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
if (error instanceof Error && error.name === "TimeoutError") {
|
|
278
|
+
throw createError(ErrorCodes.API_ERROR, "Request timeout - API did not respond within 30 seconds");
|
|
279
|
+
}
|
|
280
|
+
if (error instanceof Error && "code" in error && error.code === "AUTH_INVALID") {
|
|
281
|
+
throw error;
|
|
282
|
+
}
|
|
283
|
+
logError(error, `API ${method} ${path}`);
|
|
284
|
+
throw formatError(error, ErrorCodes.API_ERROR, { method, path });
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Get all profile groups
|
|
289
|
+
*/
|
|
290
|
+
async getProfileGroups() {
|
|
291
|
+
const response = await this.request("GET", "/profile_groups/");
|
|
292
|
+
return this.extractArray(response);
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Get profiles, optionally filtered by group ID
|
|
296
|
+
*/
|
|
297
|
+
async getProfiles(groupId) {
|
|
298
|
+
const path = groupId
|
|
299
|
+
? `/profiles?group_id=${groupId}`
|
|
300
|
+
: "/profiles";
|
|
301
|
+
const response = await this.request("GET", path);
|
|
302
|
+
return this.extractArray(response);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Create a new post
|
|
306
|
+
* API expects: { post: { body, scheduled_at, draft }, profiles: [...], media: [...], platforms: {...} }
|
|
307
|
+
* Note: draft parameter must be inside the post object, not at the top level
|
|
308
|
+
* If media contains file paths, uses multipart/form-data for file upload
|
|
309
|
+
*/
|
|
310
|
+
async createPost(params) {
|
|
311
|
+
// Check if we need to use multipart/form-data for file uploads
|
|
312
|
+
if (params.media && params.media.length > 0 && this.hasFilePaths(params.media)) {
|
|
313
|
+
const extraHeaders = {};
|
|
314
|
+
if (params.idempotency_key) {
|
|
315
|
+
extraHeaders["Idempotency-Key"] = params.idempotency_key;
|
|
316
|
+
}
|
|
317
|
+
return this.createPostWithFiles(params, extraHeaders);
|
|
318
|
+
}
|
|
319
|
+
// Transform to API format (JSON request for URLs only)
|
|
320
|
+
const apiPayload = {
|
|
321
|
+
post: {
|
|
322
|
+
body: params.content,
|
|
323
|
+
},
|
|
324
|
+
profiles: params.profiles, // Array of platform names (e.g., ["twitter"])
|
|
325
|
+
media: params.media || [], // Always include media field, even if empty
|
|
326
|
+
};
|
|
327
|
+
if (params.schedule) {
|
|
328
|
+
apiPayload.post.scheduled_at = params.schedule;
|
|
329
|
+
}
|
|
330
|
+
// Draft parameter must be inside the post object, not at the top level
|
|
331
|
+
if (params.draft !== undefined) {
|
|
332
|
+
apiPayload.post.draft = params.draft;
|
|
333
|
+
}
|
|
334
|
+
// Platform-specific parameters
|
|
335
|
+
// Only include platforms if it's a non-empty object with at least one platform
|
|
336
|
+
// Supports all platform parameter types: strings, numbers, booleans, arrays (e.g., collaborators)
|
|
337
|
+
// Empty platform objects (e.g., {"linkedin": {}}) are also supported
|
|
338
|
+
if (params.platforms &&
|
|
339
|
+
typeof params.platforms === "object" &&
|
|
340
|
+
!Array.isArray(params.platforms) &&
|
|
341
|
+
Object.keys(params.platforms).length > 0) {
|
|
342
|
+
// Validate structure: each key should be a platform name (string), value should be an object
|
|
343
|
+
// Note: We only validate the top-level structure. Detailed validation happens in validation.ts
|
|
344
|
+
// Platform parameter objects can contain: strings, numbers, booleans, arrays (e.g., collaborators), or be empty {}
|
|
345
|
+
const isValidPlatforms = Object.entries(params.platforms).every(([key, value]) => typeof key === "string" &&
|
|
346
|
+
typeof value === "object" &&
|
|
347
|
+
value !== null &&
|
|
348
|
+
!Array.isArray(value));
|
|
349
|
+
if (isValidPlatforms) {
|
|
350
|
+
apiPayload.platforms = params.platforms;
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
log("WARNING: Invalid platforms structure, skipping platform parameters");
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
// Log payload in debug mode to troubleshoot draft issues
|
|
357
|
+
if (process.env.POSTPROXY_MCP_DEBUG === "1") {
|
|
358
|
+
log("Creating post with payload:", JSON.stringify(apiPayload, null, 2));
|
|
359
|
+
log(`Draft parameter: requested=${params.draft}, sending=${apiPayload.draft}`);
|
|
360
|
+
if (params.media && params.media.length > 0) {
|
|
361
|
+
log(`Post includes ${params.media.length} media file(s)`);
|
|
362
|
+
}
|
|
363
|
+
if (params.platforms) {
|
|
364
|
+
log(`Platform parameters received: ${JSON.stringify(params.platforms, null, 2)}`);
|
|
365
|
+
log(`Platform parameter keys: ${Object.keys(params.platforms).join(", ")}`);
|
|
366
|
+
if (apiPayload.platforms) {
|
|
367
|
+
log(`Platform parameters sent to API: ${JSON.stringify(apiPayload.platforms, null, 2)}`);
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
log("WARNING: Platform parameters were provided but not included in API payload (invalid structure or empty)");
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
log("No platform parameters provided");
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
// Add idempotency key as header if provided
|
|
378
|
+
const extraHeaders = {};
|
|
379
|
+
if (params.idempotency_key) {
|
|
380
|
+
extraHeaders["Idempotency-Key"] = params.idempotency_key;
|
|
381
|
+
}
|
|
382
|
+
const response = await this.request("POST", "/posts", apiPayload, extraHeaders);
|
|
383
|
+
// Log response in debug mode, especially draft status
|
|
384
|
+
if (process.env.POSTPROXY_MCP_DEBUG === "1") {
|
|
385
|
+
log(`Post created: id=${response.id}, status=${response.status}, draft=${response.draft}`);
|
|
386
|
+
if (params.draft === true && response.draft === false) {
|
|
387
|
+
log("WARNING: Draft was requested but API returned draft=false. API may have ignored the draft parameter.");
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return response;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Get post details by ID
|
|
394
|
+
*/
|
|
395
|
+
async getPost(postId) {
|
|
396
|
+
return this.request("GET", `/posts/${postId}`);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* List posts with optional pagination
|
|
400
|
+
*/
|
|
401
|
+
async listPosts(limit, page, perPage) {
|
|
402
|
+
const params = new URLSearchParams();
|
|
403
|
+
// Map limit to per_page (API expects per_page, not limit)
|
|
404
|
+
if (limit !== undefined) {
|
|
405
|
+
params.append("per_page", String(limit));
|
|
406
|
+
}
|
|
407
|
+
if (page !== undefined) {
|
|
408
|
+
params.append("page", String(page));
|
|
409
|
+
}
|
|
410
|
+
if (perPage !== undefined) {
|
|
411
|
+
params.append("per_page", String(perPage));
|
|
412
|
+
}
|
|
413
|
+
const queryString = params.toString();
|
|
414
|
+
const path = queryString ? `/posts?${queryString}` : "/posts";
|
|
415
|
+
const response = await this.request("GET", path);
|
|
416
|
+
return this.extractArray(response);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Delete a post by ID
|
|
420
|
+
*/
|
|
421
|
+
async deletePost(postId) {
|
|
422
|
+
await this.request("DELETE", `/posts/${postId}`);
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Publish a draft post
|
|
426
|
+
* Only posts with status "draft" can be published using this endpoint
|
|
427
|
+
*/
|
|
428
|
+
async publishPost(postId) {
|
|
429
|
+
return this.request("POST", `/posts/${postId}/publish`);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AASlC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAkB,MAAM,oBAAoB,CAAC;AAC1F,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,MAAM,OAAO,eAAe;IAClB,MAAM,CAAS;IACf,OAAO,CAAS;IAExB,YAAY,MAAc,EAAE,OAAe;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,wBAAwB;IACrE,CAAC;IAED;;;;;;OAMG;IACK,YAAY,CAAI,QAAa;QACnC,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5B,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7E,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QACD,2DAA2D;QAC3D,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;OAEG;IACK,UAAU,CAAC,QAAgB;QACjC,IAAI,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,OA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,CAAC;YAC1B,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;QAC7C,CAAC;QACD,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,UAAU,WAAW,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;QAC9D,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAM,KAAK,EAAE,IAAI,CAAC,CAAC;QACtD,OAAO,IAAI,CAAC,YAAY,CAAO,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU,CAAC,MAAc;QAC7B,MAAM,IAAI,CAAC,OAAO,CAAO,QAAQ,EAAE,UAAU,MAAM,EAAE,CAAC,CAAC;IACzD,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,WAAW,CAAC,MAAc;QAC9B,OAAO,IAAI,CAAC,OAAO,CAAc,MAAM,EAAE,UAAU,MAAM,UAAU,CAAC,CAAC;IACvE,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credentials management - reading API key from environment variables
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Get API key from environment variables
|
|
6
|
+
* @returns API key or null if not found
|
|
7
|
+
*/
|
|
8
|
+
export declare function getApiKey(): string | null;
|
|
9
|
+
/**
|
|
10
|
+
* Get base URL from environment variables or use default
|
|
11
|
+
* @returns Base URL for PostProxy API
|
|
12
|
+
*/
|
|
13
|
+
export declare function getBaseUrl(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Validate API key by making a test request (optional)
|
|
16
|
+
* This can be used to verify the key is valid before using it
|
|
17
|
+
*/
|
|
18
|
+
export declare function validateApiKey(apiKey: string, baseUrl: string): Promise<boolean>;
|
|
19
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.d.ts","sourceRoot":"","sources":["../../src/auth/credentials.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;GAGG;AACH,wBAAgB,SAAS,IAAI,MAAM,GAAG,IAAI,CAGzC;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAetF"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credentials management - reading API key from environment variables
|
|
3
|
+
*/
|
|
4
|
+
const DEFAULT_BASE_URL = "https://api.postproxy.dev/api";
|
|
5
|
+
/**
|
|
6
|
+
* Get API key from environment variables
|
|
7
|
+
* @returns API key or null if not found
|
|
8
|
+
*/
|
|
9
|
+
export function getApiKey() {
|
|
10
|
+
const apiKey = process.env.POSTPROXY_API_KEY;
|
|
11
|
+
return apiKey || null;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get base URL from environment variables or use default
|
|
15
|
+
* @returns Base URL for PostProxy API
|
|
16
|
+
*/
|
|
17
|
+
export function getBaseUrl() {
|
|
18
|
+
return process.env.POSTPROXY_BASE_URL || DEFAULT_BASE_URL;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Validate API key by making a test request (optional)
|
|
22
|
+
* This can be used to verify the key is valid before using it
|
|
23
|
+
*/
|
|
24
|
+
export async function validateApiKey(apiKey, baseUrl) {
|
|
25
|
+
try {
|
|
26
|
+
const response = await fetch(`${baseUrl}/profile_groups/`, {
|
|
27
|
+
method: "GET",
|
|
28
|
+
headers: {
|
|
29
|
+
Authorization: `Bearer ${apiKey}`,
|
|
30
|
+
"Content-Type": "application/json",
|
|
31
|
+
},
|
|
32
|
+
signal: AbortSignal.timeout(5000), // 5 second timeout for validation
|
|
33
|
+
});
|
|
34
|
+
return response.ok;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/auth/credentials.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,gBAAgB,GAAG,+BAA+B,CAAC;AAEzD;;;GAGG;AACH,MAAM,UAAU,SAAS;IACvB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;IAC7C,OAAO,MAAM,IAAI,IAAI,CAAC;AACxB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,gBAAgB,CAAC;AAC5D,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,MAAc,EAAE,OAAe;IAClE,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,OAAO,kBAAkB,EAAE;YACzD,MAAM,EAAE,KAAK;YACb,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,MAAM,EAAE;gBACjC,cAAc,EAAE,kBAAkB;aACnC;YACD,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,kCAAkC;SACtE,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC,EAAE,CAAC;IACrB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;GAEG"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Entry point for PostProxy MCP Server
|
|
4
|
+
*/
|
|
5
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
|
+
import { getApiKey, getBaseUrl } from "./auth/credentials.js";
|
|
7
|
+
import { PostProxyClient } from "./api/client.js";
|
|
8
|
+
import { createMCPServer } from "./server.js";
|
|
9
|
+
import { log, logError } from "./utils/logger.js";
|
|
10
|
+
import { createError, ErrorCodes } from "./utils/errors.js";
|
|
11
|
+
async function main() {
|
|
12
|
+
// Check if setup command was called
|
|
13
|
+
if (process.argv[2] === "setup") {
|
|
14
|
+
const { setup } = await import("./setup.js");
|
|
15
|
+
await setup();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
// Read environment variables
|
|
20
|
+
const apiKey = getApiKey();
|
|
21
|
+
const baseUrl = getBaseUrl();
|
|
22
|
+
if (!apiKey) {
|
|
23
|
+
logError(createError(ErrorCodes.AUTH_MISSING, "POSTPROXY_API_KEY environment variable is not set"), "startup");
|
|
24
|
+
process.exit(1);
|
|
25
|
+
}
|
|
26
|
+
// Create API client
|
|
27
|
+
const client = new PostProxyClient(apiKey, baseUrl);
|
|
28
|
+
// Create MCP server
|
|
29
|
+
const server = await createMCPServer(client);
|
|
30
|
+
// Setup stdio transport
|
|
31
|
+
const transport = new StdioServerTransport();
|
|
32
|
+
await server.connect(transport);
|
|
33
|
+
log("PostProxy MCP Server started");
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
logError(error, "startup");
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
main().catch((error) => {
|
|
41
|
+
logError(error, "main");
|
|
42
|
+
process.exit(1);
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAC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