db.init
Initialize database tables for storing vulnerability findings and security scan results in a bug bounty platform.
Instructions
Initialize database tables (run once on first setup)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/database.ts:150-157 (handler)Handler function for 'db.init' tool that invokes createTables() to initialize the database tables and returns success/error result.async (): Promise<ToolResult> => { try { await createTables(); return formatToolResult(true, { message: 'Database tables created successfully' }); } catch (error: any) { return formatToolResult(false, null, error.message); } }
- src/tools/database.ts:145-148 (schema)Input schema for 'db.init' tool, which takes no parameters.inputSchema: { type: 'object', properties: {}, },
- src/tools/database.ts:141-158 (registration)Registration of the 'db.init' tool on the MCP server, including schema and handler.server.tool( 'db.init', { description: 'Initialize database tables (run once on first setup)', inputSchema: { type: 'object', properties: {}, }, }, async (): Promise<ToolResult> => { try { await createTables(); return formatToolResult(true, { message: 'Database tables created successfully' }); } catch (error: any) { return formatToolResult(false, null, error.message); } } );
- src/integrations/postgres.ts:28-93 (helper)Supporting function createTables() that creates the findings, test_results, and training_data tables with appropriate indexes.export async function createTables(): Promise<void> { const client = await initPostgres().connect(); try { await client.query(` CREATE TABLE IF NOT EXISTS findings ( id SERIAL PRIMARY KEY, target VARCHAR(500) NOT NULL, type VARCHAR(100) NOT NULL, severity VARCHAR(20) NOT NULL, description TEXT NOT NULL, payload TEXT, response TEXT, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP, score INTEGER, status VARCHAR(20) DEFAULT 'new', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE INDEX IF NOT EXISTS idx_findings_target ON findings(target); CREATE INDEX IF NOT EXISTS idx_findings_type ON findings(type); CREATE INDEX IF NOT EXISTS idx_findings_severity ON findings(severity); CREATE INDEX IF NOT EXISTS idx_findings_timestamp ON findings(timestamp); `); await client.query(` CREATE TABLE IF NOT EXISTS test_results ( id SERIAL PRIMARY KEY, target VARCHAR(500) NOT NULL, test_type VARCHAR(100) NOT NULL, success BOOLEAN NOT NULL, score INTEGER DEFAULT 0, result_data JSONB, error_message TEXT, payload TEXT, response_data TEXT, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE INDEX IF NOT EXISTS idx_test_results_target ON test_results(target); CREATE INDEX IF NOT EXISTS idx_test_results_type ON test_results(test_type); CREATE INDEX IF NOT EXISTS idx_test_results_success ON test_results(success); CREATE INDEX IF NOT EXISTS idx_test_results_score ON test_results(score); `); await client.query(` CREATE TABLE IF NOT EXISTS training_data ( id SERIAL PRIMARY KEY, source VARCHAR(50) NOT NULL, source_id VARCHAR(200), vulnerability_type VARCHAR(100) NOT NULL, target_pattern TEXT, payload_pattern TEXT, success_pattern TEXT, failure_pattern TEXT, context_data JSONB, score INTEGER DEFAULT 0, learned_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE INDEX IF NOT EXISTS idx_training_source ON training_data(source); CREATE INDEX IF NOT EXISTS idx_training_type ON training_data(vulnerability_type); `); } finally { client.release(); } }
- src/index.ts:46-46 (registration)Invocation of registerDatabaseTools which registers all database tools including 'db.init'.registerDatabaseTools(server);