@wenyan-md/mcp 1.0.2 → 1.0.5

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 CHANGED
@@ -2,7 +2,14 @@
2
2
 
3
3
  ![logo](data/wenyan-mcp.png)
4
4
 
5
- ## Overview
5
+ 「文颜」是一款多平台排版美化工具,让你将 Markdown 一键发布至微信公众号、知乎、今日头条等主流写作平台。
6
+
7
+ **文颜**现已推出多个版本:
8
+
9
+ * [macOS App Store 版](https://github.com/caol64/wenyan) - MAC 桌面应用
10
+ * [Windows + Linux 版](https://github.com/caol64/wenyan-pc) - 跨平台桌面应用
11
+ * [CLI 版本](https://github.com/caol64/wenyan-cli) - CI/CD 或脚本自动化发布公众号文章
12
+ * [MCP 版本](https://github.com/caol64/wenyan-mcp) - 让 AI 自动发布公众号文章
6
13
 
7
14
  文颜 MCP Server 是一个基于模型上下文协议(Model Context Protocol, MCP)的服务器组件,支持将 Markdown 格式的文章发布至微信公众号草稿箱,并使用与 [文颜](https://yuzhi.tech/wenyan) 相同的主题系统进行排版。
8
15
 
@@ -12,18 +19,26 @@ https://github.com/user-attachments/assets/2c355f76-f313-48a7-9c31-f0f69e5ec207
12
19
 
13
20
  - [让AI帮你管理公众号的排版和发布](https://babyno.top/posts/2025/06/let-ai-help-you-manage-your-gzh-layout-and-publishing/)
14
21
 
15
- 支持的主题效果预览:
16
-
17
- - [内置主题](https://yuzhi.tech/docs/wenyan/theme)
18
-
19
- ## Features
22
+ ## 功能
20
23
 
21
24
  - 列出并选择支持的文章主题
22
25
  - 使用内置主题对 Markdown 内容排版
23
26
  - 发布文章到微信公众号草稿箱
24
27
  - 自动上传本地或网络图片
25
28
 
26
- ---
29
+ ## 主题效果
30
+
31
+ 👉 [内置主题预览](https://yuzhi.tech/docs/wenyan/theme)
32
+
33
+ 文颜采用了多个开源的 Typora 主题,在此向各位作者表示感谢:
34
+
35
+ - [Orange Heart](https://github.com/evgo2017/typora-theme-orange-heart)
36
+ - [Rainbow](https://github.com/thezbm/typora-theme-rainbow)
37
+ - [Lapis](https://github.com/YiNNx/typora-theme-lapis)
38
+ - [Pie](https://github.com/kevinzhao2233/typora-theme-pie)
39
+ - [Maize](https://github.com/BEATREE/typora-maize-theme)
40
+ - [Purple](https://github.com/hliu202/typora-purple-theme)
41
+ - [物理猫-薄荷](https://github.com/sumruler/typora-theme-phycat)
27
42
 
28
43
  ## 使用方式
29
44
 
@@ -151,15 +166,11 @@ docker build --build-arg NPM_REGISTRY=https://mirrors.cloud.tencent.com/npm/ -t
151
166
  > * `WECHAT_APP_SECRET` 微信平台的 App Secret
152
167
  > * `HOST_IMAGE_PATH` 宿主机图片目录
153
168
 
154
- ---
155
-
156
169
  ## 微信公众号 IP 白名单
157
170
 
158
171
  请务必将服务器 IP 加入公众号平台的 IP 白名单,以确保上传接口调用成功。
159
172
  详细配置说明请参考:[https://yuzhi.tech/docs/wenyan/upload](https://yuzhi.tech/docs/wenyan/upload)
160
173
 
161
- ---
162
-
163
174
  ## 配置说明(Frontmatter)
164
175
 
165
176
  为了可以正确上传文章,需要在每一篇 Markdown 文章的开头添加一段`frontmatter`,提供`title`、`cover`两个字段:
@@ -177,8 +188,6 @@ cover: /Users/lei/Downloads/result_image.jpg
177
188
  * 如果正文有至少一张图片,可省略,此时将使用其中一张作为封面;
178
189
  * 如果正文无图片,则必须提供 cover。
179
190
 
180
- ---
181
-
182
191
  ## 关于图片自动上传
183
192
 
184
193
  * 支持图片路径:
@@ -186,8 +195,6 @@ cover: /Users/lei/Downloads/result_image.jpg
186
195
  * 本地路径(如:`/Users/lei/Downloads/result_image.jpg`)
187
196
  * 网络路径(如:`https://example.com/image.jpg`)
188
197
 
189
- ---
190
-
191
198
  ## 示例文章格式
192
199
 
193
200
  ```md
@@ -205,8 +212,6 @@ cover: /Users/lei/Downloads/result_image.jpg
205
212
  ![](https://mmbiz.qpic.cn/mmbiz_jpg/Jsq9IicjScDVUjkPc6O22ZMvmaZUzof5bLDjMyLg2HeAXd0icTvlqtL7oiarSlOicTtiaiacIxpVOV1EeMKl96PhRPPw/640?wx_fmt=jpeg)
206
213
  ```
207
214
 
208
- ---
209
-
210
215
  ## 如何调试
211
216
 
212
217
  使用 Inspector 进行简单调试:
@@ -235,14 +240,10 @@ npx @modelcontextprotocol/inspector
235
240
  6. 填入参数并点击 Run Tool
236
241
  7. 查看完整参数
237
242
 
238
- ---
239
-
240
243
  ## 赞助
241
244
 
242
245
  如果您觉得这个项目不错,可以给我家猫咪买点罐头吃。[喂猫❤️](https://yuzhi.tech/sponsor)
243
246
 
244
- ---
245
-
246
247
  ## License
247
248
 
248
249
  Apache License Version 2.0
package/dist/index.js ADDED
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * This is a template MCP server that implements a simple notes system.
4
+ * It demonstrates core MCP concepts like resources and tools by allowing:
5
+ * - Listing notes as resources
6
+ * - Reading individual notes
7
+ * - Creating new notes via a tool
8
+ * - Summarizing all notes via a prompt
9
+ */
10
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
11
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
12
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
13
+ import { getGzhContent } from "@wenyan-md/core/wrapper";
14
+ import { publishToDraft } from "@wenyan-md/core/publish";
15
+ import { themes } from "@wenyan-md/core/theme";
16
+ /**
17
+ * Create an MCP server with capabilities for resources (to list/read notes),
18
+ * tools (to create new notes), and prompts (to summarize notes).
19
+ */
20
+ const server = new Server({
21
+ name: "wenyan-mcp",
22
+ version: "0.1.0",
23
+ }, {
24
+ capabilities: {
25
+ resources: {},
26
+ tools: {},
27
+ prompts: {},
28
+ // logging: {},
29
+ },
30
+ });
31
+ /**
32
+ * Handler that lists available tools.
33
+ * Exposes a single "publish_article" tool that lets clients publish new article.
34
+ */
35
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
36
+ return {
37
+ tools: [
38
+ {
39
+ name: "publish_article",
40
+ description: "Format a Markdown article using a selected theme and publish it to '微信公众号'.",
41
+ inputSchema: {
42
+ type: "object",
43
+ properties: {
44
+ content: {
45
+ type: "string",
46
+ description: "The original Markdown content to publish, preserving its frontmatter (if present).",
47
+ },
48
+ theme_id: {
49
+ type: "string",
50
+ description: "ID of the theme to use (e.g., default, orangeheart, rainbow, lapis, pie, maize, purple, phycat).",
51
+ },
52
+ },
53
+ required: ["content"],
54
+ },
55
+ },
56
+ {
57
+ name: "list_themes",
58
+ description: "List the themes compatible with the 'publish_article' tool to publish an article to '微信公众号'.",
59
+ inputSchema: {
60
+ type: "object",
61
+ properties: {}
62
+ },
63
+ },
64
+ ],
65
+ };
66
+ });
67
+ /**
68
+ * Handler for the publish_article tool.
69
+ * Publish a new article with the provided title and content, and returns success message.
70
+ */
71
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
72
+ if (request.params.name === "publish_article") {
73
+ // server.sendLoggingMessage({
74
+ // level: "debug",
75
+ // data: JSON.stringify(request.params.arguments),
76
+ // });
77
+ const content = String(request.params.arguments?.content || "");
78
+ const themeId = String(request.params.arguments?.theme_id || "");
79
+ const gzhContent = await getGzhContent(content, themeId, "solarized-light", true, true);
80
+ const title = gzhContent.title ?? "this is title";
81
+ const cover = gzhContent.cover ?? "";
82
+ const response = await publishToDraft(title, gzhContent.content, cover);
83
+ return {
84
+ content: [
85
+ {
86
+ type: "text",
87
+ text: `Your article was successfully published to '公众号草稿箱'. The media ID is ${response.media_id}.`,
88
+ },
89
+ ],
90
+ };
91
+ }
92
+ else if (request.params.name === "list_themes") {
93
+ const themeResources = Object.entries(themes).map(([id, theme]) => ({
94
+ type: "text",
95
+ text: JSON.stringify({
96
+ id: theme.id,
97
+ name: theme.name,
98
+ description: theme.description
99
+ }),
100
+ }));
101
+ return {
102
+ content: themeResources,
103
+ };
104
+ }
105
+ throw new Error("Unknown tool");
106
+ });
107
+ /**
108
+ * Start the server using stdio transport.
109
+ * This allows the server to communicate via standard input/output streams.
110
+ */
111
+ async function main() {
112
+ const transport = new StdioServerTransport();
113
+ await server.connect(transport);
114
+ }
115
+ main().catch((error) => {
116
+ console.error("Server error:", error);
117
+ process.exit(1);
118
+ });
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * This is a template MCP server that implements a simple notes system.
4
+ * It demonstrates core MCP concepts like resources and tools by allowing:
5
+ * - Listing notes as resources
6
+ * - Reading individual notes
7
+ * - Creating new notes via a tool
8
+ * - Summarizing all notes via a prompt
9
+ */
10
+ export {};
package/package.json CHANGED
@@ -1,10 +1,19 @@
1
1
  {
2
2
  "name": "@wenyan-md/mcp",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
4
4
  "description": "MCP server for Wenyan, a Markdown formatting tool that allows AI assistants to apply elegant built-in themes and publish articles directly to 微信公众号.",
5
5
  "author": "Lei <caol64@gmail.com> (https://github.com/caol64)",
6
6
  "license": "Apache-2.0",
7
- "keywords": ["公众号", "markdown", "文颜", "wenyan", "wechat", "publishing", "renderer", "mcp"],
7
+ "keywords": [
8
+ "公众号",
9
+ "markdown",
10
+ "文颜",
11
+ "wenyan",
12
+ "wechat",
13
+ "publishing",
14
+ "renderer",
15
+ "mcp"
16
+ ],
8
17
  "type": "module",
9
18
  "bin": {
10
19
  "wenyan-mcp": "./dist/index.js"
@@ -12,20 +21,27 @@
12
21
  "files": [
13
22
  "dist"
14
23
  ],
15
- "scripts": {
16
- "build": "tsc -b",
17
- "watch": "tsc --watch",
18
- "inspector": "pnpx @modelcontextprotocol/inspector",
19
- "test": "pnpx vitest run",
20
- "prepublishOnly": "pnpm build"
24
+ "homepage": "https://github.com/caol64/wenyan-mcp#readme",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/caol64/wenyan-mcp.git"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/caol64/wenyan-mcp/issues"
21
31
  },
22
32
  "dependencies": {
23
33
  "@modelcontextprotocol/sdk": "0.6.0",
24
- "@wenyan-md/core": "^1.0.3"
34
+ "@wenyan-md/core": "^1.0.11"
25
35
  },
26
36
  "devDependencies": {
27
37
  "@types/node": "^20.11.24",
28
38
  "typescript": "^5.3.3",
29
39
  "vitest": "^3.2.3"
40
+ },
41
+ "scripts": {
42
+ "build": "tsc",
43
+ "watch": "tsc --watch",
44
+ "inspector": "pnpm build && node ./run-inspector.js",
45
+ "test": "pnpx vitest run"
30
46
  }
31
- }
47
+ }