Skip to main content
Glama

get_doc_chunks_info

Retrieve document chunk metadata including total chunks and character counts per chunk from Yuque knowledge bases to analyze content structure and optimize processing.

Instructions

获取文档的分块元信息,包括总块数、每块的字符数等

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
namespaceYes知识库的命名空间,格式为 user/repo
slugYes文档的唯一标识或短链接名称
chunk_sizeNo分块大小(字符数),默认为100000
accessTokenNo用于认证 API 请求的令牌

Implementation Reference

  • src/server.ts:742-831 (registration)
    Registration of the 'get_doc_chunks_info' MCP tool using McpServer.tool(), including inline schema and handler function.
    this.server.tool(
      "get_doc_chunks_info",
      "获取文档的分块元信息,包括总块数、每块的字符数等",
      {
        namespace: z.string().describe("知识库的命名空间,格式为 user/repo"),
        slug: z.string().describe("文档的唯一标识或短链接名称"),
        chunk_size: z
          .number()
          .optional()
          .describe("分块大小(字符数),默认为100000"),
        accessToken: z.string().optional().describe("用于认证 API 请求的令牌"),
      },
      async ({ namespace, slug, chunk_size = 100000, accessToken }) => {
        try {
          Logger.log(
            `Fetching document chunk info for ${slug} from repository: ${namespace}`
          );
          const yuqueService = this.createYuqueService(accessToken);
          const doc = await yuqueService.getDoc(namespace, slug);
    
          // 将整个文档转换为JSON字符串来评估总长度
          const fullDocString = JSON.stringify(doc, null, 2);
    
          // 计算会产生多少块
          const overlapSize = 200;
          let totalChunks = 1;
    
          if (fullDocString.length > chunk_size) {
            // 简单计算分块数量,考虑重叠
            // 公式:向上取整((总长度 - 重叠大小) / (块大小 - 重叠大小))
            totalChunks = Math.ceil(
              (fullDocString.length - overlapSize) / (chunk_size - overlapSize)
            );
          }
    
          // 构建分块元信息对象
          const chunksInfo = {
            document_id: doc.id,
            title: doc.title,
            total_chunks: totalChunks,
            total_length: fullDocString.length,
            chunk_size: chunk_size,
            overlap_size: overlapSize,
            estimated_chunks: Array.from(
              { length: totalChunks },
              (_, index) => {
                // 估计每个块的起始和结束位置
                const startPosition =
                  index === 0 ? 0 : index * (chunk_size - overlapSize);
                const endPosition = Math.min(
                  startPosition + chunk_size,
                  fullDocString.length
                );
    
                return {
                  index: index,
                  title: `${doc.title} [部分 ${index + 1}/${totalChunks}]`,
                  approximate_start: startPosition,
                  approximate_end: endPosition,
                  approximate_length: endPosition - startPosition,
                  how_to_get: `使用 get_doc 工具,指定 chunk_index=${index}`,
                };
              }
            ),
          };
    
          Logger.log(
            `Document would be split into ${totalChunks} chunks with size ${chunk_size}`
          );
          return {
            content: [
              { type: "text", text: JSON.stringify(chunksInfo, null, 2) },
            ],
          };
        } catch (error) {
          Logger.error(
            `Error fetching doc chunks info for ${slug} from repo ${namespace}:`,
            error
          );
          return {
            content: [
              {
                type: "text",
                text: `Error fetching doc chunks info: ${error}`,
              },
            ],
          };
        }
      }
    );
  • The core handler function that fetches the document content via YuqueService, estimates the number of chunks based on JSON string length, and returns detailed chunk metadata.
    async ({ namespace, slug, chunk_size = 100000, accessToken }) => {
      try {
        Logger.log(
          `Fetching document chunk info for ${slug} from repository: ${namespace}`
        );
        const yuqueService = this.createYuqueService(accessToken);
        const doc = await yuqueService.getDoc(namespace, slug);
    
        // 将整个文档转换为JSON字符串来评估总长度
        const fullDocString = JSON.stringify(doc, null, 2);
    
        // 计算会产生多少块
        const overlapSize = 200;
        let totalChunks = 1;
    
        if (fullDocString.length > chunk_size) {
          // 简单计算分块数量,考虑重叠
          // 公式:向上取整((总长度 - 重叠大小) / (块大小 - 重叠大小))
          totalChunks = Math.ceil(
            (fullDocString.length - overlapSize) / (chunk_size - overlapSize)
          );
        }
    
        // 构建分块元信息对象
        const chunksInfo = {
          document_id: doc.id,
          title: doc.title,
          total_chunks: totalChunks,
          total_length: fullDocString.length,
          chunk_size: chunk_size,
          overlap_size: overlapSize,
          estimated_chunks: Array.from(
            { length: totalChunks },
            (_, index) => {
              // 估计每个块的起始和结束位置
              const startPosition =
                index === 0 ? 0 : index * (chunk_size - overlapSize);
              const endPosition = Math.min(
                startPosition + chunk_size,
                fullDocString.length
              );
    
              return {
                index: index,
                title: `${doc.title} [部分 ${index + 1}/${totalChunks}]`,
                approximate_start: startPosition,
                approximate_end: endPosition,
                approximate_length: endPosition - startPosition,
                how_to_get: `使用 get_doc 工具,指定 chunk_index=${index}`,
              };
            }
          ),
        };
    
        Logger.log(
          `Document would be split into ${totalChunks} chunks with size ${chunk_size}`
        );
        return {
          content: [
            { type: "text", text: JSON.stringify(chunksInfo, null, 2) },
          ],
        };
      } catch (error) {
        Logger.error(
          `Error fetching doc chunks info for ${slug} from repo ${namespace}:`,
          error
        );
        return {
          content: [
            {
              type: "text",
              text: `Error fetching doc chunks info: ${error}`,
            },
          ],
        };
      }
    }
  • Input schema defined with Zod validators for the tool parameters: namespace, slug, optional chunk_size and accessToken.
    {
      namespace: z.string().describe("知识库的命名空间,格式为 user/repo"),
      slug: z.string().describe("文档的唯一标识或短链接名称"),
      chunk_size: z
        .number()
        .optional()
        .describe("分块大小(字符数),默认为100000"),
      accessToken: z.string().optional().describe("用于认证 API 请求的令牌"),
    },
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states it retrieves metadata (implying read-only), but doesn't disclose behavioral traits like authentication requirements (implied by 'accessToken' parameter but not described), rate limits, error conditions, or whether it's idempotent. For a tool with no annotations, this is a significant gap in transparency.

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 a single, efficient sentence in Chinese that front-loads the core purpose. It avoids unnecessary words, though it could be slightly more structured (e.g., separating purpose from details). Every part earns its place, making it appropriately concise.

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

Completeness2/5

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

Given no annotations and no output schema, the description is incomplete. It doesn't explain the return format (e.g., structure of metadata), error handling, or dependencies like authentication. For a tool with 4 parameters and no structured output, more context is needed to guide effective use.

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?

Schema description coverage is 100%, so the schema already documents all parameters. The description doesn't add meaning beyond the schema, such as explaining relationships between parameters (e.g., how 'namespace' and 'slug' identify a document) or usage examples. Baseline 3 is appropriate as the schema does the heavy lifting.

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 action ('获取' - get/retrieve) and the resource ('文档的分块元信息' - document chunk metadata), specifying what information is returned (total chunks, character count per chunk). It distinguishes from siblings like 'get_doc' (full document) and 'search' (search functionality), though not explicitly named. The purpose is specific but could be more precise about differentiation.

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?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing an existing document), exclusions, or comparisons to siblings like 'get_doc' (for full content) or 'get_repo_docs' (for listing). The description implies usage for metadata analysis but lacks explicit context.

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/HenryHaoson/Yuque-MCP-Server'

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