Skip to main content
Glama

draft_section

Generate specific sections of academic literature reviews using evidence packages. Draft methodology, findings, or gaps sections with proper citations for iterative writing.

Instructions

生成综述特定章节

基于证据包,只生成指定章节的内容。适合迭代写作某个特定部分。

Args: pack_id: 证据包 ID section: 章节类型,如 "methodology"、"findings"、"gaps" 等 outline_style: 大纲样式,默认 "econ_finance_canonical"

Returns: 章节内容和引用列表

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pack_idYes
sectionYes
outline_styleNoecon_finance_canonical

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'draft_section' tool. It generates a specific section of a literature review using keyword matching from an evidence pack, formats content with citations, and returns structured output.
    @mcp.tool()
    def draft_section(
        pack_id: int,
        section: str,
        outline_style: str = "econ_finance_canonical",
    ) -> dict[str, Any]:
        """生成综述特定章节
        
        基于证据包,只生成指定章节的内容。适合迭代写作某个特定部分。
        
        Args:
            pack_id: 证据包 ID
            section: 章节类型,如 "methodology"、"findings"、"gaps" 等
            outline_style: 大纲样式,默认 "econ_finance_canonical"
            
        Returns:
            章节内容和引用列表
        """
        try:
            # 获取证据包
            pack = get_evidence_pack(pack_id)
            if not pack:
                return {
                    "error": f"Evidence pack not found: {pack_id}",
                    "pack_id": pack_id,
                }
            
            # 获取模板
            template = OUTLINE_TEMPLATES.get(outline_style, OUTLINE_TEMPLATES["general"])
            
            # 找到对应章节
            section_template = None
            for s in template["sections"]:
                if s["id"] == section:
                    section_template = s
                    break
            
            if not section_template:
                available_sections = [s["id"] for s in template["sections"]]
                return {
                    "error": f"Section '{section}' not found. Available: {available_sections}",
                    "pack_id": pack_id,
                    "section": section,
                }
            
            # 获取文档元数据
            doc_ids = list(set(item.doc_id for item in pack.items))
            doc_metadata: dict[str, dict] = {}
            for doc_id in doc_ids:
                doc = query_one(
                    "SELECT doc_id, title, authors, year FROM documents WHERE doc_id = %s",
                    (doc_id,)
                )
                if doc:
                    doc_metadata[doc_id] = {
                        "doc_id": doc["doc_id"],
                        "title": doc["title"] or "Untitled",
                        "authors": doc["authors"] or "Unknown",
                        "year": doc["year"],
                    }
            
            # 筛选与章节相关的证据
            keywords = section_template.get("keywords", [])
            relevant_items = []
            
            for item in pack.items:
                text_lower = item.text.lower()
                match_count = sum(1 for kw in keywords if kw.lower() in text_lower)
                if match_count > 0:
                    relevant_items.append((item, match_count))
            
            # 按匹配数排序
            relevant_items.sort(key=lambda x: x[1], reverse=True)
            
            # 构建章节内容
            content_parts = []
            citations = []
            
            content_parts.append(f"# {section_template['title']}\n")
            content_parts.append(f"**{section_template['description']}**\n")
            
            for item, match_count in relevant_items[:15]:  # 最多 15 条
                meta = doc_metadata.get(item.doc_id, {"title": "Unknown", "authors": "Unknown", "year": None})
                
                citation = {
                    "doc_id": item.doc_id,
                    "title": meta["title"],
                    "authors": meta["authors"],
                    "year": meta["year"],
                    "page_start": item.page_start,
                    "page_end": item.page_end,
                    "chunk_id": item.chunk_id,
                    "relevance": match_count,
                }
                citations.append(citation)
                
                year_str = str(meta["year"]) if meta["year"] else "n.d."
                cite_key = f"[{meta['authors']}, {year_str}: p.{item.page_start}-{item.page_end}]"
                
                text = item.text
                snippet = text[:400] + "..." if len(text) > 400 else text
                
                content_parts.append(f"- {snippet} {cite_key}")
            
            if not relevant_items:
                content_parts.append("(该章节暂无匹配的相关内容)")
            
            # 去重引用
            unique_citations = []
            seen_docs = set()
            for cite in citations:
                if cite["doc_id"] not in seen_docs:
                    seen_docs.add(cite["doc_id"])
                    unique_citations.append(cite)
            
            return {
                "pack_id": pack_id,
                "section_id": section,
                "title": section_template["title"],
                "content": "\n\n".join(content_parts),
                "citations": citations,
                "unique_documents": len(unique_citations),
                "total_evidence": len(relevant_items),
            }
            
        except Exception as e:
            return {
                "error": str(e),
                "pack_id": pack_id,
                "section": section,
            }
  • Invocation of register_writing_tools(mcp) which registers the 'draft_section' tool (via @mcp.tool() decorator in writing.py) to the FastMCP server instance.
    register_writing_tools(mcp)
Behavior3/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 describes the core function (generating section content) and mentions it's based on an evidence pack, but lacks details on permissions, rate limits, error conditions, or whether this is a read-only or write operation. The description doesn't contradict annotations (none exist), but it's minimally adequate 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.

Conciseness5/5

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

The description is efficiently structured with a clear purpose statement, usage context, parameter explanations, and return value description—all in four concise sentences. Every sentence adds value: the first states the purpose, the second provides usage guidance, the third documents parameters, and the fourth describes outputs. No wasted words or redundant information.

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 moderate complexity (3 parameters, no annotations, but with an output schema), the description is reasonably complete. It covers purpose, usage, parameters, and return values. The existence of an output schema means the description doesn't need to detail return structure. However, for a tool with no annotations, it could benefit from more behavioral 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?

The description adds significant value beyond the input schema, which has 0% description coverage. It explains all three parameters: 'pack_id' is an evidence pack ID, 'section' specifies the chapter type with examples like 'methodology', and 'outline_style' has a default value. This fully compensates for the schema's lack of descriptions, though it doesn't provide exhaustive details like valid section values or outline style options.

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: '生成综述特定章节' (generate a specific section of a literature review) and specifies it's based on an evidence pack. It distinguishes itself from siblings like 'draft_lit_review_v1' by focusing on a single section rather than a full review. However, it doesn't explicitly contrast with other section-related tools like 'build_section_evidence_pack_v1' or 'lint_section_v1', preventing a perfect score.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool: '适合迭代写作某个特定部分' (suitable for iterative writing of a specific section). This implies it's for focused drafting rather than creating a full review from scratch. However, it doesn't explicitly state when NOT to use it or name specific alternatives among the many sibling tools, such as 'draft_lit_review_v1' for full reviews.

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