Skip to main content
Glama

collect_evidence

Search academic literature for evidence on a specific topic, optionally focusing on particular sections like methodology or findings, to support research and analysis.

Instructions

收集特定主题的文献证据

搜索与主题相关的文献片段,可选择聚焦于特定章节类型。

Args: topic: 搜索主题 section_focus: 聚焦的章节类型(如 "methodology", "findings") k: 返回结果数量

Returns: 按文献聚合的证据列表

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
topicYes
section_focusNo
kNo

Implementation Reference

  • The core handler implementation for the 'collect_evidence' tool. It adjusts the query based on optional section_focus, performs a hybrid search using hybrid_search, aggregates evidence chunks by document with metadata, sorts by evidence count per doc, and returns a structured dictionary.
    @mcp.tool()
    async def collect_evidence(
        topic: str,
        section_focus: str | None = None,
        k: int = 20,
    ) -> dict[str, Any]:
        """收集特定主题的文献证据
        
        搜索与主题相关的文献片段,可选择聚焦于特定章节类型。
        
        Args:
            topic: 搜索主题
            section_focus: 聚焦的章节类型(如 "methodology", "findings")
            k: 返回结果数量
            
        Returns:
            按文献聚合的证据列表
        """
        try:
            # 如果有章节聚焦,调整查询
            query = topic
            if section_focus:
                focus_keywords = {
                    "methodology": "method approach model estimation identification",
                    "findings": "result finding evidence show demonstrate",
                    "theory": "theory framework hypothesis prediction",
                    "data": "data sample variable measure",
                }
                if section_focus in focus_keywords:
                    query = f"{topic} {focus_keywords[section_focus]}"
            
            # 搜索
            search_result = await hybrid_search(query, k=k, alpha=0.6, per_doc_limit=5)
            
            # 按文档聚合
            evidence_by_doc: dict[str, dict] = {}
            
            for result in search_result.results:
                doc_id = result.doc_id
                
                if doc_id not in evidence_by_doc:
                    # 获取文档信息
                    doc = query_one(
                        "SELECT title, authors, year FROM documents WHERE doc_id = %s",
                        (doc_id,)
                    )
                    evidence_by_doc[doc_id] = {
                        "doc_id": doc_id,
                        "title": doc["title"] if doc else "Unknown",
                        "authors": doc["authors"] if doc else "Unknown",
                        "year": doc["year"] if doc else None,
                        "evidence": [],
                    }
                
                evidence_by_doc[doc_id]["evidence"].append({
                    "chunk_id": result.chunk_id,
                    "page_start": result.page_start,
                    "page_end": result.page_end,
                    "text": result.snippet,
                    "relevance_score": result.score_total,
                })
            
            # 按证据数量排序
            sorted_evidence = sorted(
                evidence_by_doc.values(),
                key=lambda x: len(x["evidence"]),
                reverse=True
            )
            
            return {
                "topic": topic,
                "section_focus": section_focus,
                "total_chunks": len(search_result.results),
                "unique_documents": len(sorted_evidence),
                "evidence": sorted_evidence,
            }
            
        except Exception as e:
            return {
                "error": str(e),
                "topic": topic,
                "evidence": [],
            }
  • Registers the writing tools module (including collect_evidence) by calling register_writing_tools on the FastMCP instance in the main server file.
    register_writing_tools(mcp)
  • The @mcp.tool() decorator directly registers the collect_evidence function as an MCP tool within the register_writing_tools function.
    @mcp.tool()

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