Files
conversation-history/SquareMCP/2026-06-12-hermes-mcp-obsidian-vault-read-failure.md
T

170 lines
6.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Debt: Hermes-MCP Obsidian Vault Reads Fail via Claude.ai MCP
**Date:** 2026-06-12
**Status:** 🔴 OPEN — workaround exists, server-side fix needed
**Priority:** Medium-High (blocks Claude.ai/web MCP vault access; CLI fallback works)
**Related:** [[2026-06-12-v1-lite-release-plan]], [[2026-04-14-hermes-mcp-obsidian-setup]]
---
## Summary
Claude (the "coworker" / Claude.ai MCP client) repeatedly fails to read or search the Obsidian vault through the hermes-mcp MCP server. The same operations succeed when called through the REST API or direct filesystem tools. The failure is isolated to the MCP Streamable HTTP transport session lifecycle.
---
## Failure Pattern
**Error message (exact):**
```json
Streamable HTTP error: Error POSTing to endpoint:
{"jsonrpc":"2.0","error":{"code":-32000,"message":"Bad Request: Server not initialized"},"id":null}
```
**Affected tools:**
- `mcp__claude_ai_hermes-mcp__obsidian_search_notes`
- `mcp__claude_ai_hermes-mcp__obsidian_read_note`
- `mcp__claude_ai_hermes-mcp__obsidian_append_to_note`
- `mcp__claude_ai_hermes-mcp__obsidian_update_note`
**Most recent occurrence:**
`2026-06-11 16:38:43 UTC` in active Claude Code session `d87bb390-4359-4bbb-bc20-fa25c853ee42`
**Frequency:** 77 matching errors found across Claude project logs.
### Historical Hits
| Session | Timestamp(s) |
|---|---|
| `d87bb390` (current) | 2026-06-11 16:38 |
| `3b4bb18f` | 2026-05-20 19:42, 2026-05-15 21:59 |
| `f9e907ef` | 2026-05-20 01:57, 02:00, 02:05, 02:07 |
| `29df9cec` | 2026-05-15 16:45, 16:58, 18:30 |
In every case Claude falls back to direct file tools (`Read`, `Edit`, `Bash`) and the vault operation succeeds, proving the Obsidian files and vault mount are healthy.
---
## Root-Cause Analysis
### What is happening
1. The MCP **Streamable HTTP** transport requires a JSON-RPC `initialize` handshake before any tool call.
2. The hermes-mcp server stores initialized sessions in an in-memory map (`httpTransports`) keyed by `mcp-session-id`.
3. When the client sends a tool call without a valid session ID — because the session expired, the pod restarted, or the client never completed the handshake — the server creates a new transport but the underlying `@modelcontextprotocol/sdk` server is not yet initialized.
4. The SDK rejects the non-initialize request with `"Server not initialized"`.
### Where it lives in code
File: `src/index.ts` (~lines 968–1023)
```ts
async function createSession(customer?: Customer): Promise<StreamableHTTPServerTransport> {
const transport = new StreamableHTTPServerTransport({
sessionIdGenerator: () => crypto.randomUUID(),
onsessioninitialized: (id) => {
console.log(`[mcp] Session initialized: ${id}`);
httpTransports.set(id, transport);
if (customer) sessionCustomers.set(id, customer);
},
});
...
const server = createMcpServer(customer);
await server.connect(transport);
return transport;
}
app.post('/mcp', requireAuth, async (req, res) => {
const sessionId = req.headers['mcp-session-id'] as string | undefined;
...
if (sessionId && httpTransports.has(sessionId)) {
transport = httpTransports.get(sessionId)!;
} else if (isInitializeRequest(req.body)) {
transport = await createSession(reqCustomer);
} else {
// Auto-recovery branch: creates new session for stale/missing IDs
console.warn(`[mcp] Unknown session ${sessionId ?? '(none)'} — auto-recovering with new session`);
transport = await createSession(reqCustomer);
}
await transport.handleRequest(req, res, req.body);
});
```
The `else` branch creates a new session but then passes a non-initialize request to `transport.handleRequest()`. The SDK's internal server state is not initialized, so it returns the error.
### Why the REST API works
Direct calls such as:
```bash
curl -H "x-api-key: $MCP_API_KEY" \
"https://hermes.squaremcp.com/api/obsidian/search?query=deployment&limit=2"
```
bypass the MCP transport entirely and call `searchNotes()` / `getNote()` directly. These are stateless and work regardless of MCP session state.
---
## Current-State Verification (2026-06-12)
| Check | Result |
|---|---|
| hermes-mcp server running | ✅ Yes, K8s pod `hermes-mcp-8fd855978-z6nfc` in namespace `fetcherpay` |
| Image deployed | `localhost:32000/hermes-mcp@sha256:1ada6f03...` (built 2026-06-12 06:36) |
| `/health` endpoint | ✅ `ok`, 55 tools exposed |
| Vault mount in pod | ✅ `/vaults` → `/home/garfield/obsidian/vaults` |
| REST `/api/obsidian/search` | ✅ Works with API key |
| REST `/api/obsidian/note` | ✅ Works with API key |
| MCP `/mcp` initialize handshake | ✅ Works when called manually with proper `Accept` header |
| MCP tool call after stale session | ❌ Returns `"Server not initialized"` |
---
## Workaround
Reconnect the MCP server in Claude Code before vault operations:
```bash
claude mcp remove hermes-mcp
claude mcp add hermes-mcp \
--transport http \
https://hermes.squaremcp.com/mcp \
--header "x-api-key: 114521f3f9e6858480d6269446a446ef"
```
Then run `/mcp` to force a fresh initialize handshake.
---
## Recommended Fix
Edit `src/index.ts` in the `POST /mcp` handler. When a request arrives with a missing/unknown session ID and the body is **not** an `initialize` request, do **not** pass it to a fresh transport. Instead:
1. Return a proper JSON-RPC error that tells the client to re-initialize:
```json
{"jsonrpc":"2.0","id":null,"error":{"code":-32000,"message":"Session not initialized — send initialize first"}}
```
OR
2. Transparently treat the first request after session loss as a fresh initialize handshake (more complex, may confuse client state).
Preferred option is **#1**: fail closed and force the client to re-run the handshake. This is cleaner than the current auto-recovery branch that creates a session but still lets the SDK emit the cryptic `"Server not initialized"` error.
Longer-term, consider storing MCP sessions in Redis so they survive pod restarts (currently sessions are in-memory only).
---
## Files to Touch
- `src/index.ts` — `POST /mcp` handler, session auto-recovery branch
- `src/index.ts` — optionally move session storage from `Map` to Redis-backed store
---
## Acceptance Criteria
- [ ] A stale or missing `mcp-session-id` on a non-initialize request returns a clear "re-initialize" error instead of `"Server not initialized"`.
- [ ] After `claude mcp add` + `/mcp`, Claude.ai can call `obsidian_search_notes` and `obsidian_read_note` without error.
- [ ] No regression in REST `/api/obsidian/*` endpoints.
- [ ] Tests added for stale-session behavior if test suite covers MCP transport.