diff --git a/src/tools/definitions.rs b/src/tools/definitions.rs deleted file mode 100644 index c6b73b3..0000000 --- a/src/tools/definitions.rs +++ /dev/null @@ -1,693 +0,0 @@ -use serde_json::{json, Value}; - -pub fn get_tools_list() -> Value { - let tools = vec![ - tool_run_backtest(), - tool_run_optimization(), - tool_get_optimization_results(), - tool_analyze_report(), - tool_analyze_monthly_pnl(), - tool_analyze_drawdown_events(), - tool_analyze_top_losses(), - tool_analyze_loss_sequences(), - tool_analyze_position_pairs(), - tool_analyze_direction_bias(), - tool_analyze_streaks(), - tool_analyze_concurrent_peak(), - tool_compare_baseline(), - tool_compile_ea(), - tool_verify_setup(), - tool_list_symbols(), - tool_list_experts(), - tool_list_indicators(), - tool_list_scripts(), - tool_get_backtest_status(), - tool_get_optimization_status(), - tool_prune_reports(), - tool_get_latest_report(), - tool_list_reports(), - tool_search_reports(), - tool_tail_log(), - tool_cache_status(), - tool_clean_cache(), - tool_read_set_file(), - tool_write_set_file(), - tool_patch_set_file(), - tool_clone_set_file(), - tool_set_from_optimization(), - tool_diff_set_files(), - tool_describe_sweep(), - tool_list_set_files(), - tool_list_jobs(), - tool_archive_report(), - tool_archive_all_reports(), - tool_get_history(), - tool_promote_to_baseline(), - tool_annotate_history(), - tool_healthcheck(), - ]; - - json!(tools) -} - -fn tool_run_backtest() -> Value { - json!({ - "name": "run_backtest", - "description": "Run a complete MT5 backtest pipeline: compile → clean cache → backtest → extract → analyze", - "inputSchema": { - "type": "object", - "required": ["expert"], - "properties": { - "expert": { "type": "string", "description": "EA name without path or extension" }, - "symbol": { "type": "string", "description": "Trading symbol" }, - "from_date": { "type": "string", "description": "Start date YYYY.MM.DD" }, - "to_date": { "type": "string", "description": "End date YYYY.MM.DD" }, - "timeframe": { "type": "string", "enum": ["M1", "M5", "M15", "M30", "H1", "H4", "D1"] }, - "deposit": { "type": "integer" }, - "model": { "type": "integer", "enum": [0, 1, 2] }, - "set_file": { "type": "string", "description": "Path to .set parameter file" }, - "skip_compile": { "type": "boolean" }, - "skip_clean": { "type": "boolean" }, - "skip_analyze": { "type": "boolean" }, - "deep": { "type": "boolean", "description": "Run deep analysis" }, - "shutdown": { "type": "boolean", "description": "Close MT5 after backtest" }, - "kill_existing": { "type": "boolean" }, - "timeout": { "type": "integer" }, - "gui": { "type": "boolean" } - } - } - }) -} - -fn tool_run_optimization() -> Value { - json!({ - "name": "run_optimization", - "description": "Launch MT5 genetic parameter optimization", - "inputSchema": { - "type": "object", - "required": ["expert", "set_file", "from_date", "to_date"], - "properties": { - "expert": { "type": "string" }, - "set_file": { "type": "string" }, - "symbol": { "type": "string" }, - "from_date": { "type": "string" }, - "to_date": { "type": "string" }, - "deposit": { "type": "integer" } - } - } - }) -} - -fn tool_get_optimization_results() -> Value { - json!({ - "name": "get_optimization_results", - "description": "Parse completed MT5 optimization results", - "inputSchema": { - "type": "object", - "properties": { - "job_id": { "type": "string" }, - "report_file": { "type": "string" }, - "dd_threshold": { "type": "number" }, - "top_n": { "type": "integer" } - } - } - }) -} - -fn tool_analyze_report() -> Value { - json!({ - "name": "analyze_report", - "description": "Run comprehensive analytics on a backtest report. By default runs all analytics. Use 'analytics' array to run specific ones: monthly_pnl, drawdown_events, top_losses, loss_sequences, position_pairs, direction_bias, streak_analysis, concurrent_peak", - "inputSchema": { - "type": "object", - "properties": { - "report_dir": { "type": "string", "description": "Path to report directory containing deals.csv" }, - "analytics": { - "type": "array", - "description": "Optional: specific analytics to run. If omitted, runs all.", - "items": { - "type": "string", - "enum": ["monthly_pnl", "drawdown_events", "top_losses", "loss_sequences", "position_pairs", "direction_bias", "streak_analysis", "concurrent_peak"] - } - }, - "top_losses_limit": { "type": "integer", "description": "Number of top losses to return (default: 10)" } - } - } - }) -} - -fn tool_analyze_monthly_pnl() -> Value { - json!({ - "name": "analyze_monthly_pnl", - "description": "Analyze monthly profit/loss breakdown from a backtest report", - "inputSchema": { - "type": "object", - "properties": { - "report_dir": { "type": "string", "description": "Path to report directory containing deals.csv" } - } - } - }) -} - -fn tool_analyze_drawdown_events() -> Value { - json!({ - "name": "analyze_drawdown_events", - "description": "Analyze drawdown events reconstructed from balance curve", - "inputSchema": { - "type": "object", - "properties": { - "report_dir": { "type": "string" } - } - } - }) -} - -fn tool_analyze_top_losses() -> Value { - json!({ - "name": "analyze_top_losses", - "description": "Get top N worst losses with grid depth analysis", - "inputSchema": { - "type": "object", - "properties": { - "report_dir": { "type": "string" }, - "limit": { "type": "integer", "description": "Number of losses to return (default: 10)", "default": 10 } - } - } - }) -} - -fn tool_analyze_loss_sequences() -> Value { - json!({ - "name": "analyze_loss_sequences", - "description": "Analyze consecutive loss streaks and their impact", - "inputSchema": { - "type": "object", - "properties": { - "report_dir": { "type": "string" } - } - } - }) -} - -fn tool_analyze_position_pairs() -> Value { - json!({ - "name": "analyze_position_pairs", - "description": "Analyze entry/exit position pairs and their performance", - "inputSchema": { - "type": "object", - "properties": { - "report_dir": { "type": "string" } - } - } - }) -} - -fn tool_analyze_direction_bias() -> Value { - json!({ - "name": "analyze_direction_bias", - "description": "Analyze long vs short performance bias", - "inputSchema": { - "type": "object", - "properties": { - "report_dir": { "type": "string" } - } - } - }) -} - -fn tool_analyze_streaks() -> Value { - json!({ - "name": "analyze_streaks", - "description": "Analyze win/loss streaks with dates and current streak", - "inputSchema": { - "type": "object", - "properties": { - "report_dir": { "type": "string" } - } - } - }) -} - -fn tool_analyze_concurrent_peak() -> Value { - json!({ - "name": "analyze_concurrent_peak", - "description": "Find peak number of concurrent open positions", - "inputSchema": { - "type": "object", - "properties": { - "report_dir": { "type": "string" } - } - } - }) -} - -fn tool_compare_baseline() -> Value { - json!({ - "name": "compare_baseline", - "description": "Compare a backtest report against a baseline", - "inputSchema": { - "type": "object", - "required": ["baseline"], - "properties": { - "baseline": { - "type": "object", - "properties": { - "net_profit": { "type": "number" }, - "max_dd_pct": { "type": "number" }, - "total_trades": { "type": "integer" } - } - }, - "report_dir": { "type": "string" }, - "promote_dd_limit": { "type": "number" } - } - } - }) -} - -fn tool_compile_ea() -> Value { - json!({ - "name": "compile_ea", - "description": "Compile an MQL5 Expert Advisor via MetaEditor. Provide either 'expert' (EA name, searches project and MT5 Experts dirs) or 'expert_path' (full path to .mq5 file).", - "inputSchema": { - "type": "object", - "properties": { - "expert": { "type": "string", "description": "EA name without extension (e.g. 'DPS21')" }, - "expert_path": { "type": "string", "description": "Full path to the .mq5 source file" } - } - } - }) -} - -fn tool_verify_setup() -> Value { - json!({ - "name": "verify_setup", - "description": "Verify MT5-Quant environment", - "inputSchema": { "type": "object", "properties": {} } - }) -} - -fn tool_list_symbols() -> Value { - json!({ - "name": "list_symbols", - "description": "List symbols with local tick history", - "inputSchema": { - "type": "object", - "properties": { - "server": { "type": "string" } - } - } - }) -} - -fn tool_list_experts() -> Value { - json!({ - "name": "list_experts", - "description": "List all compiled Expert Advisors", - "inputSchema": { - "type": "object", - "properties": { - "filter": { "type": "string" } - } - } - }) -} - -fn tool_list_indicators() -> Value { - json!({ - "name": "list_indicators", - "description": "List all custom indicators in MQL5/Indicators", - "inputSchema": { - "type": "object", - "properties": { - "filter": { "type": "string", "description": "Optional name filter pattern" }, - "include_builtin": { "type": "boolean", "description": "Include built-in MT5 indicators", "default": false } - } - } - }) -} - -fn tool_list_scripts() -> Value { - json!({ - "name": "list_scripts", - "description": "List all scripts in MQL5/Scripts", - "inputSchema": { - "type": "object", - "properties": { - "filter": { "type": "string", "description": "Optional name filter pattern" } - } - } - }) -} - -fn tool_get_backtest_status() -> Value { - json!({ - "name": "get_backtest_status", - "description": "Check progress of a running backtest pipeline", - "inputSchema": { - "type": "object", - "properties": { - "report_dir": { "type": "string" } - } - } - }) -} - -fn tool_get_optimization_status() -> Value { - json!({ - "name": "get_optimization_status", - "description": "Check if an optimization job is running", - "inputSchema": { - "type": "object", - "required": ["job_id"], - "properties": { - "job_id": { "type": "string" } - } - } - }) -} - -fn tool_prune_reports() -> Value { - json!({ - "name": "prune_reports", - "description": "Delete old backtest report directories", - "inputSchema": { - "type": "object", - "properties": { - "keep_last": { "type": "integer" } - } - } - }) -} - -fn tool_get_latest_report() -> Value { - json!({ - "name": "get_latest_report", - "description": "Get the latest backtest report with full details and equity chart image", - "inputSchema": { - "type": "object", - "properties": { - "include_chart": { "type": "boolean", "description": "Include equity chart as base64 PNG (default: true)", "default": true } - } - } - }) -} - -fn tool_list_reports() -> Value { - json!({ - "name": "list_reports", - "description": "List most recent backtest reports from the central registry (SQLite). Returns id, metrics, set file, chart paths.", - "inputSchema": { - "type": "object", - "properties": { - "limit": { "type": "integer", "description": "Max results (default 30)" } - } - } - }) -} - -fn tool_search_reports() -> Value { - json!({ - "name": "search_reports", - "description": "Search backtest history with filters. All filters are optional and combinable.", - "inputSchema": { - "type": "object", - "properties": { - "expert": { "type": "string", "description": "EA name substring match" }, - "symbol": { "type": "string", "description": "Exact symbol, e.g. XAUUSD" }, - "timeframe": { "type": "string", "description": "Exact timeframe, e.g. M5" }, - "after": { "type": "string", "description": "ISO8601 date — only reports created after this" }, - "min_profit": { "type": "number", "description": "Minimum net profit" }, - "max_dd": { "type": "number", "description": "Maximum drawdown %" }, - "verdict": { "type": "string", "enum": ["winner", "loser", "marginal", "reference"] }, - "limit": { "type": "integer", "description": "Max results (default 50)" } - } - } - }) -} - -fn tool_tail_log() -> Value { - json!({ - "name": "tail_log", - "description": "Read the last N lines of a log file", - "inputSchema": { - "type": "object", - "properties": { - "n": { "type": "integer" }, - "filter": { "type": "string", "enum": ["all", "errors", "warnings"] }, - "log_file": { "type": "string" }, - "report_dir": { "type": "string" }, - "job_id": { "type": "string" } - } - } - }) -} - -fn tool_cache_status() -> Value { - json!({ - "name": "cache_status", - "description": "Show MT5 tester cache size breakdown", - "inputSchema": { "type": "object", "properties": {} } - }) -} - -fn tool_clean_cache() -> Value { - json!({ - "name": "clean_cache", - "description": "Delete MT5 tester cache files", - "inputSchema": { - "type": "object", - "properties": { - "symbol": { "type": "string" }, - "dry_run": { "type": "boolean" } - } - } - }) -} - -fn tool_read_set_file() -> Value { - json!({ - "name": "read_set_file", - "description": "Parse an MT5 .set parameter file", - "inputSchema": { - "type": "object", - "required": ["path"], - "properties": { - "path": { "type": "string" } - } - } - }) -} - -fn tool_write_set_file() -> Value { - json!({ - "name": "write_set_file", - "description": "Write an MT5 .set parameter file", - "inputSchema": { - "type": "object", - "required": ["path", "params"], - "properties": { - "path": { "type": "string" }, - "params": { "type": "object" } - } - } - }) -} - -fn tool_patch_set_file() -> Value { - json!({ - "name": "patch_set_file", - "description": "Modify specific parameters in a .set file", - "inputSchema": { - "type": "object", - "required": ["path", "patches"], - "properties": { - "path": { "type": "string" }, - "patches": { "type": "object" } - } - } - }) -} - -fn tool_clone_set_file() -> Value { - json!({ - "name": "clone_set_file", - "description": "Copy a .set file to a new path with optional overrides", - "inputSchema": { - "type": "object", - "required": ["source", "destination"], - "properties": { - "source": { "type": "string" }, - "destination": { "type": "string" }, - "overrides": { "type": "object" } - } - } - }) -} - -fn tool_set_from_optimization() -> Value { - json!({ - "name": "set_from_optimization", - "description": "Generate .set file from optimization result params", - "inputSchema": { - "type": "object", - "required": ["path", "params"], - "properties": { - "path": { "type": "string" }, - "params": { "type": "object" }, - "template": { "type": "string" }, - "sweep": { "type": "object" } - } - } - }) -} - -fn tool_diff_set_files() -> Value { - json!({ - "name": "diff_set_files", - "description": "Compare two .set files", - "inputSchema": { - "type": "object", - "required": ["path_a", "path_b"], - "properties": { - "path_a": { "type": "string" }, - "path_b": { "type": "string" } - } - } - }) -} - -fn tool_describe_sweep() -> Value { - json!({ - "name": "describe_sweep", - "description": "Show .set file sweep configuration", - "inputSchema": { - "type": "object", - "required": ["path"], - "properties": { - "path": { "type": "string" } - } - } - }) -} - -fn tool_list_set_files() -> Value { - json!({ - "name": "list_set_files", - "description": "List all .set files in tester profiles directory", - "inputSchema": { - "type": "object", - "properties": { - "ea": { "type": "string" } - } - } - }) -} - -fn tool_list_jobs() -> Value { - json!({ - "name": "list_jobs", - "description": "List all optimization jobs", - "inputSchema": { - "type": "object", - "properties": { - "include_done": { "type": "boolean" } - } - } - }) -} - -fn tool_archive_report() -> Value { - json!({ - "name": "archive_report", - "description": "Convert report to JSON and append to history", - "inputSchema": { - "type": "object", - "properties": { - "report_dir": { "type": "string" }, - "delete_after": { "type": "boolean" }, - "notes": { "type": "string" }, - "tags": { "type": "array", "items": { "type": "string" } }, - "verdict": { "type": "string", "enum": ["winner", "loser", "marginal", "reference"] } - } - } - }) -} - -fn tool_archive_all_reports() -> Value { - json!({ - "name": "archive_all_reports", - "description": "Bulk-archive all backtest reports", - "inputSchema": { - "type": "object", - "properties": { - "delete_after": { "type": "boolean" }, - "keep_last": { "type": "integer" }, - "dry_run": { "type": "boolean" } - } - } - }) -} - -fn tool_get_history() -> Value { - json!({ - "name": "get_history", - "description": "Query backtest history with filters", - "inputSchema": { - "type": "object", - "properties": { - "ea": { "type": "string" }, - "symbol": { "type": "string" }, - "tag": { "type": "string" }, - "verdict": { "type": "string" }, - "sort_by": { "type": "string" }, - "limit": { "type": "integer" }, - "include_monthly": { "type": "boolean" } - } - } - }) -} - -fn tool_promote_to_baseline() -> Value { - json!({ - "name": "promote_to_baseline", - "description": "Promote a backtest result to baseline", - "inputSchema": { - "type": "object", - "properties": { - "history_id": { "type": "string" }, - "report_dir": { "type": "string" }, - "notes": { "type": "string" } - } - } - }) -} - -fn tool_annotate_history() -> Value { - json!({ - "name": "annotate_history", - "description": "Add notes, verdict, or tags to a report entry in the registry", - "inputSchema": { - "type": "object", - "required": ["history_id"], - "properties": { - "history_id": { "type": "string", "description": "Report id from list_reports or search_reports" }, - "notes": { "type": "string" }, - "tags": { "type": "array", "items": { "type": "string" } }, - "verdict": { "type": "string", "enum": ["winner", "loser", "marginal", "reference"] } - } - } - }) -} - -fn tool_healthcheck() -> Value { - json!({ - "name": "healthcheck", - "description": "System health check with OS detection and configuration validation", - "inputSchema": { - "type": "object", - "properties": { - "detailed": { "type": "boolean", "description": "Include detailed system info", "default": false } - } - } - }) -} diff --git a/src/tools/definitions/analytics.rs b/src/tools/definitions/analytics.rs new file mode 100644 index 0000000..05bb24c --- /dev/null +++ b/src/tools/definitions/analytics.rs @@ -0,0 +1,128 @@ +use serde_json::{json, Value}; + +pub fn tool_analyze_report() -> Value { + json!({ + "name": "analyze_report", + "description": "Run comprehensive analytics on a backtest report. By default runs all analytics. Use 'analytics' array to run specific ones: monthly_pnl, drawdown_events, top_losses, loss_sequences, position_pairs, direction_bias, streak_analysis, concurrent_peak", + "inputSchema": { + "type": "object", + "properties": { + "report_dir": { "type": "string", "description": "Path to report directory containing deals.csv" }, + "analytics": { + "type": "array", + "description": "Optional: specific analytics to run. If omitted, runs all.", + "items": { + "type": "string", + "enum": ["monthly_pnl", "drawdown_events", "top_losses", "loss_sequences", "position_pairs", "direction_bias", "streak_analysis", "concurrent_peak"] + } + }, + "top_losses_limit": { "type": "integer", "description": "Number of top losses to return (default: 10)" } + } + } + }) +} + +pub fn tool_analyze_monthly_pnl() -> Value { + json!({ + "name": "analyze_monthly_pnl", + "description": "Analyze monthly profit/loss breakdown from a backtest report", + "inputSchema": { + "type": "object", + "properties": { + "report_dir": { "type": "string", "description": "Path to report directory containing deals.csv" } + } + } + }) +} + +pub fn tool_analyze_drawdown_events() -> Value { + json!({ + "name": "analyze_drawdown_events", + "description": "Analyze drawdown events reconstructed from balance curve", + "inputSchema": { + "type": "object", + "properties": { + "report_dir": { "type": "string" } + } + } + }) +} + +pub fn tool_analyze_top_losses() -> Value { + json!({ + "name": "analyze_top_losses", + "description": "Get top N worst losses with grid depth analysis", + "inputSchema": { + "type": "object", + "properties": { + "report_dir": { "type": "string" }, + "limit": { "type": "integer", "description": "Number of losses to return (default: 10)", "default": 10 } + } + } + }) +} + +pub fn tool_analyze_loss_sequences() -> Value { + json!({ + "name": "analyze_loss_sequences", + "description": "Analyze consecutive loss streaks and their impact", + "inputSchema": { + "type": "object", + "properties": { + "report_dir": { "type": "string" } + } + } + }) +} + +pub fn tool_analyze_position_pairs() -> Value { + json!({ + "name": "analyze_position_pairs", + "description": "Analyze entry/exit position pairs and their performance", + "inputSchema": { + "type": "object", + "properties": { + "report_dir": { "type": "string" } + } + } + }) +} + +pub fn tool_analyze_direction_bias() -> Value { + json!({ + "name": "analyze_direction_bias", + "description": "Analyze long vs short performance bias", + "inputSchema": { + "type": "object", + "properties": { + "report_dir": { "type": "string" } + } + } + }) +} + +pub fn tool_analyze_streaks() -> Value { + json!({ + "name": "analyze_streaks", + "description": "Analyze win/loss streaks with dates and current streak", + "inputSchema": { + "type": "object", + "properties": { + "report_dir": { "type": "string" } + } + } + }) +} + +pub fn tool_analyze_concurrent_peak() -> Value { + json!({ + "name": "analyze_concurrent_peak", + "description": "Find peak number of concurrent open positions", + "inputSchema": { + "type": "object", + "properties": { + "report_dir": { "type": "string" } + } + } + }) +} diff --git a/src/tools/definitions/backtest.rs b/src/tools/definitions/backtest.rs new file mode 100644 index 0000000..536524f --- /dev/null +++ b/src/tools/definitions/backtest.rs @@ -0,0 +1,67 @@ +use serde_json::{json, Value}; + +pub fn tool_run_backtest() -> Value { + json!({ + "name": "run_backtest", + "description": "Run a complete MT5 backtest pipeline: compile → clean cache → backtest → extract → analyze", + "inputSchema": { + "type": "object", + "required": ["expert"], + "properties": { + "expert": { "type": "string", "description": "EA name without path or extension" }, + "symbol": { "type": "string", "description": "Trading symbol" }, + "from_date": { "type": "string", "description": "Start date YYYY.MM.DD" }, + "to_date": { "type": "string", "description": "End date YYYY.MM.DD" }, + "timeframe": { "type": "string", "enum": ["M1", "M5", "M15", "M30", "H1", "H4", "D1"] }, + "deposit": { "type": "integer" }, + "model": { "type": "integer", "enum": [0, 1, 2] }, + "set_file": { "type": "string", "description": "Path to .set parameter file" }, + "skip_compile": { "type": "boolean" }, + "skip_clean": { "type": "boolean" }, + "skip_analyze": { "type": "boolean" }, + "deep": { "type": "boolean", "description": "Run deep analysis" }, + "shutdown": { "type": "boolean", "description": "Close MT5 after backtest" }, + "kill_existing": { "type": "boolean" }, + "timeout": { "type": "integer" }, + "gui": { "type": "boolean" } + } + } + }) +} + +pub fn tool_get_backtest_status() -> Value { + json!({ + "name": "get_backtest_status", + "description": "Check progress of a running backtest pipeline", + "inputSchema": { + "type": "object", + "properties": { + "report_dir": { "type": "string" } + } + } + }) +} + +pub fn tool_cache_status() -> Value { + json!({ + "name": "cache_status", + "description": "Check tester cache disk usage", + "inputSchema": { + "type": "object" + } + }) +} + +pub fn tool_clean_cache() -> Value { + json!({ + "name": "clean_cache", + "description": "Delete old tester cache files", + "inputSchema": { + "type": "object", + "properties": { + "symbol": { "type": "string" }, + "dry_run": { "type": "boolean" } + } + } + }) +} diff --git a/src/tools/definitions/baseline.rs b/src/tools/definitions/baseline.rs new file mode 100644 index 0000000..b426b3b --- /dev/null +++ b/src/tools/definitions/baseline.rs @@ -0,0 +1,24 @@ +use serde_json::{json, Value}; + +pub fn tool_compare_baseline() -> Value { + json!({ + "name": "compare_baseline", + "description": "Compare a backtest report against a baseline", + "inputSchema": { + "type": "object", + "required": ["baseline"], + "properties": { + "baseline": { + "type": "object", + "properties": { + "net_profit": { "type": "number" }, + "max_dd_pct": { "type": "number" }, + "total_trades": { "type": "integer" } + } + }, + "report_dir": { "type": "string" }, + "promote_dd_limit": { "type": "number" } + } + } + }) +} diff --git a/src/tools/definitions/experts.rs b/src/tools/definitions/experts.rs new file mode 100644 index 0000000..522da8b --- /dev/null +++ b/src/tools/definitions/experts.rs @@ -0,0 +1,55 @@ +use serde_json::{json, Value}; + +pub fn tool_compile_ea() -> Value { + json!({ + "name": "compile_ea", + "description": "Compile an MQL5 Expert Advisor via MetaEditor. Provide either 'expert' (EA name, searches project and MT5 Experts dirs) or 'expert_path' (full path to .mq5 file).", + "inputSchema": { + "type": "object", + "properties": { + "expert": { "type": "string", "description": "EA name without extension (e.g. 'DPS21')" }, + "expert_path": { "type": "string", "description": "Full path to the .mq5 source file" } + } + } + }) +} + +pub fn tool_list_experts() -> Value { + json!({ + "name": "list_experts", + "description": "List all compiled Expert Advisors", + "inputSchema": { + "type": "object", + "properties": { + "filter": { "type": "string" } + } + } + }) +} + +pub fn tool_list_indicators() -> Value { + json!({ + "name": "list_indicators", + "description": "List all custom indicators in MQL5/Indicators", + "inputSchema": { + "type": "object", + "properties": { + "filter": { "type": "string", "description": "Optional name filter pattern" }, + "include_builtin": { "type": "boolean", "description": "Include built-in MT5 indicators", "default": false } + } + } + }) +} + +pub fn tool_list_scripts() -> Value { + json!({ + "name": "list_scripts", + "description": "List all scripts in MQL5/Scripts", + "inputSchema": { + "type": "object", + "properties": { + "filter": { "type": "string", "description": "Optional name filter pattern" } + } + } + }) +} diff --git a/src/tools/definitions/mod.rs b/src/tools/definitions/mod.rs new file mode 100644 index 0000000..fa64005 --- /dev/null +++ b/src/tools/definitions/mod.rs @@ -0,0 +1,68 @@ +use serde_json::Value; + +pub mod analytics; +pub mod backtest; +pub mod baseline; +pub mod experts; +pub mod optimization; +pub mod reports; +pub mod setfiles; +pub mod system; + +pub fn get_tools_list() -> Value { + let tools = vec![ + // Backtest + backtest::tool_run_backtest(), + backtest::tool_get_backtest_status(), + backtest::tool_cache_status(), + backtest::tool_clean_cache(), + // Optimization + optimization::tool_run_optimization(), + optimization::tool_get_optimization_status(), + optimization::tool_get_optimization_results(), + optimization::tool_list_jobs(), + // Analytics (9 tools) + analytics::tool_analyze_report(), + analytics::tool_analyze_monthly_pnl(), + analytics::tool_analyze_drawdown_events(), + analytics::tool_analyze_top_losses(), + analytics::tool_analyze_loss_sequences(), + analytics::tool_analyze_position_pairs(), + analytics::tool_analyze_direction_bias(), + analytics::tool_analyze_streaks(), + analytics::tool_analyze_concurrent_peak(), + // Baseline + baseline::tool_compare_baseline(), + // Experts + experts::tool_compile_ea(), + experts::tool_list_experts(), + experts::tool_list_indicators(), + experts::tool_list_scripts(), + // System + system::tool_verify_setup(), + system::tool_list_symbols(), + system::tool_healthcheck(), + // Set Files + setfiles::tool_read_set_file(), + setfiles::tool_write_set_file(), + setfiles::tool_patch_set_file(), + setfiles::tool_clone_set_file(), + setfiles::tool_diff_set_files(), + setfiles::tool_describe_sweep(), + setfiles::tool_list_set_files(), + setfiles::tool_set_from_optimization(), + // Reports (11 tools) + reports::tool_list_reports(), + reports::tool_search_reports(), + reports::tool_get_latest_report(), + reports::tool_prune_reports(), + reports::tool_tail_log(), + reports::tool_archive_report(), + reports::tool_archive_all_reports(), + reports::tool_get_history(), + reports::tool_promote_to_baseline(), + reports::tool_annotate_history(), + ]; + + serde_json::json!(tools) +} diff --git a/src/tools/definitions/optimization.rs b/src/tools/definitions/optimization.rs new file mode 100644 index 0000000..672b931 --- /dev/null +++ b/src/tools/definitions/optimization.rs @@ -0,0 +1,60 @@ +use serde_json::{json, Value}; + +pub fn tool_run_optimization() -> Value { + json!({ + "name": "run_optimization", + "description": "Launch MT5 genetic parameter optimization", + "inputSchema": { + "type": "object", + "required": ["expert", "set_file", "from_date", "to_date"], + "properties": { + "expert": { "type": "string" }, + "set_file": { "type": "string" }, + "symbol": { "type": "string" }, + "from_date": { "type": "string" }, + "to_date": { "type": "string" }, + "deposit": { "type": "integer" } + } + } + }) +} + +pub fn tool_get_optimization_status() -> Value { + json!({ + "name": "get_optimization_status", + "description": "Check progress of a running optimization job", + "inputSchema": { + "type": "object", + "required": ["job_id"], + "properties": { + "job_id": { "type": "string" } + } + } + }) +} + +pub fn tool_get_optimization_results() -> Value { + json!({ + "name": "get_optimization_results", + "description": "Parse completed MT5 optimization results", + "inputSchema": { + "type": "object", + "properties": { + "job_id": { "type": "string" }, + "report_file": { "type": "string" }, + "dd_threshold": { "type": "number" }, + "top_n": { "type": "integer" } + } + } + }) +} + +pub fn tool_list_jobs() -> Value { + json!({ + "name": "list_jobs", + "description": "List running and completed optimization jobs", + "inputSchema": { + "type": "object" + } + }) +} diff --git a/src/tools/definitions/reports.rs b/src/tools/definitions/reports.rs new file mode 100644 index 0000000..7347d6e --- /dev/null +++ b/src/tools/definitions/reports.rs @@ -0,0 +1,150 @@ +use serde_json::{json, Value}; + +pub fn tool_get_latest_report() -> Value { + json!({ + "name": "get_latest_report", + "description": "Get the latest backtest report with full details and equity chart image", + "inputSchema": { + "type": "object", + "properties": { + "include_chart": { "type": "boolean", "description": "Include equity chart as base64 PNG (default: true)", "default": true } + } + } + }) +} + +pub fn tool_list_reports() -> Value { + json!({ + "name": "list_reports", + "description": "List most recent backtest reports from the central registry (SQLite). Returns id, metrics, set file, chart paths.", + "inputSchema": { + "type": "object", + "properties": { + "limit": { "type": "integer", "description": "Max results (default 30)" } + } + } + }) +} + +pub fn tool_search_reports() -> Value { + json!({ + "name": "search_reports", + "description": "Search backtest history with filters. All filters are optional and combinable.", + "inputSchema": { + "type": "object", + "properties": { + "expert": { "type": "string", "description": "EA name substring match" }, + "symbol": { "type": "string", "description": "Exact symbol, e.g. XAUUSD" }, + "timeframe": { "type": "string", "description": "Exact timeframe, e.g. M5" }, + "after": { "type": "string", "description": "ISO8601 date — only reports created after this" }, + "min_profit": { "type": "number", "description": "Minimum net profit" }, + "max_dd": { "type": "number", "description": "Maximum drawdown %" }, + "verdict": { "type": "string", "description": "Only reports with this verdict (pass, fail, marginal)" }, + "limit": { "type": "integer", "default": 50 } + } + } + }) +} + +pub fn tool_tail_log() -> Value { + json!({ + "name": "tail_log", + "description": "Stream the last N lines of a job log", + "inputSchema": { + "type": "object", + "properties": { + "job_id": { "type": "string" }, + "file": { "type": "string" }, + "lines": { "type": "integer", "default": 50 } + } + } + }) +} + +pub fn tool_archive_report() -> Value { + json!({ + "name": "archive_report", + "description": "Compress a backtest report directory to tar.gz", + "inputSchema": { + "type": "object", + "required": ["report_dir"], + "properties": { + "report_dir": { "type": "string" }, + "delete_after": { "type": "boolean" } + } + } + }) +} + +pub fn tool_archive_all_reports() -> Value { + json!({ + "name": "archive_all_reports", + "description": "Archive all old reports except the N most recent", + "inputSchema": { + "type": "object", + "properties": { + "keep_last": { "type": "integer" } + } + } + }) +} + +pub fn tool_get_history() -> Value { + json!({ + "name": "get_history", + "description": "Retrieve backtest history for an EA or symbol", + "inputSchema": { + "type": "object", + "properties": { + "ea": { "type": "string" }, + "symbol": { "type": "string" }, + "verdict": { "type": "string" }, + "limit": { "type": "integer" } + } + } + }) +} + +pub fn tool_promote_to_baseline() -> Value { + json!({ + "name": "promote_to_baseline", + "description": "Copy report metrics to config/baseline.json for future comparisons", + "inputSchema": { + "type": "object", + "required": ["report_dir"], + "properties": { + "report_dir": { "type": "string" } + } + } + }) +} + +pub fn tool_annotate_history() -> Value { + json!({ + "name": "annotate_history", + "description": "Add notes, tags or verdict to a history entry", + "inputSchema": { + "type": "object", + "required": ["history_id"], + "properties": { + "history_id": { "type": "string" }, + "notes": { "type": "string" }, + "tags": { "type": "array", "items": { "type": "string" } }, + "verdict": { "type": "string", "enum": ["pass", "fail", "marginal"] } + } + } + }) +} + +pub fn tool_prune_reports() -> Value { + json!({ + "name": "prune_reports", + "description": "Delete old backtest report directories", + "inputSchema": { + "type": "object", + "properties": { + "keep_last": { "type": "integer" } + } + } + }) +} diff --git a/src/tools/definitions/setfiles.rs b/src/tools/definitions/setfiles.rs new file mode 100644 index 0000000..adaaa56 --- /dev/null +++ b/src/tools/definitions/setfiles.rs @@ -0,0 +1,114 @@ +use serde_json::{json, Value}; + +pub fn tool_read_set_file() -> Value { + json!({ + "name": "read_set_file", + "description": "Read a .set parameter file into a JSON object", + "inputSchema": { + "type": "object", + "required": ["path"], + "properties": { + "path": { "type": "string" } + } + } + }) +} + +pub fn tool_write_set_file() -> Value { + json!({ + "name": "write_set_file", + "description": "Write a JSON object to a .set parameter file", + "inputSchema": { + "type": "object", + "required": ["path", "parameters"], + "properties": { + "path": { "type": "string" }, + "parameters": { "type": "object" } + } + } + }) +} + +pub fn tool_patch_set_file() -> Value { + json!({ + "name": "patch_set_file", + "description": "Update specific keys in an existing .set file", + "inputSchema": { + "type": "object", + "required": ["path", "patches"], + "properties": { + "path": { "type": "string" }, + "patches": { "type": "object" } + } + } + }) +} + +pub fn tool_clone_set_file() -> Value { + json!({ + "name": "clone_set_file", + "description": "Duplicate an existing .set file to a new path", + "inputSchema": { + "type": "object", + "required": ["source", "destination"], + "properties": { + "source": { "type": "string" }, + "destination": { "type": "string" } + } + } + }) +} + +pub fn tool_diff_set_files() -> Value { + json!({ + "name": "diff_set_files", + "description": "Compare two .set files and return differences", + "inputSchema": { + "type": "object", + "required": ["file_a", "file_b"], + "properties": { + "file_a": { "type": "string" }, + "file_b": { "type": "string" } + } + } + }) +} + +pub fn tool_set_from_optimization() -> Value { + json!({ + "name": "set_from_optimization", + "description": "Generate a .set file from optimization best pass results", + "inputSchema": { + "type": "object", + "required": ["path", "params"], + "properties": { + "path": { "type": "string" }, + "params": { "type": "object" } + } + } + }) +} + +pub fn tool_describe_sweep() -> Value { + json!({ + "name": "describe_sweep", + "description": "List the parameters being swept in a .set file", + "inputSchema": { + "type": "object", + "required": ["path"], + "properties": { + "path": { "type": "string" } + } + } + }) +} + +pub fn tool_list_set_files() -> Value { + json!({ + "name": "list_set_files", + "description": "List all .set files in the tester profiles directory", + "inputSchema": { + "type": "object" + } + }) +} diff --git a/src/tools/definitions/system.rs b/src/tools/definitions/system.rs new file mode 100644 index 0000000..5173c27 --- /dev/null +++ b/src/tools/definitions/system.rs @@ -0,0 +1,37 @@ +use serde_json::{json, Value}; + +pub fn tool_healthcheck() -> Value { + json!({ + "name": "healthcheck", + "description": "System health check with OS detection and configuration validation", + "inputSchema": { + "type": "object", + "properties": { + "detailed": { "type": "boolean", "description": "Include detailed system info", "default": false } + } + } + }) +} + +pub fn tool_verify_setup() -> Value { + json!({ + "name": "verify_setup", + "description": "Validate MT5-Quant environment configuration", + "inputSchema": { + "type": "object" + } + }) +} + +pub fn tool_list_symbols() -> Value { + json!({ + "name": "list_symbols", + "description": "List symbols with local tick history", + "inputSchema": { + "type": "object", + "properties": { + "server": { "type": "string" } + } + } + }) +}