compose-obsidian.yml aktualisiert
This commit is contained in:
parent
e2f6f7ddbb
commit
fb810f229c
|
|
@ -1,159 +1,98 @@
|
||||||
version: '3.8'
|
const express = require('express');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const cors = require('cors');
|
||||||
|
|
||||||
services:
|
const app = express();
|
||||||
# CouchDB für Obsidian Livesync
|
app.use(cors());
|
||||||
couchdb:
|
app.use(express.json());
|
||||||
image: couchdb:3.3
|
|
||||||
container_name: cortex-couchdb
|
|
||||||
ports:
|
|
||||||
- "5984:5984"
|
|
||||||
environment:
|
|
||||||
- COUCHDB_USER=admin
|
|
||||||
- COUCHDB_PASSWORD=admin123
|
|
||||||
- PUID=1000
|
|
||||||
- PGID=1000
|
|
||||||
volumes:
|
|
||||||
- /opt/obsidian/couchdb:/opt/couchdb/data
|
|
||||||
restart: unless-stopped
|
|
||||||
networks:
|
|
||||||
- cortex-network
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD", "curl", "-f", "http://localhost:5984/_up"]
|
|
||||||
interval: 30s
|
|
||||||
timeout: 10s
|
|
||||||
retries: 3
|
|
||||||
|
|
||||||
# MCP Server für Hermes Agent
|
const VAULT_PATH = process.env.VAULT_PATH || '/vault';
|
||||||
obsidian-mcp:
|
|
||||||
image: node:20-alpine
|
|
||||||
container_name: cortex-obsidian-mcp
|
|
||||||
working_dir: /app
|
|
||||||
volumes:
|
|
||||||
- /opt/obsidian/vault:/vault
|
|
||||||
- /opt/obsidian/mcp-data:/data
|
|
||||||
ports:
|
|
||||||
- "3002:3002"
|
|
||||||
environment:
|
|
||||||
- NODE_ENV=production
|
|
||||||
- VAULT_PATH=/vault
|
|
||||||
- MCP_PORT=3002
|
|
||||||
command: >
|
|
||||||
sh -c "
|
|
||||||
npm init -y &&
|
|
||||||
npm install express cors body-parser &&
|
|
||||||
cat > server.js << 'EOFJS'
|
|
||||||
const express = require('express');
|
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
const cors = require('cors');
|
|
||||||
|
|
||||||
const app = express();
|
// Search notes
|
||||||
app.use(cors());
|
app.post('/api/mcp/search', (req, res) => {
|
||||||
app.use(express.json());
|
const { query } = req.body;
|
||||||
|
try {
|
||||||
const VAULT_PATH = process.env.VAULT_PATH || '/vault';
|
const results = [];
|
||||||
|
const walk = (dir) => {
|
||||||
// MCP Tool: Search notes
|
const files = fs.readdirSync(dir);
|
||||||
app.post('/api/mcp/search', (req, res) => {
|
files.forEach(file => {
|
||||||
const { query } = req.body;
|
const filePath = path.join(dir, file);
|
||||||
try {
|
const stat = fs.statSync(filePath);
|
||||||
const results = [];
|
if (stat.isDirectory() && !file.startsWith('.')) {
|
||||||
const walk = (dir) => {
|
walk(filePath);
|
||||||
const files = fs.readdirSync(dir);
|
} else if (file.endsWith('.md')) {
|
||||||
files.forEach(file => {
|
const content = fs.readFileSync(filePath, 'utf8');
|
||||||
const filePath = path.join(dir, file);
|
if (content.includes(query)) {
|
||||||
const stat = fs.statSync(filePath);
|
results.push({
|
||||||
if (stat.isDirectory() && !file.startsWith('.')) {
|
file: path.relative(VAULT_PATH, filePath),
|
||||||
walk(filePath);
|
matches: content.split('\n').filter(l => l.includes(query))
|
||||||
} 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 });
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
walk(VAULT_PATH);
|
||||||
|
res.json({ results, count: results.length });
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// MCP Tool: Create note
|
// Create note
|
||||||
app.post('/api/mcp/create', (req, res) => {
|
app.post('/api/mcp/create', (req, res) => {
|
||||||
const { title, content, tags } = req.body;
|
const { title, content, tags } = req.body;
|
||||||
try {
|
try {
|
||||||
const filename = title.toLowerCase().replace(/\s+/g, '-') + '.md';
|
const filename = title.toLowerCase().replace(/\s+/g, '-') + '.md';
|
||||||
const filepath = path.join(VAULT_PATH, filename);
|
const filepath = path.join(VAULT_PATH, filename);
|
||||||
const frontmatter = \`---
|
const frontmatter = `---
|
||||||
title: \${title}
|
title: ${title}
|
||||||
tags: [\${tags?.join(', ') || ''}]
|
tags: [${tags?.join(', ') || ''}]
|
||||||
created: \${new Date().toISOString()}
|
created: ${new Date().toISOString()}
|
||||||
---
|
---
|
||||||
|
|
||||||
\`;
|
`;
|
||||||
fs.writeFileSync(filepath, frontmatter + (content || ''));
|
fs.writeFileSync(filepath, frontmatter + (content || ''));
|
||||||
res.json({ success: true, file: filename });
|
res.json({ success: true, file: filename });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
res.status(500).json({ error: err.message });
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Get note
|
||||||
|
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' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// List all notes
|
||||||
|
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 });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// MCP Tool: Get note
|
app.listen(3002, () => {
|
||||||
app.get('/api/mcp/note/:filename', (req, res) => {
|
console.log('Obsidian MCP Server running on port 3002');
|
||||||
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' });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// List all notes
|
|
||||||
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');
|
|
||||||
});
|
|
||||||
EOFJS
|
|
||||||
node server.js
|
|
||||||
"
|
|
||||||
restart: unless-stopped
|
|
||||||
networks:
|
|
||||||
- cortex-network
|
|
||||||
depends_on:
|
|
||||||
- couchdb
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:3002/api/mcp/notes"]
|
|
||||||
interval: 30s
|
|
||||||
timeout: 10s
|
|
||||||
retries: 3
|
|
||||||
|
|
||||||
networks:
|
|
||||||
cortex-network:
|
|
||||||
driver: bridge
|
|
||||||
Loading…
Reference in New Issue