> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/Gentleman-Programming/engram/llms.txt
> Use this file to discover all available pages before exploring further.

# mem_context

> Get recent memory context from previous sessions

## Overview

Retrieve recent observations from previous coding sessions to understand what was done before. Unlike `mem_search` (which requires a query), this tool returns the **most recent** memories for a project or across all projects.

<Note>
  This is a **core tool** in the agent profile, always loaded in the MCP context.
</Note>

## Parameters

<ParamField path="project" type="string">
  Filter observations by project name

  **Omit to retrieve context from all projects.**

  **Example:**

  ```json theme={null}
  {
    "project": "my-api"
  }
  ```
</ParamField>

<ParamField path="scope" type="string">
  Filter observations by visibility scope

  **Options:**

  * `project` (default) — project-scoped observations
  * `personal` — cross-project personal knowledge

  **Example:**

  ```json theme={null}
  {
    "scope": "personal"
  }
  ```
</ParamField>

<ParamField path="limit" type="number">
  Number of observations to retrieve

  **Default:** `20`

  Returns the N most recent observations, ordered by creation timestamp.
</ParamField>

## Response

<ResponseField name="context" type="string">
  Formatted recent context with observations and statistics
</ResponseField>

The response includes:

1. **Recent sessions** — summary of the most recent coding sessions
2. **Recent observations** — chronological list of observations with:
   * Session ID
   * Type and title
   * Content preview (truncated)
   * Project and scope
   * Timestamp
3. **Memory statistics** — total sessions, observations, and projects

**Example response:**

```
=== Recent Sessions ===

Session: my-api (2026-03-01T14:00:00Z) — Added JWT authentication and refactored user service
Observations: 5

Session: engram (2026-02-28T09:30:00Z) — Fixed FTS5 search bugs and added deduplication
Observations: 3

=== Recent Observations ===

[#87] session-abc-123 | decision | Switched from sessions to JWT
**What**: Replaced express-session with jsonwebtoken for auth
**Why**: Session storage doesn't scale across multiple instances
...
Project: my-api | Scope: project | 2026-03-01T14:23:45Z

[#42] session-xyz-789 | bugfix | Fixed FTS5 syntax error on special chars
**What**: Wrapped each search term in quotes before passing to FTS5 MATCH
...
Project: engram | Scope: project | 2026-02-28T10:15:30Z

---
Memory stats: 12 sessions, 87 observations across projects: my-api, engram, frontend
```

If no memories exist:

```
No previous session memories found.
```

## Usage Examples

### Get Recent Context for Current Project

```json theme={null}
{
  "project": "my-api"
}
```

Returns the 20 most recent observations from the "my-api" project.

### Get Context Across All Projects

```json theme={null}
{
  "limit": 10
}
```

Returns the 10 most recent observations from all projects.

### Get Personal Knowledge Context

```json theme={null}
{
  "scope": "personal",
  "limit": 15
}
```

Returns the 15 most recent cross-project observations.

### Large Context Window

```json theme={null}
{
  "project": "my-api",
  "limit": 50
}
```

Returns up to 50 recent observations (useful for deep context recovery).

## When to Use

* **Session start** — get context about recent work when starting a new session
* **Context recovery** — understand what happened in previous sessions
* **Onboarding** — catch up on project history
* **Resume work** — recall where you left off

## Difference from `mem_search`

| Feature               | `mem_context`                  | `mem_search`                |
| --------------------- | ------------------------------ | --------------------------- |
| **Query**             | No query — returns most recent | Requires search query       |
| **Ordering**          | Chronological (newest first)   | Relevance ranking (BM25)    |
| **Use case**          | "What happened recently?"      | "Find specific information" |
| **Session summaries** | Includes session summaries     | No session summaries        |
| **Stats**             | Includes memory statistics     | No statistics               |

<Info>
  Use `mem_context` when you want recent chronological context. Use `mem_search` when you're looking for something specific.
</Info>

## Session Summaries

The context includes session summaries created via [`mem_session_summary`](/mcp/mem-session-summary):

* **Goal** — what the session aimed to accomplish
* **Discoveries** — technical findings and gotchas
* **Accomplished** — completed tasks
* **Relevant files** — files changed or important for context

<Tip>
  Session summaries provide high-level overviews, while individual observations contain detailed context.
</Tip>

## Memory Statistics

The footer includes:

* **Total sessions** — number of coding sessions tracked
* **Total observations** — number of memories saved
* **Projects** — list of all projects with observations

**Example:**

```
Memory stats: 25 sessions, 143 observations across projects: my-api, engram, frontend, mobile-app
```

## Performance

* **Fast retrieval** — simple `ORDER BY created_at DESC LIMIT N` query
* **No full-text search** — no FTS5 index lookup
* **Minimal overhead** — suitable for frequent calls

## Token Efficiency

Context is formatted for readability but can be large:

* **Default (20 observations):** \~2000-4000 tokens
* **Large (50 observations):** \~5000-10000 tokens

<Warning>
  Adjust the `limit` parameter based on your context window. Start with 10-20 observations and increase if needed.
</Warning>

## Related Tools

* [`mem_search`](/mcp/mem-search) - Search for specific observations
* [`mem_session_summary`](/mcp/mem-session-summary) - Save session summaries
* [`mem_save`](/mcp/mem-save) - Save new observations
* [`mem_timeline`](/mcp/mem-timeline) - View chronological context around a specific observation
