create_doc
Generate and publish new documents in Yuque knowledge bases with custom titles, content, and visibility settings. Supports Markdown, HTML, and Lake formats for flexible content creation.
Instructions
在指定知识库中创建新的语雀文档,支持多种格式内容
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accessToken | No | 用于认证 API 请求的令牌 | |
| body | Yes | 文档内容,支持Markdown格式 | |
| format | No | 内容格式,可选值:markdown、html、lake,默认为 markdown | |
| namespace | Yes | 知识库的命名空间,格式为 user/repo | |
| public_level | No | 公开性,可选值:0(私密)、1(公开)、2(企业内公开),默认为 1 | |
| slug | Yes | 文档的短链接名称,用于URL路径 | |
| title | Yes | 文档标题 |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"accessToken": {
"description": "用于认证 API 请求的令牌",
"type": "string"
},
"body": {
"description": "文档内容,支持Markdown格式",
"type": "string"
},
"format": {
"description": "内容格式,可选值:markdown、html、lake,默认为 markdown",
"type": "string"
},
"namespace": {
"description": "知识库的命名空间,格式为 user/repo",
"type": "string"
},
"public_level": {
"description": "公开性,可选值:0(私密)、1(公开)、2(企业内公开),默认为 1",
"type": "number"
},
"slug": {
"description": "文档的短链接名称,用于URL路径",
"type": "string"
},
"title": {
"description": "文档标题",
"type": "string"
}
},
"required": [
"namespace",
"title",
"slug",
"body"
],
"type": "object"
}
Implementation Reference
- src/server.ts:364-397 (handler)The handler function for the 'create_doc' MCP tool, which creates a new document in a Yuque repository by delegating to YuqueService.createDoc and returns the created document.async ({ namespace, title, slug, body, format = "markdown", public_level = 1, accessToken, }) => { try { Logger.log( `Creating document "${title}" in repository: ${namespace}` ); const yuqueService = this.createYuqueService(accessToken); const doc = await yuqueService.createDoc( namespace, title, slug, body, format, public_level ); Logger.log(`Successfully created document: ${doc.title}`); return { content: [{ type: "text", text: JSON.stringify(doc, null, 2) }], }; } catch (error) { Logger.error(`Error creating doc in repo ${namespace}:`, error); return { content: [{ type: "text", text: `Error creating doc: ${error}` }], }; } }
- src/server.ts:347-362 (schema)Zod input schema defining parameters for the 'create_doc' tool.{ namespace: z.string().describe("知识库的命名空间,格式为 user/repo"), title: z.string().describe("文档标题"), slug: z.string().describe("文档的短链接名称,用于URL路径"), body: z.string().describe("文档内容,支持Markdown格式"), format: z .string() .optional() .describe("内容格式,可选值:markdown、html、lake,默认为 markdown"), public_level: z .number() .optional() .describe( "公开性,可选值:0(私密)、1(公开)、2(企业内公开),默认为 1" ), accessToken: z.string().optional().describe("用于认证 API 请求的令牌"),
- src/server.ts:345-398 (registration)Registration of the 'create_doc' tool using McpServer.tool(), including name, description, input schema, and handler."create_doc", "在指定知识库中创建新的语雀文档,支持多种格式内容", { namespace: z.string().describe("知识库的命名空间,格式为 user/repo"), title: z.string().describe("文档标题"), slug: z.string().describe("文档的短链接名称,用于URL路径"), body: z.string().describe("文档内容,支持Markdown格式"), format: z .string() .optional() .describe("内容格式,可选值:markdown、html、lake,默认为 markdown"), public_level: z .number() .optional() .describe( "公开性,可选值:0(私密)、1(公开)、2(企业内公开),默认为 1" ), accessToken: z.string().optional().describe("用于认证 API 请求的令牌"), }, async ({ namespace, title, slug, body, format = "markdown", public_level = 1, accessToken, }) => { try { Logger.log( `Creating document "${title}" in repository: ${namespace}` ); const yuqueService = this.createYuqueService(accessToken); const doc = await yuqueService.createDoc( namespace, title, slug, body, format, public_level ); Logger.log(`Successfully created document: ${doc.title}`); return { content: [{ type: "text", text: JSON.stringify(doc, null, 2) }], }; } catch (error) { Logger.error(`Error creating doc in repo ${namespace}:`, error); return { content: [{ type: "text", text: `Error creating doc: ${error}` }], }; } } );
- src/services/yuque.ts:349-365 (helper)YuqueService.createDoc method that performs the actual HTTP POST request to create a document in Yuque API.async createDoc( namespace: string, title: string, slug: string, body: string, format: string = 'markdown', public_level: number = 1 ): Promise<YuqueDoc> { const response = await this.client.post(`/repos/${namespace}/docs`, { title, slug, public: public_level, format, body, }); return response.data.data; }