Metadata-Version: 2.4
Name: medxpert-library-connector
Version: 1.0.1
Summary: Local RAG MCP server for your own .md wiki: BM25 + cosine over local Ollama embeddings, offline, zero egress.
Author-email: "Zhao Xinghua (Steven Zhao)" <zhaoxinghua09@gmail.com>
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including the
              original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or Derivative
                  Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor.
        
           7. Disclaimer of Warranty. Unless required by applicable law or agreed
              to in writing, Licensor provides the Work (and each Contributor
              provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
              OR CONDITIONS OF ANY KIND, either express or implied.
        
           8. Limitation of Liability. In no event and under no legal theory shall
              any Contributor be liable to You for damages, including any direct,
              indirect, special, incidental, or consequential damages of any
              character arising as a result of this License or out of the use or
              inability to use the Work.
        
           9. Accepting Warranty or Additional Liability. While redistributing the
              Work or Derivative Works thereof, You may choose to offer, and charge
              a fee for, acceptance of support, warranty, indemnity, or other
              liability obligations and/or rights consistent with this License.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information.
        
           Copyright 2026 赵兴华 / Steven Zhao·China（ORCID 0009-0001-0512-1237）
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
        
        ------------------------------------------------------------------------------
        CONTENT NOTICE
        ------------------------------------------------------------------------------
        The source code of this repository is licensed under the Apache License 2.0
        above. No proprietary knowledge base is bundled; any sample or user-supplied
        content remains the property of its original owner.
        
        Brand status: MedXpert / SynomosAI / LGD are project identifiers only; none
        is a registered legal entity and none has a registered trademark. Their
        appearance is for source identification only and does not constitute any
        claim to a legal entity or trademark right.
        
        Disclaimer: content is not regulatory, legal, or medical advice. Always rely
        on the latest official publication of the competent authority.
        
Project-URL: Homepage, https://medxpert.cn
Project-URL: Repository, https://github.com/zhaoxinghua09-cell/medxpert-library-connector
Project-URL: Issues, https://github.com/zhaoxinghua09-cell/medxpert-library-connector/issues
Keywords: mcp,model-context-protocol,rag,knowledge-base,ollama,offline,medical-device
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Healthcare Industry
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: local-embed
Requires-Dist: fastembed>=0.3; extra == "local-embed"
Dynamic: license-file

# MedXpert Library Connector

<!-- mcp-name: io.github.zhaoxinghua09-cell/medxpert-library-connector -->

Turn **your own wiki (plain `.md` documents)** into a locally searchable, RAG-capable MCP server.

- Pure Python standard library (stdio JSON-RPC 2.0) — **no third-party runtime dependency**
- Embedding and generation run on **local Ollama** — no API keys, works offline
- The knowledge base is your own documents; only a three-page sample wiki is bundled
- Everything runs on your machine; the server makes no external network call

| Tool | What it does |
|------|--------------|
| `search_knowledge(query, top_k?)` | Semantic search over your wiki; snippets with similarity |
| `get_page(title)` | Full text of one wiki page |
| `list_sources()` | Library scope: page count, categories, index status |
| `ask_knowledge(question, top_k?)` | RAG answer: retrieval + local generation model, with citations |

```bash
pip install medxpert-library-connector      # or: uvx medxpert-library-connector
LIBRARY_WIKI_DIR=/path/to/your/wiki medxpert-library-connector
```

---

# MedXpert 图书馆（通用版）连接器

把**你自己的 wiki（.md 文档）**做成可语义检索、可 RAG 问答的本地知识库 MCP 连接器。

- 纯 Python 标准库实现（stdio JSON-RPC 2.0），**零第三方依赖**
- 仅依赖**本地 Ollama** 做嵌入/生成，**零积分、断网可用**
- 知识库为你自有文档，连接器不绑定任何预置私有数据
- 全部计算在本机完成，不访问任何外部网络，不上传任何数据

## 工具

| 工具 | 说明 |
|------|------|
| `search_knowledge(query, top_k?)` | 语义检索知识库，返回相关片段 + 相似度 |
| `get_page(title)` | 读取单个 wiki 页全文 |
| `list_sources()` | 库范围：页数 / 分类 / 索引状态 |
| `ask_knowledge(question, top_k?)` | RAG 问答：检索 + 本地生成模型，附引用 |

## 快速开始

```bash
# 1. 安装并启动 Ollama，拉取模型
ollama pull bge-m3            # 检索必备（嵌入）
ollama pull qwen2.5:7b        # 问答可选（生成）

# 2. 用你自己的文档替换 wiki/（本包自带 3 个示例页）
#    把 .md 放进 wiki/ 即可，可建子目录分类

# 3. 构建向量索引
python rag_engine.py build

# 4. 启动 MCP server（stdio）
python medxpert_library_server.py
```

## 接入 WorkBuddy

包内 `mcp.json` 已提供标准配置；在开放平台或客户端中引用本包目录即可。
也可用环境变量覆盖默认行为：

| 变量 | 默认值 | 说明 |
|------|--------|------|
| `LIBRARY_WIKI_DIR` | 本包 `wiki/` | 知识库目录（指向你的文档） |
| `OLLAMA_BASE_URL` | `http://127.0.0.1:11434` | Ollama 地址 |
| `LIBRARY_EMBED_MODEL` | `bge-m3` | 嵌入模型 |
| `LIBRARY_GEN_MODEL` | `qwen2.5:7b` | 生成模型（问答） |

## 包结构

```
medxpert-library-connector/
├── medxpert_library_server.py   # MCP server（stdio，纯标准库）
├── rag_engine.py                # 嵌入 / 余弦 / 构建 / 检索引擎
├── wiki/                        # 示例知识库（替换成你自己的 .md）
├── connector-meta.json          # 开放平台元数据
├── mcp.json                     # MCP 启动配置
├── icon.svg                     # 头像
├── LICENSE                  # Apache-2.0
├── requirements.txt             # 依赖说明（仅 Ollama）
└── README.md
```

## 合规与隐私

- 不内嵌受版权保护的标准正文，仅索引标准号与公开要点。
- 所有内容在本机处理，文档与查询均不上传外部服务。
- 知识库为使用者自有内容，发布者不对其内容负责。

---

## 许可说明 · License Notice

- **代码许可**：本仓库源代码以 **Apache-2.0** 许可发布（见根目录 [LICENSE](LICENSE)）。
© 2026 赵兴华 / Steven Zhao (ORCID 0009-0001-0512-1237). All rights reserved.
- **内容权属**：本仓库不捆绑专有知识库；随附示例内容仅供演示，归其原始所有者所有。代码以 Apache-2.0 许可发布。
- **品牌状态限定**：MedXpert、SynomosAI、LGD 等为相关项目标识，**均未申请实体注册、未申请商标注册**；出现仅作来源标识，不构成对法人实体或商标权的任何主张。
- **免责**：本仓库内容不构成法规意见、法律意见或注册代理服务；关键数据以监管机构最新发布为准。
- **联系**：zhaoxinghua09@gmail.com ｜ ORCID 0009-0001-0512-1237

`mcp-name: io.github.zhaoxinghua09-cell/medxpert-library-connector`
