create_doc
Create new documents in Yuque knowledge bases with Markdown, HTML, or lake format content, specifying visibility levels and URL slugs.
Instructions
在指定知识库中创建新的语雀文档,支持多种格式内容
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| namespace | Yes | 知识库的命名空间,格式为 user/repo | |
| title | Yes | 文档标题 | |
| slug | Yes | 文档的短链接名称,用于URL路径 | |
| body | Yes | 文档内容,支持Markdown格式 | |
| format | No | 内容格式,可选值:markdown、html、lake,默认为 markdown | |
| public_level | No | 公开性,可选值:0(私密)、1(公开)、2(企业内公开),默认为 1 | |
| accessToken | No | 用于认证 API 请求的令牌 |
Implementation Reference
- src/server.ts:364-397 (handler)The MCP tool handler function that executes the create_doc tool logic by instantiating YuqueService and calling its createDoc method.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-363 (schema)Zod input schema defining parameters for the create_doc tool: namespace, title, slug, body, format, public_level, accessToken.{ 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:344-344 (registration)Registration of the create_doc tool using McpServer.tool method.this.server.tool(
- src/server.ts:345-345 (registration)Tool name 'create_doc' specified in registration."create_doc",
- src/services/yuque.ts:349-365 (helper)YuqueService helper method that performs the actual API POST request to create a document in Yuque.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; }