Skip to main content
Glama

build_claim_groups_v1_2

Organizes academic claims into structured groups for literature review analysis using Paperlib MCP's knowledge graph capabilities.

Instructions

基于 claim_features 构建 v1.2 claim groups

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scopeNoall

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the 'build_claim_groups_v1_2' tool, decorated with @mcp.tool(). It queries precomputed claim features, groups claims by a composite key (topic, outcome_family, etc.), deletes old groups, and inserts new groups and members into the database.
    @mcp.tool()
    def build_claim_groups_v1_2(
        scope: str = "all",
    ) -> dict[str, Any]:
        """基于 claim_features 构建 v1.2 claim groups"""
        try:
            # 从 claim_features 读取,按 group_key 分组
            features = query_all("""
                SELECT claim_id, primary_topic_key, outcome_family, treatment_family, 
                       sign, id_family, setting_bin
                FROM claim_features
            """)
            
            if not features:
                return {"error": "No claim features found. Run assign_claim_features_v1_2 first."}
    
            groups: dict[str, list[int]] = defaultdict(list)
            group_meta: dict[str, dict] = {}
            
            for f in features:
                # v1.2 group_key 使用预计算的 features
                group_key = "|".join([
                    f["primary_topic_key"] or "unknown",
                    f["outcome_family"],
                    f["treatment_family"],
                    f["sign"] or "null",
                    f["id_family"] or "general",
                    f["setting_bin"],
                ])
                groups[group_key].append(f["claim_id"])
                
                if group_key not in group_meta:
                    # 查找 topic entity id
                    topic_ent = query_one(
                        "SELECT entity_id FROM entities WHERE canonical_key = %s",
                        (f["primary_topic_key"],)
                    )
                    group_meta[group_key] = {
                        "topic_entity_id": topic_ent["entity_id"] if topic_ent else None,
                        "sign": f["sign"],
                        "setting": f["setting_bin"],
                        "id_family": f["id_family"],
                    }
    
            # 写入 claim_groups (清空旧组后重建)
            params_json = json.dumps(V1_2_PARAMS, sort_keys=True)
            total_members = 0
            
            with get_db() as conn:
                with conn.cursor() as cur:
                    # 清空旧的 v1 组
                    cur.execute("DELETE FROM claim_group_members")
                    cur.execute("DELETE FROM claim_groups")
                
                for key, claim_ids in groups.items():
                    meta = group_meta[key]
                    try:
                        with conn.cursor() as cur:
                            with conn.transaction():
                                cur.execute("""
                                    INSERT INTO claim_groups 
                                    (group_key, topic_entity_id, sign, setting, id_family, params_json)
                                    VALUES (%s, %s, %s, %s, %s, %s::jsonb)
                                    RETURNING group_id
                                """, (key, meta["topic_entity_id"], meta["sign"], 
                                      meta["setting"], meta["id_family"], params_json))
                                group_id = cur.fetchone()["group_id"]
                                
                                for cid in claim_ids:
                                    cur.execute("""
                                        INSERT INTO claim_group_members (group_id, claim_id)
                                        VALUES (%s, %s)
                                    """, (group_id, cid))
                                    total_members += 1
                    except Exception as e:
                        print(f"Error creating group {key}: {e}")
    
                with conn.cursor() as cur:
                    cur.execute("SELECT COUNT(*) as n FROM claim_groups")
                    group_count = cur.fetchone()["n"]
    
            return {"groups_created": group_count, "total_members": total_members}
        except Exception as e:
            return {"error": str(e)}
  • The call to register_graph_v12_tools(mcp) which registers the build_claim_groups_v1_2 tool (among others) to the FastMCP instance.
    register_graph_v12_tools(mcp)
  • Configuration parameters used in the tool for v1.2 grouping rules, including normalization settings and grouping fields. Referenced as params_json in the handler.
    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 states the tool 'builds' claim groups, implying a write/mutation operation, but doesn't specify if it creates new data, modifies existing data, requires specific permissions, or has side effects. No information on rate limits, idempotency, or output behavior is given, leaving significant gaps for a tool with a 'build' action.

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 a single, efficient sentence: '基于 claim_features 构建 v1.2 claim groups'. It is front-loaded with the core action and resource, with no wasted words. Every part of the sentence contributes directly to the tool's purpose, making it highly concise and well-structured.

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 (which handles return values), no annotations, and a simple input schema with 1 parameter, the description is minimally adequate. It states what the tool does but lacks details on behavior, usage context, and parameter meaning. For a 'build' operation with potential data mutation, more completeness would be expected, but the output schema reduces the burden slightly.

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 input schema has 1 parameter ('scope') with 0% description coverage, meaning the schema provides no details. The description doesn't mention parameters at all, so it adds no semantic value beyond the schema. However, with 0 parameters documented in the schema and the tool having only 1 optional parameter, the baseline is high (4) as the parameter burden is low, though the description misses an opportunity to clarify the 'scope' parameter's purpose.

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 'builds v1.2 claim groups based on claim_features', which provides a specific verb ('builds') and resource ('claim groups v1.2'). However, it doesn't differentiate from sibling tools like 'build_claim_groups_v1' or 'build_communities_v1', leaving the scope unclear. The purpose is understandable but lacks sibling distinction.

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 guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing claim_features from 'assign_claim_features_v1_2'), exclusions, or comparisons to similar tools like 'build_claim_groups_v1'. The description offers no usage context beyond the basic action.

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