Skip to main content
Glama

get_document_chunks

Retrieve all text chunks from a document to analyze content structure. Provides chunk IDs, page numbers, and text summaries for comprehensive document examination.

Instructions

获取指定文档的所有 chunks 列表

根据 doc_id 获取该文档的所有文本块摘要信息。

Args: doc_id: 文档的唯一标识符

Returns: chunks 列表,每个包含 chunk_id、页码和文本摘要

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
doc_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'get_document_chunks' tool. It retrieves all chunks for a given document ID from the database, providing summaries including chunk_id, index, pages, token count, snippet, and embedding status.
    @mcp.tool()
    def get_document_chunks(doc_id: str) -> dict[str, Any]:
        """获取指定文档的所有 chunks 列表
        
        根据 doc_id 获取该文档的所有文本块摘要信息。
        
        Args:
            doc_id: 文档的唯一标识符
            
        Returns:
            chunks 列表,每个包含 chunk_id、页码和文本摘要
        """
        try:
            chunks = query_all(
                """
                SELECT 
                    c.chunk_id,
                    c.chunk_index,
                    c.page_start,
                    c.page_end,
                    c.token_count,
                    LEFT(c.text, 100) as snippet,
                    CASE WHEN ce.chunk_id IS NOT NULL THEN true ELSE false END as has_embedding
                FROM chunks c
                LEFT JOIN chunk_embeddings ce ON c.chunk_id = ce.chunk_id
                WHERE c.doc_id = %s
                ORDER BY c.chunk_index
                """,
                (doc_id,)
            )
            
            return {
                "doc_id": doc_id,
                "chunk_count": len(chunks),
                "chunks": [
                    {
                        "chunk_id": c["chunk_id"],
                        "chunk_index": c["chunk_index"],
                        "page_start": c["page_start"],
                        "page_end": c["page_end"],
                        "token_count": c["token_count"],
                        "snippet": c["snippet"] + "..." if len(c["snippet"]) >= 100 else c["snippet"],
                        "has_embedding": c["has_embedding"],
                    }
                    for c in chunks
                ],
            }
            
        except Exception as e:
            return {
                "error": str(e),
                "doc_id": doc_id,
                "chunks": [],
            }
  • Registers the fetch tools module, which includes the get_document_chunks tool, on the MCP server instance.
    register_fetch_tools(mcp)
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 '所有文本块摘要信息' (all text chunk summary information), implying a read-only operation, but doesn't disclose behavioral traits like pagination, rate limits, authentication needs, error conditions, or what happens if the doc_id is invalid. This is inadequate for a tool with no annotation coverage.

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 sized and front-loaded with the main purpose. It uses a clear structure with 'Args' and 'Returns' sections, though the initial sentence is slightly redundant with the 'Args' explanation. Every sentence adds value, making it efficient.

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 low complexity (one parameter) and the presence of an output schema (which handles return values), the description is minimally complete. However, with no annotations and incomplete behavioral disclosure, it leaves gaps in understanding operational context like error handling or performance characteristics.

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

Parameters4/5

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

Schema description coverage is 0%, but the description compensates by explaining the single parameter 'doc_id' as '文档的唯一标识符' (the unique identifier of the document). This adds clear meaning beyond the schema's basic type definition, though it doesn't specify format or constraints. With only one parameter, this is sufficient for a high score.

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: '获取指定文档的所有 chunks 列表' (get all chunks list for a specified document). It specifies the verb (获取/get) and resource (chunks), though it doesn't explicitly differentiate from sibling tools like 'get_chunk' (singular) or 'rechunk_document'.

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. The description doesn't mention sibling tools like 'get_chunk' (for single chunks) or 'list_documents' (for document listing), nor does it specify prerequisites or exclusions for usage.

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/h-lu/paperlib-mcp'

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