national-stats-mcp 1.0.2 → 1.1.0
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.
- package/README.md +46 -2
- package/dist/api-client.js +14 -7
- package/dist/index.js +1 -1
- package/national-stats-mcp-1.1.0.tgz +0 -0
- package/package.json +1 -1
- package/zb.json +0 -226
package/README.md
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
主要特点:
|
|
7
7
|
- ✅ 关键词搜索:直接搜索获取指标代码及最新值(推荐用于快速查询)
|
|
8
8
|
- ✅ 树形分类:可浏览和递归获取所有分类/指标体系
|
|
9
|
+
- ✅ 预遍历数据:提供完整的预遍历分类编码体系,可直接读取使用(减少递归调用)
|
|
9
10
|
- ✅ 时间范围:可查询各数据库对应可用时间维度
|
|
10
11
|
- ✅ 标准API:遵循国家统计局接口文档的全部规范
|
|
11
12
|
- ✅ 容错机制:内置重试逻辑、请求延迟、数据验证等功能
|
|
@@ -76,15 +77,27 @@ node dist/index.js --port 8080
|
|
|
76
77
|
|
|
77
78
|
## 数据编码对应
|
|
78
79
|
- `dbcode.json`: 存储数据库代码及其相应的名称
|
|
79
|
-
- `zb.json`: 包含用于查询不同类型国家数据的类别和子类别代码
|
|
80
80
|
- `wbcode.json`: 维度代码定义
|
|
81
|
+
- **预遍历编码数据**:
|
|
82
|
+
- **npm包中不包含**: `nbs_data_repository/` (因文件体积较大)
|
|
83
|
+
- **需从GitHub获取**: 预先遍历获取的完整的国家统计局分类编码体系(可减少递归调用)
|
|
84
|
+
- 完整数据集在 GitHub 仓库中,请从 [GitHub 仓库](https://github.com/Ddhjx-code/notional_data) 下载
|
|
85
|
+
- `csnd/`, `csyd/`: 城市统计数据(年度、月度)
|
|
86
|
+
- `fsnd/`, `fsyd/`: 分省年度、月度数据
|
|
87
|
+
- `hgnd/`, `hgjd/`, `hgyd/`: 国民经济核算数据(年度、季度、月度)
|
|
88
|
+
- `gjnd/`, `gjyd/`, `gatnd/`, `gatyd/`: 国际、港澳台统计数据(年度、月度)
|
|
89
|
+
- 每个数据库目录下包含预遍历的分类编码(以JSON文件形式存储):
|
|
90
|
+
- 如 `nbs_data_repository/hgjd/A01.json` 包含A01分类下的具体指标
|
|
91
|
+
- 文件内容格式: `[{"id": "指标ID", "pid": "父级ID", "name": "指标名", "isParent": 是否为父级}]`
|
|
81
92
|
|
|
82
93
|
## 为AI Agent的使用
|
|
83
94
|
本项目专门设计为MCP服务器,可以直接集成到AI Agent系统中,提供国家统计局数据查询能力。Agent可根据使用场景选择最合适的工具:
|
|
84
95
|
|
|
85
96
|
- **快速查询**:使用 `search_statistics` 直接通过关键词获取指标和最新值
|
|
86
|
-
- **分类浏览**:使用 `get_statistics_categories`
|
|
97
|
+
- **分类浏览**:使用 `get_statistics_categories` 获取分类体系;对于完整指标体系,可优先参考 `nbs_data_repository` 目录下的预遍历编码文件
|
|
98
|
+
- **递归获取**:`get_statistics_leaf_categories` 用于递归获取所有叶子节点(由于已有预遍历数据,此功能使用频率较低)
|
|
87
99
|
- **深度查询**:使用 `get_statistics_time_options` 和 `get_statistics_data` 获取历史序列数据
|
|
100
|
+
- **预遍历数据**:`nbs_data_repository` 目录下已预存各类统计数据库的详细分类编码,可直接读取使用,避免实时API递归调用
|
|
88
101
|
|
|
89
102
|
## 开发
|
|
90
103
|
进行开发时可使用:
|
|
@@ -92,6 +105,37 @@ node dist/index.js --port 8080
|
|
|
92
105
|
npm run dev
|
|
93
106
|
```
|
|
94
107
|
|
|
108
|
+
## 使用建议
|
|
109
|
+
|
|
110
|
+
对于AI Agent开发者,根据使用方式采用不同策略:
|
|
111
|
+
|
|
112
|
+
### npm 包使用(核心库):
|
|
113
|
+
1. **安装**: `npm install national-stats-mcp`
|
|
114
|
+
2. **功能**: 使用 API 工具进行动态数据查询
|
|
115
|
+
3. **使用**: `search_statistics`、`get_statistics_data` 等
|
|
116
|
+
4. **递归调用**: 当需要完整分类体系时,使用 `get_statistics_leaf_categories`
|
|
117
|
+
|
|
118
|
+
### GitHub 仓库使用(完整版本):
|
|
119
|
+
1. **克隆完整仓库**:
|
|
120
|
+
```bash
|
|
121
|
+
git clone https://github.com/Ddhjx-code/notional_data.git
|
|
122
|
+
```
|
|
123
|
+
2. **优先使用预遍历数据**: 从 `nbs_data_repository` 目录直接读取已存在的分类编码信息
|
|
124
|
+
3. **快速查询**: 使用 `search_statistics` 工具进行关键词搜索
|
|
125
|
+
4. **实时数据获取**: 使用 `get_statistics_data` 获取具体统计数据
|
|
126
|
+
5. **递归调用**: 仅在预遍历数据不满足需求时使用 `get_statistics_leaf_categories`
|
|
127
|
+
|
|
128
|
+
### 预遍历数据优势(当可访问完整数据集时):
|
|
129
|
+
- ✅ 快速访问:无需等待实时API调用和递归遍历
|
|
130
|
+
- ✅ 大数据量:包含国家统计局完整分类体系
|
|
131
|
+
- ✅ 稳定性好:离线数据访问不受API限制
|
|
132
|
+
- ✅ 减少API调用:降低对国家统计局服务器压力
|
|
133
|
+
|
|
134
|
+
### 递归API使用场景:
|
|
135
|
+
- 临时获取最新指标(若预遍历数据未及时更新)
|
|
136
|
+
- 特殊查询需求超出预遍历数据范围
|
|
137
|
+
- 在较小环境中仅安装了 npm 包的情况
|
|
138
|
+
|
|
95
139
|
## 贡献
|
|
96
140
|
欢迎对本代码进行修改。请确保遵循项目的编码标准。
|
|
97
141
|
|
package/dist/api-client.js
CHANGED
|
@@ -16,15 +16,16 @@ class StatsApiClient {
|
|
|
16
16
|
* 搜索指标
|
|
17
17
|
*/
|
|
18
18
|
async search(keyword, db = '', page = 0) {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
// 使用 axios 的 params 选项来避免编码问题
|
|
20
|
+
const params = {
|
|
21
|
+
s: keyword, // 让 axios 正确处理编码
|
|
21
22
|
m: 'searchdata',
|
|
22
|
-
db
|
|
23
|
+
db,
|
|
23
24
|
p: page.toString(),
|
|
24
|
-
}
|
|
25
|
-
|
|
25
|
+
};
|
|
26
|
+
console.error(`GET Request URL (base): ${this.baseUrl}/search.htm with params:`, JSON.stringify(params));
|
|
26
27
|
try {
|
|
27
|
-
const response = await axios_1.default.get(
|
|
28
|
+
const response = await axios_1.default.get(`${this.baseUrl}/search.htm`, { params });
|
|
28
29
|
return response.data;
|
|
29
30
|
}
|
|
30
31
|
catch (error) {
|
|
@@ -69,6 +70,8 @@ class StatsApiClient {
|
|
|
69
70
|
dbcode,
|
|
70
71
|
wdcode
|
|
71
72
|
};
|
|
73
|
+
console.error(`POST Request URL: ${this.baseUrl}/easyquery.htm`);
|
|
74
|
+
console.error(`POST Request Body:`, JSON.stringify(params));
|
|
72
75
|
try {
|
|
73
76
|
const response = await axios_1.default.post(`${this.baseUrl}/easyquery.htm`, new URLSearchParams(params));
|
|
74
77
|
return response.data;
|
|
@@ -105,7 +108,7 @@ class StatsApiClient {
|
|
|
105
108
|
}
|
|
106
109
|
catch (error) {
|
|
107
110
|
retries++;
|
|
108
|
-
console.
|
|
111
|
+
console.error(`Category request failed for node ${nodeId}, attempt ${retries}/${maxRetries}.`);
|
|
109
112
|
if (retries >= maxRetries) {
|
|
110
113
|
throw error;
|
|
111
114
|
}
|
|
@@ -127,6 +130,8 @@ class StatsApiClient {
|
|
|
127
130
|
dbcode,
|
|
128
131
|
wdcode
|
|
129
132
|
};
|
|
133
|
+
console.error(`POST Request URL: ${this.baseUrl}/easyquery.htm`);
|
|
134
|
+
console.error(`POST Request Body:`, JSON.stringify(params));
|
|
130
135
|
try {
|
|
131
136
|
const response = await axios_1.default.post(`${this.baseUrl}/easyquery.htm`, new URLSearchParams(params));
|
|
132
137
|
return response.data;
|
|
@@ -152,6 +157,7 @@ class StatsApiClient {
|
|
|
152
157
|
k1: Date.now(), // 添加时间戳防止缓存
|
|
153
158
|
h: 1
|
|
154
159
|
};
|
|
160
|
+
console.error(`GET Request URL: ${this.baseUrl}/easyquery.htm with params:`, JSON.stringify(params));
|
|
155
161
|
try {
|
|
156
162
|
const response = await axios_1.default.get(`${this.baseUrl}/easyquery.htm`, { params });
|
|
157
163
|
return response.data;
|
|
@@ -180,6 +186,7 @@ class StatsApiClient {
|
|
|
180
186
|
k1: Date.now(), // 添加时间戳防止缓存
|
|
181
187
|
h: 1
|
|
182
188
|
};
|
|
189
|
+
console.error(`GET Request URL: ${this.baseUrl}/easyquery.htm with params:`, JSON.stringify(params));
|
|
183
190
|
try {
|
|
184
191
|
const response = await axios_1.default.get(`${this.baseUrl}/easyquery.htm`, { params });
|
|
185
192
|
return response.data;
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ const api_client_1 = require("./api-client");
|
|
|
9
9
|
const zod_1 = require("zod");
|
|
10
10
|
const commander_1 = require("commander");
|
|
11
11
|
// 获取版本号,这里使用package.json中的版本
|
|
12
|
-
const VERSION = '1.0.
|
|
12
|
+
const VERSION = '1.0.2';
|
|
13
13
|
// 创建API客户端实例
|
|
14
14
|
const apiClient = new api_client_1.StatsApiClient();
|
|
15
15
|
// 创建MCP服务器
|
|
Binary file
|
package/package.json
CHANGED
package/zb.json
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"dbcode": "hgnd",
|
|
4
|
-
"id": "A01",
|
|
5
|
-
"isParent": true,
|
|
6
|
-
"name": "综合",
|
|
7
|
-
"pid": "",
|
|
8
|
-
"wdcode": "zb"
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"dbcode": "hgnd",
|
|
12
|
-
"id": "A02",
|
|
13
|
-
"isParent": true,
|
|
14
|
-
"name": "国民经济核算",
|
|
15
|
-
"pid": "",
|
|
16
|
-
"wdcode": "zb"
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"dbcode": "hgnd",
|
|
20
|
-
"id": "A03",
|
|
21
|
-
"isParent": true,
|
|
22
|
-
"name": "人口",
|
|
23
|
-
"pid": "",
|
|
24
|
-
"wdcode": "zb"
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
"dbcode": "hgnd",
|
|
28
|
-
"id": "A04",
|
|
29
|
-
"isParent": true,
|
|
30
|
-
"name": "就业人员和工资",
|
|
31
|
-
"pid": "",
|
|
32
|
-
"wdcode": "zb"
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
"dbcode": "hgnd",
|
|
36
|
-
"id": "A05",
|
|
37
|
-
"isParent": true,
|
|
38
|
-
"name": "固定资产投资和房地产",
|
|
39
|
-
"pid": "",
|
|
40
|
-
"wdcode": "zb"
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
"dbcode": "hgnd",
|
|
44
|
-
"id": "A06",
|
|
45
|
-
"isParent": true,
|
|
46
|
-
"name": "对外经济贸易",
|
|
47
|
-
"pid": "",
|
|
48
|
-
"wdcode": "zb"
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
"dbcode": "hgnd",
|
|
52
|
-
"id": "A07",
|
|
53
|
-
"isParent": true,
|
|
54
|
-
"name": "能源",
|
|
55
|
-
"pid": "",
|
|
56
|
-
"wdcode": "zb"
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
"dbcode": "hgnd",
|
|
60
|
-
"id": "A08",
|
|
61
|
-
"isParent": true,
|
|
62
|
-
"name": "财政",
|
|
63
|
-
"pid": "",
|
|
64
|
-
"wdcode": "zb"
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
"dbcode": "hgnd",
|
|
68
|
-
"id": "A09",
|
|
69
|
-
"isParent": true,
|
|
70
|
-
"name": "价格指数",
|
|
71
|
-
"pid": "",
|
|
72
|
-
"wdcode": "zb"
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
"dbcode": "hgnd",
|
|
76
|
-
"id": "A0A",
|
|
77
|
-
"isParent": true,
|
|
78
|
-
"name": "人民生活",
|
|
79
|
-
"pid": "",
|
|
80
|
-
"wdcode": "zb"
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
"dbcode": "hgnd",
|
|
84
|
-
"id": "A0B",
|
|
85
|
-
"isParent": true,
|
|
86
|
-
"name": "城市概况",
|
|
87
|
-
"pid": "",
|
|
88
|
-
"wdcode": "zb"
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
"dbcode": "hgnd",
|
|
92
|
-
"id": "A0C",
|
|
93
|
-
"isParent": true,
|
|
94
|
-
"name": "资源和环境",
|
|
95
|
-
"pid": "",
|
|
96
|
-
"wdcode": "zb"
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
"dbcode": "hgnd",
|
|
100
|
-
"id": "A0D",
|
|
101
|
-
"isParent": true,
|
|
102
|
-
"name": "农业",
|
|
103
|
-
"pid": "",
|
|
104
|
-
"wdcode": "zb"
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
"dbcode": "hgnd",
|
|
108
|
-
"id": "A0E",
|
|
109
|
-
"isParent": true,
|
|
110
|
-
"name": "工业",
|
|
111
|
-
"pid": "",
|
|
112
|
-
"wdcode": "zb"
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
"dbcode": "hgnd",
|
|
116
|
-
"id": "A0F",
|
|
117
|
-
"isParent": true,
|
|
118
|
-
"name": "建筑业",
|
|
119
|
-
"pid": "",
|
|
120
|
-
"wdcode": "zb"
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
"dbcode": "hgnd",
|
|
124
|
-
"id": "A0G",
|
|
125
|
-
"isParent": true,
|
|
126
|
-
"name": "运输和邮电",
|
|
127
|
-
"pid": "",
|
|
128
|
-
"wdcode": "zb"
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
"dbcode": "hgnd",
|
|
132
|
-
"id": "A0H",
|
|
133
|
-
"isParent": false,
|
|
134
|
-
"name": "社会消费品零售总额",
|
|
135
|
-
"pid": "",
|
|
136
|
-
"wdcode": "zb"
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
"dbcode": "hgnd",
|
|
140
|
-
"id": "A0I",
|
|
141
|
-
"isParent": true,
|
|
142
|
-
"name": "批发和零售业",
|
|
143
|
-
"pid": "",
|
|
144
|
-
"wdcode": "zb"
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
"dbcode": "hgnd",
|
|
148
|
-
"id": "A0J",
|
|
149
|
-
"isParent": true,
|
|
150
|
-
"name": "住宿和餐饮业",
|
|
151
|
-
"pid": "",
|
|
152
|
-
"wdcode": "zb"
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
"dbcode": "hgnd",
|
|
156
|
-
"id": "A0K",
|
|
157
|
-
"isParent": true,
|
|
158
|
-
"name": "旅游业",
|
|
159
|
-
"pid": "",
|
|
160
|
-
"wdcode": "zb"
|
|
161
|
-
},
|
|
162
|
-
{
|
|
163
|
-
"dbcode": "hgnd",
|
|
164
|
-
"id": "A0L",
|
|
165
|
-
"isParent": true,
|
|
166
|
-
"name": "金融业",
|
|
167
|
-
"pid": "",
|
|
168
|
-
"wdcode": "zb"
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
"dbcode": "hgnd",
|
|
172
|
-
"id": "A0M",
|
|
173
|
-
"isParent": true,
|
|
174
|
-
"name": "教育",
|
|
175
|
-
"pid": "",
|
|
176
|
-
"wdcode": "zb"
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
"dbcode": "hgnd",
|
|
180
|
-
"id": "A0N",
|
|
181
|
-
"isParent": true,
|
|
182
|
-
"name": "科技",
|
|
183
|
-
"pid": "",
|
|
184
|
-
"wdcode": "zb"
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
"dbcode": "hgnd",
|
|
188
|
-
"id": "A0O",
|
|
189
|
-
"isParent": true,
|
|
190
|
-
"name": "卫生",
|
|
191
|
-
"pid": "",
|
|
192
|
-
"wdcode": "zb"
|
|
193
|
-
},
|
|
194
|
-
{
|
|
195
|
-
"dbcode": "hgnd",
|
|
196
|
-
"id": "A0P",
|
|
197
|
-
"isParent": true,
|
|
198
|
-
"name": "社会服务",
|
|
199
|
-
"pid": "",
|
|
200
|
-
"wdcode": "zb"
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
"dbcode": "hgnd",
|
|
204
|
-
"id": "A0Q",
|
|
205
|
-
"isParent": true,
|
|
206
|
-
"name": "文化",
|
|
207
|
-
"pid": "",
|
|
208
|
-
"wdcode": "zb"
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
"dbcode": "hgnd",
|
|
212
|
-
"id": "A0R",
|
|
213
|
-
"isParent": true,
|
|
214
|
-
"name": "体育",
|
|
215
|
-
"pid": "",
|
|
216
|
-
"wdcode": "zb"
|
|
217
|
-
},
|
|
218
|
-
{
|
|
219
|
-
"dbcode": "hgnd",
|
|
220
|
-
"id": "A0S",
|
|
221
|
-
"isParent": true,
|
|
222
|
-
"name": "公共管理、社会保障及其他",
|
|
223
|
-
"pid": "",
|
|
224
|
-
"wdcode": "zb"
|
|
225
|
-
}
|
|
226
|
-
]
|