aigroup-econ-mcp 1.3.3__py3-none-any.whl → 2.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- .gitignore +253 -0
- PKG-INFO +732 -0
- README.md +687 -0
- __init__.py +14 -0
- aigroup_econ_mcp-2.0.1.dist-info/METADATA +732 -0
- aigroup_econ_mcp-2.0.1.dist-info/RECORD +170 -0
- aigroup_econ_mcp-2.0.1.dist-info/entry_points.txt +2 -0
- aigroup_econ_mcp-2.0.1.dist-info/licenses/LICENSE +21 -0
- cli.py +32 -0
- econometrics/README.md +18 -0
- econometrics/__init__.py +191 -0
- econometrics/advanced_methods/modern_computing_machine_learning/__init__.py +30 -0
- econometrics/advanced_methods/modern_computing_machine_learning/causal_forest.py +253 -0
- econometrics/advanced_methods/modern_computing_machine_learning/double_ml.py +268 -0
- econometrics/advanced_methods/modern_computing_machine_learning/gradient_boosting.py +249 -0
- econometrics/advanced_methods/modern_computing_machine_learning/hierarchical_clustering.py +243 -0
- econometrics/advanced_methods/modern_computing_machine_learning/kmeans_clustering.py +293 -0
- econometrics/advanced_methods/modern_computing_machine_learning/neural_network.py +264 -0
- econometrics/advanced_methods/modern_computing_machine_learning/random_forest.py +195 -0
- econometrics/advanced_methods/modern_computing_machine_learning/support_vector_machine.py +226 -0
- econometrics/advanced_methods/modern_computing_machine_learning/test_all_modules.py +329 -0
- econometrics/advanced_methods/modern_computing_machine_learning/test_report.md +107 -0
- econometrics/basic_parametric_estimation/__init__.py +31 -0
- econometrics/basic_parametric_estimation/gmm/__init__.py +13 -0
- econometrics/basic_parametric_estimation/gmm/gmm_model.py +256 -0
- econometrics/basic_parametric_estimation/mle/__init__.py +13 -0
- econometrics/basic_parametric_estimation/mle/mle_model.py +241 -0
- econometrics/basic_parametric_estimation/ols/__init__.py +13 -0
- econometrics/basic_parametric_estimation/ols/ols_model.py +141 -0
- econometrics/causal_inference/__init__.py +66 -0
- econometrics/causal_inference/causal_identification_strategy/__init__.py +104 -0
- econometrics/causal_inference/causal_identification_strategy/control_function.py +112 -0
- econometrics/causal_inference/causal_identification_strategy/difference_in_differences.py +107 -0
- econometrics/causal_inference/causal_identification_strategy/event_study.py +119 -0
- econometrics/causal_inference/causal_identification_strategy/first_difference.py +89 -0
- econometrics/causal_inference/causal_identification_strategy/fixed_effects.py +103 -0
- econometrics/causal_inference/causal_identification_strategy/hausman_test.py +69 -0
- econometrics/causal_inference/causal_identification_strategy/instrumental_variables.py +145 -0
- econometrics/causal_inference/causal_identification_strategy/mediation_analysis.py +121 -0
- econometrics/causal_inference/causal_identification_strategy/moderation_analysis.py +109 -0
- econometrics/causal_inference/causal_identification_strategy/propensity_score_matching.py +140 -0
- econometrics/causal_inference/causal_identification_strategy/random_effects.py +100 -0
- econometrics/causal_inference/causal_identification_strategy/regression_discontinuity.py +98 -0
- econometrics/causal_inference/causal_identification_strategy/synthetic_control.py +111 -0
- econometrics/causal_inference/causal_identification_strategy/triple_difference.py +86 -0
- econometrics/distribution_analysis/__init__.py +28 -0
- econometrics/distribution_analysis/oaxaca_blinder.py +184 -0
- econometrics/distribution_analysis/time_series_decomposition.py +152 -0
- econometrics/distribution_analysis/variance_decomposition.py +179 -0
- econometrics/missing_data/__init__.py +18 -0
- econometrics/missing_data/imputation_methods.py +219 -0
- econometrics/missing_data/missing_data_measurement_error/__init__.py +0 -0
- econometrics/model_specification_diagnostics_robust_inference/README.md +173 -0
- econometrics/model_specification_diagnostics_robust_inference/__init__.py +78 -0
- econometrics/model_specification_diagnostics_robust_inference/diagnostic_tests/__init__.py +20 -0
- econometrics/model_specification_diagnostics_robust_inference/diagnostic_tests/diagnostic_tests_model.py +149 -0
- econometrics/model_specification_diagnostics_robust_inference/generalized_least_squares/__init__.py +15 -0
- econometrics/model_specification_diagnostics_robust_inference/generalized_least_squares/gls_model.py +130 -0
- econometrics/model_specification_diagnostics_robust_inference/model_selection/__init__.py +18 -0
- econometrics/model_specification_diagnostics_robust_inference/model_selection/model_selection_model.py +286 -0
- econometrics/model_specification_diagnostics_robust_inference/regularization/__init__.py +15 -0
- econometrics/model_specification_diagnostics_robust_inference/regularization/regularization_model.py +177 -0
- econometrics/model_specification_diagnostics_robust_inference/robust_errors/__init__.py +15 -0
- econometrics/model_specification_diagnostics_robust_inference/robust_errors/robust_errors_model.py +122 -0
- econometrics/model_specification_diagnostics_robust_inference/simultaneous_equations/__init__.py +15 -0
- econometrics/model_specification_diagnostics_robust_inference/simultaneous_equations/simultaneous_equations_model.py +246 -0
- econometrics/model_specification_diagnostics_robust_inference/weighted_least_squares/__init__.py +15 -0
- econometrics/model_specification_diagnostics_robust_inference/weighted_least_squares/wls_model.py +127 -0
- econometrics/nonparametric/__init__.py +35 -0
- econometrics/nonparametric/gam_model.py +117 -0
- econometrics/nonparametric/kernel_regression.py +161 -0
- econometrics/nonparametric/nonparametric_semiparametric_methods/__init__.py +0 -0
- econometrics/nonparametric/quantile_regression.py +249 -0
- econometrics/nonparametric/spline_regression.py +100 -0
- econometrics/spatial_econometrics/__init__.py +68 -0
- econometrics/spatial_econometrics/geographically_weighted_regression.py +211 -0
- econometrics/spatial_econometrics/gwr_simple.py +154 -0
- econometrics/spatial_econometrics/spatial_autocorrelation.py +356 -0
- econometrics/spatial_econometrics/spatial_durbin_model.py +177 -0
- econometrics/spatial_econometrics/spatial_econometrics_new/__init__.py +0 -0
- econometrics/spatial_econometrics/spatial_regression.py +315 -0
- econometrics/spatial_econometrics/spatial_weights.py +226 -0
- econometrics/specific_data_modeling/micro_discrete_limited_data/README.md +164 -0
- econometrics/specific_data_modeling/micro_discrete_limited_data/__init__.py +40 -0
- econometrics/specific_data_modeling/micro_discrete_limited_data/count_data_models.py +311 -0
- econometrics/specific_data_modeling/micro_discrete_limited_data/discrete_choice_models.py +294 -0
- econometrics/specific_data_modeling/micro_discrete_limited_data/limited_dependent_variable_models.py +282 -0
- econometrics/specific_data_modeling/survival_duration_data/__init__.py +0 -0
- econometrics/specific_data_modeling/time_series_panel_data/__init__.py +143 -0
- econometrics/specific_data_modeling/time_series_panel_data/arima_model.py +104 -0
- econometrics/specific_data_modeling/time_series_panel_data/cointegration_vecm.py +334 -0
- econometrics/specific_data_modeling/time_series_panel_data/dynamic_panel_models.py +653 -0
- econometrics/specific_data_modeling/time_series_panel_data/exponential_smoothing.py +176 -0
- econometrics/specific_data_modeling/time_series_panel_data/garch_model.py +198 -0
- econometrics/specific_data_modeling/time_series_panel_data/panel_diagnostics.py +125 -0
- econometrics/specific_data_modeling/time_series_panel_data/panel_var.py +60 -0
- econometrics/specific_data_modeling/time_series_panel_data/structural_break_tests.py +87 -0
- econometrics/specific_data_modeling/time_series_panel_data/time_varying_parameter_models.py +106 -0
- econometrics/specific_data_modeling/time_series_panel_data/unit_root_tests.py +204 -0
- econometrics/specific_data_modeling/time_series_panel_data/var_svar_model.py +372 -0
- econometrics/statistical_inference/__init__.py +21 -0
- econometrics/statistical_inference/bootstrap_methods.py +162 -0
- econometrics/statistical_inference/permutation_test.py +177 -0
- econometrics/statistical_inference/statistical_inference_techniques/__init__.py +0 -0
- econometrics/statistics/distribution_decomposition_methods/__init__.py +0 -0
- econometrics/survival_analysis/__init__.py +18 -0
- econometrics/survival_analysis/survival_models.py +259 -0
- econometrics/tests/basic_parametric_estimation_tests/__init__.py +3 -0
- econometrics/tests/basic_parametric_estimation_tests/test_gmm.py +128 -0
- econometrics/tests/basic_parametric_estimation_tests/test_mle.py +127 -0
- econometrics/tests/basic_parametric_estimation_tests/test_ols.py +100 -0
- econometrics/tests/causal_inference_tests/__init__.py +3 -0
- econometrics/tests/causal_inference_tests/detailed_test.py +441 -0
- econometrics/tests/causal_inference_tests/test_all_methods.py +418 -0
- econometrics/tests/causal_inference_tests/test_causal_identification_strategy.py +202 -0
- econometrics/tests/causal_inference_tests/test_difference_in_differences.py +53 -0
- econometrics/tests/causal_inference_tests/test_instrumental_variables.py +44 -0
- econometrics/tests/model_specification_diagnostics_tests/__init__.py +3 -0
- econometrics/tests/model_specification_diagnostics_tests/test_diagnostic_tests.py +86 -0
- econometrics/tests/model_specification_diagnostics_tests/test_robust_errors.py +89 -0
- econometrics/tests/specific_data_modeling_tests/__init__.py +3 -0
- econometrics/tests/specific_data_modeling_tests/test_arima.py +98 -0
- econometrics/tests/specific_data_modeling_tests/test_dynamic_panel.py +198 -0
- econometrics/tests/specific_data_modeling_tests/test_exponential_smoothing.py +105 -0
- econometrics/tests/specific_data_modeling_tests/test_garch.py +118 -0
- econometrics/tests/specific_data_modeling_tests/test_micro_discrete_limited_data.py +189 -0
- econometrics/tests/specific_data_modeling_tests/test_unit_root.py +156 -0
- econometrics/tests/specific_data_modeling_tests/test_var.py +124 -0
- econometrics//321/206/320/254/320/272/321/205/342/225/235/320/220/321/205/320/237/320/241/321/205/320/264/320/267/321/207/342/226/222/342/225/227/321/204/342/225/235/320/250/321/205/320/225/320/230/321/207/342/225/221/320/267/321/205/320/230/320/226/321/206/320/256/320/240.md +544 -0
- prompts/__init__.py +0 -0
- prompts/analysis_guides.py +43 -0
- pyproject.toml +85 -0
- resources/MCP_MASTER_GUIDE.md +422 -0
- resources/MCP_TOOLS_DATA_FORMAT_GUIDE.md +185 -0
- resources/__init__.py +0 -0
- server.py +97 -0
- tools/README.md +88 -0
- tools/__init__.py +119 -0
- tools/causal_inference_adapter.py +658 -0
- tools/data_loader.py +213 -0
- tools/decorators.py +38 -0
- tools/distribution_analysis_adapter.py +121 -0
- tools/econometrics_adapter.py +286 -0
- tools/gwr_simple_adapter.py +54 -0
- tools/machine_learning_adapter.py +567 -0
- tools/mcp_tool_groups/__init__.py +15 -0
- tools/mcp_tool_groups/basic_parametric_tools.py +173 -0
- tools/mcp_tool_groups/causal_inference_tools.py +643 -0
- tools/mcp_tool_groups/distribution_analysis_tools.py +169 -0
- tools/mcp_tool_groups/machine_learning_tools.py +422 -0
- tools/mcp_tool_groups/microecon_tools.py +325 -0
- tools/mcp_tool_groups/missing_data_tools.py +117 -0
- tools/mcp_tool_groups/model_specification_tools.py +402 -0
- tools/mcp_tool_groups/nonparametric_tools.py +225 -0
- tools/mcp_tool_groups/spatial_econometrics_tools.py +323 -0
- tools/mcp_tool_groups/statistical_inference_tools.py +131 -0
- tools/mcp_tool_groups/time_series_tools.py +494 -0
- tools/mcp_tools_registry.py +124 -0
- tools/microecon_adapter.py +412 -0
- tools/missing_data_adapter.py +73 -0
- tools/model_specification_adapter.py +369 -0
- tools/nonparametric_adapter.py +190 -0
- tools/output_formatter.py +563 -0
- tools/spatial_econometrics_adapter.py +318 -0
- tools/statistical_inference_adapter.py +90 -0
- tools/survival_analysis_adapter.py +46 -0
- tools/time_series_panel_data_adapter.py +858 -0
- tools/time_series_panel_data_tools.py +65 -0
- aigroup_econ_mcp/__init__.py +0 -19
- aigroup_econ_mcp/cli.py +0 -82
- aigroup_econ_mcp/config.py +0 -561
- aigroup_econ_mcp/server.py +0 -452
- aigroup_econ_mcp/tools/__init__.py +0 -19
- aigroup_econ_mcp/tools/base.py +0 -470
- aigroup_econ_mcp/tools/cache.py +0 -533
- aigroup_econ_mcp/tools/data_loader.py +0 -195
- aigroup_econ_mcp/tools/file_parser.py +0 -1027
- aigroup_econ_mcp/tools/machine_learning.py +0 -60
- aigroup_econ_mcp/tools/ml_ensemble.py +0 -210
- aigroup_econ_mcp/tools/ml_evaluation.py +0 -272
- aigroup_econ_mcp/tools/ml_models.py +0 -54
- aigroup_econ_mcp/tools/ml_regularization.py +0 -186
- aigroup_econ_mcp/tools/monitoring.py +0 -555
- aigroup_econ_mcp/tools/optimized_example.py +0 -229
- aigroup_econ_mcp/tools/panel_data.py +0 -619
- aigroup_econ_mcp/tools/regression.py +0 -214
- aigroup_econ_mcp/tools/statistics.py +0 -154
- aigroup_econ_mcp/tools/time_series.py +0 -698
- aigroup_econ_mcp/tools/timeout.py +0 -283
- aigroup_econ_mcp/tools/tool_descriptions.py +0 -410
- aigroup_econ_mcp/tools/tool_handlers.py +0 -1016
- aigroup_econ_mcp/tools/tool_registry.py +0 -478
- aigroup_econ_mcp/tools/validation.py +0 -482
- aigroup_econ_mcp-1.3.3.dist-info/METADATA +0 -525
- aigroup_econ_mcp-1.3.3.dist-info/RECORD +0 -30
- aigroup_econ_mcp-1.3.3.dist-info/entry_points.txt +0 -2
- /aigroup_econ_mcp-1.3.3.dist-info/licenses/LICENSE → /LICENSE +0 -0
- {aigroup_econ_mcp-1.3.3.dist-info → aigroup_econ_mcp-2.0.1.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
# AIGroup计量经济学MCP工具完整指南
|
|
2
|
+
|
|
3
|
+
## 概述
|
|
4
|
+
|
|
5
|
+
本MCP服务器提供**21个**计量经济学分析工具,采用组件化架构设计,支持多种数据格式输入和输出。
|
|
6
|
+
|
|
7
|
+
## 服务器配置
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"server_name": "aigroup-econ-mcp",
|
|
12
|
+
"version": "2.2.0-component",
|
|
13
|
+
"architecture": "Component-Based",
|
|
14
|
+
"tool_groups": 3,
|
|
15
|
+
"total_tools": 21,
|
|
16
|
+
"tools": [
|
|
17
|
+
"basic_parametric_estimation_ols",
|
|
18
|
+
"basic_parametric_estimation_mle",
|
|
19
|
+
"basic_parametric_estimation_gmm",
|
|
20
|
+
"model_diagnostic_tests",
|
|
21
|
+
"generalized_least_squares",
|
|
22
|
+
"weighted_least_squares",
|
|
23
|
+
"robust_errors_regression",
|
|
24
|
+
"model_selection_criteria",
|
|
25
|
+
"regularized_regression",
|
|
26
|
+
"simultaneous_equations_model",
|
|
27
|
+
"time_series_arima_model",
|
|
28
|
+
"time_series_exponential_smoothing",
|
|
29
|
+
"time_series_garch_model",
|
|
30
|
+
"time_series_unit_root_tests",
|
|
31
|
+
"time_series_var_svar_model",
|
|
32
|
+
"time_series_cointegration_analysis",
|
|
33
|
+
"panel_data_dynamic_model",
|
|
34
|
+
"panel_data_diagnostics",
|
|
35
|
+
"panel_var_model",
|
|
36
|
+
"structural_break_tests",
|
|
37
|
+
"time_varying_parameter_models"
|
|
38
|
+
],
|
|
39
|
+
"description": "Econometrics MCP Tools with component-based architecture"
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 工具概览
|
|
44
|
+
|
|
45
|
+
### 基础参数估计工具 (3个)
|
|
46
|
+
|
|
47
|
+
1. **OLS回归分析 (basic_parametric_estimation_ols)**
|
|
48
|
+
- 核心算法: econometrics/basic_parametric_estimation/ols/ols_model.py
|
|
49
|
+
- 输入方式: 直接数据(y_data + x_data) 或 文件(file_path)
|
|
50
|
+
- 支持格式: txt/json/csv/excel
|
|
51
|
+
|
|
52
|
+
2. **最大似然估计 (basic_parametric_estimation_mle)**
|
|
53
|
+
- 核心算法: econometrics/basic_parametric_estimation/mle/mle_model.py
|
|
54
|
+
- 输入方式: 直接数据(data) 或 文件(file_path)
|
|
55
|
+
- 分布类型: normal, poisson, exponential
|
|
56
|
+
- 支持格式: txt/json/csv/excel
|
|
57
|
+
|
|
58
|
+
3. **广义矩估计 (basic_parametric_estimation_gmm)**
|
|
59
|
+
- 核心算法: econometrics/basic_parametric_estimation/gmm/gmm_model.py
|
|
60
|
+
- 输入方式: 直接数据(y_data + x_data) 或 文件(file_path)
|
|
61
|
+
- 已修复: j_p_value bug
|
|
62
|
+
- 支持格式: txt/json/csv/excel
|
|
63
|
+
|
|
64
|
+
### 模型规范、诊断和稳健推断工具 (7个) 🆕
|
|
65
|
+
|
|
66
|
+
4. **模型诊断检验 (model_diagnostic_tests)**
|
|
67
|
+
- 核心算法: econometrics/model_specification_diagnostics_robust_inference/diagnostic_tests/
|
|
68
|
+
- 功能: 异方差检验(Breusch-Pagan, White)、自相关检验(Durbin-Watson)、正态性检验(Jarque-Bera)、多重共线性诊断(VIF)
|
|
69
|
+
- 输入方式: 直接数据(y_data + x_data) 或 文件(file_path)
|
|
70
|
+
- 支持格式: txt/json/csv/excel
|
|
71
|
+
|
|
72
|
+
5. **广义最小二乘法 (generalized_least_squares)**
|
|
73
|
+
- 核心算法: econometrics/model_specification_diagnostics_robust_inference/generalized_least_squares/
|
|
74
|
+
- 功能: 处理异方差性和自相关的GLS回归
|
|
75
|
+
- 特点: 可指定误差项协方差矩阵
|
|
76
|
+
- 输入方式: 直接数据 或 文件
|
|
77
|
+
|
|
78
|
+
6. **加权最小二乘法 (weighted_least_squares)**
|
|
79
|
+
- 核心算法: econometrics/model_specification_diagnostics_robust_inference/weighted_least_squares/
|
|
80
|
+
- 功能: 使用权重处理已知异方差性
|
|
81
|
+
- 特点: 需要提供观测值权重(通常为方差的倒数)
|
|
82
|
+
- 输入方式: 直接数据 或 文件
|
|
83
|
+
|
|
84
|
+
7. **稳健标准误回归 (robust_errors_regression)**
|
|
85
|
+
- 核心算法: econometrics/model_specification_diagnostics_robust_inference/robust_errors/
|
|
86
|
+
- 功能: 计算异方差稳健的标准误
|
|
87
|
+
- 支持类型: HC0, HC1, HC2, HC3
|
|
88
|
+
- 特点: 不改变系数估计,只调整标准误
|
|
89
|
+
|
|
90
|
+
8. **模型选择准则 (model_selection_criteria)**
|
|
91
|
+
- 核心算法: econometrics/m odel_specification_diagnostics_robust_inference/model_selection/
|
|
92
|
+
- 功能: 计算AIC、BIC、HQIC信息准则
|
|
93
|
+
- 附加功能: K折交叉验证、留一法交叉验证
|
|
94
|
+
- 用途: 模型比较和变量选择
|
|
95
|
+
|
|
96
|
+
9. **正则化回归 (regularized_regression)**
|
|
97
|
+
- 核心算法: econometrics/model_specification_diagnostics_robust_inference/regularization/
|
|
98
|
+
- 方法: Ridge回归(L2)、LASSO(L1)、Elastic Net(L1+L2)
|
|
99
|
+
- 功能: 处理多重共线性和高维数据
|
|
100
|
+
- 特点: 可进行变量选择(LASSO)
|
|
101
|
+
|
|
102
|
+
10. **联立方程模型 (simultaneous_equations_model)**
|
|
103
|
+
- 核心算法: econometrics/model_specification_diagnostics_robust_inference/simultaneous_equations/
|
|
104
|
+
- 方法: 两阶段最小二乘法(2SLS)
|
|
105
|
+
- 功能: 处理联立方程系统和内生性问题
|
|
106
|
+
- 要求: 需要有效的工具变量
|
|
107
|
+
|
|
108
|
+
### 时间序列工具 (6个)
|
|
109
|
+
|
|
110
|
+
11. **ARIMA模型 (time_series_arima_model)**
|
|
111
|
+
- 参数: (p,d,q) 阶数
|
|
112
|
+
- 功能: 多步预测
|
|
113
|
+
|
|
114
|
+
12. **指数平滑模型 (time_series_exponential_smoothing)**
|
|
115
|
+
- 组件: 趋势项, 季节项
|
|
116
|
+
- 功能: 多步预测
|
|
117
|
+
|
|
118
|
+
13. **GARCH模型 (time_series_garch_model)**
|
|
119
|
+
- 功能: 条件方差建模
|
|
120
|
+
- 参数: (p,q) 阶数
|
|
121
|
+
|
|
122
|
+
14. **单位根检验 (time_series_unit_root_tests)**
|
|
123
|
+
- 检验方法: ADF, PP, KPSS
|
|
124
|
+
- 功能: 平稳性检验
|
|
125
|
+
|
|
126
|
+
15. **VAR/SVAR模型 (time_series_var_svar_model)**
|
|
127
|
+
- 模型类型: VAR, SVAR
|
|
128
|
+
- 功能: 多变量时间序列分析
|
|
129
|
+
|
|
130
|
+
16. **协整分析 (time_series_cointegration_analysis)**
|
|
131
|
+
- 检验方法: Engle-Granger, Johansen
|
|
132
|
+
- 模型: VECM
|
|
133
|
+
- 功能: 长期均衡关系分析
|
|
134
|
+
|
|
135
|
+
### 面板数据工具 (3个)
|
|
136
|
+
|
|
137
|
+
17. **动态面板模型 (panel_data_dynamic_model)**
|
|
138
|
+
- 模型类型: 差分GMM, 系统GMM
|
|
139
|
+
- 数据: 横截面和时间序列数据
|
|
140
|
+
|
|
141
|
+
18. **面板数据诊断测试 (panel_data_diagnostics)**
|
|
142
|
+
- 检验方法: Hausman, Pooling F, LM, 组内相关性
|
|
143
|
+
- 功能: 模型选择 (FE vs RE vs Pooled)
|
|
144
|
+
|
|
145
|
+
19. **面板VAR模型 (panel_var_model)**
|
|
146
|
+
- 功能: 面板向量自回归
|
|
147
|
+
- 效应: 个体效应和时间效应
|
|
148
|
+
|
|
149
|
+
### 高级计量工具 (2个)
|
|
150
|
+
|
|
151
|
+
20. **结构断点检验 (structural_break_tests)**
|
|
152
|
+
- 检验方法: Chow, Quandt-Andrews, Bai-Perron
|
|
153
|
+
- 功能: 检测时间序列结构变化
|
|
154
|
+
|
|
155
|
+
21. **时变参数模型 (time_varying_parameter_models)**
|
|
156
|
+
- 模型类型: TAR, STAR, Markov Switching
|
|
157
|
+
- 功能: 基于阈值的机制转换
|
|
158
|
+
|
|
159
|
+
## 详细参数说明
|
|
160
|
+
|
|
161
|
+
### 通用参数格式
|
|
162
|
+
|
|
163
|
+
#### 输入数据格式
|
|
164
|
+
- **直接数据输入**: 使用 `y_data`, `x_data`, `data` 等参数
|
|
165
|
+
- **文件输入**: 使用 `file_path` 参数
|
|
166
|
+
- **支持的文件格式**: txt, json, csv, excel (.xlsx, .xls)
|
|
167
|
+
|
|
168
|
+
#### 输出格式选项
|
|
169
|
+
- `output_format`: json, markdown, txt
|
|
170
|
+
- `save_path`: 可指定输出文件路径保存结果
|
|
171
|
+
|
|
172
|
+
#### 通用配置参数
|
|
173
|
+
- `confidence_level`: 置信水平(默认0.95)
|
|
174
|
+
- `constant`: 是否包含常数项(默认true)
|
|
175
|
+
- `feature_names`: 特征名称列表
|
|
176
|
+
|
|
177
|
+
### 工具特定参数示例
|
|
178
|
+
|
|
179
|
+
#### 1. OLS回归分析
|
|
180
|
+
```json
|
|
181
|
+
{
|
|
182
|
+
"y_data": [1, 2, 3, 4, 5],
|
|
183
|
+
"x_data": [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],
|
|
184
|
+
"feature_names": ["X1", "X2"],
|
|
185
|
+
"constant": true,
|
|
186
|
+
"confidence_level": 0.95
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
#### 2. 模型诊断检验 🆕
|
|
191
|
+
```json
|
|
192
|
+
{
|
|
193
|
+
"y_data": [1, 2, 3, 4, 5],
|
|
194
|
+
"x_data": [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],
|
|
195
|
+
"feature_names": ["X1", "X2"],
|
|
196
|
+
"constant": true
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
#### 3. 稳健标准误回归 🆕
|
|
201
|
+
```json
|
|
202
|
+
{
|
|
203
|
+
"y_data": [1, 2, 3, 4, 5],
|
|
204
|
+
"x_data": [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],
|
|
205
|
+
"cov_type": "HC1",
|
|
206
|
+
"confidence_level": 0.95
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
#### 4. 正则化回归 🆕
|
|
211
|
+
```json
|
|
212
|
+
{
|
|
213
|
+
"y_data": [1, 2, 3, 4, 5],
|
|
214
|
+
"x_data": [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],
|
|
215
|
+
"method": "ridge",
|
|
216
|
+
"alpha": 1.0,
|
|
217
|
+
"l1_ratio": 0.5
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
#### 5. 加权最小二乘法 🆕
|
|
222
|
+
```json
|
|
223
|
+
{
|
|
224
|
+
"y_data": [1, 2, 3, 4, 5],
|
|
225
|
+
"x_data": [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],
|
|
226
|
+
"weights": [1.0, 0.8, 1.2, 0.9, 1.1],
|
|
227
|
+
"confidence_level": 0.95
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
#### 6. ARIMA模型
|
|
232
|
+
```json
|
|
233
|
+
{
|
|
234
|
+
"data": [1.2, 2.1, 3.4, 4.2, 5.1, 6.3, 7.2, 8.1, 9.4, 10.2],
|
|
235
|
+
"order": [1, 1, 1],
|
|
236
|
+
"forecast_steps": 3
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
#### 7. 动态面板模型
|
|
241
|
+
```json
|
|
242
|
+
{
|
|
243
|
+
"y_data": [1.2, 2.1, 3.4, 4.2, 5.1],
|
|
244
|
+
"x_data": [[1, 0.5], [2, 1.2], [3, 1.8], [4, 2.5], [5, 3.1]],
|
|
245
|
+
"entity_ids": [1, 1, 1, 2, 2],
|
|
246
|
+
"time_periods": [1, 2, 3, 1, 2],
|
|
247
|
+
"model_type": "diff_gmm"
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## 参数选项说明
|
|
252
|
+
|
|
253
|
+
### 分布类型 (MLE)
|
|
254
|
+
- `normal`: 正态分布
|
|
255
|
+
- `poisson`: 泊松分布
|
|
256
|
+
- `exponential`: 指数分布
|
|
257
|
+
|
|
258
|
+
### 稳健标准误类型 🆕
|
|
259
|
+
- `HC0`: 白异方差一致性标准误
|
|
260
|
+
- `HC1`: 修正的HC0(小样本调整)
|
|
261
|
+
- `HC2`: 杠杆调整的标准误
|
|
262
|
+
- `HC3`: 杠杆调整的标准误(更稳健)
|
|
263
|
+
|
|
264
|
+
### 正则化方法 🆕
|
|
265
|
+
- `ridge`: 岭回归(L2惩罚)
|
|
266
|
+
- `lasso`: LASSO回归(L1惩罚,可变量选择)
|
|
267
|
+
- `elastic_net`: 弹性网络(L1+L2惩罚)
|
|
268
|
+
|
|
269
|
+
### 单位根检验类型
|
|
270
|
+
- `adf`: Augmented Dickey-Fuller检验
|
|
271
|
+
- `pp`: Phillips-Perron检验
|
|
272
|
+
- `kpss`: KPSS检验
|
|
273
|
+
|
|
274
|
+
### VAR/SVAR模型类型
|
|
275
|
+
- `var`: 向量自回归模型
|
|
276
|
+
- `svar`: 结构向量自回归模型
|
|
277
|
+
|
|
278
|
+
### 协整分析方法
|
|
279
|
+
- `johansen`: Johansen协整检验
|
|
280
|
+
- `engle-granger`: Engle-Granger协整检验
|
|
281
|
+
|
|
282
|
+
### 动态面板模型类型
|
|
283
|
+
- `diff_gmm`: 差分GMM模型
|
|
284
|
+
- `sys_gmm`: 系统GMM模型
|
|
285
|
+
|
|
286
|
+
### 面板诊断测试类型
|
|
287
|
+
- `hausman`: Hausman检验 (FE vs RE)
|
|
288
|
+
- `pooling_f`: Pooling F检验
|
|
289
|
+
- `lm`: LM检验
|
|
290
|
+
- `within_correlation`: 组内相关性检验
|
|
291
|
+
|
|
292
|
+
### 结构断点检验类型
|
|
293
|
+
- `chow`: Chow检验
|
|
294
|
+
- `quandt-andrews`: Quandt-Andrews检验
|
|
295
|
+
- `bai-perron`: Bai-Perron多重断点检验
|
|
296
|
+
|
|
297
|
+
### 时变参数模型类型
|
|
298
|
+
- `tar`: 门限自回归模型
|
|
299
|
+
- `star`: 平滑转换自回归模型
|
|
300
|
+
- `markov_switching`: 马尔科夫转换模型
|
|
301
|
+
|
|
302
|
+
### STAR类型
|
|
303
|
+
- `logistic`: Logistic转换函数
|
|
304
|
+
- `exponential`: 指数转换函数
|
|
305
|
+
|
|
306
|
+
## 工具组分类
|
|
307
|
+
|
|
308
|
+
### 第一组:基础参数估计 (3个工具)
|
|
309
|
+
专注于基本的统计估计方法,适用于大多数标准回归分析场景。
|
|
310
|
+
|
|
311
|
+
### 第二组:模型规范、诊断和稳健推断 (7个工具) 🆕
|
|
312
|
+
提供全面的模型诊断、规范检验和稳健估计方法,确保模型的可靠性和有效性。
|
|
313
|
+
|
|
314
|
+
### 第三组:时间序列和面板数据 (11个工具)
|
|
315
|
+
涵盖时间序列分析、面板数据建模和高级计量方法。
|
|
316
|
+
|
|
317
|
+
## 架构信息
|
|
318
|
+
|
|
319
|
+
**架构**: Component-Based
|
|
320
|
+
**版本**: 2.2.0
|
|
321
|
+
**Python版本**: 3.8+
|
|
322
|
+
**MCP协议**: FastMCP
|
|
323
|
+
**工具组数量**: 3
|
|
324
|
+
**总工具数**: 21
|
|
325
|
+
**文件格式**: txt, json, csv, excel (.xlsx, .xls)
|
|
326
|
+
**输出格式**: json, markdown, txt
|
|
327
|
+
|
|
328
|
+
## 优势特点
|
|
329
|
+
|
|
330
|
+
- **组件化设计**: 工具按功能分组,便于维护和扩展
|
|
331
|
+
- **模块化**: 每个工具组独立管理
|
|
332
|
+
- **DRY原则**: 复用核心算法,无重复代码
|
|
333
|
+
- **易于扩展**: 轻松添加新工具类别
|
|
334
|
+
- **性能优化**: 高效的数据处理和计算
|
|
335
|
+
- **全面诊断**: 新增完整的模型诊断和稳健推断工具 🆕
|
|
336
|
+
- **稳健性**: 支持多种稳健估计方法处理数据问题 🆕
|
|
337
|
+
|
|
338
|
+
## 使用建议
|
|
339
|
+
|
|
340
|
+
1. **数据准备**: 确保数据格式正确,特别是多维数组的嵌套结构
|
|
341
|
+
2. **参数选择**: 根据具体分析需求选择合适的模型参数
|
|
342
|
+
3. **模型诊断**: 在进行推断前使用诊断工具检验模型假设 🆕
|
|
343
|
+
4. **稳健性检查**: 对于可能存在异方差的数据使用稳健标准误 🆕
|
|
344
|
+
5. **输出格式**: 根据后续处理需求选择合适的输出格式
|
|
345
|
+
6. **错误处理**: 注意工具可能返回的错误信息,如矩阵奇异等
|
|
346
|
+
|
|
347
|
+
## 典型工作流程 🆕
|
|
348
|
+
|
|
349
|
+
### 标准回归分析流程
|
|
350
|
+
1. 使用 `basic_parametric_estimation_ols` 进行OLS回归
|
|
351
|
+
2. 使用 `model_diagnostic_tests` 检验模型假设
|
|
352
|
+
3. 如发现异方差:
|
|
353
|
+
- 使用 `robust_errors_regression` 获取稳健标准误,或
|
|
354
|
+
- 使用 `weighted_least_squares` 或 `generalized_least_squares`
|
|
355
|
+
4. 使用 `model_selection_criteria` 进行模型比较
|
|
356
|
+
|
|
357
|
+
### 高维数据分析流程
|
|
358
|
+
1. 使用 `regularized_regression` 处理多重共线性
|
|
359
|
+
2. 通过LASSO进行变量选择
|
|
360
|
+
3. 使用交叉验证选择最优alpha参数
|
|
361
|
+
|
|
362
|
+
## 示例调用
|
|
363
|
+
|
|
364
|
+
```python
|
|
365
|
+
# OLS回归分析示例
|
|
366
|
+
result = await mcp.basic_parametric_estimation_ols(
|
|
367
|
+
y_data=[1, 2, 3, 4, 5],
|
|
368
|
+
x_data=[[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],
|
|
369
|
+
feature_names=["X1", "X2"],
|
|
370
|
+
constant=True,
|
|
371
|
+
output_format="json"
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
# 模型诊断检验示例 🆕
|
|
375
|
+
diagnostic_result = await mcp.model_diagnostic_tests(
|
|
376
|
+
y_data=[1, 2, 3, 4, 5],
|
|
377
|
+
x_data=[[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],
|
|
378
|
+
feature_names=["X1", "X2"],
|
|
379
|
+
constant=True
|
|
380
|
+
)
|
|
381
|
+
|
|
382
|
+
# 稳健标准误回归示例 🆕
|
|
383
|
+
robust_result = await mcp.robust_errors_regression(
|
|
384
|
+
y_data=[1, 2, 3, 4, 5],
|
|
385
|
+
x_data=[[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],
|
|
386
|
+
cov_type="HC1",
|
|
387
|
+
confidence_level=0.95
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
# 正则化回归示例 🆕
|
|
391
|
+
ridge_result = await mcp.regularized_regression(
|
|
392
|
+
y_data=[1, 2, 3, 4, 5],
|
|
393
|
+
x_data=[[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]],
|
|
394
|
+
method="ridge",
|
|
395
|
+
alpha=1.0
|
|
396
|
+
)
|
|
397
|
+
|
|
398
|
+
# ARIMA模型示例
|
|
399
|
+
arima_result = await mcp.time_series_arima_model(
|
|
400
|
+
data=[1.2, 2.1, 3.4, 4.2, 5.1, 6.3, 7.2, 8.1, 9.4, 10.2],
|
|
401
|
+
order=[1, 1, 1],
|
|
402
|
+
forecast_steps=3,
|
|
403
|
+
output_format="json"
|
|
404
|
+
)
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
## 更新历史
|
|
408
|
+
|
|
409
|
+
### v2.2.0 (当前版本) 🆕
|
|
410
|
+
- 新增7个模型规范、诊断和稳健推断工具
|
|
411
|
+
- 总工具数从14个增加到21个
|
|
412
|
+
- 增强了模型诊断和稳健推断能力
|
|
413
|
+
- 添加了正则化方法支持
|
|
414
|
+
|
|
415
|
+
### v2.1.0
|
|
416
|
+
- 提供14个基础工具
|
|
417
|
+
- 实现组件化架构
|
|
418
|
+
- 支持多种数据格式
|
|
419
|
+
|
|
420
|
+
---
|
|
421
|
+
|
|
422
|
+
这个完整指南包含了所有必要信息,帮助大模型正确理解和使用所有**21个**计量经济学工具。
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# MCP工具数据格式指南
|
|
2
|
+
|
|
3
|
+
## 概述
|
|
4
|
+
本文档详细说明各个MCP工具的数据输入格式要求,帮助大模型正确调用工具。
|
|
5
|
+
|
|
6
|
+
## 1. VAR/SVAR模型工具
|
|
7
|
+
|
|
8
|
+
### 数据格式
|
|
9
|
+
```python
|
|
10
|
+
# 多元时间序列数据格式
|
|
11
|
+
data = [
|
|
12
|
+
[var1_t1, var2_t1, var3_t1], # 时间点1的所有变量值
|
|
13
|
+
[var1_t2, var2_t2, var3_t2], # 时间点2的所有变量值
|
|
14
|
+
[var1_t3, var2_t3, var3_t3], # 时间点3的所有变量值
|
|
15
|
+
# ...
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
# 变量名称(可选)
|
|
19
|
+
variables = ["GDP", "Inflation", "Interest"]
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 示例调用
|
|
23
|
+
```python
|
|
24
|
+
{
|
|
25
|
+
"data": [[1.0, 2.5, 1.8], [1.2, 2.7, 2.0], [1.4, 2.9, 2.2]],
|
|
26
|
+
"model_type": "var",
|
|
27
|
+
"lags": 1,
|
|
28
|
+
"variables": ["GDP", "Inflation", "Interest"],
|
|
29
|
+
"output_format": "json"
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 2. 联立方程模型工具
|
|
34
|
+
|
|
35
|
+
### 数据格式说明
|
|
36
|
+
联立方程模型需要三个主要数据组件:
|
|
37
|
+
|
|
38
|
+
#### 因变量数据 (y_data)
|
|
39
|
+
- **格式**: 二维列表,每个子列表代表一个方程的因变量时间序列
|
|
40
|
+
- **要求**: 所有方程的观测数量必须相同
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
# 两个方程的示例
|
|
44
|
+
y_data = [
|
|
45
|
+
[1.0, 1.2, 1.4, 1.6], # 方程1的因变量
|
|
46
|
+
[2.0, 2.2, 2.4, 2.6] # 方程2的因变量
|
|
47
|
+
]
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### 自变量数据 (x_data)
|
|
51
|
+
- **格式**: 二维列表,每个子列表代表一个观测的所有自变量值
|
|
52
|
+
- **要求**: 观测数量必须与因变量相同
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
# 4个观测,每个观测有2个自变量
|
|
56
|
+
x_data = [
|
|
57
|
+
[1.5, 2.5], # 观测1的自变量
|
|
58
|
+
[1.7, 2.7], # 观测2的自变量
|
|
59
|
+
[1.9, 2.9], # 观测3的自变量
|
|
60
|
+
[2.1, 3.1] # 观测4的自变量
|
|
61
|
+
]
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
#### 工具变量数据 (instruments)
|
|
65
|
+
- **格式**: 二维列表,每个子列表代表一个观测的所有工具变量值
|
|
66
|
+
- **要求**: 观测数量必须与其他变量相同
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
# 4个观测,每个观测有2个工具变量
|
|
70
|
+
instruments = [
|
|
71
|
+
[1.8, 2.8], # 观测1的工具变量
|
|
72
|
+
[2.0, 3.0], # 观测2的工具变量
|
|
73
|
+
[2.2, 3.2], # 观测3的工具变量
|
|
74
|
+
[2.4, 3.4] # 观测4的工具变量
|
|
75
|
+
]
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 示例调用
|
|
79
|
+
```python
|
|
80
|
+
{
|
|
81
|
+
"y_data": [[1.0, 1.2, 1.4, 1.6], [2.0, 2.2, 2.4, 2.6]],
|
|
82
|
+
"x_data": [[1.5, 2.5], [1.7, 2.7], [1.9, 2.9], [2.1, 3.1]],
|
|
83
|
+
"instruments": [[1.8, 2.8], [2.0, 3.0], [2.2, 3.2], [2.4, 3.4]],
|
|
84
|
+
"equation_names": ["Demand", "Supply"],
|
|
85
|
+
"instrument_names": ["Income", "Price"],
|
|
86
|
+
"constant": true,
|
|
87
|
+
"output_format": "json"
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## 3. 动态面板数据模型工具
|
|
92
|
+
|
|
93
|
+
### 数据格式说明
|
|
94
|
+
动态面板数据需要四个主要数据组件:
|
|
95
|
+
|
|
96
|
+
#### 因变量数据 (y_data)
|
|
97
|
+
- **格式**: 一维列表,所有个体的因变量时间序列
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
y_data = [1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8]
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### 自变量数据 (x_data)
|
|
104
|
+
- **格式**: 二维列表,每个子列表代表一个自变量的时间序列
|
|
105
|
+
- **重要**: 每个自变量的观测数量必须与因变量相同
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
# 1个自变量,10个观测
|
|
109
|
+
x_data = [[1.5, 1.7, 1.9, 2.1, 2.3, 2.5, 2.7, 2.9, 3.1, 3.3]]
|
|
110
|
+
|
|
111
|
+
# 2个自变量,10个观测
|
|
112
|
+
x_data = [
|
|
113
|
+
[1.5, 1.7, 1.9, 2.1, 2.3, 2.5, 2.7, 2.9, 3.1, 3.3], # 自变量1
|
|
114
|
+
[2.5, 2.7, 2.9, 3.1, 3.3, 3.5, 3.7, 3.9, 4.1, 4.3] # 自变量2
|
|
115
|
+
]
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### 个体标识符 (entity_ids)
|
|
119
|
+
- **格式**: 一维列表,标识每个观测属于哪个个体
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
# 2个个体,每个个体5个时间点
|
|
123
|
+
entity_ids = [1, 1, 1, 1, 1, 2, 2, 2, 2, 2]
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### 时间标识符 (time_periods)
|
|
127
|
+
- **格式**: 一维列表,标识每个观测的时间点
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
# 10个观测,时间从1到5重复两次
|
|
131
|
+
time_periods = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 示例调用
|
|
135
|
+
```python
|
|
136
|
+
{
|
|
137
|
+
"y_data": [1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8],
|
|
138
|
+
"x_data": [[1.5, 1.7, 1.9, 2.1, 2.3, 2.5, 2.7, 2.9, 3.1, 3.3]],
|
|
139
|
+
"entity_ids": [1, 1, 1, 1, 1, 2, 2, 2, 2, 2],
|
|
140
|
+
"time_periods": [1, 2, 3, 4, 5, 1, 2, 3, 4, 5],
|
|
141
|
+
"model_type": "diff_gmm",
|
|
142
|
+
"lags": 1,
|
|
143
|
+
"output_format": "json"
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## 4. 数据格式验证要点
|
|
148
|
+
|
|
149
|
+
### 通用规则
|
|
150
|
+
1. **数据维度一致性**: 所有相关数据的观测数量必须相同
|
|
151
|
+
2. **数据类型**: 必须为数值类型
|
|
152
|
+
3. **数据完整性**: 不能有空值或缺失值
|
|
153
|
+
|
|
154
|
+
### 联立方程模型特殊要求
|
|
155
|
+
- 因变量数据是二维列表,每个子列表代表一个方程
|
|
156
|
+
- 自变量和工具变量是二维列表,每个子列表代表一个观测
|
|
157
|
+
- 所有数据的观测数量必须严格一致
|
|
158
|
+
|
|
159
|
+
### 动态面板数据特殊要求
|
|
160
|
+
- 自变量数据是二维列表,每个子列表代表一个自变量的完整时间序列
|
|
161
|
+
- 个体和时间标识符必须与因变量观测数量一致
|
|
162
|
+
- 面板数据必须平衡(每个个体有相同数量的时间点)
|
|
163
|
+
|
|
164
|
+
## 5. 常见错误及解决方案
|
|
165
|
+
|
|
166
|
+
### 错误: "自变量的观测数量必须与因变量相同"
|
|
167
|
+
**原因**: 数据维度不匹配
|
|
168
|
+
**解决方案**: 检查所有数据的观测数量是否一致
|
|
169
|
+
|
|
170
|
+
### 错误: "所有数据序列的长度必须一致"
|
|
171
|
+
**原因**: 动态面板数据中某个自变量的观测数量与因变量不同
|
|
172
|
+
**解决方案**: 确保每个自变量的时间序列长度与因变量相同
|
|
173
|
+
|
|
174
|
+
### 错误: "输入数据不能为空"
|
|
175
|
+
**原因**: 数据为空或格式错误
|
|
176
|
+
**解决方案**: 提供有效的数据或检查文件路径
|
|
177
|
+
|
|
178
|
+
## 6. 最佳实践
|
|
179
|
+
|
|
180
|
+
1. **使用文件输入**: 对于复杂数据,建议使用CSV文件格式
|
|
181
|
+
2. **数据预处理**: 在调用工具前确保数据格式正确
|
|
182
|
+
3. **逐步测试**: 先用小样本数据测试,确认格式正确后再使用完整数据
|
|
183
|
+
4. **检查维度**: 始终验证所有相关数据的观测数量是否一致
|
|
184
|
+
|
|
185
|
+
通过遵循这些指南,可以确保MCP工具的正确调用和稳定运行。
|
resources/__init__.py
ADDED
|
File without changes
|
server.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AIGroup 计量经济学 MCP 服务器 - 简化修复版
|
|
3
|
+
直接注册工具,避免复杂的包装器
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import sys
|
|
7
|
+
import os
|
|
8
|
+
import asyncio
|
|
9
|
+
from typing import List, Optional, Union
|
|
10
|
+
from mcp.server.fastmcp import FastMCP, Context
|
|
11
|
+
from mcp.server.session import ServerSession
|
|
12
|
+
|
|
13
|
+
# 设置Windows控制台编码
|
|
14
|
+
if sys.platform == "win32":
|
|
15
|
+
try:
|
|
16
|
+
# 尝试设置UTF-8编码
|
|
17
|
+
sys.stdout.reconfigure(encoding='utf-8')
|
|
18
|
+
sys.stderr.reconfigure(encoding='utf-8')
|
|
19
|
+
except:
|
|
20
|
+
# 如果失败,使用ASCII字符
|
|
21
|
+
pass
|
|
22
|
+
|
|
23
|
+
# 导入工具注册中心
|
|
24
|
+
from tools.mcp_tools_registry import registry
|
|
25
|
+
|
|
26
|
+
# 创建 FastMCP 服务器实例
|
|
27
|
+
mcp = FastMCP("aigroup-econ-mcp")
|
|
28
|
+
|
|
29
|
+
# 自动发现并注册所有工具组
|
|
30
|
+
print("正在自动发现工具组...")
|
|
31
|
+
registry.auto_discover_groups()
|
|
32
|
+
|
|
33
|
+
# 显示发现的工具组
|
|
34
|
+
print(f"发现工具组数量: {len(registry.tool_groups)}")
|
|
35
|
+
for group in registry.tool_groups:
|
|
36
|
+
print(f" - {group.name}")
|
|
37
|
+
|
|
38
|
+
# 直接注册所有工具
|
|
39
|
+
print("正在注册工具...")
|
|
40
|
+
for tool_name, tool_info in registry.get_all_tools().items():
|
|
41
|
+
# 获取原始工具处理器
|
|
42
|
+
original_handler = tool_info["handler"]
|
|
43
|
+
|
|
44
|
+
# 直接注册工具
|
|
45
|
+
mcp.tool(name=tool_name, description=tool_info["description"])(original_handler)
|
|
46
|
+
|
|
47
|
+
print(f" - 已注册: {tool_name}")
|
|
48
|
+
|
|
49
|
+
@mcp.resource("guide://econometrics")
|
|
50
|
+
def get_econometrics_guide() -> str:
|
|
51
|
+
"""Get complete econometrics tools guide"""
|
|
52
|
+
try:
|
|
53
|
+
with open("resources/MCP_MASTER_GUIDE.md", "r", encoding="utf-8") as f:
|
|
54
|
+
return f.read()
|
|
55
|
+
except FileNotFoundError:
|
|
56
|
+
return "完整使用指南文件未找到,请检查 resources/MCP_MASTER_GUIDE.md 文件是否存在。"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def main():
|
|
60
|
+
"""Start FastMCP server"""
|
|
61
|
+
print("=" * 60)
|
|
62
|
+
print("AIGroup Econometrics MCP Server - SIMPLE FIXED")
|
|
63
|
+
print("=" * 60)
|
|
64
|
+
print("\n架构: 简化修复版")
|
|
65
|
+
print("\n已注册工具组:")
|
|
66
|
+
|
|
67
|
+
# 显示工具组信息
|
|
68
|
+
for group in registry.tool_groups:
|
|
69
|
+
tools_in_group = [name for name, info in registry.tools.items() if info["group"] == group.name]
|
|
70
|
+
print(f" - {group.name} ({len(tools_in_group)} tools)")
|
|
71
|
+
|
|
72
|
+
print(f"\n总工具数: {len(registry.tools)}")
|
|
73
|
+
print("\n支持格式:")
|
|
74
|
+
print(" 输入: txt/json/csv/excel (.xlsx, .xls)")
|
|
75
|
+
print(" 输出: json/markdown/txt")
|
|
76
|
+
|
|
77
|
+
print("\n优势:")
|
|
78
|
+
print(" * 简化工具注册")
|
|
79
|
+
print(" * 避免包装器问题")
|
|
80
|
+
print(" * 直接使用原始处理器")
|
|
81
|
+
|
|
82
|
+
print("\n启动服务器...")
|
|
83
|
+
print("=" * 60)
|
|
84
|
+
|
|
85
|
+
# 正确使用FastMCP.run方法,不传递timeout参数
|
|
86
|
+
try:
|
|
87
|
+
mcp.run(transport="stdio")
|
|
88
|
+
except KeyboardInterrupt:
|
|
89
|
+
print("\n服务器已停止")
|
|
90
|
+
except Exception as e:
|
|
91
|
+
print(f"\n服务器运行出错: {e}")
|
|
92
|
+
import traceback
|
|
93
|
+
traceback.print_exc()
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
if __name__ == "__main__":
|
|
97
|
+
main()
|