@claudeink/mcp-server 0.2.0 → 0.3.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/dist/index.js +163 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1252,8 +1252,8 @@ async function workflowStatus() {
|
|
|
1252
1252
|
allOk = false;
|
|
1253
1253
|
}
|
|
1254
1254
|
try {
|
|
1255
|
-
const { glob:
|
|
1256
|
-
const yamlFiles = await
|
|
1255
|
+
const { glob: glob5 } = await import("glob");
|
|
1256
|
+
const yamlFiles = await glob5("accounts/*.yaml", { cwd, ignore: "accounts/_template.yaml" });
|
|
1257
1257
|
if (yamlFiles.length > 0) {
|
|
1258
1258
|
checks.push(`\u2705 ${yamlFiles.length} \u4E2A\u8D26\u53F7\u914D\u7F6E`);
|
|
1259
1259
|
} else {
|
|
@@ -1274,6 +1274,163 @@ async function workflowStatus() {
|
|
|
1274
1274
|
};
|
|
1275
1275
|
}
|
|
1276
1276
|
|
|
1277
|
+
// src/tools/sync.ts
|
|
1278
|
+
import { z as z7 } from "zod";
|
|
1279
|
+
import { readFile as readFile6, stat as stat2 } from "fs/promises";
|
|
1280
|
+
import { join as join8, basename as basename2, extname as extname2 } from "path";
|
|
1281
|
+
import matter3 from "gray-matter";
|
|
1282
|
+
import { glob as glob4 } from "glob";
|
|
1283
|
+
var syncPushSchema = z7.object({
|
|
1284
|
+
workDir: z7.string().optional().describe("\u5DE5\u4F5C\u76EE\u5F55\uFF08\u9ED8\u8BA4\u4F7F\u7528\u914D\u7F6E\u4E2D\u7684 workflowDir\uFF09")
|
|
1285
|
+
});
|
|
1286
|
+
async function syncPush(input) {
|
|
1287
|
+
const config = await getConfig();
|
|
1288
|
+
const creds = await getCredentials();
|
|
1289
|
+
if (!creds?.token) {
|
|
1290
|
+
return { success: false, message: "\u672A\u6FC0\u6D3B\uFF0C\u8BF7\u5148\u4F7F\u7528 auth.activate \u6FC0\u6D3B License" };
|
|
1291
|
+
}
|
|
1292
|
+
const workDir = input.workDir || config.workflowDir;
|
|
1293
|
+
if (!workDir) {
|
|
1294
|
+
return { success: false, message: "\u672A\u8BBE\u7F6E\u5DE5\u4F5C\u76EE\u5F55\uFF0C\u8BF7\u5728 config.json \u4E2D\u914D\u7F6E workflowDir" };
|
|
1295
|
+
}
|
|
1296
|
+
const sources = [];
|
|
1297
|
+
const drafts = [];
|
|
1298
|
+
const published = [];
|
|
1299
|
+
try {
|
|
1300
|
+
const sourceFiles = await glob4("sources/**/*.md", { cwd: workDir });
|
|
1301
|
+
for (const file of sourceFiles) {
|
|
1302
|
+
try {
|
|
1303
|
+
const raw = await readFile6(join8(workDir, file), "utf-8");
|
|
1304
|
+
const { data } = matter3(raw);
|
|
1305
|
+
const id = basename2(file, extname2(file));
|
|
1306
|
+
sources.push({
|
|
1307
|
+
id,
|
|
1308
|
+
title: data.title || id,
|
|
1309
|
+
source: data.source || "unknown",
|
|
1310
|
+
tags: Array.isArray(data.tags) ? data.tags : [],
|
|
1311
|
+
sourceUrl: data.url || null,
|
|
1312
|
+
createdAt: data.published || (/* @__PURE__ */ new Date()).toISOString()
|
|
1313
|
+
});
|
|
1314
|
+
} catch {
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
} catch {
|
|
1318
|
+
}
|
|
1319
|
+
const accounts = {};
|
|
1320
|
+
try {
|
|
1321
|
+
const yamlFiles = await glob4("accounts/*.yaml", { cwd: workDir, ignore: "accounts/_template.yaml" });
|
|
1322
|
+
for (const file of yamlFiles) {
|
|
1323
|
+
try {
|
|
1324
|
+
const content = await readFile6(join8(workDir, file), "utf-8");
|
|
1325
|
+
const nameMatch = content.match(/^name:\s*"?([^"\n]+)"?/m);
|
|
1326
|
+
const idMatch = content.match(/^id:\s*"?([^"\n]+)"?/m);
|
|
1327
|
+
const platformMatch = content.match(/^platform:\s*"?([^"\n]+)"?/m);
|
|
1328
|
+
const draftsMatch = content.match(/drafts:\s*"?([^"\n]+)"?/m);
|
|
1329
|
+
const publishedMatch = content.match(/published:\s*"?([^"\n]+)"?/m);
|
|
1330
|
+
if (idMatch && nameMatch) {
|
|
1331
|
+
const id = idMatch[1].trim();
|
|
1332
|
+
const name = nameMatch[1].trim();
|
|
1333
|
+
const platform = platformMatch?.[1]?.trim() || "unknown";
|
|
1334
|
+
const dp = (draftsMatch?.[1] || `accounts/${id}/drafts/`).replace("{id}", id).trim();
|
|
1335
|
+
const pp = (publishedMatch?.[1] || `accounts/${id}/published/`).replace("{id}", id).trim();
|
|
1336
|
+
accounts[id] = { name, platform, draftsPath: dp, publishedPath: pp };
|
|
1337
|
+
}
|
|
1338
|
+
} catch {
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
} catch {
|
|
1342
|
+
}
|
|
1343
|
+
for (const [accId, acc] of Object.entries(accounts)) {
|
|
1344
|
+
try {
|
|
1345
|
+
const draftFiles = await glob4("**/*.md", { cwd: join8(workDir, acc.draftsPath) });
|
|
1346
|
+
for (const file of draftFiles) {
|
|
1347
|
+
try {
|
|
1348
|
+
const fullPath = join8(workDir, acc.draftsPath, file);
|
|
1349
|
+
const raw = await readFile6(fullPath, "utf-8");
|
|
1350
|
+
const { data, content } = matter3(raw);
|
|
1351
|
+
const fileStat = await stat2(fullPath);
|
|
1352
|
+
const id = basename2(file, extname2(file));
|
|
1353
|
+
drafts.push({
|
|
1354
|
+
id,
|
|
1355
|
+
account: acc.name,
|
|
1356
|
+
platform: acc.platform,
|
|
1357
|
+
title: data.title || id,
|
|
1358
|
+
status: data.status || "draft",
|
|
1359
|
+
wordCount: content.trim().length,
|
|
1360
|
+
tags: Array.isArray(data.tags) ? data.tags : [],
|
|
1361
|
+
createdAt: data.created || fileStat.birthtime.toISOString(),
|
|
1362
|
+
updatedAt: fileStat.mtime.toISOString()
|
|
1363
|
+
});
|
|
1364
|
+
} catch {
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
} catch {
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
for (const [accId, acc] of Object.entries(accounts)) {
|
|
1371
|
+
try {
|
|
1372
|
+
const pubFiles = await glob4("**/*.md", { cwd: join8(workDir, acc.publishedPath) });
|
|
1373
|
+
for (const file of pubFiles) {
|
|
1374
|
+
try {
|
|
1375
|
+
const raw = await readFile6(join8(workDir, acc.publishedPath, file), "utf-8");
|
|
1376
|
+
const { data } = matter3(raw);
|
|
1377
|
+
const id = basename2(file, extname2(file));
|
|
1378
|
+
published.push({
|
|
1379
|
+
id,
|
|
1380
|
+
account: acc.name,
|
|
1381
|
+
platform: acc.platform,
|
|
1382
|
+
title: data.title || id,
|
|
1383
|
+
platformUrl: data.url || data.platform_url || null,
|
|
1384
|
+
publishedAt: data.published_at || data.publishedAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
1385
|
+
});
|
|
1386
|
+
} catch {
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
} catch {
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
const payload = { sources, drafts, published, analytics: [] };
|
|
1393
|
+
try {
|
|
1394
|
+
const res = await fetch(`${config.apiBaseUrl}/api/sync/batch`, {
|
|
1395
|
+
method: "POST",
|
|
1396
|
+
headers: {
|
|
1397
|
+
"Content-Type": "application/json",
|
|
1398
|
+
"Authorization": `Bearer ${creds.token}`
|
|
1399
|
+
},
|
|
1400
|
+
body: JSON.stringify(payload)
|
|
1401
|
+
});
|
|
1402
|
+
const result = await res.json();
|
|
1403
|
+
if (res.ok) {
|
|
1404
|
+
return {
|
|
1405
|
+
success: true,
|
|
1406
|
+
message: [
|
|
1407
|
+
`\u2705 \u540C\u6B65\u5B8C\u6210`,
|
|
1408
|
+
` \u7D20\u6750: ${sources.length} \u7BC7`,
|
|
1409
|
+
` \u8349\u7A3F: ${drafts.length} \u7BC7`,
|
|
1410
|
+
` \u5DF2\u53D1\u5E03: ${published.length} \u7BC7`,
|
|
1411
|
+
` \u4E91\u7AEF\u63A5\u53D7: ${result.accepted || 0} \u6761`
|
|
1412
|
+
].join("\n"),
|
|
1413
|
+
data: {
|
|
1414
|
+
sources: sources.length,
|
|
1415
|
+
drafts: drafts.length,
|
|
1416
|
+
published: published.length,
|
|
1417
|
+
accepted: result.accepted || 0
|
|
1418
|
+
}
|
|
1419
|
+
};
|
|
1420
|
+
} else {
|
|
1421
|
+
return {
|
|
1422
|
+
success: false,
|
|
1423
|
+
message: `\u540C\u6B65\u5931\u8D25: HTTP ${res.status} \u2014 ${JSON.stringify(result)}`
|
|
1424
|
+
};
|
|
1425
|
+
}
|
|
1426
|
+
} catch (err) {
|
|
1427
|
+
return {
|
|
1428
|
+
success: false,
|
|
1429
|
+
message: `\u540C\u6B65\u7F51\u7EDC\u9519\u8BEF: ${err instanceof Error ? err.message : err}`
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1277
1434
|
// src/index.ts
|
|
1278
1435
|
var server = new McpServer({
|
|
1279
1436
|
name: "ClaudeInk",
|
|
@@ -1367,6 +1524,10 @@ server.tool("account.create", "\u521B\u5EFA\u65B0\u8D26\u53F7", accountCreateSch
|
|
|
1367
1524
|
const result = await accountCreate(input);
|
|
1368
1525
|
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1369
1526
|
});
|
|
1527
|
+
server.tool("sync.push", "\u5C06\u672C\u5730\u7D20\u6750\u3001\u8349\u7A3F\u3001\u5DF2\u53D1\u5E03\u6587\u7AE0\u7684\u5143\u6570\u636E\u540C\u6B65\u5230 ClaudeInk \u4E91\u7AEF\u63A7\u5236\u53F0", syncPushSchema.shape, async (input) => {
|
|
1528
|
+
const result = await syncPush(input);
|
|
1529
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1530
|
+
});
|
|
1370
1531
|
server.tool("workflow.init", "\u521D\u59CB\u5316\u5199\u4F5C\u5DE5\u4F5C\u6D41\uFF08\u91CA\u653E\u4E09\u5C42\u914D\u7F6E + \u5E73\u53F0\u89C4\u5219 + \u8D26\u53F7\u6A21\u677F + \u722C\u866B\u5DE5\u5177\u5230\u5DE5\u4F5C\u76EE\u5F55\uFF09", workflowInitSchema.shape, async (input) => {
|
|
1371
1532
|
const result = await workflowInit(input);
|
|
1372
1533
|
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|