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

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)

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