mcp-cnbs 1.0.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.
Files changed (57) hide show
  1. package/License +201 -0
  2. package/README.md +226 -0
  3. package/README.zh-CN.md +225 -0
  4. package/dist/constants/index.d.ts +3 -0
  5. package/dist/constants/index.d.ts.map +1 -0
  6. package/dist/constants/index.js +3 -0
  7. package/dist/constants/index.js.map +1 -0
  8. package/dist/constants/regions.d.ts +16 -0
  9. package/dist/constants/regions.d.ts.map +1 -0
  10. package/dist/constants/regions.js +68 -0
  11. package/dist/constants/regions.js.map +1 -0
  12. package/dist/constants.d.ts +7 -0
  13. package/dist/constants.d.ts.map +1 -0
  14. package/dist/constants.js +7 -0
  15. package/dist/constants.js.map +1 -0
  16. package/dist/index.d.ts +3 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +306 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/server.d.ts +3 -0
  21. package/dist/server.d.ts.map +1 -0
  22. package/dist/server.js +44 -0
  23. package/dist/server.js.map +1 -0
  24. package/dist/services/api.d.ts +47 -0
  25. package/dist/services/api.d.ts.map +1 -0
  26. package/dist/services/api.js +434 -0
  27. package/dist/services/api.js.map +1 -0
  28. package/dist/services/cache.d.ts +48 -0
  29. package/dist/services/cache.d.ts.map +1 -0
  30. package/dist/services/cache.js +215 -0
  31. package/dist/services/cache.js.map +1 -0
  32. package/dist/services/data.d.ts +16 -0
  33. package/dist/services/data.d.ts.map +1 -0
  34. package/dist/services/data.js +90 -0
  35. package/dist/services/data.js.map +1 -0
  36. package/dist/services/error.d.ts +44 -0
  37. package/dist/services/error.d.ts.map +1 -0
  38. package/dist/services/error.js +171 -0
  39. package/dist/services/error.js.map +1 -0
  40. package/dist/services/search.d.ts +18 -0
  41. package/dist/services/search.d.ts.map +1 -0
  42. package/dist/services/search.js +39 -0
  43. package/dist/services/search.js.map +1 -0
  44. package/dist/tools/index.d.ts +3 -0
  45. package/dist/tools/index.d.ts.map +1 -0
  46. package/dist/tools/index.js +686 -0
  47. package/dist/tools/index.js.map +1 -0
  48. package/dist/types/index.d.ts +182 -0
  49. package/dist/types/index.d.ts.map +1 -0
  50. package/dist/types/index.js +16 -0
  51. package/dist/types/index.js.map +1 -0
  52. package/dist/worker.d.ts +17 -0
  53. package/dist/worker.d.ts.map +1 -0
  54. package/dist/worker.js +262 -0
  55. package/dist/worker.js.map +1 -0
  56. package/llms.txt +603 -0
  57. package/package.json +63 -0
package/License ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,226 @@
1
+ # CNBS MCP Server
2
+
3
+ MCP server for querying China National Bureau of Statistics data.
4
+
5
+ ## Installation
6
+
7
+ ### Use with npx (Recommended)
8
+
9
+ ```bash
10
+ npx @icen.ai/mcp-cnbs
11
+ ```
12
+
13
+ ### Use with HTTP transport
14
+
15
+ ```bash
16
+ npx @icen.ai/mcp-cnbs --port 12345
17
+ ```
18
+
19
+ ### Install globally
20
+
21
+ ```bash
22
+ npm install -g @icen.ai/mcp-cnbs
23
+ mcp-cnbs
24
+ ```
25
+
26
+ ## MCP Client Configuration
27
+
28
+ ### NPX Mode (Local)
29
+
30
+ **Supported clients:** Claude Desktop, Cursor, Windsurf, Cherry Studio, Trae, Continue, and other MCP clients.
31
+
32
+ Add to your MCP client configuration file:
33
+
34
+ ```json
35
+ {
36
+ "mcpServers": {
37
+ "cnbs": {
38
+ "command": "npx",
39
+ "args": ["@icen.ai/mcp-cnbs"]
40
+ }
41
+ }
42
+ }
43
+ ```
44
+
45
+ ### HTTP Mode (Remote Access)
46
+
47
+ **Supported clients:** Trae, Cherry Studio, and other MCP clients with HTTP transport support.
48
+
49
+ **Free Demo on ModelScope (recommended):**
50
+ ```json
51
+ {
52
+ "mcpServers": {
53
+ "cnbs": {
54
+ "url": "https://mcp.api-inference.modelscope.net/3d34f0e0c26a44/mcp"
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ > **Note:** This is a free public demo provided by Alibaba Cloud ModelScope. No authentication required.
61
+ >
62
+ > Since free services may change, we recommend deploying your own instance: [Deploy on ModelScope](https://modelscope.cn/mcp/servers/thatcoder/cnbs)
63
+
64
+ ## Endpoints
65
+
66
+ | Endpoint | Method | Description |
67
+ |----------|--------|-------------|
68
+ | `/` | POST | Streamable HTTP (recommended) |
69
+ | `/` | GET | SSE stream for notifications |
70
+ | `/sse` | GET | Legacy SSE mode |
71
+ | `/message` | POST | Legacy SSE messages |
72
+
73
+ ## Tools
74
+
75
+ ### Data Query
76
+
77
+ | Tool | Description |
78
+ |------|-------------|
79
+ | `cnbs_search` | Search by keyword, returns latest data value |
80
+ | `cnbs_fetch_nodes` | Get category tree nodes |
81
+ | `cnbs_fetch_metrics` | Get indicator list for a dataset |
82
+ | `cnbs_fetch_series` | Get time series data |
83
+ | `cnbs_fetch_end_nodes` | Recursively get all leaf nodes |
84
+ | `cnbs_batch_search` | Batch search multiple keywords |
85
+ | `cnbs_compare` | Compare data across regions or time periods |
86
+
87
+ ### Reference Data
88
+
89
+ | Tool | Description |
90
+ |------|-------------|
91
+ | `cnbs_get_regions` | Get available region codes and names |
92
+ | `cnbs_get_categories` | Get all data category information |
93
+
94
+ ### Utilities
95
+
96
+ | Tool | Description |
97
+ |------|-------------|
98
+ | `cnbs_get_guide` | Get usage guide |
99
+ | `cnbs_get_cache_stats` | Get cache statistics |
100
+ | `cnbs_format_number` | Format numbers |
101
+ | `cnbs_transform_unit` | Unit conversion |
102
+ | `cnbs_compute_stats` | Compute statistics |
103
+
104
+ ## Quick Examples
105
+
106
+ ```
107
+ // Search GDP
108
+ cnbs_search(keyword="GDP")
109
+
110
+ // Search birth rate
111
+ cnbs_search(keyword="出生率")
112
+
113
+ // Batch search
114
+ cnbs_batch_search(keywords=["GDP", "CPI", "人口"])
115
+
116
+ // Compare regions
117
+ cnbs_compare(keyword="GDP", regions=["北京", "上海"], compareType="region")
118
+
119
+ // Get region codes
120
+ cnbs_get_regions(keyword="广东")
121
+ ```
122
+
123
+ ## Notes
124
+
125
+ `cnbs_search` returns `value` field with data. `cnbs_fetch_series` may return empty `value` - this is an API limitation.
126
+
127
+ For latest values, use `cnbs_search`.
128
+
129
+ ## Category Codes
130
+
131
+ | Code | Category |
132
+ |------|----------|
133
+ | 1 | Monthly |
134
+ | 2 | Quarterly |
135
+ | 3 | Yearly |
136
+ | 5 | Provincial Quarterly |
137
+ | 6 | Provincial Yearly |
138
+ | 7 | Other |
139
+ | 8 | Major Cities Yearly |
140
+ | 9 | Hong Kong/Macau/Taiwan Monthly |
141
+ | 10 | Hong Kong/Macau/Taiwan Yearly |
142
+
143
+ ## Time Format
144
+
145
+ - Yearly: `2024YY`, range `["2020YY-2024YY"]`
146
+ - Quarterly: `2024A/B/C/D`, shortcuts `LAST6/LAST12/LAST18`
147
+ - Monthly: `202401MM`, range `["202301MM-202412MM"]`
148
+
149
+ ## Region Codes
150
+
151
+ Region codes follow GB/T 2260 standard. Use `cnbs_get_regions` to get the full list.
152
+
153
+ Examples:
154
+ - Beijing: `110000000000`
155
+ - Shanghai: `310000000000`
156
+ - Guangdong: `440000000000`
157
+
158
+ ## Development
159
+
160
+ ```bash
161
+ # Install dependencies
162
+ npm install
163
+
164
+ # Build
165
+ npm run build
166
+
167
+ # Run locally
168
+ npm run start
169
+
170
+ # Development mode with watch
171
+ npm run dev
172
+ ```
173
+
174
+ ## Authentication
175
+
176
+ By default, no authentication is required. You can enable authentication using Bearer token.
177
+
178
+ ### Local / HTTP Mode
179
+
180
+ ```bash
181
+ # Using command line argument
182
+ npx @icen.ai/mcp-cnbs --port 12345 --auth-token your-secret-token
183
+
184
+ # Using environment variable
185
+ MCP_CNBS_AUTH_TOKEN=your-secret-token npx @icen.ai/mcp-cnbs --port 12345
186
+ ```
187
+
188
+ When authentication is enabled, requests must include:
189
+ ```
190
+ Authorization: Bearer your-secret-token
191
+ ```
192
+
193
+ ### Cloudflare Workers
194
+
195
+ Set `MCP_CNBS_AUTH_TOKEN` in Cloudflare dashboard secrets:
196
+
197
+ ```bash
198
+ # Deploy with secret
199
+ npx wrangler secret put MCP_CNBS_AUTH_TOKEN
200
+ # Enter your token when prompted
201
+
202
+ # Or use wrangler.toml
203
+ # (secrets cannot be set in wrangler.toml for security)
204
+ ```
205
+
206
+ ### MCP Client Configuration with Auth
207
+
208
+ ```json
209
+ {
210
+ "mcpServers": {
211
+ "cnbs": {
212
+ "command": "npx",
213
+ "args": ["@icen.ai/mcp-cnbs", "--port", "12345", "--auth-token", "your-secret-token"]
214
+ }
215
+ }
216
+ }
217
+ ```
218
+
219
+ ## Requirements
220
+
221
+ - Node.js >= 18.0.0
222
+ - Network access to `data.stats.gov.cn`
223
+
224
+ ## License
225
+
226
+ MIT
@@ -0,0 +1,225 @@
1
+ # CNBS MCP 服务器
2
+
3
+ 国家统计局数据查询的 MCP 服务器。
4
+
5
+ ## 安装使用
6
+
7
+ ### npx 直接运行(推荐)
8
+
9
+ ```bash
10
+ npx @icen.ai/mcp-cnbs
11
+ ```
12
+
13
+ ### HTTP 模式
14
+
15
+ ```bash
16
+ npx @icen.ai/mcp-cnbs --port 12345
17
+ ```
18
+
19
+ ### 全局安装
20
+
21
+ ```bash
22
+ npm install -g @icen.ai/mcp-cnbs
23
+ mcp-cnbs
24
+ ```
25
+
26
+ ## MCP 客户端配置
27
+
28
+ ### NPX 模式(本地运行)
29
+
30
+ **支持的客户端:** Claude Desktop、Cursor、Windsurf、Cherry Studio、Trae、Continue 等所有支持 MCP 的客户端。
31
+
32
+ 添加到 MCP 客户端配置文件:
33
+
34
+ ```json
35
+ {
36
+ "mcpServers": {
37
+ "cnbs": {
38
+ "command": "npx",
39
+ "args": ["@icen.ai/mcp-cnbs"]
40
+ }
41
+ }
42
+ }
43
+ ```
44
+
45
+ ### HTTP 模式(远程访问)
46
+
47
+ **支持的客户端:** Trae、Cherry Studio 等支持 HTTP transport 的客户端。
48
+
49
+ **魔搭免费演示(推荐):**
50
+ ```json
51
+ {
52
+ "mcpServers": {
53
+ "cnbs": {
54
+ "url": "https://mcp.api-inference.modelscope.net/3d34f0e0c26a44/mcp"
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ > **注意:** 这是阿里云 ModelScope 提供的免费公共演示服务,无需认证。
61
+ >
62
+ > 由于免费服务可能变更,建议自行部署:[在魔搭免费部署](https://modelscope.cn/mcp/servers/thatcoder/cnbs)
63
+
64
+ ## 端点说明
65
+
66
+ | 端点 | 方法 | 说明 |
67
+ |------|------|------|
68
+ | `/` | POST | Streamable HTTP(推荐) |
69
+ | `/` | GET | SSE 流(通知) |
70
+ | `/sse` | GET | 旧版 SSE 模式 |
71
+ | `/message` | POST | 旧版 SSE 消息 |
72
+
73
+ ## 工具列表
74
+
75
+ ### 数据查询
76
+
77
+ | 工具 | 功能 |
78
+ |------|------|
79
+ | `cnbs_search` | 关键词搜索,返回最新数据值 |
80
+ | `cnbs_fetch_nodes` | 获取分类树节点 |
81
+ | `cnbs_fetch_metrics` | 获取数据集的指标列表 |
82
+ | `cnbs_fetch_series` | 获取时间序列数据 |
83
+ | `cnbs_fetch_end_nodes` | 递归获取所有叶子节点 |
84
+ | `cnbs_batch_search` | 批量搜索多个关键词 |
85
+ | `cnbs_compare` | 数据对比(地区对比/时间对比) |
86
+
87
+ ### 参考数据
88
+
89
+ | 工具 | 功能 |
90
+ |------|------|
91
+ | `cnbs_get_regions` | 获取地区代码列表 |
92
+ | `cnbs_get_categories` | 获取所有分类信息 |
93
+
94
+ ### 辅助功能
95
+
96
+ | 工具 | 功能 |
97
+ |------|------|
98
+ | `cnbs_get_guide` | 获取使用指南 |
99
+ | `cnbs_get_cache_stats` | 获取缓存统计 |
100
+ | `cnbs_format_number` | 格式化数字 |
101
+ | `cnbs_transform_unit` | 单位转换 |
102
+ | `cnbs_compute_stats` | 计算统计信息 |
103
+
104
+ ## 快速示例
105
+
106
+ ```
107
+ // 查询 GDP
108
+ cnbs_search(keyword="GDP")
109
+
110
+ // 查询出生率
111
+ cnbs_search(keyword="出生率")
112
+
113
+ // 批量查询
114
+ cnbs_batch_search(keywords=["GDP", "CPI", "人口"])
115
+
116
+ // 地区对比
117
+ cnbs_compare(keyword="GDP", regions=["北京", "上海"], compareType="region")
118
+
119
+ // 获取地区代码
120
+ cnbs_get_regions(keyword="广东")
121
+ ```
122
+
123
+ ## 说明
124
+
125
+ `cnbs_search` 返回的 `value` 字段有值。`cnbs_fetch_series` 返回的 `value` 字段可能为空,这是国家统计局 API 的限制。
126
+
127
+ 只需最新值时,用 `cnbs_search`。
128
+
129
+ ## 分类代码
130
+
131
+ | 代码 | 分类 |
132
+ |------|------|
133
+ | 1 | 月度数据 |
134
+ | 2 | 季度数据 |
135
+ | 3 | 年度数据 |
136
+ | 5 | 分省季度 |
137
+ | 6 | 分省年度 |
138
+ | 7 | 其他 |
139
+ | 8 | 主要城市年度 |
140
+ | 9 | 港澳台月度 |
141
+ | 10 | 港澳台年度 |
142
+
143
+ ## 时间格式
144
+
145
+ - 年度: `2024YY`, 范围 `["2020YY-2024YY"]`
146
+ - 季度: `2024A/B/C/D`, 快捷范围 `LAST6/LAST12/LAST18`
147
+ - 月度: `202401MM`, 范围 `["202301MM-202412MM"]`
148
+
149
+ ## 地区代码
150
+
151
+ 地区代码遵循 GB/T 2260 标准。使用 `cnbs_get_regions` 获取完整列表。
152
+
153
+ 示例:
154
+ - 北京: `110000000000`
155
+ - 上海: `310000000000`
156
+ - 广东: `440000000000`
157
+
158
+ ## 开发
159
+
160
+ ```bash
161
+ # 安装依赖
162
+ npm install
163
+
164
+ # 编译
165
+ npm run build
166
+
167
+ # 运行
168
+ npm run start
169
+
170
+ # 开发模式
171
+ npm run dev
172
+ ```
173
+
174
+ ## 鉴权配置
175
+
176
+ 默认无需鉴权。可通过 Bearer Token 启用鉴权。
177
+
178
+ ### 本地 / HTTP 模式
179
+
180
+ ```bash
181
+ # 命令行参数
182
+ npx @icen.ai/mcp-cnbs --port 12345 --auth-token your-secret-token
183
+
184
+ # 环境变量
185
+ MCP_CNBS_AUTH_TOKEN=your-secret-token npx @icen.ai/mcp-cnbs --port 12345
186
+ ```
187
+
188
+ 启用鉴权后,请求需包含:
189
+ ```
190
+ Authorization: Bearer your-secret-token
191
+ ```
192
+
193
+ ### Cloudflare Workers
194
+
195
+ 在 Cloudflare 控制台设置密钥:
196
+
197
+ ```bash
198
+ # 部署时设置密钥
199
+ npx wrangler secret put MCP_CNBS_AUTH_TOKEN
200
+ # 按提示输入 token
201
+
202
+ # 注意:出于安全考虑,密钥不能在 wrangler.toml 中设置
203
+ ```
204
+
205
+ ### 带鉴权的 MCP 客户端配置
206
+
207
+ ```json
208
+ {
209
+ "mcpServers": {
210
+ "cnbs": {
211
+ "command": "npx",
212
+ "args": ["@icen.ai/mcp-cnbs", "--port", "12345", "--auth-token", "your-secret-token"]
213
+ }
214
+ }
215
+ }
216
+ ```
217
+
218
+ ## 环境要求
219
+
220
+ - Node.js >= 18.0.0
221
+ - 网络能访问 `data.stats.gov.cn`
222
+
223
+ ## 许可证
224
+
225
+ MIT
@@ -0,0 +1,3 @@
1
+ export * from './regions.js';
2
+ export * from '../constants.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './regions.js';
2
+ export * from '../constants.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,16 @@
1
+ export interface CnbsRegion {
2
+ code: string;
3
+ name: string;
4
+ shortName: string;
5
+ level: 'province' | 'city' | 'county';
6
+ }
7
+ export declare const CNBS_REGIONS: CnbsRegion[];
8
+ export declare const CNBS_CATEGORY_INFO: Record<string, {
9
+ name: string;
10
+ code: string;
11
+ dtType: string;
12
+ }>;
13
+ export declare function getRegionByCode(code: string): CnbsRegion | undefined;
14
+ export declare function getRegionByName(name: string): CnbsRegion | undefined;
15
+ export declare function searchRegions(keyword: string): CnbsRegion[];
16
+ //# sourceMappingURL=regions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regions.d.ts","sourceRoot":"","sources":["../../src/constants/regions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,QAAQ,CAAC;CACvC;AAED,eAAO,MAAM,YAAY,EAAE,UAAU,EAoCpC,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAc7F,CAAC;AAEF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAEpE;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAOpE;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,EAAE,CAO3D"}