get_session_history
Retrieve session history with timestamped stress scores and heart rate data to track emotional patterns. Analyze psychological trends using rising, falling, or stable indicators over configurable lookback periods.
Instructions
Get state history for a session over time.
Returns timestamped datapoints with stress_score, state, and heart_rate for each observation.
Includes an overall trend: rising | falling | stable.
Use minutes parameter to control the lookback window (default: 5, max: 60).
Useful for detecting stress patterns during a conversation. Not a medical device.Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| session_id | Yes | ||
| minutes | No |
Implementation Reference
- proxy.py:174-191 (handler)The main handler function for get_session_history tool. It makes an HTTP GET request to the API to retrieve session state history including stress_score, state, and heart_rate datapoints over time. Returns JSON response with trend analysis (rising/falling/stable).
async def get_session_history(session_id: str, minutes: int = 5) -> dict: """Get state history for a session over time. Returns timestamped datapoints with stress_score, state, and heart_rate for each observation. Includes an overall trend: rising | falling | stable. Use minutes parameter to control the lookback window (default: 5, max: 60). Useful for detecting stress patterns during a conversation. Not a medical device. """ async with httpx.AsyncClient(timeout=10) as client: resp = await client.get( f"{API_URL}/v1/history", params={"session_id": session_id, "minutes": minutes}, headers=_headers(), ) if resp.status_code == 200: return resp.json() return {"error": f"No history found for session {session_id}."} - proxy.py:173-174 (registration)Tool registration using FastMCP's @mcp.tool() decorator. This registers the get_session_history function as an MCP tool, making it available to clients. FastMCP automatically derives the JSON schema from the function signature and docstring.
@mcp.tool() async def get_session_history(session_id: str, minutes: int = 5) -> dict: - proxy.py:174-174 (schema)Input/output schema defined via Python type hints in the function signature. Input: session_id (str), minutes (int, default=5). Output: dict. FastMCP automatically generates JSON Schema from these type hints for MCP tool registration.
async def get_session_history(session_id: str, minutes: int = 5) -> dict: - proxy.py:33-41 (helper)FastMCP server instance initialization. The 'mcp' object is used to register tools via the @mcp.tool() decorator. This is the MCP server that hosts the get_session_history tool.
mcp = FastMCP( "nefesh", instructions=( "Human State Fusion — send any body signal, " "get a unified state for your LLM. " "Includes trigger memory for cross-session context. " "Not a medical device. MCP + A2A native. Version 4.0.0." ), ) - proxy.py:26-29 (helper)Helper function _headers() used by get_session_history to build HTTP headers with the caller's API key from context variables.
def _headers() -> dict: """Build proxy headers with the caller's API key.""" key = _nefesh_key.get() return {"X-Nefesh-Key": key, "Content-Type": "application/json"}