@yyaylt/zhipu-web-search-mcp-server 1.0.2 → 1.0.5
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/CONTRIBUTING.md +51 -0
- package/LICENSE +5 -197
- package/README.md +25 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +2 -3
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -20
- package/dist/index.js.map +1 -1
- package/dist/schemas/webSearch.d.ts +80 -2
- package/dist/schemas/webSearch.d.ts.map +1 -1
- package/dist/schemas/webSearch.js +21 -3
- package/dist/schemas/webSearch.js.map +1 -1
- package/dist/services/webSearchApi.d.ts.map +1 -1
- package/dist/services/webSearchApi.js +1 -0
- package/dist/services/webSearchApi.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/package.json +14 -4
- package/src/constants.ts +2 -3
- package/src/index.ts +31 -20
- package/src/schemas/webSearch.ts +23 -3
- package/src/services/webSearchApi.ts +1 -0
- package/src/types.ts +1 -0
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
感谢你愿意为 `zhipu-web-search-mcp-server` 贡献代码!
|
|
4
|
+
|
|
5
|
+
## 版权与许可
|
|
6
|
+
|
|
7
|
+
本项目基于 **MIT License** 发布(见 [LICENSE](./LICENSE))。
|
|
8
|
+
|
|
9
|
+
- 所有贡献(代码、文档、测试等)在提交后,均视为以 **MIT License** 授权给本项目。
|
|
10
|
+
- 在本项目**之外**,你仍保留对自己贡献的完整版权;仅在贡献给本项目时,将该贡献按 MIT 条款授予本项目及其他使用者。
|
|
11
|
+
- 通过提交代码(Pull Request / Merge Request),即表示你同意以上条款。
|
|
12
|
+
|
|
13
|
+
## 开发环境
|
|
14
|
+
|
|
15
|
+
- Node.js >= 18
|
|
16
|
+
- 安装依赖:`npm install`
|
|
17
|
+
- 构建:`npm run build`
|
|
18
|
+
- 开发:`npm run dev`(tsx watch 模式)
|
|
19
|
+
|
|
20
|
+
## 代码规范
|
|
21
|
+
|
|
22
|
+
- 保持现有代码风格(TypeScript、严格模式)。
|
|
23
|
+
- 所有源码文件**必须**保留 `// SPDX-License-Identifier: MIT` 头部注释。
|
|
24
|
+
- 复杂逻辑请添加中文注释说明。
|
|
25
|
+
- 新增功能时,请同步补充或更新 `README.md` 中的相关说明。
|
|
26
|
+
|
|
27
|
+
## 测试
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm test
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
提交前请确保测试通过。
|
|
34
|
+
|
|
35
|
+
## 提交信息
|
|
36
|
+
|
|
37
|
+
请使用清晰、简洁的提交信息,建议遵循 Conventional Commits 风格:
|
|
38
|
+
|
|
39
|
+
```text
|
|
40
|
+
feat: 增加 XX 功能
|
|
41
|
+
fix: 修复 XX 问题
|
|
42
|
+
docs: 更新文档
|
|
43
|
+
chore: 维护性改动
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 提交前检查清单
|
|
47
|
+
|
|
48
|
+
- [ ] `npm run build` 构建通过
|
|
49
|
+
- [ ] `npm test` 测试通过
|
|
50
|
+
- [ ] 新增文件包含 SPDX 许可证头
|
|
51
|
+
- [ ] README 是否需同步更新
|
package/LICENSE
CHANGED
|
@@ -1,201 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
1
|
+
MIT License
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
Copyright (c) 2026 lost_fish
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
11
8
|
|
|
12
|
-
|
|
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.
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -67,12 +67,20 @@ opencode mcp add zhipu-web-search -- node D:\path\to\zhipu-web-search-mcp-server
|
|
|
67
67
|
| search_query | string | 必填 | 搜索内容,不超过 70 字符 |
|
|
68
68
|
| search_engine | string | search_std | 搜索引擎:search_std / search_pro / search_pro_sogou / search_pro_quark |
|
|
69
69
|
| search_intent | boolean | false | 是否执行搜索意图识别 |
|
|
70
|
-
| count | number | 10 |
|
|
70
|
+
| count | number | 支持的引擎默认 10 | search_std / search_pro:1-50 的整数;search_pro_sogou:仅 10/20/30/40/50;search_pro_quark:不支持,不能指定 |
|
|
71
71
|
| search_domain_filter | string | - | 白名单域名过滤(search_std / search_pro / search_pro_sogou 支持) |
|
|
72
72
|
| search_recency_filter | string | noLimit | 时间过滤:oneDay / oneWeek / oneMonth / oneYear / noLimit |
|
|
73
73
|
| content_size | string | medium | 内容长短:medium / high |
|
|
74
74
|
| user_id | string | - | 终端用户 ID,6-128 字符 |
|
|
75
75
|
|
|
76
|
+
条数行为依据 [Web Search API 官方参数文档](https://docs.bigmodel.cn/api-reference/工具-api/网络搜索):
|
|
77
|
+
|
|
78
|
+
- `count` 是请求条数,输出 JSON 的 `count` 是实际收到的 `results.length`,不能将两者视为必然相等。
|
|
79
|
+
- 官网在搜狗枚举说明后注明同时指定 `search_domain_filter` 和 `search_recency_filter` 时 `count` 不生效,未明确此备注对其他引擎的适用范围。项目保留用户的具体过滤条件并提示此限制。
|
|
80
|
+
- `search_recency_filter` 为 `noLimit` 时省略该请求字段,避免默认值导致同时携带域名和时间过滤;官网未明确服务端是否将显式 `noLimit` 计入上述限制。
|
|
81
|
+
- 夸克不发送 `count`;显式指定会返回参数错误。搜狗的非法条数也会在发送请求前拒绝。
|
|
82
|
+
- Markdown 按约 25,000 字符的条目预算截断,截断标题显示“展示 X 条,共 Y 条”;结构化结果始终保留完整列表,文本同时说明请求与实际返回数量。
|
|
83
|
+
|
|
76
84
|
## 隐私与安全提示
|
|
77
85
|
|
|
78
86
|
- `ZHIPU_API_KEY` 仅通过环境变量注入,请勿将其写入代码、配置仓库或提交到 Git 历史。
|
|
@@ -103,3 +111,19 @@ npm run build # 编译到 dist/
|
|
|
103
111
|
node dist/index.js
|
|
104
112
|
# ERROR: ZHIPU_API_KEY 环境变量是必需的
|
|
105
113
|
```
|
|
114
|
+
|
|
115
|
+
## License & Acknowledgments
|
|
116
|
+
|
|
117
|
+
This project is licensed under the MIT License. See [LICENSE](./LICENSE) for details.
|
|
118
|
+
|
|
119
|
+
Contributions are welcome — please read [CONTRIBUTING.md](./CONTRIBUTING.md) before submitting code.
|
|
120
|
+
|
|
121
|
+
It includes third-party packages with the following licenses (updated at build time via `npx license-checker --summary`; counts may vary with dependency versions):
|
|
122
|
+
- MIT (95 packages)
|
|
123
|
+
- BlueOak-1.0.0 (7 packages)
|
|
124
|
+
- ISC (7 packages)
|
|
125
|
+
- Apache-2.0 (1 package)
|
|
126
|
+
- BSD-3-Clause (2 packages)
|
|
127
|
+
- BSD-2-Clause (1 package)
|
|
128
|
+
|
|
129
|
+
> 提示:以上数量为生成本文档时的快照。依赖升级后可用 `npx license-checker --summary` 重新生成核对。
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,YAAY,oDAAoD,CAAC;AAG9E,eAAO,MAAM,eAAe,QAAQ,CAAC;AAGrC,eAAO,MAAM,cAAc;;;;;CAKjB,CAAC;AAGX,eAAO,MAAM,eAAe;;;;;;CAMlB,CAAC;AAGX,eAAO,MAAM,aAAa;;;CAGhB,CAAC;AAGX,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAEpD,CAAC;AAGF,eAAO,MAAM,kBAAkB,QAAQ,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
1
2
|
// 智谱 Web Search API 相关常量定义
|
|
2
3
|
// API 基础地址(智谱开放平台)
|
|
3
4
|
export const API_BASE_URL = "https://open.bigmodel.cn/api/paas/v4/web_search";
|
|
@@ -23,10 +24,8 @@ export const CONTENT_SIZES = {
|
|
|
23
24
|
MEDIUM: "medium",
|
|
24
25
|
HIGH: "high"
|
|
25
26
|
};
|
|
26
|
-
//
|
|
27
|
+
// 仅搜狗限制为枚举;基础版和高阶版支持 1-50 的整数。
|
|
27
28
|
export const COUNT_BY_ENGINE = {
|
|
28
|
-
[SEARCH_ENGINES.STORE]: [10, 20, 30, 40, 50],
|
|
29
|
-
[SEARCH_ENGINES.PRO]: [10, 20, 30, 40, 50],
|
|
30
29
|
[SEARCH_ENGINES.PRO_SOGOU]: [10, 20, 30, 40, 50]
|
|
31
30
|
};
|
|
32
31
|
// 请求超时时间(毫秒)
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],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AAM,aAAa,GAAG;IAC3B,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;CACJ,CAAC;AAEX,+BAA+B;AAC/B,MAAM,CAAC,MAAM,eAAe,GAA6B;IACvD,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;CACjD,CAAC;AAEF,aAAa;AACb,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
* 环境变量:
|
|
9
9
|
* ZHIPU_API_KEY - 智谱 API Key(必填),从 https://bigmodel.cn/usercenter/proj-mgmt/apikeys 获取
|
|
10
10
|
*/
|
|
11
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
11
12
|
import type { WebSearchToolOutput } from "./types.js";
|
|
13
|
+
export declare const server: McpServer;
|
|
12
14
|
export declare function formatResultsMarkdown(output: WebSearchToolOutput, charLimit?: number): {
|
|
13
15
|
text: string;
|
|
14
16
|
truncated: boolean;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAItD,eAAO,MAAM,MAAM,WAGjB,CAAC;AAMH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,mBAAmB,EAC3B,SAAS,CAAC,EAAE,MAAM,GACjB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAwDtC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
/**
|
|
3
4
|
* 智谱 Web Search MCP Server
|
|
4
5
|
*
|
|
@@ -11,11 +12,11 @@
|
|
|
11
12
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
12
13
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
13
14
|
import { callWebSearch, handleApiError } from "./services/webSearchApi.js";
|
|
14
|
-
import { WebSearchInputSchema } from "./schemas/webSearch.js";
|
|
15
|
+
import { WebSearchInputSchema, WebSearchRequestSchema } from "./schemas/webSearch.js";
|
|
15
16
|
import { CHARACTER_LIMIT } from "./constants.js";
|
|
16
17
|
import { pathToFileURL } from "node:url";
|
|
17
18
|
// 创建 MCP 服务器实例
|
|
18
|
-
const server = new McpServer({
|
|
19
|
+
export const server = new McpServer({
|
|
19
20
|
name: "zhipu-web-search-mcp-server",
|
|
20
21
|
version: "1.0.0"
|
|
21
22
|
});
|
|
@@ -39,9 +40,11 @@ export function formatResultsMarkdown(output, charLimit) {
|
|
|
39
40
|
if (output.results.length === 0) {
|
|
40
41
|
return { text: "未找到相关搜索结果。", truncated: false };
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
+
const headingIndex = lines.length;
|
|
44
|
+
lines.push(`# 搜索结果 (${output.results.length})`);
|
|
43
45
|
lines.push("");
|
|
44
46
|
let truncated = false;
|
|
47
|
+
let displayedCount = 0;
|
|
45
48
|
for (let index = 0; index < output.results.length; index++) {
|
|
46
49
|
const item = output.results[index];
|
|
47
50
|
const itemLines = [`## ${index + 1}. ${item.title}`];
|
|
@@ -65,6 +68,10 @@ export function formatResultsMarkdown(output, charLimit) {
|
|
|
65
68
|
}
|
|
66
69
|
lines.push(itemText);
|
|
67
70
|
charCount += itemText.length + 1;
|
|
71
|
+
displayedCount++;
|
|
72
|
+
}
|
|
73
|
+
if (truncated) {
|
|
74
|
+
lines[headingIndex] = `# 搜索结果(展示 ${displayedCount} 条,共 ${output.results.length} 条)`;
|
|
68
75
|
}
|
|
69
76
|
return { text: lines.join("\n"), truncated };
|
|
70
77
|
}
|
|
@@ -79,7 +86,7 @@ Args:
|
|
|
79
86
|
- search_query (string): 需要搜索的内容,建议不超过 70 个字符
|
|
80
87
|
- search_engine (string): 搜索引擎编码(默认 search_std)
|
|
81
88
|
- search_intent (boolean): 是否执行搜索意图识别(默认 false)
|
|
82
|
-
- count (number):
|
|
89
|
+
- count (number): 请求条数,search_std/search_pro 支持 1-50,搜狗仅支持 10/20/30/40/50(默认 10);夸克不支持,请勿指定。官网注明同时指定域名和时间过滤时 count 不生效
|
|
83
90
|
- search_domain_filter (string): 白名单域名过滤,仅返回指定域名内容(可选)
|
|
84
91
|
- search_recency_filter (string): 时间范围过滤:oneDay/oneWeek/oneMonth/oneYear/noLimit(默认 noLimit)
|
|
85
92
|
- content_size (string): 返回内容长短:medium/high(默认 medium)
|
|
@@ -87,7 +94,7 @@ Args:
|
|
|
87
94
|
|
|
88
95
|
Returns:
|
|
89
96
|
Markdown 文本:搜索意图识别结果 + 搜索结果列表(标题、发布时间、来源、链接、摘要)
|
|
90
|
-
|
|
97
|
+
同时返回完整结构化 JSON 数据,count 表示实际返回条数;Markdown 超长时显示展示条数和总条数。
|
|
91
98
|
|
|
92
99
|
Examples:
|
|
93
100
|
- "帮我搜索今天的天气" -> search_query="今天北京天气"
|
|
@@ -106,6 +113,13 @@ Error Handling:
|
|
|
106
113
|
openWorldHint: true
|
|
107
114
|
}
|
|
108
115
|
}, async (params) => {
|
|
116
|
+
const request = WebSearchRequestSchema.safeParse(params);
|
|
117
|
+
if (!request.success) {
|
|
118
|
+
return {
|
|
119
|
+
isError: true,
|
|
120
|
+
content: [{ type: "text", text: request.error.issues.map((issue) => issue.message).join("\n") }]
|
|
121
|
+
};
|
|
122
|
+
}
|
|
109
123
|
const apiKey = process.env.ZHIPU_API_KEY;
|
|
110
124
|
if (!apiKey) {
|
|
111
125
|
return {
|
|
@@ -119,18 +133,7 @@ Error Handling:
|
|
|
119
133
|
};
|
|
120
134
|
}
|
|
121
135
|
try {
|
|
122
|
-
const data = await callWebSearch(apiKey,
|
|
123
|
-
search_query: params.search_query,
|
|
124
|
-
search_engine: params.search_engine,
|
|
125
|
-
search_intent: params.search_intent,
|
|
126
|
-
count: params.count,
|
|
127
|
-
...(params.search_domain_filter
|
|
128
|
-
? { search_domain_filter: params.search_domain_filter }
|
|
129
|
-
: {}),
|
|
130
|
-
search_recency_filter: params.search_recency_filter,
|
|
131
|
-
content_size: params.content_size,
|
|
132
|
-
...(params.user_id ? { user_id: params.user_id } : {})
|
|
133
|
-
});
|
|
136
|
+
const data = await callWebSearch(apiKey, request.data);
|
|
134
137
|
const results = data.search_result ?? [];
|
|
135
138
|
const output = {
|
|
136
139
|
id: data.id,
|
|
@@ -142,9 +145,17 @@ Error Handling:
|
|
|
142
145
|
};
|
|
143
146
|
// 一次性限长构建 Markdown,超限即截断,避免先构建完整文本再二次格式化的内存峰值
|
|
144
147
|
const { text, truncated } = formatResultsMarkdown(output, CHARACTER_LIMIT);
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
+
const notes = [];
|
|
149
|
+
if (request.data.count !== undefined) {
|
|
150
|
+
notes.push(`请求 ${request.data.count} 条,实际返回 ${results.length} 条。`);
|
|
151
|
+
}
|
|
152
|
+
if (request.data.count !== undefined && request.data.search_domain_filter && request.data.search_recency_filter) {
|
|
153
|
+
notes.push("官网注明同时指定域名和时间过滤时 count 不生效;请以实际返回条数为准。");
|
|
154
|
+
}
|
|
155
|
+
if (truncated) {
|
|
156
|
+
notes.push(`文本因过长被截断,完整 ${results.length} 条结果保留在 structuredContent.results 中。`);
|
|
157
|
+
}
|
|
158
|
+
const finalText = notes.length ? `${text}\n\n> ${notes.join("\n> ")}` : text;
|
|
148
159
|
return {
|
|
149
160
|
content: [{ type: "text", text: finalText }],
|
|
150
161
|
structuredContent: output
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,+BAA+B;AAC/B;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,eAAe;AACf,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IAClC,IAAI,EAAE,6BAA6B;IACnC,OAAO,EAAE,OAAO;CACjB,CAAC,CAAC;AAEH,yBAAyB;AACzB,6CAA6C;AAC7C,+BAA+B;AAC/B,0DAA0D;AAC1D,MAAM,UAAU,qBAAqB,CACnC,MAA2B,EAC3B,SAAkB;IAElB,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,SAAS,GAAG,CAAC,CAAC;IAElB,IAAI,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5D,MAA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AC,CAAC;QAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;AACzD,CAAC;AAED,sCAAsC;AACtC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC/E,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACrB,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QACjC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -8,7 +8,7 @@ export declare const WebSearchInputSchema: z.ZodObject<{
|
|
|
8
8
|
readonly PRO_QUARK: "search_pro_quark";
|
|
9
9
|
}>>;
|
|
10
10
|
search_intent: z.ZodDefault<z.ZodBoolean>;
|
|
11
|
-
count: z.
|
|
11
|
+
count: z.ZodOptional<z.ZodNumber>;
|
|
12
12
|
search_domain_filter: z.ZodOptional<z.ZodString>;
|
|
13
13
|
search_recency_filter: z.ZodDefault<z.ZodNativeEnum<{
|
|
14
14
|
readonly ONE_DAY: "oneDay";
|
|
@@ -26,9 +26,9 @@ export declare const WebSearchInputSchema: z.ZodObject<{
|
|
|
26
26
|
search_query: string;
|
|
27
27
|
search_engine: "search_std" | "search_pro" | "search_pro_sogou" | "search_pro_quark";
|
|
28
28
|
search_intent: boolean;
|
|
29
|
-
count: number;
|
|
30
29
|
search_recency_filter: "oneDay" | "oneWeek" | "oneMonth" | "oneYear" | "noLimit";
|
|
31
30
|
content_size: "medium" | "high";
|
|
31
|
+
count?: number | undefined;
|
|
32
32
|
search_domain_filter?: string | undefined;
|
|
33
33
|
user_id?: string | undefined;
|
|
34
34
|
}, {
|
|
@@ -42,4 +42,82 @@ export declare const WebSearchInputSchema: z.ZodObject<{
|
|
|
42
42
|
user_id?: string | undefined;
|
|
43
43
|
}>;
|
|
44
44
|
export type WebSearchInput = z.infer<typeof WebSearchInputSchema>;
|
|
45
|
+
export declare const WebSearchRequestSchema: z.ZodEffects<z.ZodEffects<z.ZodObject<{
|
|
46
|
+
search_query: z.ZodString;
|
|
47
|
+
search_engine: z.ZodDefault<z.ZodNativeEnum<{
|
|
48
|
+
readonly STORE: "search_std";
|
|
49
|
+
readonly PRO: "search_pro";
|
|
50
|
+
readonly PRO_SOGOU: "search_pro_sogou";
|
|
51
|
+
readonly PRO_QUARK: "search_pro_quark";
|
|
52
|
+
}>>;
|
|
53
|
+
search_intent: z.ZodDefault<z.ZodBoolean>;
|
|
54
|
+
count: z.ZodOptional<z.ZodNumber>;
|
|
55
|
+
search_domain_filter: z.ZodOptional<z.ZodString>;
|
|
56
|
+
search_recency_filter: z.ZodDefault<z.ZodNativeEnum<{
|
|
57
|
+
readonly ONE_DAY: "oneDay";
|
|
58
|
+
readonly ONE_WEEK: "oneWeek";
|
|
59
|
+
readonly ONE_MONTH: "oneMonth";
|
|
60
|
+
readonly ONE_YEAR: "oneYear";
|
|
61
|
+
readonly NO_LIMIT: "noLimit";
|
|
62
|
+
}>>;
|
|
63
|
+
content_size: z.ZodDefault<z.ZodNativeEnum<{
|
|
64
|
+
readonly MEDIUM: "medium";
|
|
65
|
+
readonly HIGH: "high";
|
|
66
|
+
}>>;
|
|
67
|
+
user_id: z.ZodOptional<z.ZodString>;
|
|
68
|
+
}, "strict", z.ZodTypeAny, {
|
|
69
|
+
search_query: string;
|
|
70
|
+
search_engine: "search_std" | "search_pro" | "search_pro_sogou" | "search_pro_quark";
|
|
71
|
+
search_intent: boolean;
|
|
72
|
+
search_recency_filter: "oneDay" | "oneWeek" | "oneMonth" | "oneYear" | "noLimit";
|
|
73
|
+
content_size: "medium" | "high";
|
|
74
|
+
count?: number | undefined;
|
|
75
|
+
search_domain_filter?: string | undefined;
|
|
76
|
+
user_id?: string | undefined;
|
|
77
|
+
}, {
|
|
78
|
+
search_query: string;
|
|
79
|
+
search_engine?: "search_std" | "search_pro" | "search_pro_sogou" | "search_pro_quark" | undefined;
|
|
80
|
+
search_intent?: boolean | undefined;
|
|
81
|
+
count?: number | undefined;
|
|
82
|
+
search_domain_filter?: string | undefined;
|
|
83
|
+
search_recency_filter?: "oneDay" | "oneWeek" | "oneMonth" | "oneYear" | "noLimit" | undefined;
|
|
84
|
+
content_size?: "medium" | "high" | undefined;
|
|
85
|
+
user_id?: string | undefined;
|
|
86
|
+
}>, {
|
|
87
|
+
search_query: string;
|
|
88
|
+
search_engine: "search_std" | "search_pro" | "search_pro_sogou" | "search_pro_quark";
|
|
89
|
+
search_intent: boolean;
|
|
90
|
+
search_recency_filter: "oneDay" | "oneWeek" | "oneMonth" | "oneYear" | "noLimit";
|
|
91
|
+
content_size: "medium" | "high";
|
|
92
|
+
count?: number | undefined;
|
|
93
|
+
search_domain_filter?: string | undefined;
|
|
94
|
+
user_id?: string | undefined;
|
|
95
|
+
}, {
|
|
96
|
+
search_query: string;
|
|
97
|
+
search_engine?: "search_std" | "search_pro" | "search_pro_sogou" | "search_pro_quark" | undefined;
|
|
98
|
+
search_intent?: boolean | undefined;
|
|
99
|
+
count?: number | undefined;
|
|
100
|
+
search_domain_filter?: string | undefined;
|
|
101
|
+
search_recency_filter?: "oneDay" | "oneWeek" | "oneMonth" | "oneYear" | "noLimit" | undefined;
|
|
102
|
+
content_size?: "medium" | "high" | undefined;
|
|
103
|
+
user_id?: string | undefined;
|
|
104
|
+
}>, {
|
|
105
|
+
search_recency_filter?: "oneDay" | "oneWeek" | "oneMonth" | "oneYear" | undefined;
|
|
106
|
+
search_domain_filter?: string | undefined;
|
|
107
|
+
count?: number | undefined;
|
|
108
|
+
search_query: string;
|
|
109
|
+
search_engine: "search_std" | "search_pro" | "search_pro_sogou" | "search_pro_quark";
|
|
110
|
+
search_intent: boolean;
|
|
111
|
+
content_size: "medium" | "high";
|
|
112
|
+
user_id?: string | undefined;
|
|
113
|
+
}, {
|
|
114
|
+
search_query: string;
|
|
115
|
+
search_engine?: "search_std" | "search_pro" | "search_pro_sogou" | "search_pro_quark" | undefined;
|
|
116
|
+
search_intent?: boolean | undefined;
|
|
117
|
+
count?: number | undefined;
|
|
118
|
+
search_domain_filter?: string | undefined;
|
|
119
|
+
search_recency_filter?: "oneDay" | "oneWeek" | "oneMonth" | "oneYear" | "noLimit" | undefined;
|
|
120
|
+
content_size?: "medium" | "high" | undefined;
|
|
121
|
+
user_id?: string | undefined;
|
|
122
|
+
}>;
|
|
45
123
|
//# sourceMappingURL=webSearch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webSearch.d.ts","sourceRoot":"","sources":["../../src/schemas/webSearch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webSearch.d.ts","sourceRoot":"","sources":["../../src/schemas/webSearch.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4DtB,CAAC;AAEZ,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAIlE,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAchC,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
1
2
|
// Web Search 工具的 Zod 输入校验 schema
|
|
2
3
|
import { z } from "zod";
|
|
3
|
-
import { SEARCH_ENGINES, RECENCY_FILTERS, CONTENT_SIZES } from "../constants.js";
|
|
4
|
+
import { SEARCH_ENGINES, RECENCY_FILTERS, CONTENT_SIZES, COUNT_BY_ENGINE } from "../constants.js";
|
|
4
5
|
export const WebSearchInputSchema = z
|
|
5
6
|
.object({
|
|
6
7
|
search_query: z
|
|
@@ -21,8 +22,8 @@ export const WebSearchInputSchema = z
|
|
|
21
22
|
.int()
|
|
22
23
|
.min(1)
|
|
23
24
|
.max(50)
|
|
24
|
-
.
|
|
25
|
-
.describe("
|
|
25
|
+
.optional()
|
|
26
|
+
.describe("请求结果条数:search_std、search_pro 支持 1-50,默认 10;search_pro_sogou 仅支持 10/20/30/40/50,默认 10;search_pro_quark 不支持,请勿指定。官网注明同时指定域名和时间过滤时 count 不生效,实际条数以返回结果为准"),
|
|
26
27
|
search_domain_filter: z
|
|
27
28
|
.string()
|
|
28
29
|
.optional()
|
|
@@ -43,4 +44,21 @@ export const WebSearchInputSchema = z
|
|
|
43
44
|
.describe("终端用户的唯一 ID,用于平台对非法活动的干预,长度 6-128 个字符")
|
|
44
45
|
})
|
|
45
46
|
.strict();
|
|
47
|
+
// 保留工具输入为普通对象 schema,避免跨字段校验影响 MCP 的 JSON Schema 展示。
|
|
48
|
+
// 请求前单独校验:count 不提前填默认值,才能区分夸克的省略与显式指定。
|
|
49
|
+
export const WebSearchRequestSchema = WebSearchInputSchema.superRefine((params, ctx) => {
|
|
50
|
+
if (params.search_engine === SEARCH_ENGINES.PRO_QUARK && params.count !== undefined) {
|
|
51
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["count"], message: "search_pro_quark 不支持 count,请移除此参数。" });
|
|
52
|
+
}
|
|
53
|
+
const counts = COUNT_BY_ENGINE[params.search_engine];
|
|
54
|
+
if (counts && !counts.includes(params.count ?? 10)) {
|
|
55
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["count"], message: "search_pro_sogou 的 count 仅支持 10/20/30/40/50。" });
|
|
56
|
+
}
|
|
57
|
+
}).transform(({ count, search_recency_filter, search_domain_filter, ...params }) => ({
|
|
58
|
+
...params,
|
|
59
|
+
...(params.search_engine === SEARCH_ENGINES.PRO_QUARK ? {} : { count: count ?? 10 }),
|
|
60
|
+
...(search_domain_filter ? { search_domain_filter } : {}),
|
|
61
|
+
// noLimit 与省略均表示不限时间;省略可避免无意中同时指定域名和时间字段。
|
|
62
|
+
...(search_recency_filter === RECENCY_FILTERS.NO_LIMIT ? {} : { search_recency_filter })
|
|
63
|
+
}));
|
|
46
64
|
//# sourceMappingURL=webSearch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webSearch.js","sourceRoot":"","sources":["../../src/schemas/webSearch.ts"],"names":[],"mappings":"AAAA,iCAAiC;AAEjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,cAAc,EACd,eAAe,EACf,aAAa,
|
|
1
|
+
{"version":3,"file":"webSearch.js","sourceRoot":"","sources":["../../src/schemas/webSearch.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,iCAAiC;AAEjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,cAAc,EACd,eAAe,EACf,aAAa,EACb,eAAe,EAChB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC;KAClC,MAAM,CAAC;IACN,YAAY,EAAE,CAAC;SACZ,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC;SACnB,GAAG,CAAC,EAAE,EAAE,kBAAkB,CAAC;SAC3B,QAAQ,CAAC,sBAAsB,CAAC;IAEnC,aAAa,EAAE,CAAC;SACb,UAAU,CAAC,cAAc,CAAC;SAC1B,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC;SAC7B,QAAQ,CACP,4FAA4F,CAC7F;IAEH,aAAa,EAAE,CAAC;SACb,OAAO,EAAE;SACT,OAAO,CAAC,KAAK,C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AM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;QACnD,GAAG,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,8CAA8C,EAAE,CAAC,CAAC;IAC1H,CAAC;AACH,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;IACnF,GAAG,MAAM;IACT,GAAG,CAAC,MAAM,CAAC,aAAa,KAAK,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,IAAI,EAAE,EAAE,CAAC;IACpF,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,oBAAoB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACzD,0CAA0C;IAC1C,GAAG,CAAC,qBAAqB,KAAK,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,qBAAqB,EAAE,CAAC;CACzF,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webSearchApi.d.ts","sourceRoot":"","sources":["../../src/services/webSearchApi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webSearchApi.d.ts","sourceRoot":"","sources":["../../src/services/webSearchApi.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE1E;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,iBAAiB,CAAC,CAkB5B;AASD;;;;GAIG;AAC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CAAC;YAED,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;gBACnB,OAAO,oCAAoC,CAAC;YAC9C,CAAC;YACD,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;gBACnB,OAAO,0BAA0B,CAAC;YACpC,CAAC;YACD,OAAO,qBAAqB,MAAM,GAAG,CAAC;QACxC,CAAC;QACD,IAAI,UAAU,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;YACvC,OAAO,wBAAwB,CAAC;QAClC,CAAC;QACD,IAAI,UAAU,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;YACvC,OAAO,yBAAyB,CAAC;QACnC,CAAC;IACH,CAAC;IACD,iDAAiD;IACjD,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;IAChD,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAED,iBAAiB;AACjB,SAAS,cAAc,CAAC,IAAa;IACnC,IACE,IAAI;QACJ,OAAO,IAAI,KAAK,QAAQ;QACxB,OAAO,IAAI,IAAI;QACf,IAAI,CAAC,KAAK;QACV,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ;QAC9B,MAAM,IAAI,IAAI,CAAC,KAAK,EACpB,CAAC;QACD,MAAM,IAAI,GAAI,IAAI,CAAC,KAA2B,CAAC,IAAI,CAAC;QACpD,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IACrD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAA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HANGED
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,8BAA8B"}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,8BAA8B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yyaylt/zhipu-web-search-mcp-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "MCP server for ZHIPU AI Web Search API integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zhipu",
|
|
@@ -11,8 +11,17 @@
|
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://gitee.com/yyaylt/zhipu-web-search-mcp-server.git"
|
|
13
13
|
},
|
|
14
|
-
"license": "
|
|
15
|
-
"author":
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "lost_fish",
|
|
17
|
+
"url": "https://gitee.com/yyaylt"
|
|
18
|
+
},
|
|
19
|
+
"contributors": [
|
|
20
|
+
{
|
|
21
|
+
"name": "lost_fish",
|
|
22
|
+
"url": "https://gitee.com/yyaylt"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
16
25
|
"type": "module",
|
|
17
26
|
"main": "dist/index.js",
|
|
18
27
|
"types": "./dist/index.d.ts",
|
|
@@ -43,8 +52,9 @@
|
|
|
43
52
|
"files": [
|
|
44
53
|
"dist/**/*",
|
|
45
54
|
"src/**/*",
|
|
55
|
+
"CONTRIBUTING.md",
|
|
46
56
|
"README.md",
|
|
47
57
|
"LICENSE",
|
|
48
58
|
"package.json"
|
|
49
59
|
]
|
|
50
|
-
}
|
|
60
|
+
}
|
package/src/constants.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
1
2
|
// 智谱 Web Search API 相关常量定义
|
|
2
3
|
|
|
3
4
|
// API 基础地址(智谱开放平台)
|
|
@@ -29,10 +30,8 @@ export const CONTENT_SIZES = {
|
|
|
29
30
|
HIGH: "high"
|
|
30
31
|
} as const;
|
|
31
32
|
|
|
32
|
-
//
|
|
33
|
+
// 仅搜狗限制为枚举;基础版和高阶版支持 1-50 的整数。
|
|
33
34
|
export const COUNT_BY_ENGINE: Record<string, number[]> = {
|
|
34
|
-
[SEARCH_ENGINES.STORE]: [10, 20, 30, 40, 50],
|
|
35
|
-
[SEARCH_ENGINES.PRO]: [10, 20, 30, 40, 50],
|
|
36
35
|
[SEARCH_ENGINES.PRO_SOGOU]: [10, 20, 30, 40, 50]
|
|
37
36
|
};
|
|
38
37
|
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
/**
|
|
3
4
|
* 智谱 Web Search MCP Server
|
|
4
5
|
*
|
|
@@ -12,13 +13,13 @@
|
|
|
12
13
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
13
14
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
14
15
|
import { callWebSearch, handleApiError } from "./services/webSearchApi.js";
|
|
15
|
-
import { WebSearchInputSchema } from "./schemas/webSearch.js";
|
|
16
|
+
import { WebSearchInputSchema, WebSearchRequestSchema } from "./schemas/webSearch.js";
|
|
16
17
|
import { CHARACTER_LIMIT } from "./constants.js";
|
|
17
18
|
import type { WebSearchToolOutput } from "./types.js";
|
|
18
19
|
import { pathToFileURL } from "node:url";
|
|
19
20
|
|
|
20
21
|
// 创建 MCP 服务器实例
|
|
21
|
-
const server = new McpServer({
|
|
22
|
+
export const server = new McpServer({
|
|
22
23
|
name: "zhipu-web-search-mcp-server",
|
|
23
24
|
version: "1.0.0"
|
|
24
25
|
});
|
|
@@ -49,10 +50,12 @@ export function formatResultsMarkdown(
|
|
|
49
50
|
return { text: "未找到相关搜索结果。", truncated: false };
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
const headingIndex = lines.length;
|
|
54
|
+
lines.push(`# 搜索结果 (${output.results.length})`);
|
|
53
55
|
lines.push("");
|
|
54
56
|
|
|
55
57
|
let truncated = false;
|
|
58
|
+
let displayedCount = 0;
|
|
56
59
|
for (let index = 0; index < output.results.length; index++) {
|
|
57
60
|
const item = output.results[index];
|
|
58
61
|
const itemLines = [`## ${index + 1}. ${item.title}`];
|
|
@@ -77,8 +80,12 @@ export function formatResultsMarkdown(
|
|
|
77
80
|
}
|
|
78
81
|
lines.push(itemText);
|
|
79
82
|
charCount += itemText.length + 1;
|
|
83
|
+
displayedCount++;
|
|
80
84
|
}
|
|
81
85
|
|
|
86
|
+
if (truncated) {
|
|
87
|
+
lines[headingIndex] = `# 搜索结果(展示 ${displayedCount} 条,共 ${output.results.length} 条)`;
|
|
88
|
+
}
|
|
82
89
|
return { text: lines.join("\n"), truncated };
|
|
83
90
|
}
|
|
84
91
|
|
|
@@ -95,7 +102,7 @@ Args:
|
|
|
95
102
|
- search_query (string): 需要搜索的内容,建议不超过 70 个字符
|
|
96
103
|
- search_engine (string): 搜索引擎编码(默认 search_std)
|
|
97
104
|
- search_intent (boolean): 是否执行搜索意图识别(默认 false)
|
|
98
|
-
- count (number):
|
|
105
|
+
- count (number): 请求条数,search_std/search_pro 支持 1-50,搜狗仅支持 10/20/30/40/50(默认 10);夸克不支持,请勿指定。官网注明同时指定域名和时间过滤时 count 不生效
|
|
99
106
|
- search_domain_filter (string): 白名单域名过滤,仅返回指定域名内容(可选)
|
|
100
107
|
- search_recency_filter (string): 时间范围过滤:oneDay/oneWeek/oneMonth/oneYear/noLimit(默认 noLimit)
|
|
101
108
|
- content_size (string): 返回内容长短:medium/high(默认 medium)
|
|
@@ -103,7 +110,7 @@ Args:
|
|
|
103
110
|
|
|
104
111
|
Returns:
|
|
105
112
|
Markdown 文本:搜索意图识别结果 + 搜索结果列表(标题、发布时间、来源、链接、摘要)
|
|
106
|
-
|
|
113
|
+
同时返回完整结构化 JSON 数据,count 表示实际返回条数;Markdown 超长时显示展示条数和总条数。
|
|
107
114
|
|
|
108
115
|
Examples:
|
|
109
116
|
- "帮我搜索今天的天气" -> search_query="今天北京天气"
|
|
@@ -123,6 +130,13 @@ Error Handling:
|
|
|
123
130
|
}
|
|
124
131
|
},
|
|
125
132
|
async (params) => {
|
|
133
|
+
const request = WebSearchRequestSchema.safeParse(params);
|
|
134
|
+
if (!request.success) {
|
|
135
|
+
return {
|
|
136
|
+
isError: true,
|
|
137
|
+
content: [{ type: "text" as const, text: request.error.issues.map((issue) => issue.message).join("\n") }]
|
|
138
|
+
};
|
|
139
|
+
}
|
|
126
140
|
const apiKey = process.env.ZHIPU_API_KEY;
|
|
127
141
|
if (!apiKey) {
|
|
128
142
|
return {
|
|
@@ -137,18 +151,7 @@ Error Handling:
|
|
|
137
151
|
}
|
|
138
152
|
|
|
139
153
|
try {
|
|
140
|
-
const data = await callWebSearch(apiKey,
|
|
141
|
-
search_query: params.search_query,
|
|
142
|
-
search_engine: params.search_engine,
|
|
143
|
-
search_intent: params.search_intent,
|
|
144
|
-
count: params.count,
|
|
145
|
-
...(params.search_domain_filter
|
|
146
|
-
? { search_domain_filter: params.search_domain_filter }
|
|
147
|
-
: {}),
|
|
148
|
-
search_recency_filter: params.search_recency_filter,
|
|
149
|
-
content_size: params.content_size,
|
|
150
|
-
...(params.user_id ? { user_id: params.user_id } : {})
|
|
151
|
-
});
|
|
154
|
+
const data = await callWebSearch(apiKey, request.data);
|
|
152
155
|
|
|
153
156
|
const results = data.search_result ?? [];
|
|
154
157
|
const output: WebSearchToolOutput = {
|
|
@@ -162,9 +165,17 @@ Error Handling:
|
|
|
162
165
|
|
|
163
166
|
// 一次性限长构建 Markdown,超限即截断,避免先构建完整文本再二次格式化的内存峰值
|
|
164
167
|
const { text, truncated } = formatResultsMarkdown(output, CHARACTER_LIMIT);
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
const notes: string[] = [];
|
|
169
|
+
if (request.data.count !== undefined) {
|
|
170
|
+
notes.push(`请求 ${request.data.count} 条,实际返回 ${results.length} 条。`);
|
|
171
|
+
}
|
|
172
|
+
if (request.data.count !== undefined && request.data.search_domain_filter && request.data.search_recency_filter) {
|
|
173
|
+
notes.push("官网注明同时指定域名和时间过滤时 count 不生效;请以实际返回条数为准。");
|
|
174
|
+
}
|
|
175
|
+
if (truncated) {
|
|
176
|
+
notes.push(`文本因过长被截断,完整 ${results.length} 条结果保留在 structuredContent.results 中。`);
|
|
177
|
+
}
|
|
178
|
+
const finalText = notes.length ? `${text}\n\n> ${notes.join("\n> ")}` : text;
|
|
168
179
|
|
|
169
180
|
return {
|
|
170
181
|
content: [{ type: "text" as const, text: finalText }],
|
package/src/schemas/webSearch.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
1
2
|
// Web Search 工具的 Zod 输入校验 schema
|
|
2
3
|
|
|
3
4
|
import { z } from "zod";
|
|
4
5
|
import {
|
|
5
6
|
SEARCH_ENGINES,
|
|
6
7
|
RECENCY_FILTERS,
|
|
7
|
-
CONTENT_SIZES
|
|
8
|
+
CONTENT_SIZES,
|
|
9
|
+
COUNT_BY_ENGINE
|
|
8
10
|
} from "../constants.js";
|
|
9
11
|
|
|
10
12
|
export const WebSearchInputSchema = z
|
|
@@ -34,9 +36,9 @@ export const WebSearchInputSchema = z
|
|
|
34
36
|
.int()
|
|
35
37
|
.min(1)
|
|
36
38
|
.max(50)
|
|
37
|
-
.
|
|
39
|
+
.optional()
|
|
38
40
|
.describe(
|
|
39
|
-
"
|
|
41
|
+
"请求结果条数:search_std、search_pro 支持 1-50,默认 10;search_pro_sogou 仅支持 10/20/30/40/50,默认 10;search_pro_quark 不支持,请勿指定。官网注明同时指定域名和时间过滤时 count 不生效,实际条数以返回结果为准"
|
|
40
42
|
),
|
|
41
43
|
|
|
42
44
|
search_domain_filter: z
|
|
@@ -70,3 +72,21 @@ export const WebSearchInputSchema = z
|
|
|
70
72
|
.strict();
|
|
71
73
|
|
|
72
74
|
export type WebSearchInput = z.infer<typeof WebSearchInputSchema>;
|
|
75
|
+
|
|
76
|
+
// 保留工具输入为普通对象 schema,避免跨字段校验影响 MCP 的 JSON Schema 展示。
|
|
77
|
+
// 请求前单独校验:count 不提前填默认值,才能区分夸克的省略与显式指定。
|
|
78
|
+
export const WebSearchRequestSchema = WebSearchInputSchema.superRefine((params, ctx) => {
|
|
79
|
+
if (params.search_engine === SEARCH_ENGINES.PRO_QUARK && params.count !== undefined) {
|
|
80
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["count"], message: "search_pro_quark 不支持 count,请移除此参数。" });
|
|
81
|
+
}
|
|
82
|
+
const counts = COUNT_BY_ENGINE[params.search_engine];
|
|
83
|
+
if (counts && !counts.includes(params.count ?? 10)) {
|
|
84
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["count"], message: "search_pro_sogou 的 count 仅支持 10/20/30/40/50。" });
|
|
85
|
+
}
|
|
86
|
+
}).transform(({ count, search_recency_filter, search_domain_filter, ...params }) => ({
|
|
87
|
+
...params,
|
|
88
|
+
...(params.search_engine === SEARCH_ENGINES.PRO_QUARK ? {} : { count: count ?? 10 }),
|
|
89
|
+
...(search_domain_filter ? { search_domain_filter } : {}),
|
|
90
|
+
// noLimit 与省略均表示不限时间;省略可避免无意中同时指定域名和时间字段。
|
|
91
|
+
...(search_recency_filter === RECENCY_FILTERS.NO_LIMIT ? {} : { search_recency_filter })
|
|
92
|
+
}));
|
package/src/types.ts
CHANGED