Skip to main content
Glama

列出知识库文档

list-yuque-docs

Retrieve all documents from a specified Yuque knowledge base, returning titles, slugs, and update times for organized content management.

Instructions

列出指定知识库中的所有文档。

返回文档列表,包括标题、slug、更新时间等基本信息。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
namespaceNo知识库命名空间 (例如: username/repo),如果未提供则使用默认命名空间

Implementation Reference

  • The primary handler function for executing the 'list-yuque-docs' tool. It processes the input namespace, validates it, fetches book metadata via API, scrapes the document list using browser automation, formats the output as a markdown list, and returns it as MCP content.
    async ({ namespace }) => {
      try {
        const finalNamespace = namespace || YUQUE_CONFIG.namespace;
    
        if (!finalNamespace) {
          return {
            content: [
              {
                type: "text",
                text: `错误: 请提供知识库命名空间。\n\n示例: "username/repo"`,
              },
            ],
          };
        }
    
        if (!isValidNamespace(finalNamespace)) {
          return {
            content: [
              {
                type: "text",
                text: `错误: 命名空间格式无效。\n\n命名空间应该是 "username/repo" 的格式。`,
              },
            ],
          };
        }
    
        // 获取知识库信息
        const book = await fetchYuqueBook(finalNamespace, YUQUE_CONFIG);
        if (!book) {
          return {
            content: [
              {
                type: "text",
                text: `错误: 无法获取知识库 ${finalNamespace}。\n\n请检查命名空间是否正确,以及是否有访问权限。`,
              },
            ],
          };
        }
    
        // 获取文档列表(使用无头浏览器)
        const docs = await listYuqueDocsByBrowser(finalNamespace, YUQUE_CONFIG);
    
        if (docs.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: `知识库 "${book.name}" 暂无文档。`,
              },
            ],
          };
        }
    
        // 格式化输出
        let output = `# 知识库文档列表\n\n`;
        output += `**知识库**: ${book.name}\n`;
        output += `**命名空间**: ${book.namespace}\n`;
        output += `**文档总数**: ${docs.length}\n\n`;
        output += `---\n\n`;
    
        docs.forEach((doc, index) => {
          output += formatDocListItem(doc, index + 1);
        });
    
        return {
          content: [
            {
              type: "text",
              text: output,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `错误: ${error instanceof Error ? error.message : "未知错误"}`,
            },
          ],
        };
      }
    }
  • Input schema definition for the tool, including title, description, and Zod schema for optional 'namespace' parameter.
      {
        title: "列出知识库文档",
        description: `列出指定知识库中的所有文档。
    
    返回文档列表,包括标题、slug、更新时间等基本信息。`,
        inputSchema: {
          namespace: z
            .string()
            .optional()
            .describe("知识库命名空间 (例如: username/repo),如果未提供则使用默认命名空间"),
        },
  • src/index.ts:396-397 (registration)
    The server.registerTool call that registers the 'list-yuque-docs' tool with its schema and handler.
    server.registerTool(
      "list-yuque-docs",
  • Core helper function that uses Puppeteer browser automation to scrape the Yuque knowledge base page for the list of documents, parsing links to extract titles and slugs.
    export async function listYuqueDocsByBrowser(
      namespace: string,
      config: YuqueConfig
    ): Promise<YuqueDocListItem[]> {
      let page = null;
      try {
        const browserInstance = await getBrowser();
        page = await browserInstance.newPage();
    
        // 设置 Cookie
        const domain = new URL(config.baseUrl).hostname;
        const cookies = parseCookies(config.cookie, domain);
        await page.setCookie(...cookies);
    
        // 访问知识库页面
        const url = `${config.baseUrl}/${namespace}`;
    
        await page.goto(url, {
          waitUntil: "networkidle2",
          timeout: 30000,
        });
    
        // 等待文档列表加载
        try {
          await page.waitForSelector(".book-item, .doc-item, a[href*='/" + namespace + "/']", { timeout: 10000 });
        } catch (e) {
          // 超时后继续尝试提取
        }
    
        // 提取文档列表
        const docs: any[] = await page.evaluate(() => {
          const items: any[] = [];
          // @ts-ignore
          const links = document.querySelectorAll('a[href]');
          
          links.forEach((link: any) => {
            const href = link.getAttribute('href');
            const text = link.textContent?.trim();
            
            // 匹配知识库文档链接
            if (href && text && href.includes('/') && !href.startsWith('http') && !href.includes('?')) {
              const parts = href.split('/').filter((p: string) => p);
              if (parts.length >= 3) {
                items.push({
                  title: text,
                  slug: parts[parts.length - 1],
                  href: href,
                });
              }
            }
          });
          
          return items;
        });
    
        // 去重
        const uniqueDocs = Array.from(
          new Map(docs.map((doc: any) => [doc.slug, doc])).values()
        );
    
        // 转换为标准格式
        return uniqueDocs.map((doc, index) => ({
          id: index,
          slug: doc.slug,
          title: doc.title,
          description: "",
          user_id: 0,
          book_id: 0,
          format: "markdown",
          public: 1,
          status: 1,
          created_at: new Date().toISOString(),
          updated_at: new Date().toISOString(),
          published_at: new Date().toISOString(),
          word_count: 0,
          cover: null,
          hits: 0,
          likes_count: 0,
          comments_count: 0,
        }));
      } catch (error) {
        // 获取失败,返回空数组
        return [];
      } finally {
        if (page) {
          await page.close();
        }
      }
    }
  • Utility function to format each document item in the list as a markdown bullet list with key details like title, slug, word count, update time, etc.
    export function formatDocListItem(doc: YuqueDocListItem, index?: number): string {
      let output = "";
      if (index !== undefined) {
        output += `## ${index}. `;
      }
      output += `${doc.title}\n\n`;
      output += `- **Slug**: ${doc.slug}\n`;
      output += `- **格式**: ${doc.format}\n`;
      output += `- **字数**: ${doc.word_count}\n`;
      output += `- **更新时间**: ${new Date(doc.updated_at).toLocaleString("zh-CN")}\n`;
      output += `- **浏览量**: ${doc.hits}\n`;
    
      if (doc.description) {
        output += `- **描述**: ${doc.description}\n`;
      }
    
      output += `\n`;
    
      return output;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool returns a list with basic information (title, slug, update time), which is helpful. However, it doesn't disclose important behavioral traits like whether this is a read-only operation, pagination behavior, rate limits, authentication requirements, error conditions, or what happens when namespace isn't provided (though the schema mentions default namespace). For a list operation with zero annotation coverage, this leaves significant gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately concise with two sentences that directly address purpose and return value. The first sentence states what the tool does, and the second describes the return format. There's no wasted text or unnecessary elaboration. However, it could be slightly more front-loaded by integrating the return information into the purpose statement for even tighter structure.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (list operation with one optional parameter), no annotations, and no output schema, the description is minimally adequate. It covers the basic purpose and return format but lacks important contextual information about behavioral traits, usage guidelines, and error handling. The absence of output schema means the description should ideally provide more detail about the return structure, but it only mentions basic fields without format or examples.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with the single parameter 'namespace' well-documented in the schema. The description doesn't add any parameter-specific information beyond what's in the schema. It mentions '指定知识库' (specified knowledge base) which aligns with the namespace parameter, but provides no additional context about format, examples, or usage. With high schema coverage, the baseline of 3 is appropriate as the description doesn't compensate but doesn't need to.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('列出' meaning 'list') and resource ('指定知识库中的所有文档' meaning 'all documents in the specified knowledge base'). It distinguishes from sibling tools like 'get-yuque-doc' (retrieves a single document) and 'search-yuque-docs' (searches documents), but doesn't explicitly differentiate from 'get-yuque-toc' (which might list table of contents). The purpose is clear but sibling differentiation could be more explicit.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to prefer 'list-yuque-docs' over 'search-yuque-docs' for filtering, or when 'get-yuque-toc' might be more appropriate. There's no discussion of prerequisites, context, or exclusions. The only implied usage is when you want to list all documents in a knowledge base, but no comparative guidance is given.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/saoqixiaomm/yuque-mcp'

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