milvus-knowledge-mcp-server 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,262 @@
1
+ # Milvus Knowledge MCP Server
2
+
3
+ [![npm version](https://img.shields.io/npm/v/milvus-knowledge-mcp-server.svg)](https://www.npmjs.com/package/milvus-knowledge-mcp-server)
4
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.7-blue)](https://www.typescriptlang.org/)
5
+ [![Node.js](https://img.shields.io/badge/Node.js-18+-green)](https://nodejs.org/)
6
+ [![MCP](https://img.shields.io/badge/MCP-1.6.1-purple)](https://modelcontextprotocol.io/)
7
+ [![License](https://img.shields.io/badge/License-MIT-yellow)](LICENSE)
8
+
9
+ 基于 Model Context Protocol (MCP) 的 Milvus 知识库服务器,为 AI 助手提供语义搜索能力。
10
+
11
+ ## 功能特性
12
+
13
+ - **语义搜索**: 在 Milvus 向量数据库中进行语义搜索
14
+ - **多集合支持**: 同时搜索多个知识集合
15
+ - **灵活输出**: 支持 Markdown 和 JSON 输出格式
16
+ - **双传输模式**: 支持 stdio 和 HTTP 两种传输方式
17
+ - **类型安全**: 使用 TypeScript 和 Zod 进行完整类型检查
18
+ - **完善的测试**: 36 个单元测试和集成测试全部通过
19
+
20
+ ## 安装
21
+
22
+ ### 方式一:使用 npx (推荐)
23
+
24
+ 无需安装,直接使用 npx 运行:
25
+
26
+ ```bash
27
+ npx -y milvus-knowledge-mcp-server
28
+ ```
29
+
30
+ ### 方式二:全局安装
31
+
32
+ ```bash
33
+ npm install -g milvus-knowledge-mcp-server
34
+ milvus-knowledge-mcp-server
35
+ ```
36
+
37
+ ### 方式三:从源码安装
38
+
39
+ ```bash
40
+ # 克隆仓库
41
+ git clone https://gitee.com/xywdy/knowage_mcp.git
42
+ cd knowage_mcp
43
+
44
+ # 安装依赖并构建
45
+ npm install
46
+ npm run build
47
+
48
+ # 运行
49
+ npm start
50
+ ```
51
+
52
+ ## 配置
53
+
54
+ ### 环境变量
55
+
56
+ | 变量 | 默认值 | 说明 |
57
+ |------|--------|------|
58
+ | `MILVUS_HOST` | 127.0.0.1 | Milvus 服务器地址 |
59
+ | `MILVUS_PORT` | 19530 | Milvus 服务器端口 |
60
+ | `TRANSPORT` | stdio | 传输模式 (stdio/http) |
61
+ | `PORT` | 3000 | HTTP 模式端口 |
62
+
63
+ ### 默认集合
64
+
65
+ 项目默认搜索以下集合:
66
+ - `components` - 组件文档和代码
67
+ - `asserts` - 断言模式和测试用例
68
+ - `chunks_v1` - 通用知识块
69
+
70
+ ## 与 Claude Desktop 集成
71
+
72
+ 编辑 Claude Desktop 配置文件:
73
+
74
+ **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
75
+ **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
76
+
77
+ ### 使用 npx (推荐)
78
+
79
+ ```json
80
+ {
81
+ "mcpServers": {
82
+ "milvus-knowledge": {
83
+ "command": "npx",
84
+ "args": ["-y", "milvus-knowledge-mcp-server"],
85
+ "env": {
86
+ "MILVUS_HOST": "127.0.0.1",
87
+ "MILVUS_PORT": "19530"
88
+ }
89
+ }
90
+ }
91
+ }
92
+ ```
93
+
94
+ ### 使用全局安装
95
+
96
+ ```json
97
+ {
98
+ "mcpServers": {
99
+ "milvus-knowledge": {
100
+ "command": "milvus-knowledge-mcp-server",
101
+ "env": {
102
+ "MILVUS_HOST": "127.0.0.1",
103
+ "MILVUS_PORT": "19530"
104
+ }
105
+ }
106
+ }
107
+ }
108
+ ```
109
+
110
+ ### 使用本地路径
111
+
112
+ ```json
113
+ {
114
+ "mcpServers": {
115
+ "milvus-knowledge": {
116
+ "command": "node",
117
+ "args": ["/path/to/knowage_mcp/dist/index.js"],
118
+ "env": {
119
+ "MILVUS_HOST": "127.0.0.1",
120
+ "MILVUS_PORT": "19530"
121
+ }
122
+ }
123
+ }
124
+ }
125
+ ```
126
+
127
+ ## 使用方法
128
+
129
+ ### stdio 模式 (默认)
130
+
131
+ ```bash
132
+ npx -y milvus-knowledge-mcp-server
133
+ ```
134
+
135
+ ### HTTP 模式
136
+
137
+ ```bash
138
+ MILVUS_HOST=127.0.0.1 MILVUS_PORT=19530 TRANSPORT=http PORT=3000 npx -y milvus-knowledge-mcp-server
139
+ ```
140
+
141
+ 服务将在 `http://localhost:3000/mcp` 启动,健康检查端点为 `http://localhost:3000/health`。
142
+
143
+ ## MCP 工具
144
+
145
+ ### knowledge_search
146
+
147
+ 搜索知识库获取相关信息。
148
+
149
+ **参数**:
150
+ | 参数 | 类型 | 默认值 | 说明 |
151
+ |------|------|--------|------|
152
+ | query | string | 必填 | 搜索查询 |
153
+ | collections | string[] | ["components", "asserts", "chunks_v1"] | 要搜索的集合 |
154
+ | top_k | number | 5 | 每个集合返回的结果数 (1-20) |
155
+ | output_format | "markdown" \| "json" | "markdown" | 输出格式 |
156
+ | min_score | number | 0.5 | 最小相似度阈值 (0-1) |
157
+
158
+ **示例**:
159
+ ```json
160
+ {
161
+ "query": "如何实现用户认证",
162
+ "collections": ["components", "chunks_v1"],
163
+ "top_k": 5,
164
+ "min_score": 0.5
165
+ }
166
+ ```
167
+
168
+ ### knowledge_list_collections
169
+
170
+ 列出所有可用的知识集合。
171
+
172
+ ### knowledge_get_collection_info
173
+
174
+ 获取指定集合的详细信息,包括 schema。
175
+
176
+ ## 触发方式
177
+
178
+ 当用户消息包含 `@知识库` 前缀时,AI 助手应自动调用 `knowledge_search` 工具进行知识检索。
179
+
180
+ 示例:
181
+ - `@知识库 如何实现用户认证?`
182
+ - `@知识库 API 文档`
183
+
184
+ ## 开发
185
+
186
+ ### 项目结构
187
+
188
+ ```
189
+ knowage_mcp/
190
+ ├── src/
191
+ │ ├── index.ts # 主入口
192
+ │ ├── milvus-client.ts # Milvus 客户端
193
+ │ ├── schemas.ts # Zod 验证模式
194
+ │ ├── formatters.ts # 输出格式化
195
+ │ └── tools/
196
+ │ └── knowledge-tools.ts # MCP 工具定义
197
+ │ └── tests/ # 测试文件
198
+ ├── dist/ # 编译输出
199
+ ├── docs/ # 文档
200
+ ├── package.json
201
+ ├── tsconfig.json
202
+ └── vitest.config.ts
203
+ ```
204
+
205
+ ### 命令
206
+
207
+ ```bash
208
+ # 开发模式 (热重载)
209
+ npm run dev
210
+
211
+ # 构建
212
+ npm run build
213
+
214
+ # 运行测试
215
+ npm test
216
+
217
+ # 测试覆盖率
218
+ npm run test:coverage
219
+
220
+ # 使用 MCP Inspector 调试
221
+ npm run inspector
222
+ ```
223
+
224
+ ## 测试
225
+
226
+ ```bash
227
+ npm test
228
+ ```
229
+
230
+ 测试结果:
231
+ - **测试文件**: 3
232
+ - **测试用例**: 36
233
+ - **通过率**: 100%
234
+
235
+ 详细报告见 [测试报告](docs/TEST_REPORT.md)。
236
+
237
+ ## 文档
238
+
239
+ - [代码审查报告](docs/CODE_REVIEW.md)
240
+ - [测试报告](docs/TEST_REPORT.md)
241
+
242
+ ## 技术栈
243
+
244
+ - [TypeScript](https://www.typescriptlang.org/) - 类型安全
245
+ - [MCP SDK](https://github.com/modelcontextprotocol/typescript-sdk) - Model Context Protocol
246
+ - [Milvus SDK](https://github.com/milvus-io/milvus-sdk-node) - 向量数据库
247
+ - [Zod](https://zod.dev/) - Schema 验证
248
+ - [Vitest](https://vitest.dev/) - 测试框架
249
+ - [Express](https://expressjs.com/) - HTTP 服务器
250
+
251
+ ## 许可证
252
+
253
+ MIT License
254
+
255
+ ## 贡献
256
+
257
+ 欢迎提交 Issue 和 Pull Request!
258
+
259
+ ## 链接
260
+
261
+ - [npm 包](https://www.npmjs.com/package/milvus-knowledge-mcp-server)
262
+ - [Gitee 仓库](https://gitee.com/xywdy/knowage_mcp)
@@ -0,0 +1,8 @@
1
+ import { SearchResult } from './milvus-client.js';
2
+ export declare function formatResultsAsMarkdown(results: Map<string, SearchResult[]>, minScore: number): string;
3
+ export declare function formatResultsAsJson(results: Map<string, SearchResult[]>, minScore: number): string;
4
+ export declare function formatCollectionsAsMarkdown(collections: {
5
+ name: string;
6
+ rowCount: number;
7
+ }[]): string;
8
+ //# sourceMappingURL=formatters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../src/formatters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIlD,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,EACpC,QAAQ,EAAE,MAAM,GACf,MAAM,CA6CR;AAED,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC,EACpC,QAAQ,EAAE,MAAM,GACf,MAAM,CA2BR;AAED,wBAAgB,2BAA2B,CAAC,WAAW,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,MAAM,CAkBrG"}
@@ -0,0 +1,80 @@
1
+ const MAX_CONTENT_LENGTH = 8000;
2
+ export function formatResultsAsMarkdown(results, minScore) {
3
+ const lines = ['# Knowledge Search Results', ''];
4
+ let totalResults = 0;
5
+ for (const [collection, searchResults] of results) {
6
+ const filtered = searchResults.filter(r => r.score >= minScore);
7
+ if (filtered.length === 0)
8
+ continue;
9
+ totalResults += filtered.length;
10
+ lines.push(`## Collection: ${collection}`);
11
+ lines.push(`Found ${filtered.length} relevant results`);
12
+ lines.push('');
13
+ for (let i = 0; i < filtered.length; i++) {
14
+ const result = filtered[i];
15
+ lines.push(`### Result ${i + 1} (Score: ${result.score.toFixed(3)})`);
16
+ if (result.content) {
17
+ const truncatedContent = result.content.length > MAX_CONTENT_LENGTH
18
+ ? result.content.substring(0, MAX_CONTENT_LENGTH) + '...(truncated)'
19
+ : result.content;
20
+ lines.push(truncatedContent);
21
+ }
22
+ if (result.metadata && Object.keys(result.metadata).length > 0) {
23
+ lines.push('');
24
+ lines.push('**Metadata:**');
25
+ for (const [key, value] of Object.entries(result.metadata)) {
26
+ lines.push(`- ${key}: ${JSON.stringify(value)}`);
27
+ }
28
+ }
29
+ lines.push('');
30
+ }
31
+ }
32
+ if (totalResults === 0) {
33
+ lines.push('No results found matching the criteria.');
34
+ lines.push('Try lowering the min_score threshold or using different keywords.');
35
+ }
36
+ else {
37
+ lines.unshift(`Total results: ${totalResults}`, '');
38
+ }
39
+ return lines.join('\n');
40
+ }
41
+ export function formatResultsAsJson(results, minScore) {
42
+ const output = {
43
+ total: 0,
44
+ collections: {}
45
+ };
46
+ let total = 0;
47
+ for (const [collection, searchResults] of results) {
48
+ const filtered = searchResults.filter(r => r.score >= minScore);
49
+ total += filtered.length;
50
+ output.collections[collection] = {
51
+ count: filtered.length,
52
+ results: filtered.map(r => ({
53
+ id: r.id,
54
+ score: r.score,
55
+ content: r.content?.length && r.content.length > MAX_CONTENT_LENGTH
56
+ ? r.content.substring(0, MAX_CONTENT_LENGTH) + '...(truncated)'
57
+ : r.content,
58
+ metadata: r.metadata
59
+ }))
60
+ };
61
+ }
62
+ output.total = total;
63
+ return JSON.stringify(output, null, 2);
64
+ }
65
+ export function formatCollectionsAsMarkdown(collections) {
66
+ const lines = ['# Available Collections', ''];
67
+ if (collections.length === 0) {
68
+ lines.push('No collections found in the knowledge base.');
69
+ return lines.join('\n');
70
+ }
71
+ lines.push(`Total collections: ${collections.length}`);
72
+ lines.push('');
73
+ for (const col of collections) {
74
+ lines.push(`## ${col.name}`);
75
+ lines.push(`- **Documents**: ${col.rowCount.toLocaleString()}`);
76
+ lines.push('');
77
+ }
78
+ return lines.join('\n');
79
+ }
80
+ //# sourceMappingURL=formatters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatters.js","sourceRoot":"","sources":["../src/formatters.ts"],"names":[],"mappings":"AAEA,MAAM,kBAAkB,GAAG,IAA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AAC,CAAC;QAC7B,KAAK,CAAC,IAAI,CAAC,oBAAoB,GAAG,CAAC,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;QAChE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
5
+ import express from 'express';
6
+ import { registerKnowledgeTools } from './tools/knowledge-tools.js';
7
+ import { getMilvusClient } from './milvus-client.js';
8
+ const SERVER_NAME = 'milvus-knowledge-mcp-server';
9
+ const SERVER_VERSION = '1.0.0';
10
+ function createServer() {
11
+ const server = new McpServer({
12
+ name: SERVER_NAME,
13
+ version: SERVER_VERSION
14
+ });
15
+ registerKnowledgeTools(server);
16
+ return server;
17
+ }
18
+ async function runStdio() {
19
+ console.error(`Starting ${SERVER_NAME} v${SERVER_VERSION} (stdio mode)`);
20
+ try {
21
+ const client = getMilvusClient();
22
+ await client.connect();
23
+ console.error('Milvus connection established');
24
+ }
25
+ catch (error) {
26
+ console.error('Warning: Could not connect to Milvus on startup:', error);
27
+ console.error('Server will attempt to connect when tools are used.');
28
+ }
29
+ const server = createServer();
30
+ const transport = new StdioServerTransport();
31
+ await server.connect(transport);
32
+ console.error(`${SERVER_NAME} running via stdio`);
33
+ }
34
+ async function runHTTP() {
35
+ const port = parseInt(process.env.PORT || '3000', 10);
36
+ console.error(`Starting ${SERVER_NAME} v${SERVER_VERSION} (HTTP mode)`);
37
+ try {
38
+ const client = getMilvusClient();
39
+ await client.connect();
40
+ console.error('Milvus connection established');
41
+ }
42
+ catch (error) {
43
+ console.error('Warning: Could not connect to Milvus on startup:', error);
44
+ }
45
+ const app = express();
46
+ app.use(express.json());
47
+ app.get('/health', (_req, res) => {
48
+ res.json({
49
+ status: 'ok',
50
+ server: SERVER_NAME,
51
+ version: SERVER_VERSION
52
+ });
53
+ });
54
+ app.post('/mcp', async (req, res) => {
55
+ const server = createServer();
56
+ const transport = new StreamableHTTPServerTransport({
57
+ sessionIdGenerator: undefined,
58
+ enableJsonResponse: true
59
+ });
60
+ res.on('close', () => transport.close());
61
+ await server.connect(transport);
62
+ await transport.handleRequest(req, res, req.body);
63
+ });
64
+ app.listen(port, () => {
65
+ console.error(`${SERVER_NAME} running on http://localhost:${port}/mcp`);
66
+ console.error(`Health check: http://localhost:${port}/health`);
67
+ });
68
+ }
69
+ const transport = process.env.TRANSPORT || 'stdio';
70
+ if (transport === 'http') {
71
+ runHTTP().catch(error => {
72
+ console.error('Server error:', error);
73
+ process.exit(1);
74
+ });
75
+ }
76
+ else {
77
+ runStdio().catch(error => {
78
+ console.error('Server error:', error);
79
+ process.exit(1);
80
+ });
81
+ }
82
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,WAAW,GAA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