update_doc
Modify existing documents in Yuque knowledge bases by updating titles, content, or access permissions using document IDs and namespaces.
Instructions
更新语雀中已存在的文档,可以修改标题、内容或权限设置
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| namespace | Yes | 知识库的命名空间,格式为 user/repo | |
| id | Yes | 要更新的文档ID | |
| title | No | 文档的新标题 | |
| slug | No | 文档的新短链接名称 | |
| body | No | 文档的新内容,支持Markdown格式 | |
| public | No | 文档的公开状态,0(私密)、1(公开)、2(企业内公开) | |
| format | No | 内容格式,可选值:markdown、html、lake | |
| accessToken | No | 用于认证 API 请求的令牌 |
Implementation Reference
- src/server.ts:421-452 (handler)MCP tool handler for 'update_doc' that prepares update data and delegates to YuqueService.updateDoc, handles errors and formats response.namespace, id, title, slug, body, public: publicLevel, format, accessToken, }) => { try { Logger.log(`Updating document ${id} in repository: ${namespace}`); const yuqueService = this.createYuqueService(accessToken); const updateData: any = {}; if (title !== undefined) updateData.title = title; if (slug !== undefined) updateData.slug = slug; if (body !== undefined) updateData.body = body; if (publicLevel !== undefined) updateData.public = publicLevel; if (format !== undefined) updateData.format = format; const doc = await yuqueService.updateDoc(namespace, id, updateData); Logger.log(`Successfully updated document: ${doc.title}`); return { content: [{ type: "text", text: JSON.stringify(doc, null, 2) }], }; } catch (error) { Logger.error(`Error updating doc ${id} in repo ${namespace}:`, error); return { content: [{ type: "text", text: `Error updating doc: ${error}` }], }; } }
- src/server.ts:405-419 (schema)Zod input schema defining parameters for the update_doc tool.namespace: z.string().describe("知识库的命名空间,格式为 user/repo"), id: z.number().describe("要更新的文档ID"), title: z.string().optional().describe("文档的新标题"), slug: z.string().optional().describe("文档的新短链接名称"), body: z.string().optional().describe("文档的新内容,支持Markdown格式"), public: z .number() .optional() .describe("文档的公开状态,0(私密)、1(公开)、2(企业内公开)"), format: z .string() .optional() .describe("内容格式,可选值:markdown、html、lake"), accessToken: z.string().optional().describe("用于认证 API 请求的令牌"), },
- src/server.ts:402-453 (registration)Registration of the 'update_doc' tool using McpServer.tool() method, including name, description, schema, and handler."update_doc", "更新语雀中已存在的文档,可以修改标题、内容或权限设置", { namespace: z.string().describe("知识库的命名空间,格式为 user/repo"), id: z.number().describe("要更新的文档ID"), title: z.string().optional().describe("文档的新标题"), slug: z.string().optional().describe("文档的新短链接名称"), body: z.string().optional().describe("文档的新内容,支持Markdown格式"), public: z .number() .optional() .describe("文档的公开状态,0(私密)、1(公开)、2(企业内公开)"), format: z .string() .optional() .describe("内容格式,可选值:markdown、html、lake"), accessToken: z.string().optional().describe("用于认证 API 请求的令牌"), }, async ({ namespace, id, title, slug, body, public: publicLevel, format, accessToken, }) => { try { Logger.log(`Updating document ${id} in repository: ${namespace}`); const yuqueService = this.createYuqueService(accessToken); const updateData: any = {}; if (title !== undefined) updateData.title = title; if (slug !== undefined) updateData.slug = slug; if (body !== undefined) updateData.body = body; if (publicLevel !== undefined) updateData.public = publicLevel; if (format !== undefined) updateData.format = format; const doc = await yuqueService.updateDoc(namespace, id, updateData); Logger.log(`Successfully updated document: ${doc.title}`); return { content: [{ type: "text", text: JSON.stringify(doc, null, 2) }], }; } catch (error) { Logger.error(`Error updating doc ${id} in repo ${namespace}:`, error); return { content: [{ type: "text", text: `Error updating doc: ${error}` }], }; } } );
- src/services/yuque.ts:367-380 (helper)YuqueService helper method that makes the actual PUT API request to update the document in Yuque.async updateDoc( namespace: string, id: number, data: { title?: string; slug?: string; body?: string; public?: number; format?: string; } ): Promise<YuqueDoc> { const response = await this.client.put(`/repos/${namespace}/docs/${id}`, data); return response.data.data; }