Skip to main content
Glama

export_section_packet_v1

Generate JSON packets with evidence, paper matrices, and citations for AI-assisted academic writing and literature review automation.

Instructions

导出章节写作输入包

生成包含所有必要信息的 JSON,供 Agent 写作使用。

Args: pack_id: 证据包 ID

Returns: evidence[], paper_matrix[], claim_matrix[], doc_citations[]

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pack_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Full implementation of the export_section_packet_v1 tool handler. Queries database for pack contents, builds structured output with evidence chunks, paper metadata matrix, claim matrix, and citation info.
    @mcp.tool()
    def export_section_packet_v1(pack_id: int) -> dict[str, Any]:
        """导出章节写作输入包
    
        生成包含所有必要信息的 JSON,供 Agent 写作使用。
    
        Args:
            pack_id: 证据包 ID
    
        Returns:
            evidence[], paper_matrix[], claim_matrix[], doc_citations[]
        """
        try:
            # 获取 pack 信息
            pack = query_one(
                "SELECT pack_id, query, params_json FROM evidence_packs WHERE pack_id = %s",
                (pack_id,),
            )
            if not pack:
                return {"error": f"Pack not found: {pack_id}"}
    
            # 获取所有 chunk 内容
            chunks = query_all(
                """
                SELECT
                    epi.doc_id,
                    epi.chunk_id,
                    epi.rank,
                    c.text,
                    c.page_start,
                    c.page_end,
                    d.title,
                    d.authors,
                    d.year
                FROM evidence_pack_items epi
                JOIN chunks c ON epi.chunk_id = c.chunk_id
                JOIN documents d ON epi.doc_id = d.doc_id
                WHERE epi.pack_id = %s
                ORDER BY epi.rank
                """,
                (pack_id,),
            )
    
            # 构建 evidence 列表
            evidence = []
            doc_ids = set()
            chunk_ids = []
    
            for chunk in chunks:
                doc_ids.add(chunk["doc_id"])
                chunk_ids.append(chunk["chunk_id"])
                evidence.append({
                    "doc_id": chunk["doc_id"],
                    "chunk_id": chunk["chunk_id"],
                    "page_start": chunk["page_start"],
                    "page_end": chunk["page_end"],
                    "text": chunk["text"],
                    "title": chunk["title"],
                    "authors": chunk["authors"],
                    "year": chunk["year"],
                    "citation_anchor": f"[[chunk:{chunk['chunk_id']}]]",
                })
    
            doc_ids_list = list(doc_ids)
    
            # 构建 paper_matrix
            paper_matrix = []
            for doc_id in doc_ids_list:
                doc = query_one(
                    "SELECT doc_id, title, authors, year FROM documents WHERE doc_id = %s",
                    (doc_id,),
                )
                if doc:
                    # 获取该文档关联的实体
                    entities = query_all(
                        """
                        SELECT DISTINCT e.type, e.canonical_name
                        FROM entities e
                        JOIN mentions m ON e.entity_id = m.entity_id
                        WHERE m.doc_id = %s
                        """,
                        (doc_id,),
                    )
    
                    entity_by_type: dict[str, list[str]] = defaultdict(list)
                    for ent in entities:
                        entity_by_type[ent["type"]].append(ent["canonical_name"])
    
                    paper_matrix.append({
                        "doc_id": doc_id,
                        "title": doc["title"],
                        "authors": doc["authors"],
                        "year": doc["year"],
                        "topics": entity_by_type.get("Topic", []),
                        "measures": entity_by_type.get("MeasureProxy", []),
                        "identification_strategies": entity_by_type.get("IdentificationStrategy", []),
                        "methods": entity_by_type.get("Method", []),
                        "settings": entity_by_type.get("Setting", []),
                        "limitations": entity_by_type.get("LimitationGap", []),
                    })
    
            # 构建 claim_matrix
            claim_matrix = []
            if chunk_ids:
                claims = query_all(
                    """
                    SELECT claim_id, doc_id, chunk_id, claim_text, sign, conditions, confidence
                    FROM claims
                    WHERE chunk_id = ANY(%s)
                    ORDER BY confidence DESC
                    """,
                    (chunk_ids,),
                )
                for claim in claims:
                    claim_matrix.append({
                        "claim_id": claim["claim_id"],
                        "doc_id": claim["doc_id"],
                        "chunk_id": claim["chunk_id"],
                        "claim_text": claim["claim_text"],
                        "sign": claim["sign"],
                        "conditions": claim["conditions"] or {},
                        "confidence": claim["confidence"],
                        "citation_anchor": f"[[chunk:{claim['chunk_id']}]]",
                    })
    
            # 获取引用信息
            doc_citations = []
            for doc_id in doc_ids_list:
                citation = query_one(
                    """
                    SELECT d.doc_id, d.title, d.authors, d.year,
                           c.bibtex, c.apa
                    FROM documents d
                    LEFT JOIN citations c ON d.doc_id = c.doc_id
                    WHERE d.doc_id = %s
                    """,
                    (doc_id,),
                )
                if citation:
                    doc_citations.append({
                        "doc_id": citation["doc_id"],
                        "title": citation["title"],
                        "authors": citation["authors"],
                        "year": citation["year"],
                        "bibtex": citation["bibtex"],
                        "apa": citation["apa"],
                    })
    
            return {
                "pack_id": pack_id,
                "query": pack["query"],
                "evidence": evidence,
                "paper_matrix": paper_matrix,
                "claim_matrix": claim_matrix,
                "doc_citations": doc_citations,
                "stats": {
                    "total_chunks": len(evidence),
                    "unique_docs": len(doc_ids_list),
                    "total_claims": len(claim_matrix),
                },
            }
    
        except Exception as e:
            return {"error": str(e)}
  • Imports and calls register_review_tools(mcp) to register the review tools including export_section_packet_v1 in the main MCP server.
    from paperlib_mcp.tools.review import register_review_tools
    
    # M4 Canonicalization & Grouping 工具
    from paperlib_mcp.tools.graph_relation_canonicalize import register_graph_relation_canonicalize_tools
    from paperlib_mcp.tools.graph_claim_grouping import register_graph_claim_grouping_tools
    from paperlib_mcp.tools.graph_v12 import register_graph_v12_tools
    
    register_health_tools(mcp)
    register_import_tools(mcp)
    register_search_tools(mcp)
    register_fetch_tools(mcp)
    register_writing_tools(mcp)
    
    # 注册 M2 GraphRAG 工具
    register_graph_extract_tools(mcp)
    register_graph_canonicalize_tools(mcp)
    register_graph_community_tools(mcp)
    register_graph_summarize_tools(mcp)
    register_graph_maintenance_tools(mcp)
    
    # 注册 M3 Review 工具
    register_review_tools(mcp)
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 mentions generating JSON for Agent writing use, but doesn't specify whether this is a read-only operation, what permissions are required, if it has side effects, rate limits, or error conditions. For a tool with no annotation coverage, this leaves significant behavioral 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 three brief sections: purpose statement, parameter documentation, and return value overview. It's front-loaded with the core functionality. The 'Args' and 'Returns' sections could be integrated more smoothly, but overall it avoids unnecessary verbosity.

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 has an output schema (implied by the Returns section), the description doesn't need to fully document return values. However, with no annotations and minimal behavioral context, it provides adequate but incomplete guidance for a tool that appears to be a data export operation. The description covers the basics but leaves questions about operational constraints.

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 description includes an 'Args' section that documents the single parameter 'pack_id' as '证据包 ID' (evidence pack ID), adding semantic meaning beyond the schema's type information. However, with 0% schema description coverage and only 1 parameter, this provides basic but incomplete context—it doesn't explain format constraints or valid values for pack_id.

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: '导出章节写作输入包' (export section writing input package) and '生成包含所有必要信息的 JSON,供 Agent 写作使用' (generate JSON containing all necessary information for Agent writing use). It specifies the action (export/generate) and resource (section writing input package), though it doesn't explicitly differentiate from sibling tools like 'export_claim_matrix_grouped_v1' or 'export_evidence_matrix_v1'.

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 prerequisites, context, or compare it to sibling tools such as 'build_section_evidence_pack_v1' or 'export_claim_matrix_grouped_v1'. The agent must infer usage from the name and description alone.

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