@junis/ghost-mcp 0.3.0 → 0.4.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.
@@ -11,13 +11,13 @@ function registerRedirectsAndRoutesTools(server) {
11
11
  content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
12
12
  };
13
13
  });
14
- server.tool("redirects_upload", "Upload a redirects.yaml or redirects.json file to Ghost", { file: zod_1.z.string().describe("Absolute path to the redirects file") }, async (args, _extra) => {
14
+ server.tool("redirects_upload", "Upload a redirects.yaml or redirects.json file to Ghost", { file: zod_1.z.string().describe("Absolute local file path or URL to the redirects file") }, async (args, _extra) => {
15
15
  const result = await (0, ghostHttp_1.ghostUploadFile)("redirects/upload/", args.file);
16
16
  return {
17
17
  content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
18
18
  };
19
19
  });
20
- server.tool("routes_upload", "Upload a routes.yaml file to Ghost", { file: zod_1.z.string().describe("Absolute path to the routes.yaml file") }, async (args, _extra) => {
20
+ server.tool("routes_upload", "Upload a routes.yaml file to Ghost", { file: zod_1.z.string().describe("Absolute local file path or URL to the routes.yaml file") }, async (args, _extra) => {
21
21
  const result = await (0, ghostHttp_1.ghostUploadFile)("settings/routes/yaml/", args.file);
22
22
  return {
23
23
  content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
@@ -16,11 +16,18 @@ function registerThemeTools(server) {
16
16
  content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
17
17
  };
18
18
  });
19
- server.tool("themes_upload", "Upload a Ghost theme zip file", { file: zod_1.z.string().describe("Absolute path to the theme zip file") }, async (args, _extra) => {
20
- const result = await ghostApi_1.ghostApiClient.themes.upload(args);
21
- return {
22
- content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
23
- };
19
+ server.tool("themes_upload", "Upload a Ghost theme zip file", { file: zod_1.z.string().describe("Absolute local file path or URL to the theme zip file") }, async (args, _extra) => {
20
+ const { filePath, isTemp } = await (0, ghostHttp_1.resolveFileInput)(args.file);
21
+ try {
22
+ const result = await ghostApi_1.ghostApiClient.themes.upload({ ...args, file: filePath });
23
+ return {
24
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
25
+ };
26
+ }
27
+ finally {
28
+ if (isTemp)
29
+ fs_1.default.unlinkSync(filePath);
30
+ }
24
31
  });
25
32
  server.tool("themes_activate", "Activate an installed Ghost theme by name", { name: zod_1.z.string().describe("Theme name to activate") }, async (args, _extra) => {
26
33
  const result = await ghostApi_1.ghostApiClient.themes.activate(args.name);
@@ -1,58 +1,124 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.registerUploadTools = registerUploadTools;
4
37
  // src/tools/upload.ts
5
38
  const zod_1 = require("zod");
6
39
  const ghostApi_1 = require("../ghostApi");
40
+ const ghostHttp_1 = require("../utils/ghostHttp");
41
+ const fs = __importStar(require("fs"));
7
42
  const imageUploadParams = {
8
- file: zod_1.z.string().describe("Absolute path to the image file"),
43
+ file: zod_1.z.string().describe("Absolute local file path or URL to the image"),
9
44
  purpose: zod_1.z.string().optional().describe("Purpose of the image (default: 'image')"),
10
45
  ref: zod_1.z.string().optional().describe("Reference string returned in the response"),
11
46
  };
12
47
  const mediaUploadParams = {
13
- file: zod_1.z.string().describe("Absolute path to the audio/video file"),
14
- thumbnail: zod_1.z.string().optional().describe("Absolute path to a thumbnail image for the media"),
48
+ file: zod_1.z.string().describe("Absolute local file path or URL to the audio/video file"),
49
+ thumbnail: zod_1.z.string().optional().describe("Absolute local file path or URL to a thumbnail image"),
15
50
  purpose: zod_1.z.string().optional().describe("Purpose of the media"),
16
51
  };
17
52
  const fileUploadParams = {
18
- file: zod_1.z.string().describe("Absolute path to the file"),
53
+ file: zod_1.z.string().describe("Absolute local file path or URL to the file"),
19
54
  ref: zod_1.z.string().optional().describe("Reference string returned in the response"),
20
55
  };
21
56
  function registerUploadTools(server) {
22
57
  // Upload image
23
58
  server.tool("images_upload", "Upload an image to Ghost (jpg, jpeg, png, gif, svg, svgz, ico, webp). Returns the CDN URL.", imageUploadParams, async (args, _extra) => {
24
- const result = await ghostApi_1.ghostApiClient.images.upload(args);
25
- return {
26
- content: [
27
- {
28
- type: "text",
29
- text: JSON.stringify(result, null, 2),
30
- },
31
- ],
32
- };
59
+ const { filePath, isTemp } = await (0, ghostHttp_1.resolveFileInput)(args.file);
60
+ try {
61
+ const result = await ghostApi_1.ghostApiClient.images.upload({ ...args, file: filePath });
62
+ return {
63
+ content: [
64
+ {
65
+ type: "text",
66
+ text: JSON.stringify(result, null, 2),
67
+ },
68
+ ],
69
+ };
70
+ }
71
+ finally {
72
+ if (isTemp)
73
+ fs.unlinkSync(filePath);
74
+ }
33
75
  });
34
76
  // Upload media (audio/video)
35
77
  server.tool("media_upload", "Upload audio/video to Ghost (mp4, webm, ogv, mp3, wav, ogg, m4a). Returns the CDN URL.", mediaUploadParams, async (args, _extra) => {
36
- const result = await ghostApi_1.ghostApiClient.media.upload(args);
37
- return {
38
- content: [
39
- {
40
- type: "text",
41
- text: JSON.stringify(result, null, 2),
42
- },
43
- ],
44
- };
78
+ const { filePath, isTemp } = await (0, ghostHttp_1.resolveFileInput)(args.file);
79
+ let thumbnailResolved = null;
80
+ if (args.thumbnail) {
81
+ thumbnailResolved = await (0, ghostHttp_1.resolveFileInput)(args.thumbnail);
82
+ }
83
+ try {
84
+ const result = await ghostApi_1.ghostApiClient.media.upload({
85
+ ...args,
86
+ file: filePath,
87
+ ...(thumbnailResolved ? { thumbnail: thumbnailResolved.filePath } : {}),
88
+ });
89
+ return {
90
+ content: [
91
+ {
92
+ type: "text",
93
+ text: JSON.stringify(result, null, 2),
94
+ },
95
+ ],
96
+ };
97
+ }
98
+ finally {
99
+ if (isTemp)
100
+ fs.unlinkSync(filePath);
101
+ if (thumbnailResolved?.isTemp)
102
+ fs.unlinkSync(thumbnailResolved.filePath);
103
+ }
45
104
  });
46
105
  // Upload file
47
106
  server.tool("files_upload", "Upload a file to Ghost (pdf, docx, xlsx, csv, epub, zip, etc. 50+ formats). Returns the CDN URL.", fileUploadParams, async (args, _extra) => {
48
- const result = await ghostApi_1.ghostApiClient.files.upload(args);
49
- return {
50
- content: [
51
- {
52
- type: "text",
53
- text: JSON.stringify(result, null, 2),
54
- },
55
- ],
56
- };
107
+ const { filePath, isTemp } = await (0, ghostHttp_1.resolveFileInput)(args.file);
108
+ try {
109
+ const result = await ghostApi_1.ghostApiClient.files.upload({ ...args, file: filePath });
110
+ return {
111
+ content: [
112
+ {
113
+ type: "text",
114
+ text: JSON.stringify(result, null, 2),
115
+ },
116
+ ],
117
+ };
118
+ }
119
+ finally {
120
+ if (isTemp)
121
+ fs.unlinkSync(filePath);
122
+ }
57
123
  });
58
124
  }
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resolveFileInput = resolveFileInput;
6
7
  exports.ghostGet = ghostGet;
7
8
  exports.ghostPut = ghostPut;
8
9
  exports.ghostPost = ghostPost;
@@ -12,7 +13,29 @@ exports.ghostDownload = ghostDownload;
12
13
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
13
14
  const axios_1 = __importDefault(require("axios"));
14
15
  const fs_1 = __importDefault(require("fs"));
16
+ const path_1 = __importDefault(require("path"));
17
+ const os_1 = __importDefault(require("os"));
15
18
  const config_1 = require("../config");
19
+ /**
20
+ * If input is a URL, download to a temp file and return the path.
21
+ * If input is a local path, return as-is.
22
+ */
23
+ async function resolveFileInput(input) {
24
+ if (!input.startsWith("http://") && !input.startsWith("https://")) {
25
+ return { filePath: input, isTemp: false };
26
+ }
27
+ const urlPath = new URL(input).pathname;
28
+ const ext = path_1.default.extname(urlPath) || ".tmp";
29
+ const tempFile = path_1.default.join(os_1.default.tmpdir(), `ghost-mcp-${Date.now()}${ext}`);
30
+ const response = await axios_1.default.get(input, { responseType: "stream" });
31
+ const writer = fs_1.default.createWriteStream(tempFile);
32
+ response.data.pipe(writer);
33
+ await new Promise((resolve, reject) => {
34
+ writer.on("finish", resolve);
35
+ writer.on("error", reject);
36
+ });
37
+ return { filePath: tempFile, isTemp: true };
38
+ }
16
39
  function generateToken() {
17
40
  const [id, secret] = config_1.GHOST_ADMIN_API_KEY.split(":");
18
41
  return jsonwebtoken_1.default.sign({}, Buffer.from(secret, "hex"), {
@@ -48,16 +71,23 @@ async function ghostPost(endpoint, data) {
48
71
  return res.data;
49
72
  }
50
73
  async function ghostUploadFile(endpoint, filePath, fieldName = "file") {
51
- const FormData = (await import("form-data")).default;
52
- const form = new FormData();
53
- form.append(fieldName, fs_1.default.createReadStream(filePath));
54
- const res = await axios_1.default.post(apiUrl(endpoint), form, {
55
- headers: {
56
- ...authHeaders(),
57
- ...form.getHeaders(),
58
- },
59
- });
60
- return res.data;
74
+ const { filePath: resolvedPath, isTemp } = await resolveFileInput(filePath);
75
+ try {
76
+ const FormData = (await import("form-data")).default;
77
+ const form = new FormData();
78
+ form.append(fieldName, fs_1.default.createReadStream(resolvedPath));
79
+ const res = await axios_1.default.post(apiUrl(endpoint), form, {
80
+ headers: {
81
+ ...authHeaders(),
82
+ ...form.getHeaders(),
83
+ },
84
+ });
85
+ return res.data;
86
+ }
87
+ finally {
88
+ if (isTemp)
89
+ fs_1.default.unlinkSync(resolvedPath);
90
+ }
61
91
  }
62
92
  async function ghostDownload(endpoint) {
63
93
  const res = await axios_1.default.get(apiUrl(endpoint), {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@junis/ghost-mcp",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "MCP server for using the Ghost API",
5
5
  "main": "build/server.js",
6
6
  "bin": {