mcp-obsidian-via-rest
CLAUDE.md13 starsChanged 11 months agoMITView on GitHub
This is an MCP (Model Context Protocol) server that provides access to Obsidian vaults via the Local REST API plugin. The server can run as a standalone Node/Bun application or as a Docker container, enabling AI assistants to read, search, and interact with Obsidian notes. Multi-Transport Architecture: - Transport Manager (src/transports/manager.ts) - Manages lifecycle of multiple transport types - MCP Server Factory (src/server/mcp-server.ts) - Creates MCP server instances with tools and resources - Transports: - stdio - Standard input/output transport…
- Reads credentials
- Sends data out
In this repository2 other files it gives its agents.
- AGENTS.mdAGENTS.md
- release-itSkill
The file
We split this CLAUDE.md into the rules it gives an agent
10 rules. About 0 are common, 6 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 200
Use API_URLS with multiple URLs including $WSL_GATEWAY_IP for automatic failover
- Distinctive: line 226
Test individual modules and functions
- Distinctive: line 232
Test real API calls against actual Obsidian vault
- Very specific: line 233
Use API_KEY and API_URLS (or legacy API_HOST) environment variables
- Distinctive: line 236
Use testcontainers to spin up dockerized Obsidian
- Distinctive: line 237
Test MCP server in containerized environment
- Very specific: line 246
Test vault located at dockerize/obsidian/data/vault-tests
- Distinctive: line 250
When developing on WSL2 with Obsidian running on Windows host:
- Distinctive: line 274
Must allow inbound connections on port 27124
- Very specific: line 321
Run bun run release (uses release-it + conventional-changelog)
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
This is an MCP (Model Context Protocol) server that provides access to Obsidian vaults via the Local REST API plugin. The server can run as a standalone Node/Bun application or as a Docker container, enabling AI assistants to read, search, and interact with Obsidian notes.
Multi-Transport Architecture:
- Transport Manager (
src/transports/manager.ts) - Manages lifecycle of multiple transport types - MCP Server Factory (
src/server/mcp-server.ts) - Creates MCP server instances with tools and resources - Transports:
stdio- Standard input/output transport (default, best for local MCP clients)http- HTTP JSON-RPC with streaming support (best for remote access)
- Self-Healing API (
src/api/self-healing.ts) - Automatic URL selection and reconnection - Configuration System (
src/config.ts) - Multi-URL and transport configuration
Development Commands
Building and Running
# Install dependencies
bun install
# Build production bundle
bun run build
# Run locally (development mode with DEBUG logs)
bun run start:dev
# Run locally (production mode)
bun run startTesting
# Unit tests (src/**/*.test.ts)
bun test ./src
# E2E tests (requires Obsidian REST API running)
bun test:e2e
# Container tests (uses testcontainers)
bun test:containersCode Quality
# Type checking
bun run checks:types
# Linting (Biome)
bun run checks:lint
# Formatting (Biome)
bun run checks:format
# Unused code detection
bun run checks:knipDocker Operations
# Build local Docker image
bun run docker:latest
# Run Docker container (requires API_KEY and API_URLS env vars)
bun run docker:run
# Start E2E test environment (dockerized Obsidian)
bun run docker:e2e:start
# Stop E2E test environment
bun run docker:e2e:stopMCP Inspector (Debugging)
# Debug with local source
bun run mcp:inspector:local
# Debug with Docker container
bun run mcp:inspector:dockerPublishing
# Prepare package for publishing
bun run publish:prepare
# Create release (uses release-it)
bun run release
# Dry-run release
bun run release:dry
# Create conventional commit
bun run commitArchitecture Details
Multi-Transport Architecture
The MCP server supports multiple transport types simultaneously. Each transport gets its own isolated MCP server instance with tools and resources registered.
Transport Manager (src/transports/manager.ts):
- Accepts a server factory function that creates new MCP server instances
- Creates a separate server instance for each enabled transport
- Manages lifecycle (start/stop) for all transports
- Provides status information for all transports
Why Separate Server Instances?
The MCP SDK's server.connect(transport) method replaces any existing transport. To support multiple transports simultaneously, each transport needs its own server instance.
Architecture Diagram:
┌─────────────────────────────────────────┐
│ Self-Healing Obsidian API │
│ (Multi-URL selection & reconnection) │
└──────────────────┬──────────────────────┘
│
┌──────────┴──────────┐
│ Server Factory │
│ (creates instances)│
└──────────┬──────────┘
│
┌──────┴──────┐
│ │
┌─────▼───┐ ┌─────▼────┐
│ MCP │ │ MCP │
│ Server │ │ Server │
│ (stdio) │ │ (http) │
└────┬────┘ └─────┬────┘
│ │
┌────▼────┐ ┌─────▼──────┐
│ Stdio │ │ HTTP │
│Transport│ │ Transport │
└─────────┘ │ (Hono + │
│ SSE) │
└────────────┘MCP Server Implementation
The MCP server factory (src/server/mcp-server.ts) creates server instances that register:
Tools:
get_note_content- Retrieves note content and metadata by file pathobsidian_search- Searches notes using query stringsobsidian_semantic_search- Semantic search (currently same as regular search)
Resources:
obsidian://{name}- Resource template for accessing notes via URI (e.g.,obsidian://Skills/JavaScript/CORS.md)
Each server instance is independent, so tools/resources are registered on each instance separately.
HTTP Transport
Hono-based HTTP Server (src/transports/http.transport.ts):
- Uses
WebStandardStreamableHTTPServerTransportfor full MCP protocol support - Supports JSON-RPC over HTTP POST
- Supports SSE streaming for responses
- Includes
/healthendpoint for health checks - Optional Bearer token authentication via
MCP_HTTP_TOKEN
Request Logger (src/transports/hono-logger.ts):
- Logs incoming/outgoing HTTP requests
- Uses
debuglibrary (writes to stderr, not stdout) - Inspired by Hono's built-in logger middleware
Self-Healing API
Self-Healing Wrapper (src/api/self-healing.ts):
- Tests multiple URLs in parallel on startup
- Selects fastest responding URL
- Monitors connection health every 30 seconds
- Automatically reconnects to alternative URLs on failure
- Uses exponential backoff to prevent connection thrashing
URL Tester (src/api/url-tester.ts):
- Tests multiple URLs in parallel using
Promise.all - Measures latency for each URL
- Returns results sorted by response time
Configuration Loading Priority
The configuration system (src/config.ts) loads settings in this order (highest priority first):
- Environment variables (
API_KEY,API_URLS, or legacyAPI_HOST+API_PORT) .env.[NODE_ENV].localfiles.env.localfiles (skipped in test mode).env.[NODE_ENV]files.envfile- JSON config file (specified via
--configor defaults toconfigs/config.default.jsonc) - Hardcoded defaults
WSL2 Support:
- Use
API_URLSwith multiple URLs including$WSL_GATEWAY_IPfor automatic failover - The
.envrcfile (loaded by direnv) automatically sets WSL_GATEWAY_IP variable - Example:
API_URLS='["https://127.0.0.1:27124", "https://'$WSL_GATEWAY_IP':27124"]'
Obsidian API Client
The client (src/client/obsidian-api.ts) features:
- Axios-based HTTP client with self-signed certificate support
- Automatic retry logic (5 retries, 1 second timeout per request)
- Bearer token authentication via
Authorizationheader - Comprehensive error handling with detailed logging
Implemented Endpoints:
- Core: list notes, read/write notes, search, get metadata
- Active Note: get/set/close active note, append/patch content
- Commands: list available Obsidian commands
- Extended: batch file reading, directory listing, JSON-based search
Not Implemented (throw "Not implemented"):
- Command execution
- Periodic notes (daily/weekly/monthly notes)
- Note deletion
Testing Strategy
Unit Tests (src/**/*.test.ts):
- Test individual modules and functions
- Mock external dependencies
- Run with
bun test ./src
E2E Tests (tests/*.e2e.test.ts):
- Require a running Obsidian instance with Local REST API plugin
- Test real API calls against actual Obsidian vault
- Use
API_KEYandAPI_URLS(or legacyAPI_HOST) environment variables
Container Tests (tests/*.containers.test.ts):
- Use testcontainers to spin up dockerized Obsidian
- Test MCP server in containerized environment
- Require Docker daemon running
Docker Setup
The project includes a dockerized Obsidian setup for automated testing:
- Base image: Uses VNC for GUI access (port 5900)
- Required capabilities:
--cap-add SYS_ADMIN --device /dev/fuse --security-opt apparmor:unconfined(for AppImage mounting) - Obsidian REST API exposed on port 27124
- Test vault located at
dockerize/obsidian/data/vault-tests
WSL2 Development Notes
When developing on WSL2 with Obsidian running on Windows host:
- Get Windows host IP:
export WSL_GATEWAY_IP=$(ip route show | grep -i default | awk '{ print $3}') Configure API_URLS with automatic failover:
export API_URLS='["https://127.0.0.1:27124", "https://'$WSL_GATEWAY_IP':27124"]'For legacy single-URL configuration:
export API_HOST="https://$WSL_GATEWAY_IP" export API_PORT="27124"- Verify connectivity:
http --verify=no https://$WSL_GATEWAY_IP:27124 - Windows Firewall:
- Must allow inbound connections on port 27124
- Add rule:
New-NetFirewallRule -DisplayName "WSL2 Obsidian REST API" -Direction Inbound -LocalPort 27124 -Protocol TCP -Action Allow
Code Style
- Formatter: Biome (2 spaces, 120 line width, semicolons as needed)
- Linter: Biome with recommended rules
- Import Organization: Enabled via Biome
- TypeScript: Strict mode enabled, bundler module resolution
- Pre-commit Hooks: Lint-staged + Husky for automatic formatting/linting
Environment Variables
Required:
API_KEY- Obsidian Local REST API key (minimum 32 characters)
Obsidian API Configuration:
API_URLS- JSON array of multiple URLs for automatic failover (e.g.,["https://127.0.0.1:27124","https://172.26.32.1:27124"])API_HOST- Single REST API host (fallback for legacy config, default: "localhost")API_PORT- REST API port (default: "27124")API_TEST_TIMEOUT- Timeout in milliseconds for API health checks (default: "2000")API_RETRY_INTERVAL- Interval in milliseconds for reconnection attempts (default: "30000")
Transport Configuration:
MCP_TRANSPORTS- Comma-separated list of transports to enable (default: "stdio,http", options: "stdio,http")stdio- Standard input/output transport (for local MCP clients)http- HTTP transport with built-in SSE streaming support (for remote access)
MCP_HTTP_PORT- HTTP transport port (default: "3000")MCP_HTTP_HOST- HTTP bind address (default: "0.0.0.0")MCP_HTTP_PATH- MCP endpoint path (default: "/mcp")MCP_HTTP_TOKEN- Bearer token for HTTP authentication (optional, enables auth)
Debugging:
DEBUG- Debug logging filter (e.g., "mcp:*" for all MCP logs)NODE_ENV- Environment mode (development/production/test)
Testing (testcontainers):
TESTCONTAINERS_RYUK_DISABLED- Set to "true" to disable resource reaper
Publishing Process
The project publishes to:
- NPM (npmjs.org):
@oleksandrkucherenko/mcp-obsidian - GitHub Packages:
@oleksandrkucherenko/mcp-obsidian - Docker Registry (GHCR):
ghcr.io/oleksandrkucherenko/obsidian-mcp
Release workflow:
- Run
bun run release(uses release-it + conventional-changelog) - GitHub Actions automatically publish to all registries
- Cleanup workflows run monthly to remove old packages/images
Common Patterns
Running with Specific Transports
Stdio only (default):
bun run start
# or explicitly
MCP_TRANSPORTS=stdio bun run startHTTP only:
MCP_TRANSPORTS=http MCP_HTTP_PORT=3000 bun run startBoth transports simultaneously:
MCP_TRANSPORTS=stdio,http MCP_HTTP_PORT=3000 bun run startHTTP with authentication:
MCP_TRANSPORTS=http MCP_HTTP_TOKEN=secret123 bun run startTesting HTTP Transport
Health check:
curl http://localhost:3000/healthInitialize MCP connection:
curl -X POST http://localhost:3000/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {"name": "test", "version": "1.0"}
}
}'List tools:
curl -X POST http://localhost:3000/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}'Running Single Test File
bun test ./tests/obsidian-api.e2e.test.tsDebug Logging
# Enable all MCP logs
DEBUG=mcp:* bun run src/index.ts
# Enable specific log namespaces
DEBUG=mcp:client,mcp:config bun run src/index.ts
# Show STDIN/STDOUT communication
DEBUG=mcp:push,mcp:pull bun run src/index.ts
# Show transport logs
DEBUG=mcp:transports:* bun run src/index.tsManual STDIN Testing
echo '{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test-client", "version": "1.0.0"}}}' | DEBUG=mcp:* bun run src/index.tsMulti-URL Configuration
WSL2 with automatic failover:
export WSL_GATEWAY_IP=$(ip route show | grep -i default | awk '{ print $3}')
API_URLS='["https://127.0.0.1:27124", "https://'$WSL_GATEWAY_IP':27124"]' \
MCP_TRANSPORTS=http \
bun run startDocker with multiple URLs:
docker run --rm -p 3000:3000 \
-e API_KEY=xxx \
-e API_URLS='["https://host.docker.internal:27124","https://172.17.0.1:27124"]' \
-e MCP_TRANSPORTS=http \
ghcr.io/oleksandrkucherenko/obsidian-mcp:latestLoad Custom Config
bun run src/index.ts --config ./configs/config.wsl2.jsoncDiagnostic Scripts
The project includes diagnostic scripts in the scripts/ directory for troubleshooting connectivity and environment issues:
WSL2 Network Diagnostics:
./scripts/diag.wsl2_networking.shComprehensive WSL2 network diagnostics showing:
- WSL2 and Windows host IP addresses
- Network interfaces and Docker networks
- DNS configuration (both WSL and Windows)
- Listening ports on both WSL and Windows sides
Verify API Access from Docker:
./scripts/diag.docker_api.sh [port]Tests Obsidian API connectivity from inside a Docker container using both direct IP and host.docker.internal. Default port: 27124
macOS Docker/Colima Diagnostics:
./scripts/diag.docker_colima.shDiagnoses Docker/Colima issues on macOS Apple Silicon:
- Colima status and Docker environment
- Architecture compatibility (ARM64 vs x86_64 emulation)
- FUSE capability tests
- Container build verification
Additional Resources
- @docs/00_project_knowledge_dump.md
- @docs/01_cleanup_docker_strategy.md
- @docs/02_deprecate_npm_package.md
- @docs/03_releases_publishing.md
- @docs/04_manual_testing.md
- @docs/05_e2e_verification.md
- @docs/06_direnv_setup.md
- @docs/07_pre_release.md
- @docs/08_mcp_registry.md
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

