@claudeink/mcp-server 0.2.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.
Files changed (2) hide show
  1. package/dist/index.js +200 -2
  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: glob4 } = await import("glob");
1256
- const yamlFiles = await glob4("accounts/*.yaml", { cwd, ignore: "accounts/_template.yaml" });
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,200 @@ 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 configs = [];
1393
+ try {
1394
+ const baseRules = await readFile6(join8(workDir, "base-rules.md"), "utf-8");
1395
+ configs.push({ type: "base_rules", name: "base", displayName: "\u901A\u7528\u5E95\u5EA7", content: baseRules });
1396
+ } catch {
1397
+ }
1398
+ try {
1399
+ const platformFiles = await glob4("platforms/*.md", { cwd: workDir });
1400
+ for (const file of platformFiles) {
1401
+ const content = await readFile6(join8(workDir, file), "utf-8");
1402
+ const name = basename2(file, ".md");
1403
+ const displayNames = {
1404
+ wechat: "\u5FAE\u4FE1\u516C\u4F17\u53F7",
1405
+ xiaohongshu: "\u5C0F\u7EA2\u4E66",
1406
+ "x-twitter": "X (Twitter)",
1407
+ toutiao: "\u5934\u6761\u53F7",
1408
+ blog: "\u4E2A\u4EBA\u535A\u5BA2"
1409
+ };
1410
+ configs.push({ type: "platform", name, displayName: displayNames[name] || name, content });
1411
+ }
1412
+ } catch {
1413
+ }
1414
+ for (const [accId, acc] of Object.entries(accounts)) {
1415
+ try {
1416
+ const content = await readFile6(join8(workDir, `accounts/${accId}.yaml`), "utf-8");
1417
+ configs.push({
1418
+ type: "account",
1419
+ name: accId,
1420
+ displayName: acc.name,
1421
+ content,
1422
+ metadata: { platform: acc.platform }
1423
+ });
1424
+ } catch {
1425
+ }
1426
+ }
1427
+ const payload = { sources, drafts, published, analytics: [], configs };
1428
+ try {
1429
+ const res = await fetch(`${config.apiBaseUrl}/api/sync/batch`, {
1430
+ method: "POST",
1431
+ headers: {
1432
+ "Content-Type": "application/json",
1433
+ "Authorization": `Bearer ${creds.token}`
1434
+ },
1435
+ body: JSON.stringify(payload)
1436
+ });
1437
+ const result = await res.json();
1438
+ if (res.ok) {
1439
+ return {
1440
+ success: true,
1441
+ message: [
1442
+ `\u2705 \u540C\u6B65\u5B8C\u6210`,
1443
+ ` \u7D20\u6750: ${sources.length} \u7BC7`,
1444
+ ` \u8349\u7A3F: ${drafts.length} \u7BC7`,
1445
+ ` \u5DF2\u53D1\u5E03: ${published.length} \u7BC7`,
1446
+ ` \u914D\u7F6E: ${configs.length} \u4E2A\uFF08\u901A\u7528\u5E95\u5EA7 + \u5E73\u53F0\u89C4\u5219 + \u8D26\u53F7\u914D\u7F6E\uFF09`,
1447
+ ` \u4E91\u7AEF\u63A5\u53D7: ${result.accepted || 0} \u6761`
1448
+ ].join("\n"),
1449
+ data: {
1450
+ sources: sources.length,
1451
+ drafts: drafts.length,
1452
+ published: published.length,
1453
+ configs: configs.length,
1454
+ accepted: result.accepted || 0
1455
+ }
1456
+ };
1457
+ } else {
1458
+ return {
1459
+ success: false,
1460
+ message: `\u540C\u6B65\u5931\u8D25: HTTP ${res.status} \u2014 ${JSON.stringify(result)}`
1461
+ };
1462
+ }
1463
+ } catch (err) {
1464
+ return {
1465
+ success: false,
1466
+ message: `\u540C\u6B65\u7F51\u7EDC\u9519\u8BEF: ${err instanceof Error ? err.message : err}`
1467
+ };
1468
+ }
1469
+ }
1470
+
1277
1471
  // src/index.ts
1278
1472
  var server = new McpServer({
1279
1473
  name: "ClaudeInk",
@@ -1367,6 +1561,10 @@ server.tool("account.create", "\u521B\u5EFA\u65B0\u8D26\u53F7", accountCreateSch
1367
1561
  const result = await accountCreate(input);
1368
1562
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1369
1563
  });
1564
+ 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) => {
1565
+ const result = await syncPush(input);
1566
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1567
+ });
1370
1568
  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
1569
  const result = await workflowInit(input);
1372
1570
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claudeink/mcp-server",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "ClaudeInk MCP Server - 自媒体多平台写作系统的本地 MCP 服务,连接 Claude 与云端后台",
5
5
  "mcpName": "io.github.weekdmond/claudeink",
6
6
  "type": "module",