compose-obsidian.yml aktualisiert
This commit is contained in:
parent
e5465d26d7
commit
ee8a538bd0
|
|
@ -14,11 +14,6 @@ services:
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
networks:
|
networks:
|
||||||
- cortex-network
|
- cortex-network
|
||||||
healthcheck:
|
|
||||||
test: ["CMD", "curl", "-f", "http://localhost:5984/_up"]
|
|
||||||
interval: 30s
|
|
||||||
timeout: 10s
|
|
||||||
retries: 3
|
|
||||||
|
|
||||||
obsidian-mcp:
|
obsidian-mcp:
|
||||||
image: node:20-alpine
|
image: node:20-alpine
|
||||||
|
|
@ -26,14 +21,112 @@ services:
|
||||||
working_dir: /app
|
working_dir: /app
|
||||||
volumes:
|
volumes:
|
||||||
- /opt/obsidian/vault:/vault
|
- /opt/obsidian/vault:/vault
|
||||||
- ./mcp-server.js:/app/server.js
|
|
||||||
ports:
|
ports:
|
||||||
- "3002:3002"
|
- "3002:3002"
|
||||||
environment:
|
environment:
|
||||||
- NODE_ENV=production
|
|
||||||
- VAULT_PATH=/vault
|
- VAULT_PATH=/vault
|
||||||
- MCP_PORT=3002
|
command: >
|
||||||
command: sh -c "npm init -y && npm install express cors body-parser && node server.js"
|
/bin/sh -c "
|
||||||
|
npm init -y &&
|
||||||
|
npm install express cors body-parser &&
|
||||||
|
cat > server.js << 'EOFSERVER'
|
||||||
|
const express = require('express');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const cors = require('cors');
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
app.use(cors());
|
||||||
|
app.use(express.json());
|
||||||
|
|
||||||
|
const VAULT_PATH = '/vault';
|
||||||
|
|
||||||
|
app.post('/api/mcp/search', (req, res) => {
|
||||||
|
const { query } = req.body;
|
||||||
|
try {
|
||||||
|
const results = [];
|
||||||
|
const walk = (dir) => {
|
||||||
|
const files = fs.readdirSync(dir);
|
||||||
|
files.forEach(file => {
|
||||||
|
const filePath = path.join(dir, file);
|
||||||
|
const stat = fs.statSync(filePath);
|
||||||
|
if (stat.isDirectory() && !file.startsWith('.')) {
|
||||||
|
walk(filePath);
|
||||||
|
} else if (file.endsWith('.md')) {
|
||||||
|
const content = fs.readFileSync(filePath, 'utf8');
|
||||||
|
if (content.includes(query)) {
|
||||||
|
results.push({
|
||||||
|
file: path.relative(VAULT_PATH, filePath),
|
||||||
|
matches: content.split('\n').filter(l => l.includes(query))
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
walk(VAULT_PATH);
|
||||||
|
res.json({ results, count: results.length });
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/api/mcp/create', (req, res) => {
|
||||||
|
const { title, content, tags } = req.body;
|
||||||
|
try {
|
||||||
|
const filename = title.toLowerCase().replace(/\s+/g, '-') + '.md';
|
||||||
|
const filepath = path.join(VAULT_PATH, filename);
|
||||||
|
const frontmatter = \`---
|
||||||
|
title: \${title}
|
||||||
|
tags: [\${tags?.join(', ') || ''}]
|
||||||
|
created: \${new Date().toISOString()}
|
||||||
|
---
|
||||||
|
|
||||||
|
\`;
|
||||||
|
fs.writeFileSync(filepath, frontmatter + (content || ''));
|
||||||
|
res.json({ success: true, file: filename });
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/api/mcp/note/:filename', (req, res) => {
|
||||||
|
try {
|
||||||
|
const filepath = path.join(VAULT_PATH, req.params.filename);
|
||||||
|
const content = fs.readFileSync(filepath, 'utf8');
|
||||||
|
res.json({ content });
|
||||||
|
} catch (err) {
|
||||||
|
res.status(404).json({ error: 'Note not found' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/api/mcp/notes', (req, res) => {
|
||||||
|
try {
|
||||||
|
const notes = [];
|
||||||
|
const walk = (dir) => {
|
||||||
|
const files = fs.readdirSync(dir);
|
||||||
|
files.forEach(file => {
|
||||||
|
const filePath = path.join(dir, file);
|
||||||
|
const stat = fs.statSync(filePath);
|
||||||
|
if (stat.isDirectory() && !file.startsWith('.')) {
|
||||||
|
walk(filePath);
|
||||||
|
} else if (file.endsWith('.md')) {
|
||||||
|
notes.push(path.relative(VAULT_PATH, filePath));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
walk(VAULT_PATH);
|
||||||
|
res.json({ notes });
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.listen(3002, () => {
|
||||||
|
console.log('Obsidian MCP Server running on port 3002');
|
||||||
|
});
|
||||||
|
EOFSERVER
|
||||||
|
node server.js
|
||||||
|
"
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
networks:
|
networks:
|
||||||
- cortex-network
|
- cortex-network
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue