mcp-server-knowledgebase 0.2.0__tar.gz → 0.2.2__tar.gz

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 (19) hide show
  1. mcp_server_knowledgebase-0.2.2/PKG-INFO +513 -0
  2. mcp_server_knowledgebase-0.2.2/README.md +502 -0
  3. mcp_server_knowledgebase-0.2.2/README_zh.md +488 -0
  4. {mcp_server_knowledgebase-0.2.0 → mcp_server_knowledgebase-0.2.2}/pyproject.toml +1 -1
  5. {mcp_server_knowledgebase-0.2.0 → mcp_server_knowledgebase-0.2.2}/src/mcp_server_knowledgebase/config.py +1 -1
  6. mcp_server_knowledgebase-0.2.2/src/mcp_server_knowledgebase/models.py +127 -0
  7. mcp_server_knowledgebase-0.2.2/src/mcp_server_knowledgebase/server.py +361 -0
  8. mcp_server_knowledgebase-0.2.2/tests/test_tools.py +297 -0
  9. {mcp_server_knowledgebase-0.2.0 → mcp_server_knowledgebase-0.2.2}/uv.lock +1 -1
  10. mcp_server_knowledgebase-0.2.0/PKG-INFO +0 -248
  11. mcp_server_knowledgebase-0.2.0/README.md +0 -237
  12. mcp_server_knowledgebase-0.2.0/README_zh.md +0 -191
  13. mcp_server_knowledgebase-0.2.0/src/mcp_server_knowledgebase/models.py +0 -66
  14. mcp_server_knowledgebase-0.2.0/src/mcp_server_knowledgebase/server.py +0 -421
  15. {mcp_server_knowledgebase-0.2.0 → mcp_server_knowledgebase-0.2.2}/.gitignore +0 -0
  16. {mcp_server_knowledgebase-0.2.0 → mcp_server_knowledgebase-0.2.2}/.python-version +0 -0
  17. {mcp_server_knowledgebase-0.2.0 → mcp_server_knowledgebase-0.2.2}/src/mcp_server_knowledgebase/__init__.py +0 -0
  18. {mcp_server_knowledgebase-0.2.0 → mcp_server_knowledgebase-0.2.2}/src/mcp_server_knowledgebase/common/__init__.py +0 -0
  19. {mcp_server_knowledgebase-0.2.0 → mcp_server_knowledgebase-0.2.2}/src/mcp_server_knowledgebase/common/auth.py +0 -0
@@ -0,0 +1,513 @@
1
+ Metadata-Version: 2.5
2
+ Name: mcp-server-knowledgebase
3
+ Version: 0.2.2
4
+ Summary: MCP server for Viking Knowledge Base Service
5
+ License: MIT
6
+ Requires-Python: >=3.10
7
+ Requires-Dist: aiohttp>=3.11.14
8
+ Requires-Dist: mcp[cli]<3,>=2.1.1
9
+ Requires-Dist: volcengine>=1.0.171
10
+ Description-Content-Type: text/markdown
11
+
12
+ # Viking Knowledge Base MCP Server
13
+
14
+ [简体中文](README_zh.md)
15
+
16
+ ## Overview
17
+
18
+ Viking Knowledge Base MCP Server lets MCP clients such as Claude Desktop,
19
+ Cursor, Cline, and Trae interact with VolcEngine Viking Knowledge Base. It
20
+ supports managing and inspecting collections and documents, and searching for
21
+ relevant knowledge chunks.
22
+
23
+ ## Features
24
+
25
+ - Add a document to a knowledge base collection by URL
26
+ - Get document information and processing status
27
+ - List documents with cursor pagination
28
+ - Get collection information and build status
29
+ - List collections in the configured project
30
+ - Search a collection with optional document filtering
31
+ - Authenticate with either a Viking API key or VolcEngine AK/SK credentials
32
+ - Run over stdio or stateless Streamable HTTP
33
+
34
+ ## Prerequisites
35
+
36
+ - Python 3.10 or later
37
+ - A Viking Knowledge Base API key, or VolcEngine AK/SK credentials
38
+
39
+ ## Installation
40
+
41
+ Install from PyPI:
42
+
43
+ ```bash
44
+ pip install mcp-server-knowledgebase
45
+ ```
46
+
47
+ Or install it as a persistent command-line tool with `uv`:
48
+
49
+ ```bash
50
+ uv tool install mcp-server-knowledgebase
51
+ ```
52
+
53
+ For local development, clone the repository and install this package in
54
+ editable mode:
55
+
56
+ ```bash
57
+ git clone https://github.com/volcengine/mcp-server.git
58
+ cd mcp-server/server/mcp_server_knowledgebase
59
+ uv pip install -e .
60
+ ```
61
+
62
+ ## Configuration
63
+
64
+ ### Authentication
65
+
66
+ Configure at least one authentication method:
67
+
68
+ - API key: set `VIKING_API_KEY`. Requests use
69
+ `Authorization: Bearer <VIKING_API_KEY>`.
70
+ - AK/SK: set both `VOLCENGINE_ACCESS_KEY` and
71
+ `VOLCENGINE_SECRET_KEY`. Requests use VolcEngine SignerV4 authentication.
72
+
73
+ When both methods are configured, `VIKING_API_KEY` takes precedence. If no API
74
+ key is set, the access key and secret key must be configured together.
75
+
76
+ ### Environment variables
77
+
78
+ | Environment variable | Description | Default |
79
+ |---|---|---|
80
+ | `VIKING_API_KEY` | Viking Knowledge Base API key; takes precedence when configured | - |
81
+ | `VOLCENGINE_ACCESS_KEY` | VolcEngine access key | - |
82
+ | `VOLCENGINE_SECRET_KEY` | VolcEngine secret key | - |
83
+ | `KNOWLEDGE_BASE_PROJECT` | Viking Knowledge Base project | `default` |
84
+ | `KNOWLEDGE_BASE_REGION` | VolcEngine region used for AK/SK signing | `cn-north-1` |
85
+ | `KNOWLEDGE_BASE_TIMEOUT` | Upstream request timeout in seconds | `30` |
86
+ | `MCP_SERVER_HOST` | Streamable HTTP bind host | `127.0.0.1` |
87
+ | `MCP_SERVER_PORT` | Streamable HTTP port; falls back to `PORT` | `8000` |
88
+ | `STREAMABLE_HTTP_PATH` | Streamable HTTP endpoint path | `/mcp` |
89
+
90
+ ## Running the server
91
+
92
+ Run with the default stdio transport:
93
+
94
+ ```bash
95
+ mcp-server-knowledgebase
96
+ ```
97
+
98
+ Run the published package without installing it persistently:
99
+
100
+ ```bash
101
+ uvx --from mcp-server-knowledgebase mcp-server-knowledgebase
102
+ ```
103
+
104
+ Or run the module directly from a source checkout:
105
+
106
+ ```bash
107
+ python -m mcp_server_knowledgebase.server --transport stdio
108
+ ```
109
+
110
+ Run with stateless Streamable HTTP:
111
+
112
+ ```bash
113
+ mcp-server-knowledgebase --transport streamable-http
114
+ ```
115
+
116
+ The default endpoint is `http://127.0.0.1:8000/mcp`. Set
117
+ `MCP_SERVER_HOST=0.0.0.0` only when deploying behind a trusted gateway.
118
+
119
+ ### MCP protocol and deployment security
120
+
121
+ The server uses MCP Python SDK 2.x and supports protocol revision `2026-07-28`,
122
+ including stateless `server/discover` negotiation. The SDK also handles older
123
+ handshake-based clients. Legacy HTTP+SSE is not exposed because it is
124
+ deprecated by the `2026-07-28` specification.
125
+
126
+ Streamable HTTP does not turn the configured Viking API key or VolcEngine
127
+ AK/SK into client authentication. Protect remote deployments with an
128
+ authentication gateway or MCP-compatible OAuth, and never expose service
129
+ credentials to callers.
130
+
131
+ ## Available tools
132
+
133
+ - [`add_doc`](https://www.volcengine.com/docs/84313/1254624): Add a document by URL
134
+ - [`get_doc`](https://www.volcengine.com/docs/84313/1254615): Get document information and processing status
135
+ - [`list_docs`](https://docs.volcengine.com/docs/84313/2477871?lang=zh): List documents with cursor pagination
136
+ - [`get_collection`](https://www.volcengine.com/docs/84313/1254602): Get collection information
137
+ - [`list_collections`](https://www.volcengine.com/docs/84313/1254596): List collections in the configured project
138
+ - [`search_knowledge`](https://www.volcengine.com/docs/84313/1350012): Search knowledge in a collection
139
+
140
+ ### `add_doc`
141
+
142
+ Add a supported document to a collection by URL.
143
+
144
+ ```python
145
+ add_doc(
146
+ collection_name="product_docs",
147
+ add_type="url",
148
+ doc_id="product_guide_2026",
149
+ doc_name="Product Guide",
150
+ doc_type="pdf",
151
+ url="https://example.com/product-guide.pdf",
152
+ )
153
+ ```
154
+
155
+ Parameters:
156
+
157
+ - `collection_name` (required): Target collection name.
158
+ - `add_type` (required): Currently only `"url"` is supported.
159
+ - `doc_id` (required): Unique ID containing only letters, numbers, and
160
+ underscores. It must start with a letter and contain 1–128 characters.
161
+ - `doc_name` (required): Document name containing 1–256 characters.
162
+ - `doc_type` (required): One of `xlsx`, `csv`, `jsonl`, `txt`, `doc`, `docx`,
163
+ `pdf`, `markdown`, `faq.xlsx`, or `pptx`.
164
+ - `url` (required): Accessible URL of the document.
165
+
166
+ Example result:
167
+
168
+ ```json
169
+ {
170
+ "collection_name": "product_docs",
171
+ "doc_id": "product_guide_2026",
172
+ "resource_id": "kb-example"
173
+ }
174
+ ```
175
+
176
+ ### `get_doc`
177
+
178
+ Get a document's metadata and processing status.
179
+
180
+ ```python
181
+ get_doc(
182
+ collection_name="product_docs",
183
+ resource_id="kb-example",
184
+ doc_id="product_guide_2026",
185
+ )
186
+ ```
187
+
188
+ Parameters:
189
+
190
+ - `collection_name` (optional): Collection containing the document.
191
+ - `resource_id` (optional): Collection ID. Provide this or `collection_name`;
192
+ `resource_id` takes precedence when both are provided.
193
+ - `doc_id` (required): Document ID.
194
+
195
+ Example result:
196
+
197
+ ```json
198
+ {
199
+ "collection_name": "product_docs",
200
+ "doc_id": "product_guide_2026",
201
+ "doc_name": "Product Guide",
202
+ "doc_type": "pdf",
203
+ "add_type": "url",
204
+ "create_time": 1788220800,
205
+ "update_time": 1788220860,
206
+ "point_num": 53,
207
+ "status": {
208
+ "process_status": 0,
209
+ "failed_code": null
210
+ },
211
+ "title": "Product Guide",
212
+ "doc_summary": "Product setup and account management instructions.",
213
+ "brief_summary": "An introduction to the product.",
214
+ "meta": {
215
+ "category": "product",
216
+ "version": "2026"
217
+ },
218
+ "video_outline": {
219
+ "title": "Product walkthrough",
220
+ "summary": "A walkthrough of the product.",
221
+ "chapters": [
222
+ {
223
+ "title": "Account settings",
224
+ "content": "Open Account Settings.",
225
+ "start_time": "00:00:10",
226
+ "end_time": "00:00:30",
227
+ "element_content": {
228
+ "text": "Account Settings"
229
+ }
230
+ }
231
+ ]
232
+ },
233
+ "audio_outline": {
234
+ "title": "Product introduction",
235
+ "summary": "An introduction to account management.",
236
+ "chapters": [
237
+ {
238
+ "title": "Resetting your password",
239
+ "content": "Select Reset Password.",
240
+ "start_time": 10.0,
241
+ "end_time": 30.0,
242
+ "element_content": {
243
+ "text": "Reset Password"
244
+ }
245
+ }
246
+ ]
247
+ }
248
+ }
249
+ ```
250
+
251
+ `process_status` values: `0` completed, `1` failed, `2` or `3` queued, `5`
252
+ deleting, and `6` processing. Fields not returned by Viking are `null`.
253
+
254
+ Additional result fields include `title` (document title), `doc_summary` (document
255
+ summary), `brief_summary` (short summary), `meta` (metadata), `video_outline`, and
256
+ `audio_outline`. Outlines contain `title`, `summary`, and `chapters`; chapters
257
+ contain `title`, `content`, `start_time`, `end_time`, and `element_content`.
258
+
259
+ ### `list_docs`
260
+
261
+ List documents in a collection using cursor pagination.
262
+
263
+ ```python
264
+ list_docs(
265
+ collection_name="product_docs",
266
+ resource_id="kb-example",
267
+ limit=2,
268
+ next_token=None,
269
+ )
270
+ ```
271
+
272
+ Parameters:
273
+
274
+ - `collection_name` (optional): Collection whose documents will be listed.
275
+ - `resource_id` (optional): Collection ID. Provide this or `collection_name`;
276
+ `resource_id` takes precedence when both are provided.
277
+ - `limit` (optional): Number of documents to return, from 1 to 100. Defaults
278
+ to `50`.
279
+ - `next_token` (optional): Opaque cursor returned by the previous call. Omit
280
+ it for the first page. An empty cursor in the result means all documents
281
+ have been returned.
282
+
283
+ Example result:
284
+
285
+ ```json
286
+ {
287
+ "collection_name": "product_docs",
288
+ "total_num": 3,
289
+ "count": 1,
290
+ "doc_list": [
291
+ {
292
+ "doc_id": "product_guide_2026",
293
+ "doc_name": "Product Guide",
294
+ "doc_type": "pdf",
295
+ "create_time": 1788220800,
296
+ "update_time": 1788220860,
297
+ "point_num": 53,
298
+ "status": {
299
+ "process_status": 0,
300
+ "failed_code": null
301
+ },
302
+ "brief_summary": "An introduction to the product.",
303
+ "title": "Product Guide"
304
+ }
305
+ ],
306
+ "has_more": true,
307
+ "next_token": "opaque-cursor-for-next-page"
308
+ }
309
+ ```
310
+
311
+ `total_num` is `null` when Viking does not provide it.
312
+
313
+ ### `get_collection`
314
+
315
+ Get information and build status for a collection.
316
+
317
+ ```python
318
+ get_collection(
319
+ collection_name="product_docs",
320
+ resource_id="kb-example",
321
+ )
322
+ ```
323
+
324
+ Parameters:
325
+
326
+ - `collection_name` (optional): Collection name.
327
+ - `resource_id` (optional): Collection ID. Provide this or `collection_name`;
328
+ `resource_id` takes precedence when both are provided.
329
+
330
+ Example result:
331
+
332
+ ```json
333
+ {
334
+ "collection_name": "product_docs",
335
+ "description": "Product manuals and release notes",
336
+ "status": 1,
337
+ "resource_id": "kb-example",
338
+ "doc_num": 3,
339
+ "create_time": 1788220800,
340
+ "update_time": 1788220860
341
+ }
342
+ ```
343
+
344
+ Collection status values: `-1` pending build, `0` building, `1` completed,
345
+ `2` failed, and `3` changing.
346
+
347
+ ### `list_collections`
348
+
349
+ List all collections in the globally configured project.
350
+
351
+ ```python
352
+ list_collections()
353
+ ```
354
+
355
+ This tool has no parameters.
356
+
357
+ Example result:
358
+
359
+ ```json
360
+ {
361
+ "collection_list": [
362
+ {
363
+ "collection_name": "product_docs",
364
+ "description": "Product manuals and release notes",
365
+ "resource_id": "kb-example-1",
366
+ "create_time": 1788220800,
367
+ "update_time": 1788220860
368
+ },
369
+ {
370
+ "collection_name": "support_faq",
371
+ "description": "Frequently asked support questions",
372
+ "resource_id": "kb-example-2",
373
+ "create_time": 1788220800,
374
+ "update_time": 1788220860
375
+ }
376
+ ],
377
+ "total_num": 2
378
+ }
379
+ ```
380
+
381
+ ### `search_knowledge`
382
+
383
+ Search for relevant chunks in a collection. An optional document filter can
384
+ include or exclude matching document field values.
385
+
386
+ ```python
387
+ search_knowledge(
388
+ query="How do I reset my password?",
389
+ collection_name="support_faq",
390
+ resource_id="kb-example",
391
+ limit=10,
392
+ doc_filter={
393
+ "op": "must",
394
+ "field": "doc_id",
395
+ "conds": ["account_guide"],
396
+ },
397
+ )
398
+ ```
399
+
400
+ Parameters:
401
+
402
+ - `query` (required): Search query, from 1 to 8000 characters.
403
+ - `collection_name` (optional): Collection to search.
404
+ - `resource_id` (optional): Collection ID. Provide this or `collection_name`;
405
+ `resource_id` takes precedence when both are provided.
406
+ - `limit` (optional): Maximum number of chunks to return, from 1 to 100.
407
+ Defaults to `10`.
408
+ - `doc_filter` (optional): Object with the following fields:
409
+ - `op`: `"must"` to include matches or `"must_not"` to exclude them.
410
+ - `field`: Document field to filter, such as `"doc_id"`.
411
+ - `conds`: Non-empty list of values to match.
412
+
413
+ Example result:
414
+
415
+ ```json
416
+ {
417
+ "result_list": [
418
+ {
419
+ "id": "chunk_001",
420
+ "content": "Open Account Settings and select Reset Password.",
421
+ "doc_id": "account_guide",
422
+ "doc_name": "Account Guide",
423
+ "title": "Account Guide",
424
+ "doc_type": "pdf",
425
+ "score": 0.85,
426
+ "rerank_score": 0.92,
427
+ "chunk_title": "Resetting your password",
428
+ "audio_start_time": null,
429
+ "audio_end_time": null,
430
+ "video_start_time": null,
431
+ "video_end_time": null,
432
+ "chunk_attachment": [
433
+ {
434
+ "uuid": "image_1",
435
+ "caption": "Account Settings",
436
+ "type": "image"
437
+ }
438
+ ]
439
+ }
440
+ ]
441
+ }
442
+ ```
443
+
444
+ `doc_id` and `doc_name` are `null` when Viking does not provide document
445
+ metadata. A non-null `doc_id` can be passed directly to `get_doc`.
446
+
447
+ Chunks also include `title` (document title), `doc_type` (document type), `score`
448
+ (search score), `rerank_score`, `chunk_title`, `audio_start_time`, `audio_end_time`,
449
+ `video_start_time`, `video_end_time`, and `chunk_attachment` (attachments). Each
450
+ attachment contains `uuid`, `caption`, and `type`.
451
+
452
+ Image links for `image`, `doc-image`, and `table` attachments are returned as MCP
453
+ `ResourceLink` blocks with `uri`, `name`, `description`, and `mimeType` (`image/*`),
454
+ and URL is not included in `chunk_attachment`.
455
+
456
+ Example image link content block:
457
+
458
+ ```json
459
+ {
460
+ "type": "resource_link",
461
+ "uri": "https://example.com/account-settings.png",
462
+ "name": "image_1",
463
+ "description": "Account Settings",
464
+ "mimeType": "image/*"
465
+ }
466
+ ```
467
+
468
+ ## MCP client configuration
469
+
470
+ Example stdio configuration using `uvx` and a Viking API key:
471
+
472
+ ```json
473
+ {
474
+ "mcpServers": {
475
+ "knowledgebase": {
476
+ "command": "uvx",
477
+ "args": [
478
+ "--from",
479
+ "mcp-server-knowledgebase>=0.2.2",
480
+ "mcp-server-knowledgebase"
481
+ ],
482
+ "env": {
483
+ "VIKING_API_KEY": "your-viking-api-key",
484
+ "KNOWLEDGE_BASE_PROJECT": "your-project-name",
485
+ "KNOWLEDGE_BASE_REGION": "cn-north-1"
486
+ }
487
+ }
488
+ }
489
+ }
490
+ ```
491
+
492
+ You can instead configure both `VOLCENGINE_ACCESS_KEY` and
493
+ `VOLCENGINE_SECRET_KEY`. If all three credentials are present,
494
+ `VIKING_API_KEY` takes precedence.
495
+
496
+ ## Troubleshooting
497
+
498
+ 1. Authentication errors
499
+ - Verify the API key or AK/SK credentials.
500
+ - When using AK/SK, configure both values together.
501
+ - Check that the credentials can access the configured project and collection.
502
+ 2. Connection timeouts
503
+ - Check network connectivity to the VolcEngine API.
504
+ - Adjust `KNOWLEDGE_BASE_TIMEOUT` when necessary.
505
+ 3. Empty results
506
+ - Verify the project and collection names.
507
+ - For search, try a broader query or remove the document filter.
508
+ - For document listing, continue only with the exact `next_token` returned
509
+ by the previous call.
510
+
511
+ ## License
512
+
513
+ This project is licensed under the [MIT License](https://github.com/volcengine/mcp-server/blob/main/LICENSE).