opencode-history-mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- opencode_history_mcp-0.1.0/.gitignore +30 -0
- opencode_history_mcp-0.1.0/LICENSE +21 -0
- opencode_history_mcp-0.1.0/PKG-INFO +298 -0
- opencode_history_mcp-0.1.0/README.md +274 -0
- opencode_history_mcp-0.1.0/docs/design.md +237 -0
- opencode_history_mcp-0.1.0/pyproject.toml +40 -0
- opencode_history_mcp-0.1.0/src/opencode_history_mcp/__init__.py +11 -0
- opencode_history_mcp-0.1.0/src/opencode_history_mcp/__main__.py +34 -0
- opencode_history_mcp-0.1.0/src/opencode_history_mcp/build_index.py +703 -0
- opencode_history_mcp-0.1.0/src/opencode_history_mcp/paths.py +64 -0
- opencode_history_mcp-0.1.0/src/opencode_history_mcp/server.py +805 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Byte-compiled / cache
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
.eggs/
|
|
6
|
+
|
|
7
|
+
# Build artifacts
|
|
8
|
+
dist/
|
|
9
|
+
build/
|
|
10
|
+
*.whl
|
|
11
|
+
|
|
12
|
+
# Virtual environments
|
|
13
|
+
venv/
|
|
14
|
+
.venv/
|
|
15
|
+
|
|
16
|
+
# Local data (generated at runtime, never ship real user data)
|
|
17
|
+
*.db
|
|
18
|
+
*.db-shm
|
|
19
|
+
*.db-wal
|
|
20
|
+
|
|
21
|
+
# OS
|
|
22
|
+
.DS_Store
|
|
23
|
+
|
|
24
|
+
# Editors
|
|
25
|
+
.vscode/
|
|
26
|
+
.idea/
|
|
27
|
+
|
|
28
|
+
# Env
|
|
29
|
+
.env
|
|
30
|
+
.python-version
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Roberto Crotti
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: opencode-history-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server for searching your local OpenCode conversation history
|
|
5
|
+
Project-URL: Homepage, https://github.com/crottolo/opencode-history-mcp
|
|
6
|
+
Project-URL: Repository, https://github.com/crottolo/opencode-history-mcp
|
|
7
|
+
Project-URL: Issues, https://github.com/crottolo/opencode-history-mcp/issues
|
|
8
|
+
Author-email: Roberto Crotti <crotti.roberto@gmail.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: ai-agent,fts5,history,mcp,model-context-protocol,opencode,search
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Requires-Dist: fastmcp>=2.0.0
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# OpenCode History MCP
|
|
26
|
+
|
|
27
|
+
A local MCP (Model Context Protocol) server that lets AI coding agents
|
|
28
|
+
search your **past OpenCode conversations** — before they start
|
|
29
|
+
exploring files or re-doing work you already did.
|
|
30
|
+
|
|
31
|
+
Everything runs on your machine: it reads OpenCode's own SQLite database
|
|
32
|
+
and builds a private full-text search index next to it. No network
|
|
33
|
+
calls, no external services, **no data ever leaves your computer**.
|
|
34
|
+
|
|
35
|
+
[](https://www.python.org/)
|
|
36
|
+
[](LICENSE)
|
|
37
|
+
[](https://modelcontextprotocol.io)
|
|
38
|
+
|
|
39
|
+
## Why
|
|
40
|
+
|
|
41
|
+
If you use [OpenCode](https://opencode.ai) daily across many projects,
|
|
42
|
+
you build up thousands of past sessions — bug fixes, feature work,
|
|
43
|
+
diagnostics — sitting untapped in `opencode.db`. When you start a new
|
|
44
|
+
session on the same module or file, your agent has no idea any of that
|
|
45
|
+
happened. It re-explores from scratch, or worse, repeats a mistake you
|
|
46
|
+
already fixed three weeks ago.
|
|
47
|
+
|
|
48
|
+
This server exposes that history as MCP tools any agent can call:
|
|
49
|
+
*"has this file been touched before? what did we conclude last time?
|
|
50
|
+
what related work exists in this project?"*
|
|
51
|
+
|
|
52
|
+
## How it works
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
OpenCode's own DB (read-only) Our derived index (read-write)
|
|
56
|
+
┌─────────────────────────┐ ┌──────────────────────────┐
|
|
57
|
+
│ opencode.db │ builds → │ opencode-history.db │
|
|
58
|
+
│ - session / message /part│ │ - sessions (denormalized) │
|
|
59
|
+
│ - JSON blobs per row │ │ - search_idx (FTS5) │
|
|
60
|
+
└─────────────────────────┘ │ - session_files (index) │
|
|
61
|
+
└──────────────────────────┘
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
- **Source DB stays untouched.** We open it `mode=ro` (read-only, WAL-aware)
|
|
65
|
+
and never write to it.
|
|
66
|
+
- **A separate FTS5 index** holds denormalized session metadata + full-text
|
|
67
|
+
search over user/assistant text — orders of magnitude faster than
|
|
68
|
+
scanning JSON blobs on every query.
|
|
69
|
+
- **Auto-sync on startup**, TTL-cached (5 min): if OpenCode wrote new
|
|
70
|
+
sessions since the last check, the index catches up incrementally
|
|
71
|
+
before serving results.
|
|
72
|
+
- **Privacy is structural, not a policy**: the index lives next to
|
|
73
|
+
OpenCode's own DB, on your machine, under your OS user. There is no
|
|
74
|
+
hosted/shared version of this server — everyone runs their own,
|
|
75
|
+
against their own history.
|
|
76
|
+
|
|
77
|
+
## Quickstart
|
|
78
|
+
|
|
79
|
+
### 1. Build the index (first run)
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
uvx opencode-history-mcp --build-index
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
This reads your local `opencode.db` and builds `opencode-history.db`
|
|
86
|
+
next to it. Takes a few seconds per thousand sessions.
|
|
87
|
+
|
|
88
|
+
### 2. Add it to your MCP client
|
|
89
|
+
|
|
90
|
+
<details>
|
|
91
|
+
<summary><b>Hermes Agent</b></summary>
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
hermes mcp add history \
|
|
95
|
+
--command uvx \
|
|
96
|
+
--args opencode-history-mcp
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Or in `~/.hermes/config.yaml`:
|
|
100
|
+
|
|
101
|
+
```yaml
|
|
102
|
+
mcp_servers:
|
|
103
|
+
history:
|
|
104
|
+
command: uvx
|
|
105
|
+
args:
|
|
106
|
+
- opencode-history-mcp
|
|
107
|
+
enabled: true
|
|
108
|
+
```
|
|
109
|
+
</details>
|
|
110
|
+
|
|
111
|
+
<details>
|
|
112
|
+
<summary><b>OpenCode</b></summary>
|
|
113
|
+
|
|
114
|
+
In `~/.config/opencode/opencode.jsonc` (global) or `.opencode/opencode.jsonc`
|
|
115
|
+
(project):
|
|
116
|
+
|
|
117
|
+
```jsonc
|
|
118
|
+
{
|
|
119
|
+
"mcp": {
|
|
120
|
+
"history": {
|
|
121
|
+
"type": "local",
|
|
122
|
+
"command": ["uvx", "opencode-history-mcp"],
|
|
123
|
+
"enabled": true
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
</details>
|
|
129
|
+
|
|
130
|
+
<details>
|
|
131
|
+
<summary><b>Claude Desktop</b></summary>
|
|
132
|
+
|
|
133
|
+
In `claude_desktop_config.json`:
|
|
134
|
+
|
|
135
|
+
```json
|
|
136
|
+
{
|
|
137
|
+
"mcpServers": {
|
|
138
|
+
"opencode-history": {
|
|
139
|
+
"command": "uvx",
|
|
140
|
+
"args": ["opencode-history-mcp"]
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
</details>
|
|
146
|
+
|
|
147
|
+
<details>
|
|
148
|
+
<summary><b>Cursor / other MCP clients</b></summary>
|
|
149
|
+
|
|
150
|
+
Any client that supports local stdio MCP servers works the same way —
|
|
151
|
+
point it at:
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
command: uvx
|
|
155
|
+
args: ["opencode-history-mcp"]
|
|
156
|
+
```
|
|
157
|
+
</details>
|
|
158
|
+
|
|
159
|
+
### 3. Keep the index fresh (optional)
|
|
160
|
+
|
|
161
|
+
The server auto-syncs on startup (checked every 5 minutes per session).
|
|
162
|
+
For a fully up-to-date index without waiting on that check, run:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
uvx opencode-history-mcp --sync-index
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
You can schedule this with cron/launchd if you want the index always
|
|
169
|
+
warm ahead of time.
|
|
170
|
+
|
|
171
|
+
## Tools
|
|
172
|
+
|
|
173
|
+
| Tool | Purpose |
|
|
174
|
+
|---|---|
|
|
175
|
+
| `search_history` | Full-text search (FTS5) over user prompts and assistant responses. Ranked by relevance + recency + activity. |
|
|
176
|
+
| `find_related_work` | Higher-precision match on session titles and original task descriptions. Best first call for "have we done this before?" |
|
|
177
|
+
| `find_sessions_by_file` | Find every session that modified or mentioned a specific file. |
|
|
178
|
+
| `list_sessions` | Browse sessions in a directory, sorted by date/messages/cost/tokens. |
|
|
179
|
+
| `get_session_detail` | Full metadata for one session: task, files touched, cost, tokens, sub-agent count. |
|
|
180
|
+
| `get_session_messages` | Read the actual paginated message history of a session. |
|
|
181
|
+
| `get_stats` | Aggregate stats: session/message counts, cost, time range, activity distribution. |
|
|
182
|
+
|
|
183
|
+
All tools accept an optional `directory` parameter to scope results to
|
|
184
|
+
one project. **Recommended pattern**: search scoped to the current
|
|
185
|
+
project first; if nothing relevant comes back, retry without
|
|
186
|
+
`directory` for a global search — related work sometimes lives in a
|
|
187
|
+
sibling project.
|
|
188
|
+
|
|
189
|
+
## Cross-platform paths
|
|
190
|
+
|
|
191
|
+
The server resolves OpenCode's data directory the same way OpenCode
|
|
192
|
+
itself does (its `xdg-basedir`-based resolution — see
|
|
193
|
+
[`packages/core/src/global.ts`](https://github.com/anomalyco/opencode/blob/dev/packages/core/src/global.ts)
|
|
194
|
+
in the OpenCode source):
|
|
195
|
+
|
|
196
|
+
| Platform | Default path | Notes |
|
|
197
|
+
|---|---|---|
|
|
198
|
+
| **Linux** | `$XDG_DATA_HOME/opencode` → falls back to `~/.local/share/opencode` | Standard XDG Base Directory behavior. |
|
|
199
|
+
| **macOS** | `~/.local/share/opencode` | ⚠️ **Not** `~/Library/Application Support/opencode`. OpenCode has no macOS-specific branch in its path resolution — it uses the same XDG-style path as Linux. This trips people up who assume Apple conventions apply. |
|
|
200
|
+
| **Windows** | `%LOCALAPPDATA%\opencode` | Falls back to `%USERPROFILE%\AppData\Local\opencode` if the env var is unset. |
|
|
201
|
+
| **WSL (WSL2/WSL1)** | Same as Linux — `~/.local/share/opencode` | WSL runs a real Linux kernel, so `sys.platform` reports `"linux"` and the Linux path applies automatically. **This is only correct if OpenCode itself runs inside WSL.** |
|
|
202
|
+
|
|
203
|
+
### The WSL + Windows-side-OpenCode edge case
|
|
204
|
+
|
|
205
|
+
If you installed OpenCode on **Windows natively** (not inside WSL) but
|
|
206
|
+
run your MCP client or terminal **inside WSL**, the database lives on
|
|
207
|
+
the Windows filesystem, which WSL mounts under `/mnt/c/...`. The
|
|
208
|
+
automatic Linux-path resolution will look in the wrong place (your
|
|
209
|
+
WSL home directory, not the Windows one) and won't find it.
|
|
210
|
+
|
|
211
|
+
Fix: point the server explicitly at the mounted Windows path via the
|
|
212
|
+
`OPENCODE_DATA_DIR` environment variable:
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
export OPENCODE_DATA_DIR="/mnt/c/Users/<your-windows-username>/AppData/Local/opencode"
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Or set it in your MCP client's `env` config for this server, e.g. for
|
|
219
|
+
Hermes:
|
|
220
|
+
|
|
221
|
+
```yaml
|
|
222
|
+
mcp_servers:
|
|
223
|
+
history:
|
|
224
|
+
command: uvx
|
|
225
|
+
args:
|
|
226
|
+
- opencode-history-mcp
|
|
227
|
+
env:
|
|
228
|
+
OPENCODE_DATA_DIR: /mnt/c/Users/yourname/AppData/Local/opencode
|
|
229
|
+
enabled: true
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Any other custom setup
|
|
233
|
+
|
|
234
|
+
`OPENCODE_DATA_DIR` always wins over auto-detection, on every platform
|
|
235
|
+
— use it whenever OpenCode's data lives somewhere non-standard (custom
|
|
236
|
+
`XDG_DATA_HOME`, a container, a synced/mounted drive, etc).
|
|
237
|
+
|
|
238
|
+
## Teaching your agent to use this automatically
|
|
239
|
+
|
|
240
|
+
Having the tools available isn't enough — agents default to exploring
|
|
241
|
+
files directly unless told otherwise. Add this to your project's
|
|
242
|
+
`AGENTS.md` (OpenCode) or `CLAUDE.md` (Claude Code) to make history
|
|
243
|
+
search a mandatory first step:
|
|
244
|
+
|
|
245
|
+
```markdown
|
|
246
|
+
## Check history before starting work
|
|
247
|
+
|
|
248
|
+
Before exploring files or writing code for any task that touches an
|
|
249
|
+
existing module, file, or bug, call the history search tools first:
|
|
250
|
+
|
|
251
|
+
1. `find_related_work(query="<short description of the task>")` —
|
|
252
|
+
has this exact task been worked on before?
|
|
253
|
+
2. If the task names a specific file, also call
|
|
254
|
+
`find_sessions_by_file(file_path="...")`.
|
|
255
|
+
3. If step 1 returns nothing relevant, broaden with
|
|
256
|
+
`search_history(query="...")` (full-text, no directory scope).
|
|
257
|
+
|
|
258
|
+
Only start exploring the codebase directly if history search comes up
|
|
259
|
+
empty. If a relevant past session is found, read it with
|
|
260
|
+
`get_session_detail` / `get_session_messages` before proceeding —
|
|
261
|
+
don't repeat work or re-diagnose an issue that was already solved.
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
This is a strong nudge, not a hard constraint — the agent can still
|
|
265
|
+
decide history search isn't relevant for a truly new task. The goal is
|
|
266
|
+
making "check first" the default reflex instead of an afterthought.
|
|
267
|
+
|
|
268
|
+
## Development
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
git clone https://github.com/crottolo/opencode-history-mcp.git
|
|
272
|
+
cd opencode-history-mcp
|
|
273
|
+
uv venv
|
|
274
|
+
uv pip install -e .
|
|
275
|
+
|
|
276
|
+
# Build the index against your own OpenCode history
|
|
277
|
+
python -m opencode_history_mcp.build_index --full
|
|
278
|
+
|
|
279
|
+
# Run the server directly (stdio)
|
|
280
|
+
python -m opencode_history_mcp.server
|
|
281
|
+
|
|
282
|
+
# Inspect with the FastMCP dev tools
|
|
283
|
+
fastmcp dev -m opencode_history_mcp.server
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
See [`docs/design.md`](docs/design.md) for the full design rationale
|
|
287
|
+
(ranking formula, schema decisions, sync algorithm).
|
|
288
|
+
|
|
289
|
+
## Contributing
|
|
290
|
+
|
|
291
|
+
Issues and PRs welcome. If you hit a platform-specific path issue,
|
|
292
|
+
please include your OS, `OPENCODE_DATA_DIR` (if set), and the actual
|
|
293
|
+
location of your `opencode.db` — that's the fastest way to fix an edge
|
|
294
|
+
case in the resolution logic.
|
|
295
|
+
|
|
296
|
+
## License
|
|
297
|
+
|
|
298
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# OpenCode History MCP
|
|
2
|
+
|
|
3
|
+
A local MCP (Model Context Protocol) server that lets AI coding agents
|
|
4
|
+
search your **past OpenCode conversations** — before they start
|
|
5
|
+
exploring files or re-doing work you already did.
|
|
6
|
+
|
|
7
|
+
Everything runs on your machine: it reads OpenCode's own SQLite database
|
|
8
|
+
and builds a private full-text search index next to it. No network
|
|
9
|
+
calls, no external services, **no data ever leaves your computer**.
|
|
10
|
+
|
|
11
|
+
[](https://www.python.org/)
|
|
12
|
+
[](LICENSE)
|
|
13
|
+
[](https://modelcontextprotocol.io)
|
|
14
|
+
|
|
15
|
+
## Why
|
|
16
|
+
|
|
17
|
+
If you use [OpenCode](https://opencode.ai) daily across many projects,
|
|
18
|
+
you build up thousands of past sessions — bug fixes, feature work,
|
|
19
|
+
diagnostics — sitting untapped in `opencode.db`. When you start a new
|
|
20
|
+
session on the same module or file, your agent has no idea any of that
|
|
21
|
+
happened. It re-explores from scratch, or worse, repeats a mistake you
|
|
22
|
+
already fixed three weeks ago.
|
|
23
|
+
|
|
24
|
+
This server exposes that history as MCP tools any agent can call:
|
|
25
|
+
*"has this file been touched before? what did we conclude last time?
|
|
26
|
+
what related work exists in this project?"*
|
|
27
|
+
|
|
28
|
+
## How it works
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
OpenCode's own DB (read-only) Our derived index (read-write)
|
|
32
|
+
┌─────────────────────────┐ ┌──────────────────────────┐
|
|
33
|
+
│ opencode.db │ builds → │ opencode-history.db │
|
|
34
|
+
│ - session / message /part│ │ - sessions (denormalized) │
|
|
35
|
+
│ - JSON blobs per row │ │ - search_idx (FTS5) │
|
|
36
|
+
└─────────────────────────┘ │ - session_files (index) │
|
|
37
|
+
└──────────────────────────┘
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
- **Source DB stays untouched.** We open it `mode=ro` (read-only, WAL-aware)
|
|
41
|
+
and never write to it.
|
|
42
|
+
- **A separate FTS5 index** holds denormalized session metadata + full-text
|
|
43
|
+
search over user/assistant text — orders of magnitude faster than
|
|
44
|
+
scanning JSON blobs on every query.
|
|
45
|
+
- **Auto-sync on startup**, TTL-cached (5 min): if OpenCode wrote new
|
|
46
|
+
sessions since the last check, the index catches up incrementally
|
|
47
|
+
before serving results.
|
|
48
|
+
- **Privacy is structural, not a policy**: the index lives next to
|
|
49
|
+
OpenCode's own DB, on your machine, under your OS user. There is no
|
|
50
|
+
hosted/shared version of this server — everyone runs their own,
|
|
51
|
+
against their own history.
|
|
52
|
+
|
|
53
|
+
## Quickstart
|
|
54
|
+
|
|
55
|
+
### 1. Build the index (first run)
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
uvx opencode-history-mcp --build-index
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
This reads your local `opencode.db` and builds `opencode-history.db`
|
|
62
|
+
next to it. Takes a few seconds per thousand sessions.
|
|
63
|
+
|
|
64
|
+
### 2. Add it to your MCP client
|
|
65
|
+
|
|
66
|
+
<details>
|
|
67
|
+
<summary><b>Hermes Agent</b></summary>
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
hermes mcp add history \
|
|
71
|
+
--command uvx \
|
|
72
|
+
--args opencode-history-mcp
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Or in `~/.hermes/config.yaml`:
|
|
76
|
+
|
|
77
|
+
```yaml
|
|
78
|
+
mcp_servers:
|
|
79
|
+
history:
|
|
80
|
+
command: uvx
|
|
81
|
+
args:
|
|
82
|
+
- opencode-history-mcp
|
|
83
|
+
enabled: true
|
|
84
|
+
```
|
|
85
|
+
</details>
|
|
86
|
+
|
|
87
|
+
<details>
|
|
88
|
+
<summary><b>OpenCode</b></summary>
|
|
89
|
+
|
|
90
|
+
In `~/.config/opencode/opencode.jsonc` (global) or `.opencode/opencode.jsonc`
|
|
91
|
+
(project):
|
|
92
|
+
|
|
93
|
+
```jsonc
|
|
94
|
+
{
|
|
95
|
+
"mcp": {
|
|
96
|
+
"history": {
|
|
97
|
+
"type": "local",
|
|
98
|
+
"command": ["uvx", "opencode-history-mcp"],
|
|
99
|
+
"enabled": true
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
</details>
|
|
105
|
+
|
|
106
|
+
<details>
|
|
107
|
+
<summary><b>Claude Desktop</b></summary>
|
|
108
|
+
|
|
109
|
+
In `claude_desktop_config.json`:
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{
|
|
113
|
+
"mcpServers": {
|
|
114
|
+
"opencode-history": {
|
|
115
|
+
"command": "uvx",
|
|
116
|
+
"args": ["opencode-history-mcp"]
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
</details>
|
|
122
|
+
|
|
123
|
+
<details>
|
|
124
|
+
<summary><b>Cursor / other MCP clients</b></summary>
|
|
125
|
+
|
|
126
|
+
Any client that supports local stdio MCP servers works the same way —
|
|
127
|
+
point it at:
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
command: uvx
|
|
131
|
+
args: ["opencode-history-mcp"]
|
|
132
|
+
```
|
|
133
|
+
</details>
|
|
134
|
+
|
|
135
|
+
### 3. Keep the index fresh (optional)
|
|
136
|
+
|
|
137
|
+
The server auto-syncs on startup (checked every 5 minutes per session).
|
|
138
|
+
For a fully up-to-date index without waiting on that check, run:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
uvx opencode-history-mcp --sync-index
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
You can schedule this with cron/launchd if you want the index always
|
|
145
|
+
warm ahead of time.
|
|
146
|
+
|
|
147
|
+
## Tools
|
|
148
|
+
|
|
149
|
+
| Tool | Purpose |
|
|
150
|
+
|---|---|
|
|
151
|
+
| `search_history` | Full-text search (FTS5) over user prompts and assistant responses. Ranked by relevance + recency + activity. |
|
|
152
|
+
| `find_related_work` | Higher-precision match on session titles and original task descriptions. Best first call for "have we done this before?" |
|
|
153
|
+
| `find_sessions_by_file` | Find every session that modified or mentioned a specific file. |
|
|
154
|
+
| `list_sessions` | Browse sessions in a directory, sorted by date/messages/cost/tokens. |
|
|
155
|
+
| `get_session_detail` | Full metadata for one session: task, files touched, cost, tokens, sub-agent count. |
|
|
156
|
+
| `get_session_messages` | Read the actual paginated message history of a session. |
|
|
157
|
+
| `get_stats` | Aggregate stats: session/message counts, cost, time range, activity distribution. |
|
|
158
|
+
|
|
159
|
+
All tools accept an optional `directory` parameter to scope results to
|
|
160
|
+
one project. **Recommended pattern**: search scoped to the current
|
|
161
|
+
project first; if nothing relevant comes back, retry without
|
|
162
|
+
`directory` for a global search — related work sometimes lives in a
|
|
163
|
+
sibling project.
|
|
164
|
+
|
|
165
|
+
## Cross-platform paths
|
|
166
|
+
|
|
167
|
+
The server resolves OpenCode's data directory the same way OpenCode
|
|
168
|
+
itself does (its `xdg-basedir`-based resolution — see
|
|
169
|
+
[`packages/core/src/global.ts`](https://github.com/anomalyco/opencode/blob/dev/packages/core/src/global.ts)
|
|
170
|
+
in the OpenCode source):
|
|
171
|
+
|
|
172
|
+
| Platform | Default path | Notes |
|
|
173
|
+
|---|---|---|
|
|
174
|
+
| **Linux** | `$XDG_DATA_HOME/opencode` → falls back to `~/.local/share/opencode` | Standard XDG Base Directory behavior. |
|
|
175
|
+
| **macOS** | `~/.local/share/opencode` | ⚠️ **Not** `~/Library/Application Support/opencode`. OpenCode has no macOS-specific branch in its path resolution — it uses the same XDG-style path as Linux. This trips people up who assume Apple conventions apply. |
|
|
176
|
+
| **Windows** | `%LOCALAPPDATA%\opencode` | Falls back to `%USERPROFILE%\AppData\Local\opencode` if the env var is unset. |
|
|
177
|
+
| **WSL (WSL2/WSL1)** | Same as Linux — `~/.local/share/opencode` | WSL runs a real Linux kernel, so `sys.platform` reports `"linux"` and the Linux path applies automatically. **This is only correct if OpenCode itself runs inside WSL.** |
|
|
178
|
+
|
|
179
|
+
### The WSL + Windows-side-OpenCode edge case
|
|
180
|
+
|
|
181
|
+
If you installed OpenCode on **Windows natively** (not inside WSL) but
|
|
182
|
+
run your MCP client or terminal **inside WSL**, the database lives on
|
|
183
|
+
the Windows filesystem, which WSL mounts under `/mnt/c/...`. The
|
|
184
|
+
automatic Linux-path resolution will look in the wrong place (your
|
|
185
|
+
WSL home directory, not the Windows one) and won't find it.
|
|
186
|
+
|
|
187
|
+
Fix: point the server explicitly at the mounted Windows path via the
|
|
188
|
+
`OPENCODE_DATA_DIR` environment variable:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
export OPENCODE_DATA_DIR="/mnt/c/Users/<your-windows-username>/AppData/Local/opencode"
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Or set it in your MCP client's `env` config for this server, e.g. for
|
|
195
|
+
Hermes:
|
|
196
|
+
|
|
197
|
+
```yaml
|
|
198
|
+
mcp_servers:
|
|
199
|
+
history:
|
|
200
|
+
command: uvx
|
|
201
|
+
args:
|
|
202
|
+
- opencode-history-mcp
|
|
203
|
+
env:
|
|
204
|
+
OPENCODE_DATA_DIR: /mnt/c/Users/yourname/AppData/Local/opencode
|
|
205
|
+
enabled: true
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Any other custom setup
|
|
209
|
+
|
|
210
|
+
`OPENCODE_DATA_DIR` always wins over auto-detection, on every platform
|
|
211
|
+
— use it whenever OpenCode's data lives somewhere non-standard (custom
|
|
212
|
+
`XDG_DATA_HOME`, a container, a synced/mounted drive, etc).
|
|
213
|
+
|
|
214
|
+
## Teaching your agent to use this automatically
|
|
215
|
+
|
|
216
|
+
Having the tools available isn't enough — agents default to exploring
|
|
217
|
+
files directly unless told otherwise. Add this to your project's
|
|
218
|
+
`AGENTS.md` (OpenCode) or `CLAUDE.md` (Claude Code) to make history
|
|
219
|
+
search a mandatory first step:
|
|
220
|
+
|
|
221
|
+
```markdown
|
|
222
|
+
## Check history before starting work
|
|
223
|
+
|
|
224
|
+
Before exploring files or writing code for any task that touches an
|
|
225
|
+
existing module, file, or bug, call the history search tools first:
|
|
226
|
+
|
|
227
|
+
1. `find_related_work(query="<short description of the task>")` —
|
|
228
|
+
has this exact task been worked on before?
|
|
229
|
+
2. If the task names a specific file, also call
|
|
230
|
+
`find_sessions_by_file(file_path="...")`.
|
|
231
|
+
3. If step 1 returns nothing relevant, broaden with
|
|
232
|
+
`search_history(query="...")` (full-text, no directory scope).
|
|
233
|
+
|
|
234
|
+
Only start exploring the codebase directly if history search comes up
|
|
235
|
+
empty. If a relevant past session is found, read it with
|
|
236
|
+
`get_session_detail` / `get_session_messages` before proceeding —
|
|
237
|
+
don't repeat work or re-diagnose an issue that was already solved.
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
This is a strong nudge, not a hard constraint — the agent can still
|
|
241
|
+
decide history search isn't relevant for a truly new task. The goal is
|
|
242
|
+
making "check first" the default reflex instead of an afterthought.
|
|
243
|
+
|
|
244
|
+
## Development
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
git clone https://github.com/crottolo/opencode-history-mcp.git
|
|
248
|
+
cd opencode-history-mcp
|
|
249
|
+
uv venv
|
|
250
|
+
uv pip install -e .
|
|
251
|
+
|
|
252
|
+
# Build the index against your own OpenCode history
|
|
253
|
+
python -m opencode_history_mcp.build_index --full
|
|
254
|
+
|
|
255
|
+
# Run the server directly (stdio)
|
|
256
|
+
python -m opencode_history_mcp.server
|
|
257
|
+
|
|
258
|
+
# Inspect with the FastMCP dev tools
|
|
259
|
+
fastmcp dev -m opencode_history_mcp.server
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
See [`docs/design.md`](docs/design.md) for the full design rationale
|
|
263
|
+
(ranking formula, schema decisions, sync algorithm).
|
|
264
|
+
|
|
265
|
+
## Contributing
|
|
266
|
+
|
|
267
|
+
Issues and PRs welcome. If you hit a platform-specific path issue,
|
|
268
|
+
please include your OS, `OPENCODE_DATA_DIR` (if set), and the actual
|
|
269
|
+
location of your `opencode.db` — that's the fastest way to fix an edge
|
|
270
|
+
case in the resolution logic.
|
|
271
|
+
|
|
272
|
+
## License
|
|
273
|
+
|
|
274
|
+
MIT — see [LICENSE](LICENSE).
|