Skip to main content
Glama

export_claim_matrix_grouped_v1_2

Export grouped claim matrices from academic literature, organizing top claims by confidence and sign for structured analysis.

Instructions

导出分组 claim 矩阵,每组返回 top-k 代表 claims (按 confidence 排序,sign 分层)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
comm_idNo
pack_idNo
top_k_per_groupNo
include_subgroupsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The primary handler function implementing the logic for the 'export_claim_matrix_grouped_v1_2' tool. It queries claim groups, filters by comm_id or pack_id, retrieves top-k claims per group sorted by sign and confidence, and returns structured results.
    @mcp.tool()
    def export_claim_matrix_grouped_v1_2(
        comm_id: int | None = None,
        pack_id: int | None = None,
        top_k_per_group: int = 10,
        include_subgroups: bool = True,
    ) -> dict[str, Any]:
        """导出分组 claim 矩阵,每组返回 top-k 代表 claims (按 confidence 排序,sign 分层)"""
        try:
            # 构建过滤条件
            where_clauses = []
            params = []
            
            if comm_id:
                where_clauses.append("""
                    EXISTS (
                        SELECT 1 FROM claim_group_members cgm
                        JOIN claims c ON c.claim_id = cgm.claim_id
                        JOIN mentions m ON m.doc_id = c.doc_id
                        JOIN community_members cm ON cm.entity_id = m.entity_id
                        WHERE cm.comm_id = %s AND cgm.group_id = g.group_id
                    )
                """)
                params.append(comm_id)
            elif pack_id:
                where_clauses.append("""
                    EXISTS (
                        SELECT 1 FROM claim_group_members cgm
                        JOIN claims c ON c.claim_id = cgm.claim_id
                        JOIN evidence_pack_items epi ON epi.chunk_id = c.chunk_id
                        WHERE epi.pack_id = %s AND cgm.group_id = g.group_id
                    )
                """)
                params.append(pack_id)
            
            # 是否包含子组
            if not include_subgroups:
                where_clauses.append("g.parent_group_id IS NULL")
            
            where_sql = " WHERE " + " AND ".join(where_clauses) if where_clauses else ""
            
            # 获取分组
            groups = query_all(f"""
                SELECT 
                    g.group_id, g.group_key, g.parent_group_id, g.subgroup_key,
                    g.sign, g.id_family, g.setting,
                    e.canonical_name as topic_name,
                    (SELECT COUNT(*) FROM claim_group_members cgm WHERE cgm.group_id = g.group_id) as member_count
                FROM claim_groups g
                LEFT JOIN entities e ON e.entity_id = g.topic_entity_id
                {where_sql}
                ORDER BY member_count DESC
            """, tuple(params))
            
            # 为每个 group 获取 top-k claims(按 sign 分层 + confidence 排序)
            result_groups = []
            for g in groups:
                # 获取该组的 claims,按 sign 和 confidence 排序
                claims = query_all("""
                    SELECT c.claim_id, c.doc_id, c.claim_text, c.sign, c.confidence,
                           cf.outcome_family, cf.treatment_family
                    FROM claim_group_members cgm
                    JOIN claims c ON c.claim_id = cgm.claim_id
                    LEFT JOIN claim_features cf ON cf.claim_id = c.claim_id
                    WHERE cgm.group_id = %s
                    ORDER BY 
                        CASE c.sign 
                            WHEN 'positive' THEN 1 
                            WHEN 'negative' THEN 2 
                            WHEN 'mixed' THEN 3 
                            ELSE 4 
                        END,
                        c.confidence DESC
                    LIMIT %s
                """, (g["group_id"], top_k_per_group))
                
                result_groups.append({
                    "group_id": g["group_id"],
                    "group_key": g["group_key"],
                    "parent_group_id": g["parent_group_id"],
                    "subgroup_key": g["subgroup_key"],
                    "topic_name": g["topic_name"],
                    "sign": g["sign"],
                    "member_count": g["member_count"],
                    "top_claims": claims,
                })
            
            return {
                "total_groups": len(result_groups),
                "groups": result_groups
            }
        except Exception as e:
            return {"error": str(e)}
  • The call to register_graph_v12_tools(mcp) in the main server file, which defines and registers the tool among other v1.2 GraphRAG tools.
    register_graph_v12_tools(mcp)
  • Configuration constants for v1.2 tools, defining grouping fields used in claim grouping which this export tool relies on.
    V1_2_PARAMS = {
        "version": "1.2",
        "normalization": {
            "text_norm": "lower+punct+ws",
            "json_dumps": "sort_keys=True,separators=(',',':')",
            "sep": "\\u001f"
        },
        "grouping_fields": ["primary_topic_key", "outcome_family", "treatment_family", "sign", "id_family", "setting_bin"],
    }
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 that claims are sorted by confidence and sign-layered, but fails to describe critical aspects such as output format (though an output schema exists), pagination, rate limits, permissions required, or whether this is a read-only operation. This leaves significant gaps in understanding the tool's behavior.

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 a single, efficient sentence that front-loads the core action ('导出分组 claim 矩阵') and key details. There's no wasted text, making it appropriately concise for the tool's complexity, though it could benefit from slight expansion for clarity.

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's moderate complexity (4 parameters, no annotations, but with an output schema), the description is minimally adequate. The output schema mitigates the need to explain return values, but the description lacks context on prerequisites, behavioral traits, and parameter semantics, leaving it incomplete for safe and effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It only vaguely references 'top-k' and 'sign layered', which partially relates to 'top_k_per_group', but provides no explanation for 'comm_id', 'pack_id', or 'include_subgroups'. This insufficiently clarifies parameter meanings beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states the tool exports a grouped claim matrix with top-k claims per group, which provides a general purpose. However, it's somewhat vague about what 'claim matrix' entails and doesn't clearly differentiate from sibling tools like export_claim_matrix_grouped_v1 or export_evidence_matrix_v1, leaving room for confusion about scope and output format.

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?

No explicit guidance is provided on when to use this tool versus alternatives. The description lacks context about prerequisites (e.g., whether claim groups must be built first), exclusions, or comparisons to similar export tools in the sibling list, offering minimal usage direction.

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