Skip to main content
Glama

fitbit_get_weight

Fetch weight, BMI, and body fat percentage entries for a date range. Default reads from local cache; use live parameter to query Fitbit API directly.

Instructions

Get weight log entries (weight, BMI, body fat percentage).

Returns data from the local cache by default. Use live=True to fetch from Fitbit API. Run fitbit_sync first to populate the cache.

Weight data is sparse: only days with weigh-in entries are present.

Args: start_date: Start date as "YYYY-MM-DD", "YYYY-MM", or "30d". Default: last 30 days. end_date: End date as "YYYY-MM-DD". Default: today. live: If true, fetch directly from Fitbit API instead of cache.

Returns one entry per weigh-in with weight_kg, bmi, fat_pct.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
start_dateNo
end_dateNo
liveNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'fitbit_get_weight' tool. Decorated with @mcp.tool() and @require_auth. Accepts start_date, end_date, and live parameters. Fetches weight data from either the local SQLite cache (default) or the Fitbit API (live=True). Returns JSON with weight entries (weight_kg, bmi, fat_pct) and count.
    @mcp.tool()
    @require_auth
    async def fitbit_get_weight(
        start_date: str | None = None,
        end_date: str | None = None,
        live: bool = False,
    ) -> str:
        """Get weight log entries (weight, BMI, body fat percentage).
    
        Returns data from the local cache by default. Use live=True to fetch
        from Fitbit API. Run fitbit_sync first to populate the cache.
    
        Weight data is sparse: only days with weigh-in entries are present.
    
        Args:
            start_date: Start date as "YYYY-MM-DD", "YYYY-MM", or "30d". Default: last 30 days.
            end_date: End date as "YYYY-MM-DD". Default: today.
            live: If true, fetch directly from Fitbit API instead of cache.
    
        Returns one entry per weigh-in with weight_kg, bmi, fat_pct.
        """
        start, end = parse_date(start_date, end_date, default_days=30)
    
        if live:
            entries = await anyio.to_thread.run_sync(lambda: _fetch_live(start, end))
        else:
            await anyio.to_thread.run_sync(lambda: auto_sync_if_stale("weight"))
            def _query():
                conn = db.get_db()
                rows = db.query_weight(conn, start.isoformat(), end.isoformat())
                conn.close()
                return rows
            entries = await anyio.to_thread.run_sync(_query)
    
        if not entries:
            return format_response({
                "message": "No weight data found for this period.",
                "hint": "Try live=True to fetch directly from the API.",
            })
    
        return format_response({"weight": entries, "count": len(entries)})
  • Helper function _fetch_live that fetches weight data directly from the Fitbit API in chunks respecting WEIGHT_MAX_RANGE_DAYS (31 days). Builds a path like /1/user/-/body/log/weight/date/{start}/{end}.json and returns sorted entries with date, weight_kg, bmi, and fat_pct.
    def _fetch_live(start_date, end_date) -> list[dict]:
        """Fetch weight data directly from the API."""
        from ..config import WEIGHT_MAX_RANGE_DAYS
        results = {}
        d = start_date
        while d <= end_date:
            chunk_end = min(d + timedelta(days=WEIGHT_MAX_RANGE_DAYS - 1), end_date)
            path = f"/1/user/-/body/log/weight/date/{d}/{chunk_end}.json"
            data = api.get(path)
            for entry in data.get("weight", []):
                ds = entry.get("date")
                if ds:
                    results[ds] = {
                        "date": ds,
                        "weight_kg": entry.get("weight"),
                        "bmi": entry.get("bmi"),
                        "fat_pct": entry.get("fat"),
                    }
            d = chunk_end + timedelta(days=1)
        return sorted(results.values(), key=lambda x: x["date"])
  • The @mcp.tool() decorator on line 35 registers 'fitbit_get_weight' as a tool on the shared FastMCP instance (defined in mcp_instance.py). The tool name is derived from the function name.
    @mcp.tool()
  • The 'weight' table schema in the SQLite database used to store cached weight data. Columns: date (TEXT PRIMARY KEY), weight_kg (REAL), bmi (REAL), fat_pct (REAL).
    CREATE TABLE IF NOT EXISTS weight (
        date TEXT PRIMARY KEY,
        weight_kg REAL,
        bmi REAL,
        fat_pct REAL
    );
  • Database query helper query_weight that retrieves weight rows from the cache between start_date and end_date, ordered by date.
    def query_weight(conn: sqlite3.Connection, start_date: str, end_date: str) -> list[dict]:
        rows = conn.execute(
            "SELECT * FROM weight WHERE date >= ? AND date <= ? ORDER BY date",
            (start_date, end_date),
        ).fetchall()
        return _rows_to_dicts(rows)
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, description carries full burden. It discloses default caching behavior, necessity of prior sync, sparse nature of data, and return format (one entry per weigh-in with weight_kg, bmi, fat_pct). No contradictions.

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?

Concise, uses bullet list for arguments, each sentence provides unique value. No redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has output schema, and description lists return fields (weight_kg, bmi, fat_pct). Covers cache behavior, date defaults, and live mode. Fully complete for a retrieval tool with 3 parameters.

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

Parameters5/5

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

Schema coverage is 0%, but description compensates fully: explains all three parameters (start_date, end_date, live) with defaults, format ('YYYY-MM-DD', 'YYYY-MM', '30d'), and behavior.

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

Purpose5/5

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

Description clearly states 'Get weight log entries (weight, BMI, body fat percentage)', specifying the verb 'Get' and resource 'weight log entries'. Sibling tools (e.g., fitbit_get_activity, fitbit_get_sleep) are for other data types, so this tool is well-distinguished.

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?

Guidance on cache vs. live fetching is explicit: 'Returns data from the local cache by default. Use live=True to fetch from Fitbit API. Run fitbit_sync first to populate the cache.' Also notes data sparsity. Does not explicitly compare to siblings, but their distinct purposes make that implicit.

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/partymola/fitbit-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server