obsidian-mysql-mcp
by TomJiang123
README.md
# obsidian-mysql-mcp
[](https://github.com/TomJiang123/obsidian-mysql-mcp/actions/workflows/tests.yml)
[](https://www.python.org/)
[](LICENSE)
Obsidian remains the editable source of Markdown. MySQL stores a searchable
index, document revisions, sync changes, and write audit records. Codex and
DSH connect to the same stdio MCP server.
Bidirectional synchronization is available through the explicit `sync` CLI.
Writes from the MCP server itself remain restricted to `inbox/`; ordinary
notes under `wiki/`, `raw/`, and `我/` remain Obsidian-owned.
## Requirements
- Python 3.10+
- A MySQL 8 server and an account allowed to create the configured database
- An Obsidian vault containing Markdown files
The MySQL password is never written to `config.local.toml` or committed to Git.
On Windows it is stored in Credential Manager; the `OBSIDIAN_MYSQL_PASSWORD`
environment variable remains as an explicit override.
## Install
```powershell
git clone https://github.com/TomJiang123/obsidian-mysql-mcp.git
cd obsidian-mysql-mcp
python -m pip install -e ".[dev]"
```
## Configure
Create `config.local.toml` from `config.example.toml`, or launch the GUI:
```powershell
$env:PYTHONPATH = "src"
python -m obsidian_mysql_mcp.gui
```
Store the password once, then the GUI and every MCP client can read it without
an exported variable:
```powershell
$env:PYTHONPATH = "src"
python -m obsidian_mysql_mcp password set
python -m obsidian_mysql_mcp password show
```
`password set` prompts twice and writes to Windows Credential Manager under
`obsidian-mysql-mcp:mysql-password`. `password clear` removes it, and a stored
password can be inspected through Credential Manager itself. Password lookup is
skipped when `OBSIDIAN_MYSQL_PASSWORD` is already set, and can be disabled per
config with `[mysql] credential_target = false`.
The GUI can test the connection, save non-secret settings, scan the vault, and
show status.
## Index
```powershell
$env:PYTHONPATH = "src"
python -m obsidian_mysql_mcp index --full
python -m obsidian_mysql_mcp status
python -m obsidian_mysql_mcp search "matrix"
```
## MCP
Start the stdio server:
```powershell
$env:PYTHONPATH = "src"
python -m obsidian_mysql_mcp.mcp_server
```
The GUI starts the optional local HTTP transport at
`http://127.0.0.1:8765/mcp`. It binds to loopback only. Keep stdio for clients
that launch the MCP process themselves.
Exposed tools:
- `obsidian_search(query, limit)`
- `obsidian_read(path, max_chars)`
- `obsidian_status()`
- `obsidian_append(filename, content, title)`
Client examples are in [docs/codex-config.example.toml](docs/codex-config.example.toml)
and [docs/dsh-cordis.example.yml](docs/dsh-cordis.example.yml). Keep the real
password out of client profiles and source control. On Windows, store it in
Credential Manager with `password set`; the child process inherits the same
Windows account and resolves the credential itself. Export
`OBSIDIAN_MYSQL_PASSWORD` only for clients running under another account or on
a non-Windows host.
The append tool accepts vault-relative names but always stores the result under
`inbox/`. Path traversal is rejected.
## Bidirectional sync
C-stage sync lives behind an explicit CLI command:
```powershell
$env:PYTHONPATH = "src"
python -m obsidian_mysql_mcp sync
python -m obsidian_mysql_mcp sync --apply
```
The first command is a dry run. `--apply` permits the authorized sync engine to
publish MySQL changes to Markdown, but the MCP server itself remains
`inbox/`-only. Divergent edits, ambiguous renames, and deletes that require a
manual decision create rows in `sync_conflicts` and change neither content
source.
`index` establishes the common baseline for every scanned note, including files
whose content was already indexed. Run an index pass once after upgrading an
existing A-stage database before using `sync`.
## Test
```powershell
$env:PYTHONPATH = "src"
python -m pytest -q
```
The live MySQL 8 suite is opt-in and creates then drops one uniquely named
database per test:
```powershell
$env:PYTHONPATH = "src"
$env:OBSIDIAN_MYSQL_E2E = "1"
$env:OBSIDIAN_MYSQL_E2E_HOST = "127.0.0.1"
$env:OBSIDIAN_MYSQL_E2E_PORT = "3306"
$env:OBSIDIAN_MYSQL_E2E_USER = "root"
$env:OBSIDIAN_MYSQL_E2E_PASSWORD = "<your password>"
python -m pytest tests/test_mysql_e2e.py -q
```
## Windows EXE
Install the build extra and run the local build script:
```powershell
python -m pip install -e ".[build]"
.\build.ps1
```
The GUI executable is written to
`dist\ObsidianMySQLMCP\ObsidianMySQLMCP.exe`. It is a management panel: it
configures the vault and MySQL, scans the index, and starts a loopback MCP HTTP
service. Codex/DSH can alternatively launch the Python module over stdio.
The generated executable is a local build artifact and is not committed.
When the panel starts the MCP child, its output is written next to the
executable as `mcp-server.log`.
The scanner and indexer tests use `MemoryRepository`; a live MySQL check needs a
valid local account.
## Data model
- `documents`: current searchable Markdown and stable document IDs
- `sync_changes`: create, update, rename, and delete events
- `write_audit`: records writes made through MCP
- `app_meta`: persisted scan status
- `sync_baselines`: common content hash and path after a completed sync
- `sync_conflicts`: unresolved sync decisions
- `sync_apply_journal`: interrupted Markdown replacement recovery records
The schema already contains `revision`, `content_hash`, `writer_owner`,
`deleted_at`, and `sync_changes`; C-stage sync adds the three tables above.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues