@shirokuma-library/mcp-knowledge-base
Version:
MCP server for AI-powered knowledge management with semantic search, graph analysis, and automatic enrichment
63 lines (62 loc) • 2.11 kB
JavaScript
import { DataSource } from 'typeorm';
import { Item } from './entities/Item.js';
import { SystemState } from './entities/SystemState.js';
import { Status } from './entities/Status.js';
import { Tag } from './entities/Tag.js';
import { ItemTag } from './entities/ItemTag.js';
import { ItemRelation } from './entities/ItemRelation.js';
import { Keyword } from './entities/Keyword.js';
import { ItemKeyword } from './entities/ItemKeyword.js';
import { Concept } from './entities/Concept.js';
import { ItemConcept } from './entities/ItemConcept.js';
import path from 'path';
import { fileURLToPath } from 'url';
import fs from 'fs';
import os from 'os';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
function getDatabasePath() {
const envPath = process.env.SHIROKUMA_DATA_DIR;
if (envPath) {
const dbPath = path.join(envPath, 'shirokuma.db');
const dir = path.dirname(dbPath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
return dbPath;
}
const projectPath = path.resolve(__dirname, '../..', '.shirokuma', 'data', 'shirokuma.db');
const projectDir = path.dirname(projectPath);
if (fs.existsSync(projectDir) || process.cwd().includes('shirokuma')) {
if (!fs.existsSync(projectDir)) {
fs.mkdirSync(projectDir, { recursive: true });
}
return projectPath;
}
const homePath = path.join(os.homedir(), '.shirokuma', 'data', 'shirokuma.db');
const homeDir = path.dirname(homePath);
if (!fs.existsSync(homeDir)) {
fs.mkdirSync(homeDir, { recursive: true });
}
return homePath;
}
export const AppDataSource = new DataSource({
type: 'sqlite',
database: getDatabasePath(),
synchronize: false,
logging: false,
entities: [
Item,
SystemState,
Status,
Tag,
ItemTag,
ItemRelation,
Keyword,
ItemKeyword,
Concept,
ItemConcept
],
migrations: [path.join(__dirname, 'migrations', '*.js')],
subscribers: [],
});