@wenyan-md/mcp 1.0.2 → 1.0.3
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.d.ts.map +1 -0
- package/dist/index.js +118 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;GAOG"}
|
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);
|
|
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
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wenyan-md/mcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
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",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"dist"
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
|
-
"build": "tsc
|
|
16
|
+
"build": "tsc",
|
|
17
17
|
"watch": "tsc --watch",
|
|
18
18
|
"inspector": "pnpx @modelcontextprotocol/inspector",
|
|
19
19
|
"test": "pnpx vitest run",
|