Buckets:

download
raw
3.5 kB
#!/usr/bin/env python3
"""
Obsidian MCP Server for Secure Credential Storage
Reads encrypted or plaintext secrets from Obsidian vault
"""
import json
import os
from pathlib import Path
from typing import Optional
import yaml
# Obsidian Vault Path (anpassen!)
VAULT_PATH = os.getenv("OBSIDIAN_VAULT_PATH", "~/Documents/Obsidian Vault/Secrets")
def get_secret(name: str) -> Optional[str]:
"""Retrieve secret from Obsidian vault"""
vault = Path(VAULT_PATH).expanduser()
# Try YAML format (recommended)
yaml_file = vault / "secrets.yaml"
if yaml_file.exists():
with open(yaml_file) as f:
secrets = yaml.safe_load(f)
return secrets.get(name)
# Try JSON format
json_file = vault / "secrets.json"
if json_file.exists():
with open(json_file) as f:
secrets = json.load(f)
return secrets.get(name)
# Try individual markdown files
md_file = vault / f"{name}.md"
if md_file.exists():
content = md_file.read_text()
# Extract from code block: ```secret\nvalue\n```
if "```secret" in content:
return content.split("```secret")[1].split("```")[0].strip()
return None
def list_secrets() -> list:
"""List all available secrets"""
vault = Path(VAULT_PATH).expanduser()
secrets = []
if not vault.exists():
return []
# Check YAML file
yaml_file = vault / "secrets.yaml"
if yaml_file.exists():
with open(yaml_file) as f:
data = yaml.safe_load(f)
secrets.extend(data.keys())
# Check markdown files
for md_file in vault.glob("*.md"):
secrets.append(md_file.stem)
return secrets
def _mask_value(value: str) -> str:
"""Mask sensitive values for display."""
return f"{value[:4]}...{value[-4:]}"
def main():
"""MCP Server main loop"""
print("Obsidian MCP Server started", file=os.sys.stderr)
while True:
try:
line = input()
request = json.loads(line)
method = request.get("method")
params = request.get("params", {})
if method == "get_secret":
name = params.get("name")
value = get_secret(name)
if value:
# Return full value to client, but do NOT log sensitive data
response = {"result": value, "error": None}
else:
msg = f"Secret '{name}' not found"
response = {"result": None, "error": msg}
elif method == "list_secrets":
secrets = list_secrets()
response = {"result": secrets, "error": None}
elif method == "health":
vault = Path(VAULT_PATH).expanduser()
response = {
"result": {
"status": "ok",
"vault_exists": vault.exists(),
"vault_path": str(vault),
},
"error": None,
}
else:
response = {"error": f"Unknown method: {method}"}
# Output JSON response to stdout (MCP protocol)
# Note: Secret values are masked in logs but returned full
print(json.dumps(response))
except EOFError:
break
except Exception as e:
print(json.dumps({"error": str(e)}))
if __name__ == "__main__":
main()

Xet Storage Details

Size:
3.5 kB
·
Xet hash:
86ee3067ef11fb3208f2a288455bb379c356ce69d201ba38bbf4349ef1cc53c7

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.