mcp-statdb 1.3.2
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/License +201 -0
- package/README.md +351 -0
- package/README.zh-CN.md +357 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +622 -0
- package/dist/index.js.map +1 -0
- package/llms.txt +603 -0
- package/package.json +67 -0
package/llms.txt
ADDED
|
@@ -0,0 +1,603 @@
|
|
|
1
|
+
# mcp_cnbs - 中国国家统计局数据 MCP 服务器
|
|
2
|
+
|
|
3
|
+
> 为 AI 助手提供中国国家统计局数据查询能力的 MCP (Model Context Protocol) 服务器
|
|
4
|
+
>
|
|
5
|
+
> 基础地址:https://data.stats.gov.cn | 无需鉴权,公开访问
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🚀 快速开始(必读)
|
|
10
|
+
|
|
11
|
+
### 核心原则
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
15
|
+
│ ⚠️ 最重要:优先使用 cnbs_search 获取数据 │
|
|
16
|
+
│ │
|
|
17
|
+
│ 搜索接口返回的 value 字段有值 │
|
|
18
|
+
│ cnbs_fetch_series 返回的 value 字段可能为空(API限制) │
|
|
19
|
+
└─────────────────────────────────────────────────────────────┘
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 推荐工作流程
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
场景一:只需最新值(最常见)
|
|
26
|
+
┌─────────────────────────────────────────────────────────┐
|
|
27
|
+
│ cnbs_search(keyword="GDP") │
|
|
28
|
+
│ ↓ │
|
|
29
|
+
│ 直接获取 result[].value = 最新数据值 │
|
|
30
|
+
│ 一次请求搞定! │
|
|
31
|
+
└─────────────────────────────────────────────────────────┘
|
|
32
|
+
|
|
33
|
+
场景二:需要历史时间序列
|
|
34
|
+
┌─────────────────────────────────────────────────────────┐
|
|
35
|
+
│ cnbs_search(keyword="GDP") │
|
|
36
|
+
│ ↓ │
|
|
37
|
+
│ 从 result[].report 解析 zb=A010101 │
|
|
38
|
+
│ ↓ │
|
|
39
|
+
│ cnbs_fetch_series(setId, metricIds, periods) │
|
|
40
|
+
│ ↓ │
|
|
41
|
+
│ 获取历史数据(注意:value 可能为空) │
|
|
42
|
+
└─────────────────────────────────────────────────────────┘
|
|
43
|
+
|
|
44
|
+
场景三:浏览分类体系
|
|
45
|
+
┌─────────────────────────────────────────────────────────┐
|
|
46
|
+
│ cnbs_fetch_nodes(category="3") // 年度数据根节点 │
|
|
47
|
+
│ ↓ │
|
|
48
|
+
│ 递归下钻获取子节点 │
|
|
49
|
+
│ ↓ │
|
|
50
|
+
│ isLeaf=true 的节点即为可查数据的数据集 │
|
|
51
|
+
└─────────────────────────────────────────────────────────┘
|
|
52
|
+
|
|
53
|
+
场景四:批量查询多个指标
|
|
54
|
+
┌─────────────────────────────────────────────────────────┐
|
|
55
|
+
│ cnbs_batch_search(keywords=["GDP", "CPI", "人口"]) │
|
|
56
|
+
│ ↓ │
|
|
57
|
+
│ 一次性获取多个指标的最新数据 │
|
|
58
|
+
└─────────────────────────────────────────────────────────┘
|
|
59
|
+
|
|
60
|
+
场景五:地区/时间对比
|
|
61
|
+
┌─────────────────────────────────────────────────────────┐
|
|
62
|
+
│ cnbs_compare(keyword="GDP", regions=["北京", "上海"]) │
|
|
63
|
+
│ ↓ │
|
|
64
|
+
│ 获取地区对比结果 │
|
|
65
|
+
└─────────────────────────────────────────────────────────┘
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## 📊 数据分类体系
|
|
71
|
+
|
|
72
|
+
### 分类代码速查表
|
|
73
|
+
|
|
74
|
+
| 代码 | 分类名称 | 时间粒度 | 典型数据 |
|
|
75
|
+
|------|---------|---------|---------|
|
|
76
|
+
| `1` | 月度数据 | 月 | CPI、PPI、工业增加值 |
|
|
77
|
+
| `2` | 季度数据 | 季 | GDP季度值、PMI |
|
|
78
|
+
| `3` | 年度数据 | 年 | GDP年度值、人口数据 |
|
|
79
|
+
| `5` | 分省季度数据 | 季 | 各省GDP季度值 |
|
|
80
|
+
| `6` | 分省年度数据 | 年 | 各省人口、GDP年度值 |
|
|
81
|
+
| `7` | 其他数据 | - | 特殊统计 |
|
|
82
|
+
| `8` | 主要城市年度数据 | 年 | 主要城市GDP |
|
|
83
|
+
| `9` | 港澳台月度数据 | 月 | 港澳台月度统计 |
|
|
84
|
+
| `10` | 港澳台年度数据 | 年 | 港澳台年度统计 |
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## ⏰ 时间格式规范
|
|
89
|
+
|
|
90
|
+
### 年度数据
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
格式:YYYY
|
|
94
|
+
示例:2024, 2023, 2022
|
|
95
|
+
范围:["2020YY-2024YY"]
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 季度数据
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
格式:YYYY + 季度标识
|
|
102
|
+
示例:
|
|
103
|
+
2024A → 2024年第一季度
|
|
104
|
+
2024B → 2024年第二季度
|
|
105
|
+
2024C → 2024年第三季度
|
|
106
|
+
2024D → 2024年第四季度
|
|
107
|
+
|
|
108
|
+
快捷范围:
|
|
109
|
+
LAST6 → 最近6个季度
|
|
110
|
+
LAST12 → 最近12个季度
|
|
111
|
+
LAST18 → 最近18个季度
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 月度数据
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
格式:YYYYMM + MM
|
|
118
|
+
示例:
|
|
119
|
+
202401MM → 2024年1月
|
|
120
|
+
202412MM → 2024年12月
|
|
121
|
+
范围:["202301MM-202412MM"]
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## 🗺️ 地区代码
|
|
127
|
+
|
|
128
|
+
地区代码遵循 GB/T 2260 标准。使用 `cnbs_get_regions` 获取完整列表。
|
|
129
|
+
|
|
130
|
+
常用地区代码:
|
|
131
|
+
| 地区 | 代码 |
|
|
132
|
+
|------|------|
|
|
133
|
+
| 全国 | 000000000000 |
|
|
134
|
+
| 北京 | 110000000000 |
|
|
135
|
+
| 上海 | 310000000000 |
|
|
136
|
+
| 广东 | 440000000000 |
|
|
137
|
+
| 江苏 | 320000000000 |
|
|
138
|
+
| 浙江 | 330000000000 |
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 🛠️ 工具详解
|
|
143
|
+
|
|
144
|
+
### 1. cnbs_search(推荐优先使用)
|
|
145
|
+
|
|
146
|
+
**功能**:关键词搜索统计指标,直接获取最新数据值
|
|
147
|
+
|
|
148
|
+
**参数**:
|
|
149
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
150
|
+
|------|------|------|------|
|
|
151
|
+
| keyword | string | ✅ | 搜索关键词,如 "GDP"、"CPI"、"人口" |
|
|
152
|
+
| pageNum | number | ❌ | 页码,默认1 |
|
|
153
|
+
| pageSize | number | ❌ | 每页数量,默认10 |
|
|
154
|
+
|
|
155
|
+
**返回字段解读**:
|
|
156
|
+
```json
|
|
157
|
+
{
|
|
158
|
+
"show_name": "人口出生率 (‰)",
|
|
159
|
+
"value": "6.77", // ← 最新数据值!
|
|
160
|
+
"dt": "2024", // 时间
|
|
161
|
+
"dt_name": "2024年",
|
|
162
|
+
"cid": "ffed4267...", // 数据集ID(setId)
|
|
163
|
+
"indic_id": "3d4006d3...", // 指标ID(metricId)
|
|
164
|
+
"ek": "7a4cb403...", // 指标唯一键
|
|
165
|
+
"type_text": "年度数据",
|
|
166
|
+
"explain": "数据说明..."
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**使用示例**:
|
|
171
|
+
```
|
|
172
|
+
// 查询GDP
|
|
173
|
+
cnbs_search(keyword="GDP")
|
|
174
|
+
|
|
175
|
+
// 查询人口出生率
|
|
176
|
+
cnbs_search(keyword="出生率")
|
|
177
|
+
|
|
178
|
+
// 查询65岁以上人口
|
|
179
|
+
cnbs_search(keyword="65岁人口")
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
### 2. cnbs_fetch_nodes
|
|
185
|
+
|
|
186
|
+
**功能**:获取分类树节点,浏览数据分类体系
|
|
187
|
+
|
|
188
|
+
**参数**:
|
|
189
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
190
|
+
|------|------|------|------|
|
|
191
|
+
| category | string | ✅ | 分类代码:1/2/3/5/6/7/8/9/10 |
|
|
192
|
+
| parentId | string | ❌ | 父节点ID,空则从根节点开始 |
|
|
193
|
+
|
|
194
|
+
**返回字段解读**:
|
|
195
|
+
```json
|
|
196
|
+
{
|
|
197
|
+
"_id": "bee83f19...", // 节点ID
|
|
198
|
+
"name": "人口抽样调查", // 节点名称
|
|
199
|
+
"isLeaf": true, // true=叶子节点,可查数据
|
|
200
|
+
"treeinfo_pid": "父节点ID",
|
|
201
|
+
"treeinfo_level": 4
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
### 3. cnbs_fetch_metrics
|
|
208
|
+
|
|
209
|
+
**功能**:获取数据集包含的所有指标列表
|
|
210
|
+
|
|
211
|
+
**参数**:
|
|
212
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
213
|
+
|------|------|------|------|
|
|
214
|
+
| setId | string | ✅ | 数据集ID,来自搜索或节点 |
|
|
215
|
+
| name | string | ❌ | 指标名称过滤 |
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
### 4. cnbs_fetch_series
|
|
220
|
+
|
|
221
|
+
**功能**:获取时间序列历史数据
|
|
222
|
+
|
|
223
|
+
**⚠️ 重要警告**:此接口返回的 `value` 字段可能为空!这是国家统计局API的设计限制。
|
|
224
|
+
|
|
225
|
+
**参数**:
|
|
226
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
227
|
+
|------|------|------|------|
|
|
228
|
+
| setId | string | ✅ | 数据集ID |
|
|
229
|
+
| metricIds | string[] | ✅ | 指标ID数组 |
|
|
230
|
+
| periods | string[] | ✅ | 时间范围数组 |
|
|
231
|
+
| areas | array | ❌ | 地区,默认全国 |
|
|
232
|
+
|
|
233
|
+
**参数示例**:
|
|
234
|
+
```json
|
|
235
|
+
{
|
|
236
|
+
"setId": "ffed4267bba24830beea5991d4c9bcfc",
|
|
237
|
+
"metricIds": ["3d4006d356d94bdd9d75700b9788e230"],
|
|
238
|
+
"periods": ["2020YY-2024YY"],
|
|
239
|
+
"areas": [{"text": "全国", "code": "000000000000"}]
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
### 5. cnbs_fetch_end_nodes
|
|
246
|
+
|
|
247
|
+
**功能**:递归获取指定分类下所有叶子节点
|
|
248
|
+
|
|
249
|
+
**参数**:
|
|
250
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
251
|
+
|------|------|------|------|
|
|
252
|
+
| category | string | ✅ | 分类代码 |
|
|
253
|
+
|
|
254
|
+
**警告**:此操作耗时较长,不建议频繁使用
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
### 6. cnbs_batch_search(新)
|
|
259
|
+
|
|
260
|
+
**功能**:批量搜索多个关键词,一次性获取多个指标数据
|
|
261
|
+
|
|
262
|
+
**参数**:
|
|
263
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
264
|
+
|------|------|------|------|
|
|
265
|
+
| keywords | string[] | ✅ | 搜索关键词数组 |
|
|
266
|
+
| pageSize | number | ❌ | 每个关键词返回数量,默认5 |
|
|
267
|
+
|
|
268
|
+
**使用示例**:
|
|
269
|
+
```
|
|
270
|
+
cnbs_batch_search(keywords=["GDP", "CPI", "出生率"])
|
|
271
|
+
// 返回三个关键词各自的搜索结果
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
### 7. cnbs_compare(新)
|
|
277
|
+
|
|
278
|
+
**功能**:对比不同地区或不同时间的数据
|
|
279
|
+
|
|
280
|
+
**参数**:
|
|
281
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
282
|
+
|------|------|------|------|
|
|
283
|
+
| keyword | string | ✅ | 搜索关键词 |
|
|
284
|
+
| regions | string[] | ❌ | 对比地区数组,如 ["北京", "上海"] |
|
|
285
|
+
| compareType | string | ❌ | "region"(地区对比)或 "time"(时间对比) |
|
|
286
|
+
| years | string[] | ❌ | 时间对比时的年份数组 |
|
|
287
|
+
|
|
288
|
+
**使用示例**:
|
|
289
|
+
```
|
|
290
|
+
// 地区对比
|
|
291
|
+
cnbs_compare(keyword="GDP", regions=["北京", "上海", "广东"], compareType="region")
|
|
292
|
+
|
|
293
|
+
// 时间对比
|
|
294
|
+
cnbs_compare(keyword="GDP", compareType="time", years=["2022", "2023", "2024"])
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
### 8. cnbs_get_regions(新)
|
|
300
|
+
|
|
301
|
+
**功能**:获取可用的地区代码列表
|
|
302
|
+
|
|
303
|
+
**参数**:
|
|
304
|
+
| 参数 | 类型 | 必填 | 说明 |
|
|
305
|
+
|------|------|------|------|
|
|
306
|
+
| keyword | string | ❌ | 搜索关键词,过滤地区 |
|
|
307
|
+
| level | string | ❌ | 地区级别:province/city/county |
|
|
308
|
+
|
|
309
|
+
**使用示例**:
|
|
310
|
+
```
|
|
311
|
+
// 获取所有省份
|
|
312
|
+
cnbs_get_regions()
|
|
313
|
+
|
|
314
|
+
// 搜索包含"江"的省份
|
|
315
|
+
cnbs_get_regions(keyword="江")
|
|
316
|
+
// 返回:江苏、浙江、江西等
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
### 9. cnbs_get_categories(新)
|
|
322
|
+
|
|
323
|
+
**功能**:获取所有数据分类信息
|
|
324
|
+
|
|
325
|
+
**参数**:无
|
|
326
|
+
|
|
327
|
+
**返回**:分类列表,包含代码、名称、时间粒度类型
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
## 🔧 辅助工具
|
|
332
|
+
|
|
333
|
+
| 工具 | 功能 |
|
|
334
|
+
|------|------|
|
|
335
|
+
| cnbs_get_guide | 获取本指南(建议首次使用时调用) |
|
|
336
|
+
| cnbs_get_cache_stats | 获取缓存统计 |
|
|
337
|
+
| cnbs_format_number | 格式化数字 |
|
|
338
|
+
| cnbs_transform_unit | 单位转换 |
|
|
339
|
+
| cnbs_compute_stats | 计算统计信息 |
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
## 📝 常见查询示例
|
|
344
|
+
|
|
345
|
+
### 查询GDP
|
|
346
|
+
|
|
347
|
+
```
|
|
348
|
+
// 方法一:直接搜索(推荐)
|
|
349
|
+
cnbs_search(keyword="GDP")
|
|
350
|
+
// 返回最新GDP值
|
|
351
|
+
|
|
352
|
+
// 方法二:获取历史数据
|
|
353
|
+
1. cnbs_search(keyword="GDP") → 获取 cid 和 indic_id
|
|
354
|
+
2. cnbs_fetch_series(setId=cid, metricIds=[indic_id], periods=["2020YY-2024YY"])
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### 查询CPI
|
|
358
|
+
|
|
359
|
+
```
|
|
360
|
+
cnbs_search(keyword="CPI")
|
|
361
|
+
cnbs_search(keyword="居民消费价格指数")
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### 查询人口数据
|
|
365
|
+
|
|
366
|
+
```
|
|
367
|
+
cnbs_search(keyword="人口出生率")
|
|
368
|
+
cnbs_search(keyword="65岁人口")
|
|
369
|
+
cnbs_search(keyword="老龄化")
|
|
370
|
+
cnbs_search(keyword="人口总数")
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### 查询分省数据
|
|
374
|
+
|
|
375
|
+
```
|
|
376
|
+
// 先搜索指标
|
|
377
|
+
cnbs_search(keyword="GDP 分省")
|
|
378
|
+
|
|
379
|
+
// 或浏览分省年度数据分类
|
|
380
|
+
cnbs_fetch_nodes(category="6")
|
|
381
|
+
|
|
382
|
+
// 获取地区代码
|
|
383
|
+
cnbs_get_regions(keyword="广东")
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
### 批量查询
|
|
387
|
+
|
|
388
|
+
```
|
|
389
|
+
cnbs_batch_search(keywords=["GDP", "CPI", "人口", "出生率"])
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### 地区对比
|
|
393
|
+
|
|
394
|
+
```
|
|
395
|
+
cnbs_compare(keyword="GDP", regions=["北京", "上海", "广东"], compareType="region")
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## ⚠️ 常见问题
|
|
401
|
+
|
|
402
|
+
### Q1: cnbs_fetch_series 返回的 value 为空?
|
|
403
|
+
|
|
404
|
+
**原因**:这是国家统计局API的设计限制,不是代码问题。
|
|
405
|
+
|
|
406
|
+
**解决方案**:
|
|
407
|
+
1. 优先使用 `cnbs_search` 获取最新数据值
|
|
408
|
+
2. 搜索结果的 `value` 字段始终有值
|
|
409
|
+
3. 如需历史数据,可多次搜索不同年份的数据
|
|
410
|
+
|
|
411
|
+
### Q2: 如何获取指标代码(zb code)?
|
|
412
|
+
|
|
413
|
+
**方法一(推荐)**:从搜索结果解析
|
|
414
|
+
```
|
|
415
|
+
cnbs_search(keyword="GDP")
|
|
416
|
+
// 返回结果中的 indic_id 或 ek 字段
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
**方法二**:遍历指标树
|
|
420
|
+
```
|
|
421
|
+
cnbs_fetch_nodes(category="3")
|
|
422
|
+
// 递归下钻直到 isLeaf=true
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
### Q3: 时间范围怎么写?
|
|
426
|
+
|
|
427
|
+
```
|
|
428
|
+
年度:["2020YY-2024YY"]
|
|
429
|
+
季度:["2023S1-2024S4"] 或使用快捷范围 ["LAST6"]
|
|
430
|
+
月度:["202301MM-202412MM"]
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
### Q4: 如何处理分省数据?
|
|
434
|
+
|
|
435
|
+
```
|
|
436
|
+
// 分省年度数据
|
|
437
|
+
cnbs_fetch_nodes(category="6")
|
|
438
|
+
|
|
439
|
+
// areas 参数指定省份
|
|
440
|
+
areas: [{"text": "北京市", "code": "110000000000"}]
|
|
441
|
+
|
|
442
|
+
// 或使用地区查询工具
|
|
443
|
+
cnbs_get_regions(keyword="北京")
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
### Q5: 如何批量查询多个指标?
|
|
447
|
+
|
|
448
|
+
```
|
|
449
|
+
cnbs_batch_search(keywords=["GDP", "CPI", "人口"])
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
### Q6: 如何对比不同地区的数据?
|
|
453
|
+
|
|
454
|
+
```
|
|
455
|
+
cnbs_compare(keyword="GDP", regions=["北京", "上海"], compareType="region")
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
---
|
|
459
|
+
|
|
460
|
+
## 📚 数据指标编码规则
|
|
461
|
+
|
|
462
|
+
### 指标编码规律
|
|
463
|
+
|
|
464
|
+
```
|
|
465
|
+
A01 → 一级分类(国民经济核算)
|
|
466
|
+
A0101 → 二级分类
|
|
467
|
+
A010101 → 叶子指标(国内生产总值_当季值)
|
|
468
|
+
A010102 → 叶子指标(国内生产总值_累计值)
|
|
469
|
+
|
|
470
|
+
规律:
|
|
471
|
+
- 位数越多层级越深
|
|
472
|
+
- 末尾奇数 = 当季值/当期值
|
|
473
|
+
- 末尾偶数 = 累计值
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
### 常用指标代码
|
|
477
|
+
|
|
478
|
+
| 代码 | 指标名称 |
|
|
479
|
+
|------|---------|
|
|
480
|
+
| A01 | 国民经济核算 |
|
|
481
|
+
| A010101 | GDP当季值 |
|
|
482
|
+
| A010102 | GDP累计值 |
|
|
483
|
+
| A02 | 人口 |
|
|
484
|
+
| A03 | 就业与工资 |
|
|
485
|
+
| A06 | 固定资产投资 |
|
|
486
|
+
| A08 | 价格指数 |
|
|
487
|
+
|
|
488
|
+
---
|
|
489
|
+
|
|
490
|
+
## 📌 最佳实践总结
|
|
491
|
+
|
|
492
|
+
```
|
|
493
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
494
|
+
│ 1. 优先使用 cnbs_search 获取数据 │
|
|
495
|
+
│ - 一次请求获取最新值 │
|
|
496
|
+
│ - 返回的 value 字段有值 │
|
|
497
|
+
│ │
|
|
498
|
+
│ 2. cnbs_fetch_series 的 value 可能为空 │
|
|
499
|
+
│ - 这是API限制,不是代码问题 │
|
|
500
|
+
│ - 适合获取时间序列结构 │
|
|
501
|
+
│ │
|
|
502
|
+
│ 3. 选择正确的数据分类 │
|
|
503
|
+
│ - 年度数据用 category="3" │
|
|
504
|
+
│ - 季度数据用 category="2" │
|
|
505
|
+
│ - 月度数据用 category="1" │
|
|
506
|
+
│ │
|
|
507
|
+
│ 4. 时间格式要正确 │
|
|
508
|
+
│ - 年度:2024YY │
|
|
509
|
+
│ - 季度:2024S1, 2024S2, ... │
|
|
510
|
+
│ - 月度:202401MM │
|
|
511
|
+
│ │
|
|
512
|
+
│ 5. 缓存自动管理 │
|
|
513
|
+
│ - 指标树变动频率低,自动缓存 │
|
|
514
|
+
│ - 缓存对多用户共享,减少API调用 │
|
|
515
|
+
│ │
|
|
516
|
+
│ 6. 批量查询用 cnbs_batch_search │
|
|
517
|
+
│ - 一次请求获取多个指标 │
|
|
518
|
+
│ - 比多次调用 cnbs_search 更高效 │
|
|
519
|
+
│ │
|
|
520
|
+
│ 7. 地区对比用 cnbs_compare │
|
|
521
|
+
│ - 支持地区对比和时间对比 │
|
|
522
|
+
│ - 自动整理对比结果 │
|
|
523
|
+
└─────────────────────────────────────────────────────────────┘
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
---
|
|
527
|
+
|
|
528
|
+
## 🔐 鉴权配置
|
|
529
|
+
|
|
530
|
+
默认无需鉴权,公开访问。可通过 Bearer Token 启用鉴权保护服务。
|
|
531
|
+
|
|
532
|
+
### 免费演示地址
|
|
533
|
+
|
|
534
|
+
魔搭 ModelScope 提供免费演示服务,无需鉴权:
|
|
535
|
+
```
|
|
536
|
+
https://mcp.api-inference.modelscope.net/86a1a6b0b08741/mcp
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
配置示例:
|
|
540
|
+
```json
|
|
541
|
+
{
|
|
542
|
+
"mcpServers": {
|
|
543
|
+
"cnbs": {
|
|
544
|
+
"type": "streamable_http",
|
|
545
|
+
"url": "https://mcp.api-inference.modelscope.net/86a1a6b0b08741/mcp"
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
魔搭主页:https://modelscope.cn/mcp/servers/thatcoder/cnbs
|
|
552
|
+
|
|
553
|
+
### 配置方式
|
|
554
|
+
|
|
555
|
+
| 部署方式 | 配置方法 |
|
|
556
|
+
|---------|---------|
|
|
557
|
+
| 本地 HTTP 模式 | `--auth-token <token>` 参数或 `MCP_CNBS_AUTH_TOKEN` 环境变量 |
|
|
558
|
+
| Cloudflare Workers | `wrangler secret put MCP_CNBS_AUTH_TOKEN` 设置密钥 |
|
|
559
|
+
|
|
560
|
+
### 使用示例
|
|
561
|
+
|
|
562
|
+
```bash
|
|
563
|
+
# 本地启动带鉴权
|
|
564
|
+
npx mcp-cnbs --port 12345 --auth-token your-secret-token
|
|
565
|
+
|
|
566
|
+
# 或使用环境变量
|
|
567
|
+
MCP_CNBS_AUTH_TOKEN=your-secret-token npx mcp-cnbs --port 12345
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
### 请求格式
|
|
571
|
+
|
|
572
|
+
启用鉴权后,HTTP 请求需包含 Authorization 头:
|
|
573
|
+
|
|
574
|
+
```
|
|
575
|
+
Authorization: Bearer your-secret-token
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
---
|
|
579
|
+
|
|
580
|
+
## 🌐 技术说明
|
|
581
|
+
|
|
582
|
+
- **运行环境**: Node.js 18+
|
|
583
|
+
- **协议**: MCP (Model Context Protocol)
|
|
584
|
+
- **数据源**: 中国国家统计局公开API
|
|
585
|
+
- **基础地址**: https://data.stats.gov.cn
|
|
586
|
+
- **鉴权**: 可选 Bearer Token 鉴权
|
|
587
|
+
- **缓存**: 内置内存缓存,支持TTL
|
|
588
|
+
|
|
589
|
+
---
|
|
590
|
+
|
|
591
|
+
## ⚡ 速查表
|
|
592
|
+
|
|
593
|
+
| 需求 | 工具 | 关键参数 |
|
|
594
|
+
|------|------|---------|
|
|
595
|
+
| 关键词找指标+最新值 | cnbs_search | keyword |
|
|
596
|
+
| 浏览分类体系 | cnbs_fetch_nodes | category |
|
|
597
|
+
| 获取指标列表 | cnbs_fetch_metrics | setId |
|
|
598
|
+
| 查历史时间序列 | cnbs_fetch_series | setId, metricIds, periods |
|
|
599
|
+
| 批量获取数据集 | cnbs_fetch_end_nodes | category |
|
|
600
|
+
| 批量搜索多指标 | cnbs_batch_search | keywords |
|
|
601
|
+
| 地区/时间对比 | cnbs_compare | keyword, regions/years |
|
|
602
|
+
| 获取地区代码 | cnbs_get_regions | keyword |
|
|
603
|
+
| 获取分类信息 | cnbs_get_categories | - |
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mcp-statdb",
|
|
3
|
+
"version": "1.3.2",
|
|
4
|
+
"description": "MCP server for China National Bureau of Statistics (CNBS) data access",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"bin": {
|
|
9
|
+
"mcp-cnbs": "dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"llms.txt",
|
|
14
|
+
"README.md",
|
|
15
|
+
"README.zh-CN.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=18.0.0"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"start": "node dist/index.js --port 12345",
|
|
24
|
+
"clean": "rm -rf dist",
|
|
25
|
+
"prepublishOnly": "npm run build",
|
|
26
|
+
"test": "jest",
|
|
27
|
+
"test:watch": "jest --watch",
|
|
28
|
+
"test:coverage": "jest --coverage",
|
|
29
|
+
"cf:dev": "wrangler dev",
|
|
30
|
+
"cf:deploy": "wrangler deploy"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"mcp",
|
|
34
|
+
"statistics",
|
|
35
|
+
"china",
|
|
36
|
+
"nbs",
|
|
37
|
+
"cnbs",
|
|
38
|
+
"modelcontextprotocol",
|
|
39
|
+
"gdp",
|
|
40
|
+
"cpi",
|
|
41
|
+
"population"
|
|
42
|
+
],
|
|
43
|
+
"author": "J.K.",
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/icen-ai/mcp-cnbs.git"
|
|
48
|
+
},
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/icen-ai/mcp-cnbs/issues"
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://github.com/icen-ai/mcp-cnbs#readme",
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@cloudflare/workers-types": "^4.20260404.1",
|
|
55
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
56
|
+
"@types/jest": "^29.5.12",
|
|
57
|
+
"@types/node": "^20.19.0",
|
|
58
|
+
"axios": "^1.8.4",
|
|
59
|
+
"commander": "^14.0.0",
|
|
60
|
+
"jest": "^29.7.0",
|
|
61
|
+
"ts-jest": "^29.1.2",
|
|
62
|
+
"tsup": "^8.5.1",
|
|
63
|
+
"typescript": "^5.3.0",
|
|
64
|
+
"wrangler": "^4.81.1",
|
|
65
|
+
"zod": "^3.24.2"
|
|
66
|
+
}
|
|
67
|
+
}
|