Skip to main content
Glama

get_chunk

Retrieve complete text content and metadata for a specific text chunk by providing its unique identifier. Get full text, page ranges, and document information to access segmented academic content.

Instructions

获取指定 chunk 的完整内容

根据 chunk_id 获取文本块的完整信息,包括全文、页码、所属文档等。

Args: chunk_id: chunk 的唯一标识符

Returns: chunk 的详细信息,包含: - chunk_id: chunk ID - doc_id: 所属文档 ID - text: 完整文本 - page_start/page_end: 页码范围 - has_embedding: 是否有 embedding

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chunk_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'get_chunk' tool, decorated with @mcp.tool() for automatic registration. It retrieves chunk details from the database using a SQL query and returns a structured dictionary via the ChunkDetail Pydantic model.
    @mcp.tool()
    def get_chunk(chunk_id: int) -> dict[str, Any]:
        """获取指定 chunk 的完整内容
        
        根据 chunk_id 获取文本块的完整信息,包括全文、页码、所属文档等。
        
        Args:
            chunk_id: chunk 的唯一标识符
            
        Returns:
            chunk 的详细信息,包含:
            - chunk_id: chunk ID
            - doc_id: 所属文档 ID
            - text: 完整文本
            - page_start/page_end: 页码范围
            - has_embedding: 是否有 embedding
        """
        try:
            # 查询 chunk 信息
            chunk = query_one(
                """
                SELECT 
                    c.chunk_id,
                    c.doc_id,
                    c.chunk_index,
                    c.section,
                    c.page_start,
                    c.page_end,
                    c.text,
                    c.token_count,
                    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.chunk_id = %s
                """,
                (chunk_id,)
            )
            
            if not chunk:
                return {
                    "error": f"Chunk not found: {chunk_id}",
                    "chunk_id": chunk_id,
                }
            
            return ChunkDetail(
                chunk_id=chunk["chunk_id"],
                doc_id=chunk["doc_id"],
                chunk_index=chunk["chunk_index"],
                section=chunk["section"],
                page_start=chunk["page_start"],
                page_end=chunk["page_end"],
                text=chunk["text"],
                token_count=chunk["token_count"],
                has_embedding=chunk["has_embedding"],
            ).model_dump()
            
        except Exception as e:
            return {
                "error": str(e),
                "chunk_id": chunk_id,
            }
  • Pydantic BaseModel defining the output schema/structure for the get_chunk tool response.
    class ChunkDetail(BaseModel):
        """Chunk 详细信息"""
        chunk_id: int
        doc_id: str
        chunk_index: int
        section: str | None
        page_start: int
        page_end: int
        text: str
        token_count: int | None
        has_embedding: bool
  • Invocation of register_fetch_tools(mcp) in the main MCP server setup, which registers the get_chunk tool (and other fetch tools).
    register_fetch_tools(mcp)
  • The registration function that defines and registers the get_chunk tool using @mcp.tool() decorator.
    def register_fetch_tools(mcp: FastMCP) -> None:
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It states the tool retrieves information, implying it's a read operation, but doesn't disclose behavioral traits like authentication needs, rate limits, error handling, or whether it's idempotent. The description adds minimal context beyond the basic action.

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: the first sentence states the purpose clearly, followed by elaboration and a structured Args/Returns section. It avoids unnecessary fluff, though the bilingual mix (Chinese and English) might slightly affect readability in some contexts.

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

Completeness4/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 (single parameter, read operation) and the presence of an output schema (implied by 'Returns' details), the description is reasonably complete. It explains the parameter and outlines return values, though it could benefit from more behavioral context. The output schema reduces the need for detailed return explanations.

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?

The input schema has 1 parameter with 0% description coverage, but the description compensates well: it explains 'chunk_id' as 'chunk 的唯一标识符' (the unique identifier of the chunk), adding clear semantic meaning. Since there's only one parameter and the description covers it adequately, this earns a high score despite the low schema coverage.

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: '获取指定 chunk 的完整内容' (get the complete content of a specified chunk). It specifies the resource (chunk) and action (get content), though it doesn't explicitly differentiate from sibling tools like 'get_document_chunks' or 'select_high_value_chunks' in the list. The description is specific but lacks sibling comparison.

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 any prerequisites, exclusions, or compare it to sibling tools such as 'get_document_chunks' or 'search_*' tools. Usage is implied only by the description's focus on retrieving a single chunk by ID.

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