567 lines
16 KiB
Markdown
567 lines
16 KiB
Markdown
# Hermes-MCP Implementation Archive
|
|
**Date:** 2026-04-17
|
|
**Participants:** Garfield Heron, Kimi K2.6
|
|
**Project:** Universal AI Gateway - Hermes-MCP with Obsidian Integration
|
|
**Status:** Production Deployed
|
|
|
|
---
|
|
|
|
## Table of Contents
|
|
|
|
1. [Initial Request & Architecture Decision](#1-initial-request--architecture-decision)
|
|
2. [Tool Implementation](#2-tool-implementation)
|
|
3. [Deployment & Discovery](#3-deployment--discovery)
|
|
4. [Authentication & OAuth 2.0](#4-authentication--oauth-20)
|
|
5. [Universal Tool Manifest](#5-universal-tool-manifest)
|
|
6. [ChatGPT Integration Challenges](#6-chatgpt-integration-challenges)
|
|
7. [MySQL Persistence Implementation](#7-mysql-persistence-implementation)
|
|
8. [Operational Learnings](#8-operational-learnings)
|
|
9. [Documentation & Publishing](#9-documentation--publishing)
|
|
10. [Current Configuration](#10-current-configuration)
|
|
11. [Known Issues & TODOs](#11-known-issues--todos)
|
|
|
|
---
|
|
|
|
## 1. Initial Request & Architecture Decision
|
|
|
|
**User Request:**
|
|
> "now that I have https://obsidian-sync.fetcherpay.com configured how can I use it? Can I incorporate it into the custom mcp hermes-mcp that checks connects my yahoo and fetcherpay.com emails or should I create another mcp for me to use it as either a mcp service or a skill? thoughts? I want to be able to use it in all my ai agents as well as code and others like it"
|
|
|
|
**Decision:** Extend existing `hermes-mcp`, don't create separate server.
|
|
|
|
**Rationale:**
|
|
- Single connection to manage
|
|
- Shared auth infrastructure
|
|
- Unified namespace
|
|
- Easier maintenance
|
|
- MCP is for live connections, Skills are for instructions
|
|
|
|
**Architecture Principle:** One server per cohesive domain (personal productivity = email + knowledge)
|
|
|
|
---
|
|
|
|
## 2. Tool Implementation
|
|
|
|
### 2.1 Prompt Used (Kimi Code/Claude Code)
|
|
|
|
```markdown
|
|
## Task: Extend hermes-mcp with Obsidian Sync Integration
|
|
|
|
I need to add Obsidian vault integration to my existing hermes-mcp server.
|
|
The Obsidian sync service is already running at https://obsidian-sync.fetcherpay.com
|
|
|
|
### Required Changes
|
|
|
|
#### 1. Add Environment Configuration
|
|
Update `.env.example` and `.env` with:
|
|
```
|
|
OBSIDIAN_SYNC_URL=https://obsidian-sync.fetcherpay.com
|
|
OBSIDIAN_API_KEY=your_api_key_here
|
|
```
|
|
|
|
#### 2. Create Obsidian Client Module
|
|
Create `src/clients/obsidian.ts`:
|
|
- HTTP client for obsidian-sync.fetcherpay.com
|
|
- Methods: searchNotes, getNote, updateNote, appendToNote, getSyncStatus
|
|
- Error handling with proper MCP error codes
|
|
- Retry logic for network failures
|
|
|
|
#### 3. Add MCP Tools (4 tools total)
|
|
|
|
**Tool 1: obsidian_search_notes**
|
|
- Description: "Full-text + tag search across all .md files in the vault"
|
|
- Parameters: query (string), tags (string[] optional), limit (number, default 10)
|
|
- Returns: Array of {path, title, excerpt, tags, modified_date}
|
|
|
|
**Tool 2: obsidian_read_note**
|
|
- Description: "Read a note by path or title, returns content + wiki links"
|
|
- Parameters: path (string), format (enum: "markdown", "json", default "markdown")
|
|
- Returns: {path, title, content, tags, links, backlinks, modified_date}
|
|
|
|
**Tool 3: obsidian_append_to_note**
|
|
- Description: "Append markdown to any note (creates it if missing)"
|
|
- Parameters: path (string), content (string), create_if_missing (boolean, default true)
|
|
- Returns: {success, path, bytes_written}
|
|
|
|
**Tool 4: obsidian_sync_status**
|
|
- Description: "Hits Syncthing REST API — returns state, last sync time, vault size, pending changes"
|
|
- Parameters: none
|
|
- Returns: {status, last_sync, vault_size, pending_changes}
|
|
|
|
#### 4. Update Server Registration
|
|
- Import Obsidian client
|
|
- Register all 4 new tools
|
|
- Ensure tool names follow pattern: `obsidian_*` for namespacing
|
|
- Add to server capabilities
|
|
|
|
#### 5. Error Handling Standards
|
|
- Use MCP error codes: -32602 (invalid params), -32603 (internal error), -32000 (server error)
|
|
- Log errors with context but don't expose internals to client
|
|
- Graceful degradation if obsidian-sync service is unavailable
|
|
|
|
### Verification Command
|
|
After implementation, I should be able to run:
|
|
```bash
|
|
npm run build
|
|
npm run test
|
|
# Then test with MCP inspector or Claude Code:
|
|
# "Search my notes for 'funding strategy'"
|
|
# "Read my daily note from today"
|
|
# "Append 'Meeting with investor scheduled' to my daily note"
|
|
```
|
|
```
|
|
|
|
### 2.2 Implementation Result (Claude Code)
|
|
|
|
Claude Code implemented the 4 tools with direct vault access:
|
|
- Vault mounted at `/home/garfield/obsidian/vaults` → container `/vaults`
|
|
- Notes read/written directly as `.md` files
|
|
- Syncthing status from `http://host.docker.internal:8384`
|
|
|
|
**Test Results:**
|
|
| Test | Tool | Result |
|
|
|------|------|--------|
|
|
| A | obsidian_search_notes | Found note by content match |
|
|
| B | obsidian_read_note | Full content + frontmatter + wiki links |
|
|
| C | obsidian_append_to_note | Written to disk, verified |
|
|
| D | obsidian_sync_status | idle, 0 pending changes |
|
|
|
|
---
|
|
|
|
## 3. Deployment & Discovery
|
|
|
|
### 3.1 Initial Problem: K8s vs Docker
|
|
|
|
**Issue:** Local Docker builds not reaching production
|
|
|
|
**Root Cause:**
|
|
- Production runs on MicroK8s with nginx-ingress
|
|
- K8s pod was running 34-day-old image
|
|
- Public traffic never reached local Docker container
|
|
|
|
**Fix (Kimi Code):**
|
|
```bash
|
|
docker build -t localhost:32000/hermes-mcp:latest .
|
|
docker push localhost:32000/hermes-mcp:latest
|
|
microk8s kubectl apply -f hermes-k8s.yaml
|
|
microk8s kubectl rollout restart deployment/hermes-mcp -n fetcherpay
|
|
```
|
|
|
|
### 3.2 Network Architecture
|
|
|
|
```
|
|
DNS (hermes.fetcherpay.com) → 104.190.60.129
|
|
→ MicroK8s nginx-ingress-controller (hostNetwork: true, :443)
|
|
→ K8s Ingress (hermes-ingress, namespace: fetcherpay)
|
|
→ K8s Service (hermes-mcp)
|
|
→ K8s Pod (hermes-mcp-xxx, port 3456)
|
|
→ Node.js/Express app
|
|
```
|
|
|
|
**Note:** Traefik runs in Docker but nginx-ingress intercepts all public HTTPS traffic first.
|
|
|
|
---
|
|
|
|
## 4. Authentication & OAuth 2.0
|
|
|
|
### 4.1 Initial Auth: API Keys Only
|
|
|
|
- `x-api-key` header
|
|
- `?key=` query parameter
|
|
- Worked for local agents (Kimi Code, Claude Code, Cursor)
|
|
|
|
### 4.2 ChatGPT Requirement: OAuth 2.0
|
|
|
|
ChatGPT MCP connector rejected API keys. Required OAuth 2.0 with Dynamic Client Registration (DCR).
|
|
|
|
### 4.3 OAuth Implementation (Kimi Code)
|
|
|
|
**Files Changed:**
|
|
- `src/oauth.ts` — New OAuth 2.0 + DCR logic
|
|
- `src/index.ts` — Auth middleware, OAuth endpoints
|
|
- `src/manifest.ts` — OAuth metadata
|
|
|
|
**Endpoints Added:**
|
|
| Endpoint | Method | Purpose |
|
|
|----------|--------|---------|
|
|
| `/oauth/register` | POST | Dynamic Client Registration |
|
|
| `/oauth/authorize` | GET/POST | Login/consent + approval handler |
|
|
| `/oauth/token` | POST | Token exchange (code → Bearer) |
|
|
|
|
**Token Lifetimes:**
|
|
- Auth codes: 10 minutes
|
|
- Access tokens: 1 hour
|
|
- Refresh tokens: 30 days (added later)
|
|
|
|
### 4.4 Discovery Endpoints (RFC 8414)
|
|
|
|
Added for ChatGPT compatibility:
|
|
- `GET /.well-known/oauth-authorization-server`
|
|
- `GET /.well-known/openid-configuration`
|
|
|
|
**Initial Bug:** Missing `issuer` and `authorization_server_base` caused ChatGPT to show `https://example.com` placeholders.
|
|
|
|
**Fix:** Added proper discovery metadata.
|
|
|
|
---
|
|
|
|
## 5. Universal Tool Manifest
|
|
|
|
### 5.1 Purpose
|
|
|
|
Self-describing capabilities so any AI knows:
|
|
- What tools exist
|
|
- When to use each tool
|
|
- Required parameters
|
|
- Expected returns
|
|
|
|
### 5.2 Manifest Format
|
|
|
|
```json
|
|
{
|
|
"schema_version": "1.0.0",
|
|
"server": {
|
|
"name": "hermes-mcp",
|
|
"version": "1.0.0",
|
|
"url": "https://hermes.fetcherpay.com",
|
|
"auth": {
|
|
"type": "apiKey",
|
|
"header": "x-api-key"
|
|
}
|
|
},
|
|
"tools": [
|
|
{
|
|
"name": "obsidian_search_notes",
|
|
"category": "obsidian",
|
|
"description": "Full-text search across Obsidian vault",
|
|
"when_to_use": "User mentions 'my notes', 'in obsidian', or asks about personal knowledge",
|
|
"input_schema": { ... },
|
|
"returns": { ... },
|
|
"examples": [{"query": "funding strategy", "limit": 5}]
|
|
}
|
|
],
|
|
"categories": {
|
|
"obsidian": {"description": "Personal knowledge management", "icon": "📝"},
|
|
"email": {"description": "Email operations", "icon": "📧"}
|
|
}
|
|
}
|
|
```
|
|
|
|
### 5.3 Config Generators
|
|
|
|
Added endpoints for specific AI agents:
|
|
- `GET /config/cursor` — Cursor IDE config
|
|
- `GET /config/claude` — Claude Desktop config
|
|
- `GET /config/kimi` — Kimi Code settings
|
|
- `GET /config/openapi` — OpenAPI spec for ChatGPT Actions
|
|
|
|
---
|
|
|
|
## 6. ChatGPT Integration Challenges
|
|
|
|
### 6.1 Connection Never Established
|
|
|
|
**Diagnostic Finding:** Zero requests from ChatGPT in server logs.
|
|
|
|
**Possible Causes:**
|
|
1. ChatGPT MCP connector failing during discovery
|
|
2. CORS/preflight issues (browser-based client)
|
|
3. Accept header strictness (required both `application/json` AND `text/event-stream`)
|
|
4. Connector not fully configured/active
|
|
|
|
### 6.2 Invalid client_id Error
|
|
|
|
**Cause:** OAuth clients stored in-memory. K8s pod restart wiped all registrations.
|
|
|
|
**Symptom:** ChatGPT stored `client_id` from first DCR, but server no longer recognized it.
|
|
|
|
**Solution:** MySQL persistence for OAuth clients.
|
|
|
|
---
|
|
|
|
## 7. MySQL Persistence Implementation
|
|
|
|
### 7.1 Schema
|
|
|
|
```sql
|
|
CREATE TABLE oauth_clients (
|
|
client_id VARCHAR(255) PRIMARY KEY,
|
|
client_secret VARCHAR(255) NOT NULL,
|
|
client_name VARCHAR(255),
|
|
redirect_uris JSON,
|
|
grant_types JSON DEFAULT '["authorization_code"]',
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
last_used TIMESTAMP NULL,
|
|
is_static BOOLEAN DEFAULT FALSE
|
|
);
|
|
|
|
CREATE TABLE oauth_codes (
|
|
code VARCHAR(255) PRIMARY KEY,
|
|
client_id VARCHAR(255),
|
|
redirect_uri TEXT,
|
|
scope VARCHAR(255),
|
|
expires_at TIMESTAMP NOT NULL,
|
|
used BOOLEAN DEFAULT FALSE
|
|
);
|
|
|
|
CREATE TABLE oauth_tokens (
|
|
token VARCHAR(255) PRIMARY KEY,
|
|
client_id VARCHAR(255),
|
|
token_type VARCHAR(50) DEFAULT 'access',
|
|
expires_at TIMESTAMP NOT NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
revoked BOOLEAN DEFAULT FALSE
|
|
);
|
|
|
|
CREATE TABLE oauth_refresh_tokens (
|
|
token VARCHAR(255) PRIMARY KEY,
|
|
client_id VARCHAR(255),
|
|
access_token VARCHAR(255),
|
|
expires_at TIMESTAMP NOT NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
revoked BOOLEAN DEFAULT FALSE
|
|
);
|
|
```
|
|
|
|
### 7.2 Static Client Support
|
|
|
|
Added pre-registered client for ChatGPT to bypass DCR issues:
|
|
```javascript
|
|
const STATIC_CLIENT = {
|
|
client_id: "chatgpt-static-001",
|
|
client_secret: "[generated-secret]",
|
|
redirect_uris: ["https://chatgpt.com/oauth/callback"],
|
|
grant_types: ["authorization_code", "refresh_token"]
|
|
};
|
|
```
|
|
|
|
---
|
|
|
|
## 8. Operational Learnings
|
|
|
|
### 8.1 Yahoo Search Syntax (Claude Session)
|
|
|
|
**Mistake:** Used Gmail operators (`subject:linkedin`, `from:linkedin`) on Yahoo IMAP.
|
|
|
|
**Result:** Empty results, incorrect conclusion that emails didn't exist.
|
|
|
|
**Correct Approach:** Plain keywords only (`linkedin`, `funding`).
|
|
|
|
**Documented in vault:** `Job Search/2026-04-17-session.md`
|
|
|
|
### 8.2 Container Orchestration Lesson
|
|
|
|
**Rule:** Version images by Git SHA, never use `latest` in production.
|
|
|
|
**Reason:** K8s pod ran 34-day-old `latest` image, ignoring all local builds.
|
|
|
|
---
|
|
|
|
## 9. Documentation & Publishing
|
|
|
|
### 9.1 Medium Article
|
|
|
|
**Title:** Building a Universal AI Gateway: Lessons from Connecting a Personal Knowledge Base to Multiple LLMs
|
|
|
|
**URL:** https://medium.com/@garfieldheron/building-a-universal-ai-gateway-lessons-from-connecting-a-personal-knowledge-base-to-multiple-llms-3430cfa2bb09
|
|
|
|
**Topics:** Artificial Intelligence, Software Engineering, Technology, Productivity, Data Science
|
|
|
|
**Key Points:**
|
|
- MCP as universal protocol
|
|
- Auth duality (API keys + OAuth)
|
|
- Agent-native infrastructure trend
|
|
- Local-first knowledge management
|
|
|
|
### 9.2 LinkedIn Intro
|
|
|
|
```
|
|
The AI tools you use every day are blind to your actual work.
|
|
|
|
ChatGPT doesn't know what's in your notes. Claude can't see your emails.
|
|
Cursor has no idea what you wrote last week.
|
|
|
|
I built something to fix that: a universal gateway that lets any AI assistant
|
|
access my personal knowledge base and communication tools—securely, via standard protocols.
|
|
|
|
No more copy-pasting context. No more "as an AI, I don't have access to..."
|
|
|
|
Here's how I did it, and why I think personal infrastructure is becoming "agent-native":
|
|
|
|
[Link to Medium article]
|
|
```
|
|
|
|
---
|
|
|
|
## 10. Current Configuration
|
|
|
|
### 10.1 Server Details
|
|
|
|
| Setting | Value |
|
|
|---------|-------|
|
|
| **Public URL** | `https://hermes.fetcherpay.com` |
|
|
| **Health Check** | `https://hermes.fetcherpay.com/health` |
|
|
| **Tools Manifest** | `https://hermes.fetcherpay.com/tools` |
|
|
| **MCP Endpoint** | `https://hermes.fetcherpay.com/mcp` |
|
|
| **SSE Endpoint** | `https://hermes.fetcherpay.com/sse` |
|
|
|
|
### 10.2 Authentication
|
|
|
|
| Method | Header/Param | Use Case |
|
|
|--------|--------------|----------|
|
|
| API Key | `x-api-key: [key]` | Local agents |
|
|
| API Key | `?key=[key]` | Local agents |
|
|
| OAuth 2.0 | `Authorization: Bearer [token]` | External services (ChatGPT) |
|
|
|
|
### 10.3 API Key
|
|
|
|
**Value:** `114521f3f9e6858480d6269446a446ef`
|
|
|
|
**Verified locations:**
|
|
- `.env` file
|
|
- `hermes-k8s.yaml`
|
|
- `localhost:3456/health` ✅
|
|
- `hermes.fetcherpay.com/health` ✅
|
|
|
|
### 10.4 OAuth Endpoints
|
|
|
|
| Endpoint | URL |
|
|
|----------|-----|
|
|
| Authorization | `https://hermes.fetcherpay.com/oauth/authorize` |
|
|
| Token | `https://hermes.fetcherpay.com/oauth/token` |
|
|
| Registration | `https://hermes.fetcherpay.com/oauth/register` |
|
|
| Discovery | `https://hermes.fetcherpay.com/.well-known/oauth-authorization-server` |
|
|
|
|
### 10.5 Tools (10 Total)
|
|
|
|
**Email (6 tools):**
|
|
- `yahoo_search_emails`
|
|
- `yahoo_send_email`
|
|
- `yahoo_get_inbox`
|
|
- `fetcherpay_send_email`
|
|
- (plus 2 others)
|
|
|
|
**Obsidian (4 tools):**
|
|
- `obsidian_search_notes`
|
|
- `obsidian_read_note`
|
|
- `obsidian_append_to_note`
|
|
- `obsidian_sync_status`
|
|
|
|
### 10.6 Infrastructure
|
|
|
|
| Component | Technology |
|
|
|-----------|------------|
|
|
| Container Orchestration | MicroK8s |
|
|
| Ingress | nginx-ingress-controller (hostNetwork: true) |
|
|
| Registry | localhost:32000 (local) |
|
|
| TLS | Let's Encrypt (valid until Jun 2 2026) |
|
|
| Database | MySQL (OAuth persistence) |
|
|
| Sync | Syncthing (vault files) |
|
|
|
|
### 10.7 Vault Structure
|
|
|
|
```
|
|
/home/garfield/obsidian/vaults/
|
|
├── Daily Notes/
|
|
├── Projects/
|
|
├── Job Search/
|
|
├── Reference/
|
|
└── Writing/
|
|
```
|
|
|
|
Mounted to K8s pod at `/vaults` (read-write).
|
|
|
|
---
|
|
|
|
## 11. Known Issues & TODOs
|
|
|
|
### 11.1 Active Issues
|
|
|
|
| Issue | Severity | Status |
|
|
|-------|----------|--------|
|
|
| ChatGPT MCP connector not connecting | High | Debugging (0 requests in logs) |
|
|
| CORS headers may need adjustment | Medium | Untested with browser client |
|
|
| Accept header strictness (406 errors) | Medium | May need loosening |
|
|
|
|
### 11.2 TODOs
|
|
|
|
- [ ] Verify ChatGPT MCP connector configuration
|
|
- [ ] Check browser DevTools for CORS/preflight errors
|
|
- [ ] Add refresh token rotation
|
|
- [ ] Implement Kubernetes Secrets (currently plaintext env vars)
|
|
- [ ] Add webhook endpoints (GitHub, Stripe)
|
|
- [ ] Cron-triggered MCP tool calls
|
|
- [ ] Multi-modal support (image/PDF indexing)
|
|
- [ ] Version container images by Git SHA
|
|
- [ ] Add comprehensive request logging (response status codes)
|
|
|
|
### 11.3 Security Improvements
|
|
|
|
- Migrate secrets from plaintext to Kubernetes Secrets
|
|
- Add audit logging for OAuth flows
|
|
- Implement RBAC per tool
|
|
- Add rate limiting
|
|
- Token rotation policy
|
|
|
|
---
|
|
|
|
## Quick Reference Commands
|
|
|
|
### Health Check
|
|
```bash
|
|
curl https://hermes.fetcherpay.com/health
|
|
```
|
|
|
|
### List Tools
|
|
```bash
|
|
curl -H "x-api-key: 114521f3f9e6858480d6269446a446ef" https://hermes.fetcherpay.com/tools
|
|
```
|
|
|
|
### Search Notes
|
|
```bash
|
|
curl -X POST https://hermes.fetcherpay.com/mcp -H "Content-Type: application/json" -H "x-api-key: 114521f3f9e6858480d6269446a446ef" -d '{
|
|
"jsonrpc": "2.0",
|
|
"method": "tools/call",
|
|
"params": {
|
|
"name": "obsidian_search_notes",
|
|
"arguments": {
|
|
"query": "funding strategy",
|
|
"limit": 10
|
|
}
|
|
},
|
|
"id": 1
|
|
}'
|
|
```
|
|
|
|
### K8s Restart
|
|
```bash
|
|
microk8s kubectl rollout restart deployment/hermes-mcp -n fetcherpay
|
|
```
|
|
|
|
### Check Logs
|
|
```bash
|
|
microk8s kubectl logs -f deployment/hermes-mcp -n fetcherpay
|
|
```
|
|
|
|
---
|
|
|
|
## Session Metadata
|
|
|
|
**Total conversation turns:** ~50+
|
|
**Tools used:** web_search, web_open_url, ipython, memory_space_edits
|
|
**Files created:**
|
|
- `/app/.agents/skills/hermes-mcp/SKILL.md` (attempted, workspace ephemeral)
|
|
- Multiple vault entries via Kimi Code/Claude Code
|
|
|
|
**Key decisions:**
|
|
1. Extend hermes-mcp vs separate server → Extend
|
|
2. API keys only vs OAuth → Hybrid (both)
|
|
3. SQLite vs Redis vs MySQL → MySQL (existing infrastructure)
|
|
4. ChatGPT Actions vs MCP connector → MCP connector with OAuth
|
|
|
|
---
|
|
|
|
*Archive generated for Kimi Claw loading*
|
|
*Format: Markdown with frontmatter*
|
|
*Compatible with: Kimi Claw web client, Kimi CLI, Obsidian vault*
|