feishu-md-docx-mcp 0.0.1

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.
@@ -0,0 +1 @@
1
+ import "dotenv/config";
package/dist/index.js ADDED
@@ -0,0 +1,85 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import * as lark from "@larksuiteoapi/node-sdk";
4
+ import "dotenv/config";
5
+ import * as z from "zod/v4";
6
+ // 初始化飞书客户端
7
+ const client = new lark.Client({
8
+ appId: process.env.APP_ID,
9
+ appSecret: process.env.APP_SECRET,
10
+ disableTokenCache: true,
11
+ loggerLevel: lark.LoggerLevel.error,
12
+ });
13
+ // 初始化MCP服务端
14
+ const server = new McpServer({ name: "feishu-md-docx-mcp", version: "0.0.1" });
15
+ // 注册工具
16
+ server.registerTool("create_docx", {
17
+ description: "创建一个新的飞书docx文档",
18
+ inputSchema: z.object({
19
+ title: z.string().describe("文档标题"),
20
+ }),
21
+ }, async ({ title }) => {
22
+ const res = await client.docx.v1.document.create({
23
+ data: {
24
+ title,
25
+ },
26
+ }, lark.withUserAccessToken(process.env.TOKEN));
27
+ return {
28
+ content: [{ type: "text", text: JSON.stringify(res.data) }],
29
+ isError: false,
30
+ };
31
+ });
32
+ server.registerTool("update_docx_content_with_markdown", {
33
+ description: "使用markdown内容更新docx文档内容",
34
+ inputSchema: z.object({
35
+ docx_document_id: z.string().describe("docx文档ID"),
36
+ markdown_content: z.string().describe("markdown格式的内容"),
37
+ }),
38
+ }, async ({ docx_document_id, markdown_content }) => {
39
+ // 步骤1:markdown转为blocks
40
+ const convertRes = await client.docx.v1.document.convert({
41
+ data: {
42
+ content: markdown_content,
43
+ content_type: "markdown",
44
+ },
45
+ }, lark.withUserAccessToken(process.env.TOKEN));
46
+ const { blocks, first_level_block_ids } = convertRes.data;
47
+ if (!blocks || !first_level_block_ids) {
48
+ throw new Error("转换markdown失败");
49
+ }
50
+ // 步骤2:用blocks更新文档内容
51
+ // 分批插入
52
+ const BATCH_SIZE = 500;
53
+ for (let i = 0; i < blocks.length; i += BATCH_SIZE) {
54
+ const descendants = blocks?.slice(i, i + BATCH_SIZE);
55
+ const children_id = first_level_block_ids.slice(i, i + BATCH_SIZE);
56
+ await client.docx.v1.documentBlockDescendant.create({
57
+ path: {
58
+ document_id: docx_document_id,
59
+ block_id: docx_document_id,
60
+ },
61
+ params: {
62
+ document_revision_id: -1,
63
+ },
64
+ data: {
65
+ index: -1,
66
+ children_id,
67
+ descendants,
68
+ },
69
+ }, lark.withUserAccessToken(process.env.TOKEN));
70
+ }
71
+ return {
72
+ content: [{ type: "text", text: "写入成功" }],
73
+ isError: false,
74
+ };
75
+ });
76
+ // 启动服务
77
+ async function main() {
78
+ const transport = new StdioServerTransport();
79
+ await server.connect(transport);
80
+ console.error("Mcp Server started");
81
+ }
82
+ main().catch((error) => {
83
+ console.error("Fatal error in main():", error);
84
+ process.exit(1);
85
+ });
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "feishu-md-docx-mcp",
3
+ "version": "0.0.1",
4
+ "module": "dist/index.js",
5
+ "type": "module",
6
+ "files": [
7
+ "dist/*"
8
+ ],
9
+ "typings": "dist/index.d.ts",
10
+ "keywords": [
11
+ "feishu",
12
+ "markdown",
13
+ "mcp",
14
+ "document"
15
+ ],
16
+ "author": "zengzizhao",
17
+ "description": "将本地markdown内容上传至飞书云文档的mcp服务",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/Zengzzhao/feishu-md-docx-mcp"
21
+ },
22
+ "homepage": "https://github.com/Zengzzhao/feishu-md-docx-mcp",
23
+ "bugs": "https://github.com/Zengzzhao/feishu-md-docx-mcp/issues",
24
+ "license": "ISC",
25
+ "dependencies": {
26
+ "@larksuiteoapi/node-sdk": "^1.62.1",
27
+ "@modelcontextprotocol/sdk": "^1.29.0",
28
+ "dotenv": "^17.4.2",
29
+ "zod": "^4.4.3"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^25.6.0",
33
+ "typescript": "^6.0.3"
34
+ },
35
+ "scripts": {
36
+ "build": "tsc"
37
+ }
38
+ }