posterly-mcp-server 0.59.0 → 0.61.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/README.md +4 -1
- package/dist/lib/api-client.js +17 -7
- package/dist/lib/local-upload-guard.d.ts +53 -0
- package/dist/lib/local-upload-guard.js +228 -0
- package/dist/lib/version.d.ts +1 -1
- package/dist/lib/version.js +1 -1
- package/dist/tools/create-api-key.js +1 -1
- package/dist/tools/create-post.js +2 -2
- package/dist/tools/upload-media.js +37 -10
- package/package.json +3 -2
- package/server.json +2 -2
- package/tool-registry.json +24 -1
package/README.md
CHANGED
|
@@ -123,7 +123,7 @@ Add the same server definition to your Cursor MCP settings:
|
|
|
123
123
|
|
|
124
124
|
## Available tools
|
|
125
125
|
|
|
126
|
-
`posterly-mcp-server@0.
|
|
126
|
+
`posterly-mcp-server@0.61.0` exposes 74 tools covering 119 actions. The hosted HTTP endpoint exposes the same catalog minus the three signup tools: 71 tools covering 116 actions.
|
|
127
127
|
|
|
128
128
|
Many tools pick what to do with one parameter: `view` (reads), `action` (writes), or `type`. A few pick their mode from which parameters you pass (for example `update_post` with `status` changes the status instead of editing). Every tool description names all of its views and actions.
|
|
129
129
|
|
|
@@ -232,6 +232,7 @@ Accounts, posting, media, schedule, analytics, and support. What most assistants
|
|
|
232
232
|
| Mode (picked by params) | What it does |
|
|
233
233
|
| --- | --- |
|
|
234
234
|
| `file` (default) | Upload a file |
|
|
235
|
+
| `local_file` (pass `file_path`) | Upload a local file (stdio only; needs `confirm: true` after the user approves) |
|
|
235
236
|
| `chat_files` (pass `chat_files`) | Import files from the chat (ChatGPT file params, hosted only) |
|
|
236
237
|
| `url` (pass `url`) | Upload from a URL |
|
|
237
238
|
|
|
@@ -510,6 +511,8 @@ In 0.45.0, the old tools below moved into the tools above. The old names still w
|
|
|
510
511
|
|
|
511
512
|
This npm/stdio server can read local file paths. When `upload_media` receives a larger local file, it automatically requests a signed upload URL and uploads the raw bytes before returning the public media URL.
|
|
512
513
|
|
|
514
|
+
Local paths are confined, because an uploaded file gets a public URL. `upload_media` with `file_path` only reads a JPEG, PNG, GIF, WebP, MP4, MOV or WebM file (checked by its first bytes, which also set the uploaded type, so a `.jpg` that is really a WebP is sent as WebP) of at most 4GB (your plan's own limit still applies, and files over about 2GB cannot be read into memory here, so use `create_signed_upload` for those) that sits in your Pictures, Movies, Videos, Desktop, Downloads or Documents folder (or the OneDrive Desktop, Pictures, Documents or Videos folder), the system temp folder, or in the working folder the server was started in (unless that is `/` or your home folder). Hidden files and anything inside a hidden folder are refused, and symlinks are resolved before the check. To allow other folders, set `POSTERLY_MCP_UPLOAD_ROOTS` in the server's `env` to a list of absolute paths, separated by `:` (`;` on Windows); it replaces the defaults. Each local upload also needs `confirm: true`, which your assistant should only send after you approve the file.
|
|
515
|
+
|
|
513
516
|
The hosted HTTP MCP endpoint cannot do that for local files by itself because MCP tool calls are JSON-only. On hosted HTTP MCP, `upload_media` is for small base64 uploads up to 5MB decoded. For larger media there, use `upload_media` with `url` for public direct media URLs, or call `create_signed_upload` only from clients that can also `PUT` the raw file bytes to the returned `upload_url`. One call covers 1 to 20 files with `files`; each file gets its own slot (or its own error), and slots expire in 15 minutes.
|
|
514
517
|
|
|
515
518
|
## What the brand tools are for
|
package/dist/lib/api-client.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { readFile } from 'fs/promises';
|
|
2
|
-
import { resolve } from 'path';
|
|
3
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
2
|
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { filenameForDetectedType, readConfinedLocalMedia } from './local-upload-guard.js';
|
|
5
4
|
/**
|
|
6
5
|
* Scopes the current tool name/call id to the async execution of a single
|
|
7
6
|
* tool call, so request() can tag its headers without a mutable "current
|
|
@@ -854,8 +853,16 @@ export class PosterlyClient {
|
|
|
854
853
|
async uploadMedia(input) {
|
|
855
854
|
this.requireApiKey();
|
|
856
855
|
let fileBuffer;
|
|
856
|
+
let detectedLocalType = null;
|
|
857
|
+
let uploadFilename = input.filename;
|
|
857
858
|
if (input.filePath) {
|
|
858
|
-
|
|
859
|
+
// The path comes from the model: confine it to allowed media folders and
|
|
860
|
+
// real media bytes (see local-upload-guard.ts) before reading anything.
|
|
861
|
+
const local = await readConfinedLocalMedia(input.filePath);
|
|
862
|
+
fileBuffer = local.buffer;
|
|
863
|
+
detectedLocalType = local.contentType;
|
|
864
|
+
// The stored extension comes from the filename, so make it match the bytes.
|
|
865
|
+
uploadFilename = filenameForDetectedType(input.filename, local.contentType);
|
|
859
866
|
}
|
|
860
867
|
else if (input.base64Data) {
|
|
861
868
|
fileBuffer = Buffer.from(input.base64Data, 'base64');
|
|
@@ -863,12 +870,14 @@ export class PosterlyClient {
|
|
|
863
870
|
else {
|
|
864
871
|
throw new Error('Provide filePath or base64Data');
|
|
865
872
|
}
|
|
866
|
-
|
|
873
|
+
// A local file is uploaded as the type its bytes prove, never a declared one.
|
|
874
|
+
const contentType = detectedLocalType ||
|
|
875
|
+
input.contentType ||
|
|
867
876
|
guessContentType(input.filename);
|
|
868
877
|
const SIZE_THRESHOLD = 3 * 1024 * 1024; // 3MB
|
|
869
878
|
if (fileBuffer.length > SIZE_THRESHOLD) {
|
|
870
879
|
// Large file: PUT to the object-storage signed URL (not a Vercel relay).
|
|
871
|
-
const signed = await this.getSignedUploadUrl(
|
|
880
|
+
const signed = await this.getSignedUploadUrl(uploadFilename, contentType, fileBuffer.length, input.workspaceId);
|
|
872
881
|
// Send the returned headers verbatim. The storage URL can be signed for
|
|
873
882
|
// that exact Content-Type (pinned uploads answer 403 otherwise), and
|
|
874
883
|
// header names are case-insensitive: adding our own 'Content-Type' next
|
|
@@ -881,7 +890,8 @@ export class PosterlyClient {
|
|
|
881
890
|
headers: hasReturnedContentType
|
|
882
891
|
? returnedHeaders
|
|
883
892
|
: { 'Content-Type': contentType, ...returnedHeaders },
|
|
884
|
-
|
|
893
|
+
// A Buffer is a Uint8Array view: pass it as is instead of copying up to 4GB.
|
|
894
|
+
body: fileBuffer,
|
|
885
895
|
});
|
|
886
896
|
if (!uploadRes.ok) {
|
|
887
897
|
const errText = await uploadRes.text().catch(() => uploadRes.statusText);
|
|
@@ -892,7 +902,7 @@ export class PosterlyClient {
|
|
|
892
902
|
// Small file: use existing base64 flow through Vercel
|
|
893
903
|
const data = fileBuffer.toString('base64');
|
|
894
904
|
return this.request('POST', '/media/upload', {
|
|
895
|
-
filename:
|
|
905
|
+
filename: uploadFilename,
|
|
896
906
|
data,
|
|
897
907
|
content_type: contentType,
|
|
898
908
|
...(input.workspaceId ? { workspace_id: input.workspaceId } : {}),
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Confinement for upload_media file_path (stdio package only).
|
|
3
|
+
*
|
|
4
|
+
* The path is chosen by the model, and a model can be steered by text it reads
|
|
5
|
+
* (inbox messages, comments, post content). A local file uploaded here gets a
|
|
6
|
+
* public URL, so reading an arbitrary path would turn a prompt injection into
|
|
7
|
+
* a file disclosure. A path is accepted only when ALL of these hold:
|
|
8
|
+
*
|
|
9
|
+
* - after resolving symlinks it sits inside an allowed root: the roots listed in
|
|
10
|
+
* POSTERLY_MCP_UPLOAD_ROOTS (separated like PATH), or by default the user's
|
|
11
|
+
* Pictures, Movies, Videos, Desktop, Downloads and Documents folders (and the
|
|
12
|
+
* OneDrive-synced Desktop, Pictures, Documents and Videos folders), the system
|
|
13
|
+
* temp directory, plus the working directory when that is neither / nor the
|
|
14
|
+
* home directory;
|
|
15
|
+
* - no path component below the root starts with "." (no dotfiles or dot dirs);
|
|
16
|
+
* - it is a regular file no bigger than the largest accepted upload;
|
|
17
|
+
* - its extension is a supported image or video type, and its first bytes are
|
|
18
|
+
* a supported type's real signature (the detected type is what gets uploaded,
|
|
19
|
+
* so a .jpg that is really a WebP is accepted and sent as image/webp).
|
|
20
|
+
*/
|
|
21
|
+
export declare const LOCAL_UPLOAD_ROOTS_ENV = "POSTERLY_MCP_UPLOAD_ROOTS";
|
|
22
|
+
export declare const LOCAL_UPLOAD_MAX_BYTES: number;
|
|
23
|
+
/**
|
|
24
|
+
* The filename to upload under once the bytes proved the type. The server takes
|
|
25
|
+
* the stored extension from the filename and publishing tells images from
|
|
26
|
+
* videos by that extension, so a filename whose extension disagrees with the
|
|
27
|
+
* detected type is rewritten (foo.png that is an MP4 becomes foo.mp4). A
|
|
28
|
+
* filename whose extension already maps to the detected type is kept as is.
|
|
29
|
+
*/
|
|
30
|
+
export declare function filenameForDetectedType(filename: string, detectedType: string): string;
|
|
31
|
+
export declare class LocalUploadRefused extends Error {
|
|
32
|
+
constructor(message: string);
|
|
33
|
+
}
|
|
34
|
+
export interface LocalUploadEnv {
|
|
35
|
+
env?: NodeJS.ProcessEnv;
|
|
36
|
+
cwd?: string;
|
|
37
|
+
home?: string;
|
|
38
|
+
tmp?: string;
|
|
39
|
+
}
|
|
40
|
+
/** The configured or default allowed roots, as given (not yet realpath'd). */
|
|
41
|
+
export declare function localUploadRoots(options?: LocalUploadEnv): string[];
|
|
42
|
+
/** The media type the first bytes prove, or null. */
|
|
43
|
+
export declare function detectMediaType(head: Uint8Array): string | null;
|
|
44
|
+
/**
|
|
45
|
+
* Validates `filePath` and reads it. Returns the bytes and the detected type,
|
|
46
|
+
* or throws LocalUploadRefused with a message safe to show the model (it never
|
|
47
|
+
* echoes file contents).
|
|
48
|
+
*/
|
|
49
|
+
export declare function readConfinedLocalMedia(filePath: string, options?: LocalUploadEnv): Promise<{
|
|
50
|
+
buffer: Buffer;
|
|
51
|
+
contentType: string;
|
|
52
|
+
realPath: string;
|
|
53
|
+
}>;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { open, realpath, stat } from 'node:fs/promises';
|
|
2
|
+
import { realpathSync } from 'node:fs';
|
|
3
|
+
import { homedir, tmpdir } from 'node:os';
|
|
4
|
+
import { delimiter, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
5
|
+
/**
|
|
6
|
+
* Confinement for upload_media file_path (stdio package only).
|
|
7
|
+
*
|
|
8
|
+
* The path is chosen by the model, and a model can be steered by text it reads
|
|
9
|
+
* (inbox messages, comments, post content). A local file uploaded here gets a
|
|
10
|
+
* public URL, so reading an arbitrary path would turn a prompt injection into
|
|
11
|
+
* a file disclosure. A path is accepted only when ALL of these hold:
|
|
12
|
+
*
|
|
13
|
+
* - after resolving symlinks it sits inside an allowed root: the roots listed in
|
|
14
|
+
* POSTERLY_MCP_UPLOAD_ROOTS (separated like PATH), or by default the user's
|
|
15
|
+
* Pictures, Movies, Videos, Desktop, Downloads and Documents folders (and the
|
|
16
|
+
* OneDrive-synced Desktop, Pictures, Documents and Videos folders), the system
|
|
17
|
+
* temp directory, plus the working directory when that is neither / nor the
|
|
18
|
+
* home directory;
|
|
19
|
+
* - no path component below the root starts with "." (no dotfiles or dot dirs);
|
|
20
|
+
* - it is a regular file no bigger than the largest accepted upload;
|
|
21
|
+
* - its extension is a supported image or video type, and its first bytes are
|
|
22
|
+
* a supported type's real signature (the detected type is what gets uploaded,
|
|
23
|
+
* so a .jpg that is really a WebP is accepted and sent as image/webp).
|
|
24
|
+
*/
|
|
25
|
+
export const LOCAL_UPLOAD_ROOTS_ENV = 'POSTERLY_MCP_UPLOAD_ROOTS';
|
|
26
|
+
// The largest plan video cap (Agency, 4GB). The server enforces the per-plan
|
|
27
|
+
// limit on the signed upload; this only stops absurd reads.
|
|
28
|
+
export const LOCAL_UPLOAD_MAX_BYTES = 4 * 1024 * 1024 * 1024;
|
|
29
|
+
const DEFAULT_HOME_FOLDERS = ['Pictures', 'Movies', 'Videos', 'Desktop', 'Downloads', 'Documents'];
|
|
30
|
+
// Windows users with OneDrive folder backup keep these folders under ~/OneDrive.
|
|
31
|
+
const ONEDRIVE_HOME_FOLDERS = ['Desktop', 'Pictures', 'Documents', 'Videos'];
|
|
32
|
+
const EXTENSION_TYPES = {
|
|
33
|
+
'.jpg': 'image/jpeg',
|
|
34
|
+
'.jpeg': 'image/jpeg',
|
|
35
|
+
'.png': 'image/png',
|
|
36
|
+
'.gif': 'image/gif',
|
|
37
|
+
'.webp': 'image/webp',
|
|
38
|
+
'.mp4': 'video/mp4',
|
|
39
|
+
'.m4v': 'video/mp4',
|
|
40
|
+
'.mov': 'video/quicktime',
|
|
41
|
+
'.webm': 'video/webm',
|
|
42
|
+
};
|
|
43
|
+
const MP4_ATOMS = new Set(['ftyp', 'moov', 'mdat', 'wide', 'free', 'skip', 'pnot']);
|
|
44
|
+
const CANONICAL_EXTENSIONS = {
|
|
45
|
+
'image/jpeg': '.jpg',
|
|
46
|
+
'image/png': '.png',
|
|
47
|
+
'image/gif': '.gif',
|
|
48
|
+
'image/webp': '.webp',
|
|
49
|
+
'video/mp4': '.mp4',
|
|
50
|
+
'video/quicktime': '.mov',
|
|
51
|
+
'video/webm': '.webm',
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* The filename to upload under once the bytes proved the type. The server takes
|
|
55
|
+
* the stored extension from the filename and publishing tells images from
|
|
56
|
+
* videos by that extension, so a filename whose extension disagrees with the
|
|
57
|
+
* detected type is rewritten (foo.png that is an MP4 becomes foo.mp4). A
|
|
58
|
+
* filename whose extension already maps to the detected type is kept as is.
|
|
59
|
+
*/
|
|
60
|
+
export function filenameForDetectedType(filename, detectedType) {
|
|
61
|
+
const canonical = CANONICAL_EXTENSIONS[detectedType];
|
|
62
|
+
if (!canonical)
|
|
63
|
+
return filename;
|
|
64
|
+
const ext = extname(filename).toLowerCase();
|
|
65
|
+
if (ext && EXTENSION_TYPES[ext] === detectedType)
|
|
66
|
+
return filename;
|
|
67
|
+
const stem = ext ? filename.slice(0, filename.length - ext.length) : filename;
|
|
68
|
+
return `${stem || 'upload'}${canonical}`;
|
|
69
|
+
}
|
|
70
|
+
export class LocalUploadRefused extends Error {
|
|
71
|
+
constructor(message) {
|
|
72
|
+
super(message);
|
|
73
|
+
this.name = 'LocalUploadRefused';
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** The configured or default allowed roots, as given (not yet realpath'd). */
|
|
77
|
+
export function localUploadRoots(options = {}) {
|
|
78
|
+
const env = options.env ?? process.env;
|
|
79
|
+
const configured = String(env[LOCAL_UPLOAD_ROOTS_ENV] || '')
|
|
80
|
+
.split(delimiter)
|
|
81
|
+
.map((entry) => entry.trim())
|
|
82
|
+
.filter((entry) => entry && isAbsolute(entry));
|
|
83
|
+
if (configured.length > 0)
|
|
84
|
+
return configured;
|
|
85
|
+
const home = options.home ?? homedir();
|
|
86
|
+
const cwd = resolve(options.cwd ?? process.cwd());
|
|
87
|
+
const roots = [
|
|
88
|
+
...DEFAULT_HOME_FOLDERS.map((folder) => join(home, folder)),
|
|
89
|
+
...ONEDRIVE_HOME_FOLDERS.map((folder) => join(home, 'OneDrive', folder)),
|
|
90
|
+
];
|
|
91
|
+
// Other tools often stage exports in the temp directory. Roots that do not
|
|
92
|
+
// exist are skipped at check time, and the check resolves real paths (so
|
|
93
|
+
// macOS /var/folders and /private/var/folders agree). Like the working
|
|
94
|
+
// directory, it is skipped when it resolves to /, the home directory or an
|
|
95
|
+
// ancestor of home (a TMPDIR set that broadly would expose everything).
|
|
96
|
+
const tmp = options.tmp ?? tmpdir();
|
|
97
|
+
if (tmp && !isBroadRoot(tmp, home))
|
|
98
|
+
roots.push(tmp);
|
|
99
|
+
// The working directory counts only when it is a project folder: not /, not
|
|
100
|
+
// the home directory, and not an ancestor of home (e.g. /Users), all of which
|
|
101
|
+
// would expose dotfiles' neighbours such as ~/Library or other users' homes.
|
|
102
|
+
if (!isBroadRoot(cwd, home))
|
|
103
|
+
roots.push(cwd);
|
|
104
|
+
return roots;
|
|
105
|
+
}
|
|
106
|
+
function realOrResolved(path) {
|
|
107
|
+
try {
|
|
108
|
+
return realpathSync(path);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return resolve(path);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/** True when `candidate` is /, the home directory, or an ancestor of home (real paths). */
|
|
115
|
+
function isBroadRoot(candidate, home) {
|
|
116
|
+
const root = realOrResolved(candidate);
|
|
117
|
+
if (root === resolve('/'))
|
|
118
|
+
return true;
|
|
119
|
+
const homeRel = relative(root, realOrResolved(home));
|
|
120
|
+
return homeRel === '' || (!homeRel.startsWith('..') && !isAbsolute(homeRel));
|
|
121
|
+
}
|
|
122
|
+
function isInside(root, target) {
|
|
123
|
+
const rel = relative(root, target);
|
|
124
|
+
if (!rel || rel.startsWith('..') || isAbsolute(rel))
|
|
125
|
+
return null;
|
|
126
|
+
return rel;
|
|
127
|
+
}
|
|
128
|
+
/** The media type the first bytes prove, or null. */
|
|
129
|
+
export function detectMediaType(head) {
|
|
130
|
+
const b = head;
|
|
131
|
+
if (b.length >= 3 && b[0] === 0xff && b[1] === 0xd8 && b[2] === 0xff)
|
|
132
|
+
return 'image/jpeg';
|
|
133
|
+
if (b.length >= 8 && b[0] === 0x89 && b[1] === 0x50 && b[2] === 0x4e && b[3] === 0x47 && b[4] === 0x0d && b[5] === 0x0a && b[6] === 0x1a && b[7] === 0x0a)
|
|
134
|
+
return 'image/png';
|
|
135
|
+
const ascii = (start, end) => String.fromCharCode(...b.subarray(start, end));
|
|
136
|
+
if (b.length >= 6 && (ascii(0, 6) === 'GIF87a' || ascii(0, 6) === 'GIF89a'))
|
|
137
|
+
return 'image/gif';
|
|
138
|
+
if (b.length >= 12 && ascii(0, 4) === 'RIFF' && ascii(8, 12) === 'WEBP')
|
|
139
|
+
return 'image/webp';
|
|
140
|
+
if (b.length >= 4 && b[0] === 0x1a && b[1] === 0x45 && b[2] === 0xdf && b[3] === 0xa3)
|
|
141
|
+
return 'video/webm';
|
|
142
|
+
if (b.length >= 12 && MP4_ATOMS.has(ascii(4, 8))) {
|
|
143
|
+
if (ascii(4, 8) === 'ftyp' && ascii(8, 10) === 'qt')
|
|
144
|
+
return 'video/quicktime';
|
|
145
|
+
return ascii(4, 8) === 'ftyp' ? 'video/mp4' : 'video/quicktime';
|
|
146
|
+
}
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Validates `filePath` and reads it. Returns the bytes and the detected type,
|
|
151
|
+
* or throws LocalUploadRefused with a message safe to show the model (it never
|
|
152
|
+
* echoes file contents).
|
|
153
|
+
*/
|
|
154
|
+
export async function readConfinedLocalMedia(filePath, options = {}) {
|
|
155
|
+
if (typeof filePath !== 'string' || !filePath.trim() || filePath.includes('\0')) {
|
|
156
|
+
throw new LocalUploadRefused('file_path must be a local file path.');
|
|
157
|
+
}
|
|
158
|
+
const requested = resolve(options.cwd ?? process.cwd(), filePath.trim());
|
|
159
|
+
if (!EXTENSION_TYPES[extname(requested).toLowerCase()]) {
|
|
160
|
+
throw new LocalUploadRefused('file_path must be a JPEG, PNG, GIF, WebP, MP4, MOV or WebM file.');
|
|
161
|
+
}
|
|
162
|
+
let real;
|
|
163
|
+
try {
|
|
164
|
+
real = await realpath(requested);
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
throw new LocalUploadRefused('That file was not found.');
|
|
168
|
+
}
|
|
169
|
+
if (!EXTENSION_TYPES[extname(real).toLowerCase()]) {
|
|
170
|
+
throw new LocalUploadRefused('file_path must be a JPEG, PNG, GIF, WebP, MP4, MOV or WebM file.');
|
|
171
|
+
}
|
|
172
|
+
const roots = localUploadRoots(options);
|
|
173
|
+
let allowed = false;
|
|
174
|
+
for (const root of roots) {
|
|
175
|
+
let realRoot;
|
|
176
|
+
try {
|
|
177
|
+
realRoot = await realpath(root);
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const rel = isInside(realRoot, real);
|
|
183
|
+
if (rel === null)
|
|
184
|
+
continue;
|
|
185
|
+
if (rel.split(sep).some((part) => part.startsWith('.')))
|
|
186
|
+
continue;
|
|
187
|
+
allowed = true;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
if (!allowed) {
|
|
191
|
+
throw new LocalUploadRefused(`That path is outside the folders posterly may upload from: your Pictures, Movies, Videos, Desktop, Downloads and Documents folders (including the OneDrive ones), the temp folder, and the project folder the server started in. Move the file into one of those, or set ${LOCAL_UPLOAD_ROOTS_ENV} in the MCP server config to the folders you want to allow. Hidden files and folders are never uploaded.`);
|
|
192
|
+
}
|
|
193
|
+
const info = await stat(real);
|
|
194
|
+
if (!info.isFile())
|
|
195
|
+
throw new LocalUploadRefused('file_path must point to a regular file.');
|
|
196
|
+
if (info.size === 0)
|
|
197
|
+
throw new LocalUploadRefused('That file is empty.');
|
|
198
|
+
if (info.size > LOCAL_UPLOAD_MAX_BYTES) {
|
|
199
|
+
throw new LocalUploadRefused('That file is larger than 4GB, the most upload_media accepts. Your plan may allow less.');
|
|
200
|
+
}
|
|
201
|
+
const handle = await open(real, 'r');
|
|
202
|
+
let buffer;
|
|
203
|
+
try {
|
|
204
|
+
buffer = await handle.readFile();
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
// Node reads at most 2GB into one buffer. Say so plainly instead of leaking
|
|
208
|
+
// a raw fs error to the model.
|
|
209
|
+
const code = error?.code;
|
|
210
|
+
if (code === 'ERR_FS_FILE_TOO_LARGE' || code === 'ERR_BUFFER_TOO_LARGE') {
|
|
211
|
+
throw new LocalUploadRefused('That file is too large to read into memory here (about 2GB is the most). Use create_signed_upload and PUT the file instead.');
|
|
212
|
+
}
|
|
213
|
+
throw error;
|
|
214
|
+
}
|
|
215
|
+
finally {
|
|
216
|
+
await handle.close();
|
|
217
|
+
}
|
|
218
|
+
if (buffer.length > LOCAL_UPLOAD_MAX_BYTES) {
|
|
219
|
+
throw new LocalUploadRefused('That file is larger than 4GB, the most upload_media accepts. Your plan may allow less.');
|
|
220
|
+
}
|
|
221
|
+
const detected = detectMediaType(buffer.subarray(0, 16));
|
|
222
|
+
// The bytes decide the type: a .jpg that is really a WebP uploads as WebP.
|
|
223
|
+
// Anything that is not a supported image or video is refused.
|
|
224
|
+
if (!detected) {
|
|
225
|
+
throw new LocalUploadRefused('That file is not a real JPEG, PNG, GIF, WebP, MP4, MOV or WebM file.');
|
|
226
|
+
}
|
|
227
|
+
return { buffer, contentType: detected, realPath: real };
|
|
228
|
+
}
|
package/dist/lib/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const POSTERLY_MCP_VERSION = "0.
|
|
1
|
+
export declare const POSTERLY_MCP_VERSION = "0.61.0";
|
package/dist/lib/version.js
CHANGED
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
// tool set (minus the intentional pre-auth signup tools that only this stdio
|
|
6
6
|
// package exposes). `npm run check:mcp-parity` enforces both the version match
|
|
7
7
|
// and the tool-list match, and runs in the pre-commit hook.
|
|
8
|
-
export const POSTERLY_MCP_VERSION = '0.
|
|
8
|
+
export const POSTERLY_MCP_VERSION = '0.61.0';
|
|
@@ -27,7 +27,7 @@ export const createApiKeyTool = {
|
|
|
27
27
|
scopes: z.array(scopeSchema).min(1).max(8).optional().describe('Scopes for the new key. Omit to copy the calling key scopes. Cannot exceed the calling key scopes. billing:read and billing:write allow managing the posterly subscription (cancel/pause/resume/downgrade).'),
|
|
28
28
|
workspace_id: z.string().trim().min(1).optional().describe('Optional workspace restriction. Workspace-scoped calling keys cannot create keys outside their workspace.'),
|
|
29
29
|
workspace_client_id: z.string().trim().min(1).optional().describe('Optional brand (workspace client id) in that workspace. Omit for a key that can see every brand. A key limited to one brand cannot create keys.'),
|
|
30
|
-
expires_in_days: z.number().int().min(1).max(365).optional().describe('Optional expiry from now, up to 365 days.
|
|
30
|
+
expires_in_days: z.number().int().min(1).max(365).optional().describe('Optional expiry from now, up to 365 days. Never later than the calling key: omitted, the new key inherits the calling key\'s expiry (none if the calling key does not expire).'),
|
|
31
31
|
confirm: z.literal(true).describe('Must be true after the user explicitly confirms that a new secret API key should be created.'),
|
|
32
32
|
}),
|
|
33
33
|
async execute(client, input) {
|
|
@@ -163,7 +163,7 @@ export const platformSettingsSchema = z.object({
|
|
|
163
163
|
is_comment_prompt_used: z.boolean().optional(),
|
|
164
164
|
is_poll_duration_extended: z.boolean().optional(),
|
|
165
165
|
// tags (z.array of strings) also serve as Bluesky hidden discovery tags
|
|
166
|
-
// AI-content disclosure (TikTok is_aigc, X made_with_ai, YouTube containsSyntheticMedia, Pinterest ai_disclosures)
|
|
166
|
+
// AI-content disclosure (TikTok is_aigc, X made_with_ai, YouTube containsSyntheticMedia, Pinterest ai_disclosures, Threads is_made_with_ai)
|
|
167
167
|
ai_generated: z.boolean().optional(),
|
|
168
168
|
}).passthrough();
|
|
169
169
|
export const createPostPayloadInputSchema = z.object({
|
|
@@ -335,7 +335,7 @@ export const createPostTool = {
|
|
|
335
335
|
'MEDIA URLS: Posterly storage URLs are used as-is. Third-party HTTP(S) media URLs are copied into posterly storage before the post is saved, so API-created posts do not later fail on expired signed URLs. Short-lived signed URLs must still be live when this tool runs. You can also call `upload_media` with `url` first if you want to upload once and reuse the returned posterly URL across posts.\n\n' +
|
|
336
336
|
'THREADS: Pass `thread_posts` (an array of 2+ strings) to schedule a multi-post thread on X (Twitter) or Threads (Meta). The first entry is the lead post; the rest are published as replies in the same chain. X entries are capped at 280 characters each (4000 for verified, 25000 for organization accounts); Threads entries are capped at 500 characters each. When `thread_posts` is set, `caption` is ignored.\n\n' +
|
|
337
337
|
'X ARTICLES: To publish on X as a long-form Article, pass `platform_settings.article` ({ title, cover?: "first_image" | "none" }) for an X account. The caption becomes the Article body and is written as Markdown (headings, bold, italic, lists, quotes, code blocks, tables, dividers). Reference attached images with ``. Needs an X Premium account; polls, threads, paid partnership, video, and GIFs are not allowed with an Article.\n\n' +
|
|
338
|
-
'PLATFORM SETTINGS: Pass `platform_settings` for composer-equivalent controls: Facebook story/reel/backgrounds, YouTube title/privacy/thumbnail/brandPartner, LinkedIn document titles/mentions/polls/content_call_to_action_label (including BUY_NOW and SHOP_NOW), TikTok direct-post privacy/toggles/commercial disclosure, Pinterest board/title/link/product_tags, GBP event/offer/CTA/recurrence, X reply settings/polls/paid_partnership, Threads reply controls/text attachments/ghost posts/spoilers/reply approvals/GIPHY, Telegram polls/buttons/video cover/live photo, Slack markdown/blocks, Mastodon visibility/quote/poll (media+poll allowed), and Instagram feed/story/reel/carousel/native media tags/collaborators/first comments/trial Reels/is_ai_generated/audio_id/caption add-ons. Instagram caption add-ons (`caption_addon`, or `poll_attachment` / `is_comment_prompt_used`) need a Facebook Login account, a non-empty caption, and a feed photo, Reel, or carousel parent. Stories are rejected. A poll and a comment prompt cannot be combined. For Instagram, @username in caption is only a caption mention; `user_tags` creates native media tags and `collaborators` sends co-author invitations only when the selected Meta-linked account reports those capabilities. Call `list_platforms` with `view: "schema"` and the account ID first. `instagram_settings` remains as a backwards-compatible alias.\n\n' +
|
|
338
|
+
'PLATFORM SETTINGS: Pass `platform_settings` for composer-equivalent controls: Facebook story/reel/backgrounds, YouTube title/privacy/thumbnail/brandPartner, LinkedIn document titles/mentions/polls/content_call_to_action_label (including BUY_NOW and SHOP_NOW), TikTok direct-post privacy/toggles/commercial disclosure, Pinterest board/title/link/product_tags, GBP event/offer/CTA/recurrence, X reply settings/polls/paid_partnership, Threads reply controls/text attachments/ghost posts/spoilers/reply approvals/GIPHY/ai_generated label, Telegram polls/buttons/video cover/live photo, Slack markdown/blocks, Mastodon visibility/quote/poll (media+poll allowed), and Instagram feed/story/reel/carousel/native media tags/collaborators/first comments/trial Reels/is_ai_generated/audio_id/caption add-ons. Instagram caption add-ons (`caption_addon`, or `poll_attachment` / `is_comment_prompt_used`) need a Facebook Login account, a non-empty caption, and a feed photo, Reel, or carousel parent. Stories are rejected. A poll and a comment prompt cannot be combined. For Instagram, @username in caption is only a caption mention; `user_tags` creates native media tags and `collaborators` sends co-author invitations only when the selected Meta-linked account reports those capabilities. Call `list_platforms` with `view: "schema"` and the account ID first. `instagram_settings` remains as a backwards-compatible alias.\n\n' +
|
|
339
339
|
'TIKTOK AUDIENCE: TikTok posts publish directly, unless the account is set to Finish in TikTok app. With no `platform_settings.privacy_level` the account\'s saved audience is used, else public, and the response says which (`tiktok_audience_defaulted`): tell the person. `post_mode: "inbox"` sends the post to the TikTok app instead.\n\n' +
|
|
340
340
|
'TIKTOK MEDIA: TikTok supports a single video or a photo slideshow of 1 to 35 images, never multiple videos. Image media auto-detects as a slideshow, so you usually do not set post_type or media_type for photos and every image is posted. Pass `platform_settings.media_type: "PHOTO"` to force a slideshow explicitly.\n\n' +
|
|
341
341
|
'IDEMPOTENCY: If this call errors, times out, or the response is lost, retry with the same idempotency_key. If you omit it, an identical create within about 10 minutes returns the original post instead of a second one (deduplicated: true, original post id). When a result is unclear, call get_post or list_posts before creating again.',
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { formatIsoTimestamp, mdError, mdKeyValue, mdSection, mdSuccess } from '../lib/format.js';
|
|
3
|
+
import { LocalUploadRefused } from '../lib/local-upload-guard.js';
|
|
3
4
|
import { previewThenConfirm, readFailedNote, readForPreview, validateArgs } from '../lib/tool-runtime.js';
|
|
4
5
|
export const uploadMediaTool = {
|
|
5
6
|
name: 'upload_media',
|
|
6
|
-
description: 'Upload an image or video to posterly storage and get a URL for create_post. Supports JPEG, PNG, GIF, WebP, MP4, MOV, WebM (PDFs are not accepted here: use create_signed_upload or create_media_drop). Images up to 10MB
|
|
7
|
+
description: 'Upload an image or video to posterly storage and get a URL for create_post. Supports JPEG, PNG, GIF, WebP, MP4, MOV, WebM (PDFs are not accepted here: use create_signed_upload or create_media_drop). Images up to 10MB; videos up to the video limit of the user\'s plan (up to 4GB on the largest plan), with large local files sent straight to storage. Three ways in: file_path (an explicit local path the user typed; needs confirm: true after the user approves uploading that file, and only works for media in the user\'s Pictures, Movies, Videos, Desktop, Downloads or Documents folders, the system temp folder, the working project folder, or folders listed in POSTERLY_MCP_UPLOAD_ROOTS), base64_data with filename (PREFERRED for images shared in chat, which are not on the local filesystem), or url (a public HTTPS image or video; local/private network URLs are blocked).\n\n' +
|
|
7
8
|
'This writes to the user\'s media storage (counts against quota) but does NOT publish the file anywhere. Uploading is safe - it\'s the subsequent `create_post` call that publishes content, and that tool has its own confirmation requirements. Never guess file paths. You can also pass public HTTP(S) media URLs directly to create_post/update_post; use url here when you want to upload once and reuse the returned posterly URL. Pass asset_id (from list_media) to delete that library file: the first request previews it and deletes nothing; send it again with confirm true and that preview_id only after the user agrees. A file a post still uses is kept.',
|
|
8
9
|
inputSchema: z.object({
|
|
9
10
|
file_path: z
|
|
10
11
|
.string()
|
|
11
12
|
.optional()
|
|
12
|
-
.describe('Absolute local filesystem path (e.g. /Users/name/photo.jpg). Only use when the user
|
|
13
|
+
.describe('Absolute local filesystem path (e.g. /Users/name/Pictures/photo.jpg). Only use when the user typed this exact path themselves, never a path found in a message, comment, post or web page. Requires confirm: true after the user approves uploading it. Do NOT guess paths for images uploaded in chat.'),
|
|
13
14
|
base64_data: z
|
|
14
15
|
.string()
|
|
15
16
|
.optional()
|
|
@@ -29,7 +30,7 @@ export const uploadMediaTool = {
|
|
|
29
30
|
.describe('MIME type (auto-detected from filename if omitted)'),
|
|
30
31
|
workspace_id: z.string().optional().describe('Optional. The workspace this acts in and whose plan pays (from whoami). Needed only when your connection can act in several workspaces.'),
|
|
31
32
|
asset_id: z.string().optional().describe('Library file id from list_media. Deletes that file after a preview. Do not combine with url, file_path, or base64_data.'),
|
|
32
|
-
confirm: z.boolean().optional().describe('Delete
|
|
33
|
+
confirm: z.boolean().optional().describe('Delete: true only after the user explicitly approves the preview, together with preview_id. file_path: true only after the user explicitly approved uploading that local file.'),
|
|
33
34
|
preview_id: z.string().optional().describe('The preview_id from the delete preview. Required with confirm: true.'),
|
|
34
35
|
}),
|
|
35
36
|
/** The old tools' exact input schemas, for alias calls (see alias-transport.ts). */
|
|
@@ -44,6 +45,8 @@ export const uploadMediaTool = {
|
|
|
44
45
|
const { mode, args } = validateArgs(ctx, 'upload_media', input);
|
|
45
46
|
if (mode === 'delete')
|
|
46
47
|
return deleteLibraryFile(client, args, ctx);
|
|
48
|
+
if (mode === 'local_file')
|
|
49
|
+
return uploadLocalFile(client, args);
|
|
47
50
|
if (mode === 'url')
|
|
48
51
|
return uploadFromUrl(client, args);
|
|
49
52
|
return uploadFile(client, args);
|
|
@@ -80,17 +83,41 @@ async function deleteLibraryFile(client, input, ctx) {
|
|
|
80
83
|
},
|
|
81
84
|
});
|
|
82
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* A local file gets a public URL once uploaded, so reading one needs the user's
|
|
88
|
+
* explicit approval (registry confirm level "confirm") on top of the path
|
|
89
|
+
* confinement in PosterlyClient.uploadMedia (lib/local-upload-guard.ts).
|
|
90
|
+
*/
|
|
91
|
+
async function uploadLocalFile(client, input) {
|
|
92
|
+
if (input.confirm !== true) {
|
|
93
|
+
return mdError(`Uploading a local file needs the user's approval. Ask the user to confirm they want to upload ${'`'}${input.file_path}${'`'}, then call upload_media again with the same fields plus confirm: true. Only upload a path the user typed themselves.`);
|
|
94
|
+
}
|
|
95
|
+
return uploadFile(client, {
|
|
96
|
+
file_path: input.file_path,
|
|
97
|
+
filename: input.filename,
|
|
98
|
+
content_type: input.content_type,
|
|
99
|
+
workspace_id: input.workspace_id,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
83
102
|
async function uploadFile(client, input) {
|
|
84
103
|
if (!input.file_path && !input.base64_data) {
|
|
85
104
|
return mdError('Provide either `file_path` or `base64_data`.');
|
|
86
105
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
106
|
+
let result;
|
|
107
|
+
try {
|
|
108
|
+
result = await client.uploadMedia({
|
|
109
|
+
filePath: input.file_path,
|
|
110
|
+
base64Data: input.base64_data,
|
|
111
|
+
filename: input.filename,
|
|
112
|
+
contentType: input.content_type,
|
|
113
|
+
workspaceId: input.workspace_id,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
if (error instanceof LocalUploadRefused)
|
|
118
|
+
return mdError(error.message);
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
94
121
|
return mdSuccess('Media uploaded', [
|
|
95
122
|
['URL', result.url],
|
|
96
123
|
['Storage path', result.path],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "posterly-mcp-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.61.0",
|
|
4
4
|
"mcpName": "io.github.awpthorp/posterly",
|
|
5
5
|
"description": "MCP server for posterly: schedule and publish social media posts across 18 platforms from any MCP client (Claude, ChatGPT, Cursor, Windsurf, Cline, and more)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,8 @@
|
|
|
43
43
|
"test:annotations": "npm run build && node scripts/test-tool-annotations.mjs",
|
|
44
44
|
"test:payloads": "npm run build && node scripts/test-payload-builders.mjs",
|
|
45
45
|
"test:client-header": "npm run build && node scripts/test-client-header-sanitization.mjs",
|
|
46
|
-
"test:alias-transport": "npm run build && node scripts/test-alias-transport.mjs"
|
|
46
|
+
"test:alias-transport": "npm run build && node scripts/test-alias-transport.mjs",
|
|
47
|
+
"test:local-upload-guard": "npm run build && node scripts/test-local-upload-guard.mjs"
|
|
47
48
|
},
|
|
48
49
|
"dependencies": {
|
|
49
50
|
"@modelcontextprotocol/sdk": "1.32.1",
|
package/server.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"name": "io.github.awpthorp/posterly",
|
|
4
4
|
"title": "posterly",
|
|
5
5
|
"description": "Validate, schedule, publish, and analyze social content across 18 platforms with posterly.",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.61.0",
|
|
7
7
|
"websiteUrl": "https://www.poster.ly/mcp",
|
|
8
8
|
"repository": {
|
|
9
9
|
"url": "https://github.com/awpthorp/posterly-mcp-server",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
{
|
|
14
14
|
"registryType": "npm",
|
|
15
15
|
"identifier": "posterly-mcp-server",
|
|
16
|
-
"version": "0.
|
|
16
|
+
"version": "0.61.0",
|
|
17
17
|
"transport": {
|
|
18
18
|
"type": "stdio"
|
|
19
19
|
},
|
package/tool-registry.json
CHANGED
|
@@ -1128,9 +1128,32 @@
|
|
|
1128
1128
|
"base64_data": {
|
|
1129
1129
|
"type": "string"
|
|
1130
1130
|
},
|
|
1131
|
-
"
|
|
1131
|
+
"filename": {
|
|
1132
|
+
"type": "string",
|
|
1133
|
+
"required": true
|
|
1134
|
+
},
|
|
1135
|
+
"content_type": {
|
|
1132
1136
|
"type": "string"
|
|
1133
1137
|
},
|
|
1138
|
+
"workspace_id": {
|
|
1139
|
+
"type": "string"
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
},
|
|
1143
|
+
"local_file": {
|
|
1144
|
+
"label": "Upload a local file",
|
|
1145
|
+
"destructive": false,
|
|
1146
|
+
"idempotent": false,
|
|
1147
|
+
"openWorld": true,
|
|
1148
|
+
"confirm": "confirm",
|
|
1149
|
+
"when": [
|
|
1150
|
+
"file_path"
|
|
1151
|
+
],
|
|
1152
|
+
"params": {
|
|
1153
|
+
"file_path": {
|
|
1154
|
+
"type": "string",
|
|
1155
|
+
"required": true
|
|
1156
|
+
},
|
|
1134
1157
|
"filename": {
|
|
1135
1158
|
"type": "string",
|
|
1136
1159
|
"required": true
|