update_doc
Modify existing documents in Yuque by updating titles, content, or permissions using specified document IDs and namespaces.
Instructions
更新语雀中已存在的文档,可以修改标题、内容或权限设置
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accessToken | No | 用于认证 API 请求的令牌 | |
| body | No | 文档的新内容,支持Markdown格式 | |
| format | No | 内容格式,可选值:markdown、html、lake | |
| id | Yes | 要更新的文档ID | |
| namespace | Yes | 知识库的命名空间,格式为 user/repo | |
| public | No | 文档的公开状态,0(私密)、1(公开)、2(企业内公开) | |
| slug | No | 文档的新短链接名称 | |
| title | No | 文档的新标题 |
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",
"type": "string"
},
"id": {
"description": "要更新的文档ID",
"type": "number"
},
"namespace": {
"description": "知识库的命名空间,格式为 user/repo",
"type": "string"
},
"public": {
"description": "文档的公开状态,0(私密)、1(公开)、2(企业内公开)",
"type": "number"
},
"slug": {
"description": "文档的新短链接名称",
"type": "string"
},
"title": {
"description": "文档的新标题",
"type": "string"
}
},
"required": [
"namespace",
"id"
],
"type": "object"
}
Implementation Reference
- src/server.ts:420-452 (handler)The main handler function for the 'update_doc' MCP tool. It destructures input parameters, creates a YuqueService instance, builds the updateData object from optional fields, calls yuqueService.updateDoc, and returns the updated document or error.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/server.ts:404-419 (schema)Zod input schema for the 'update_doc' tool defining parameters like namespace, id (required), and optional title, slug, body, public, format, accessToken.{ 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:401-453 (registration)Registration of the 'update_doc' tool using this.server.tool(), including name, description, input schema, and handler function.this.server.tool( "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.updateDoc helper method that performs the actual API PUT request to update the document and returns the updated YuqueDoc.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; }