Skip to main content
Glama

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
NameRequiredDescriptionDefault
namespaceYes知识库的命名空间,格式为 user/repo
idYes要更新的文档ID
titleNo文档的新标题
slugNo文档的新短链接名称
bodyNo文档的新内容,支持Markdown格式
publicNo文档的公开状态,0(私密)、1(公开)、2(企业内公开)
formatNo内容格式,可选值:markdown、html、lake
accessTokenNo用于认证 API 请求的令牌

Implementation Reference

  • 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}` }],
        };
      }
    }
  • 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}` }],
          };
        }
      }
    );
  • 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;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/HenryHaoson/Yuque-MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server