# MCP连接器-PrivateGPT服务器
## 基本信息
- Slug: `fujitsu-ai-mcp-server-for-mas-developments`
- Source: modelscope
- Publisher: @Fujitsu-AI/MCP-Server-for-MAS-Developments
- Categories: knowledge-and-memory / search / security-and-iam
- Hosted: No
- License: MIT License
- Source URL: https://www.modelscope.cn/mcp/servers/@Fujitsu-AI/MCP-Server-for-MAS-Developments
## 简介
一种服务器实现，允许 MCP 客户端与 privateGPT 之间进行安全通信，使用户能够使用知识库与 privateGPT 聊天，并通过标准化的模型上下文协议（Model Context Protocol）管理来源、分组和用户。
## 安装提示

```bash
在这个简化的情景中，应用程序通过代理发送请求，代理再通过 MCP 服务器与 LLM 或数据源进行交互，最后将结果返回给应用程序。 1. **用户输入：** 用户通过托管在MCP服务器上的用户界面发送请求。 2. **代理处理：** MCP服务器上的代理接收请求，验证它，并为LLM准备请求。 3. **LLM交互：** 代理将请求转发给LLM，LLM生成响应。 4. **响应处理：** 代理从LLM接收响应，如果需要进一步处理（例如格式化、与其他数据源集成），然后将其发送回用户。 5. **安全性和日志记录：** 在此过程中，代理监控交互，确保遵守安全策略，并记录相关信息以供后续分析。 ## 在此上下文中使用代理的优势 - **模块化：** 代理允许职责的明确分离，使系统更易于维护和扩展。 - **安全性：** 集中管理访问和监控活动有助于最小化安全风险。 - **效率：** 自动化代理可以比手动流程更快、更一致地执行任务。 - **灵活性：** 代理可以轻松适应或扩展以支持新功能或业务需求的变化。 ### 加密密码的重要性 在任何处理敏感数据的应用程序中，安全性是至关重要的。该服务器管理两组关键凭据： 1. **代理头：** 例如，HAProxy用于身份验证和管理流量。 2. **LLM访问密码：** 用于保护对大型语言模型的访问。 以明文形式存储这些密码存在重大安全风险，包括未经授权的访问和潜在的数据泄露。 为了缓解这些风险，必须加密这些密码，并且仅在系统内处理其密文。 ### 仅使用密文的好处 - **增强的安全性：** 即使攻击者获得了配置文件或环境变量的访问权限，没有相应的解密密钥，加密的密码仍然不可读。 - **合规性：** 加密有助于遵守要求保护敏感信息的安全标准和法规。 - **完整性：** 确保密码不会被篡改，保持认证机制的完整性。 --- # 安全 以下安全特性已实现，以确保数据保护和客户端应用程序与服务器之间的安全通信。这些特性涵盖加密、解密、密钥管理和传输安全。 --- ## 1. 传输层安全 (TLS) - 为了确保客户端和服务器之间的通信安全，可以激活TLS。所有在客户端和服务器之间传输的数据都使用TLS（最低版本1.2）进行加密。 ## 为什么应该在客户端和服务器之间启用TLS？ ### a. **通信加密** - TLS（传输层安全协议）确保客户端和服务器之间传输的所有数据都是加密的。这可以保护诸如密码、信用卡详细信息和个人数据等敏感信息免受窃听攻击（中间人攻击）。 ### b. **数据完整性** - TLS 保证传输的数据保持不变且未被篡改。完整性检查确保接收到的数据与发送时完全一致。 ### c. **身份验证** - TLS 通过数字证书实现服务器（以及可选的客户端）的安全身份验证。这可以防止用户成为假冒网站的钓鱼攻击的受害者。 ### d. **防止中间人攻击** - TLS 对连接进行加密，使得攻击者几乎不可能拦截或操纵流量。如果没有 TLS，攻击者可以捕获并修改数据包。 ### e. **符合安全标准和法规** - 许多监管要求（例如 GDPR、PCI-DSS）强制要求安全的数据传输。TLS 是这些安全要求的基本组成部分。 ### f. **防止降级攻击和重放攻击** - TLS 可以防止攻击者试图将连接降级到不安全版本（降级攻击）或重放之前有效的请求（重放攻击）。 ## 结论 在客户端和服务器之间启用 TLS 是确保数据隐私、安全性和通信完整性的关键。它不仅保护敏感信息，还有助于满足合规性要求并增加用户的信任。 --- ## 2. 密码加密 可以使用 RSA（Rivest–Shamir–Adleman）公钥加密来加密密码。这样可以确保像用户密码这样的敏感数据永远不会以明文形式传输。 ### 方法…
```

## MCP Server 详情

![privateGPT MCP Server](images/privateGPT-MCP.png)

## 目录

- [**privateGPT MCP Server**](#privateGPT-mcp-server)
- [**What is MCP?**](#what-is-mcp)
  - [Why MCP?](#why-mcp)
  - [Why Agents](#why-agents)
  - [How it Works](#how-it-works) 
- [**Interaction Between Agents, LLMs, and MCP Servers**](#interaction-between-agents-llms-and-mcp-servers)
  - [Scenario](#scenario)
    1. [User Input](#user-input)
    2. [Agent Processing](#agent-processing)
    3. [LLM Interaction](#llm-interaction)
    4. [Response Processing](#response-processing)
    5. [Security and Logging](#security-and-logging)
- [**Advantages of Using Agents in This Context**](#advantages-of-using-agents-in-this-context)
  - [Modularity](#modularity)
  - [Security](#security)
  - [Efficiency](#efficiency)
  - [Flexibility](#flexibility)
- [**Overview**](#overview)
- [**Security Features Overview**](#security)
  - [1. Transport Layer Security (TLS)](#1-transport-layer-security-(tls))
  - [2. Password Encryption](#2-password-encryption)
  - [3. Key Management](#3-key-management)
  - [4. Decryption on the Server](#4-decryption-on-the-server)
  - [5. Authorization Tokens](#5-authorization-tokens)
  - [6. Restriction of Key Generation (Keygen)](#6-restriction-of-key-generation-keygen)
  - [7. Certificate-Based Access Control (CBAC)](#7-certificate-based-access-control-cbac)
  - [8. Secure Configuration](#8-secure-configuration)
  - [9. Logging and Monitoring](#9-logging-and-monitoring)
  - [Summary](#summary)
  - [Encrypted Password Generation Tool](#encrypted-password-generation-tool)
    1. [Generate a password for the client and/or the server's Proxy_Config](#generate-encrypted-password)
    2. [Check the generated encrypted password](#check-the-generated-encrypted-password)
  - [Encrypted Password Decryption Tool](#encrypted-password-decryption-tool)
    1. [Check the generated encrypted password](#check-the-generated-encrypted-password)
- [**Feature Overview for privateGPT Server**](#feature-overview-for-privateGPT-server)
  - [1. Authentication and Authorization](#1-authentication-and-authorization)
  - [2. Chat Management](#2-chat-management)
  - [3. Group Management](#3-group-management)
  - [4. Source Management](#4-source-management)
  - [5. User Management](#5-user-management)
  - [6. Configuration Flexibility](#6-configuration-flexibility)
  - [7. Error Handling and Logging](#7-error-handling-and-logging)
  - [8. Security Features](#8-security-features)
  - [Example Use Cases](#example-use-cases)
  - [How to Use](#how-to-use)
- [**Installation**](#installation)
  - [Prerequisites](#prerequisites)
  - [Install Dependencies](#install-dependencies)
  - [Build the Project](#build-the-project)
- [**Configuration Description**](#configuration-description)
  - [Proxy Configuration](#proxy-configuration)
    - [Use Proxy](#use-proxy)
    - [Header Encryption](#header-encryption)
    - [Access Header](#access-header)
      - [Example Configuration](#example-configuration)
      - [Notes](#notes)
  - [Server Configuration](#server-configuration)
    - [Server Port](#server-port)
    - [Language](#language)
    - [SSL Validation](#ssl-validation)
    - [Encryption](#encryption)
    - [SSL/TLS](#ssltls)
  - [Restrictions](#restrictions)
    - [Group Restrictions](#restrictions)
    - [Enable OpenAI compatible API](#restrictions)
  - [Logging](#logging)
    - [Written Logfile](#logging)
    - [Log IPs](#logging)
    - [Anonymous Mode](#logging)
  - [Feature Activation/Deactivation](#feature-activationdeactivation)
    - [ENABLE_LOGIN](#feature-activationdeactivation)
    - [ENABLE_LOGOUT](#feature-activationdeactivation)
    - [ENABLE_CHAT](#feature-activationdeactivation)
    - [ENABLE_CONTINUE_CHAT](#feature-activationdeactivation)
    - [ENABLE_GET_CHAT_INFO](#feature-activationdeactivation)
    - [ENABLE_DELETE_ALL_CHATS](#feature-activationdeactivation)
    - [ENABLE_DELETE_CHAT](#feature-activationdeactivation)
    - [ENABLE_LIST_GROUPS](#feature-activationdeactivation)
    - [ENABLE_STORE_GROUP](#feature-activationdeactivation)
    - [ENABLE_DELETE_GROUP](#feature-activationdeactivation)
    - [ENABLE_CREATE_SOURCE](#feature-activationdeactivation)
    - [ENABLE_EDIT_SOURCE](#feature-activationdeactivation)
    - [ENABLE_DELETE_SOURCE](#feature-activationdeactivation)
    - [ENABLE_GET_SOURCE](#feature-activationdeactivation)
    - [ENABLE_LIST_SOURCES](#feature-activationdeactivation)
    - [ENABLE_STORE_USER](#feature-activationdeactivation)
    - [ENABLE_EDIT_USER](#feature-activationdeactivation)
    - [ENABLE_DELETE_USER](#feature-activationdeactivation)
    - [ENABLE_REACTIVATE_USER](#feature-activationdeactivation)
  - [Usage](#usage)
    - [Available Tools](#available-tools)
- [**Project Structure**](#project-structure)
- [License](#license)

# privateGPT MCP 服务器
这是一个 Model Context Protocol (MCP) 服务器实现，允许你将 privateGPT 作为你首选的 MCP 客户端的代理使用。这使得 privateGPT 的强大功能能够与任何兼容 MCP 的应用程序无缝集成。

## 什么是 MCP？
MCP 是一个开放协议，它标准化了应用程序如何向 LLM 提供上下文。可以将 MCP 视为 AI 应用程序的 USB-C 端口。就像 USB-C 提供了一种标准化的方式来连接你的设备到各种外围设备和配件一样，MCP 提供了一种标准化的方式将 AI 模型连接到不同的数据源和工具。

### 为什么选择 MCP？
MCP 帮助你在 LLM 上构建代理和复杂的工作流。LLM 经常需要与数据和工具集成，而 MCP 提供了：
- 一个不断增长的预构建集成列表，你的 LLM 可以直接接入
- 在不同 LLM 提供商和供应商之间切换的灵活性
- 在你的基础设施中保护数据的最佳实践

### 工作原理
在核心上，MCP 遵循客户端-服务器架构，其中主机应用程序可以连接到多个服务器：

![MCP 通用架构](images/mcp-general-architecture.png)

- **MCP 主机**：希望通过 MCP 访问数据的应用程序、Claude Desktop、IDE 或 AI 工具
- **MCP 客户端**：与服务器保持 1:1 连接的协议客户端
- **MCP 服务器**：轻量级程序，每个都通过标准化的 Model Context Protocol 暴露特定功能
- **本地数据源**：MCP 服务器可以安全访问的你的计算机文件、数据库和服务
- **远程服务**：可以通过互联网（例如，通过 API）访问的外部系统，MCP 服务器可以连接到这些系统

## 概述
此服务器提供了 MCP 客户端和 privateGPT API 之间的桥梁，允许你：
- 使用公共和私有知识库与 privateGPT 聊天
- 创建和管理知识来源
- 将来源组织成组
- 通过基于组的权限控制访问


---

# 为什么需要代理
在 **LLMs**（大型语言模型）和 **MCP 服务器** 中，**代理**是一个专门的软件组件，充当语言模型和应用程序之间的中介。它处理诸如请求处理、通过 MCP 与 LLM 交互、管理工作流、确保整个系统的安全性和效率等任务。通过利用代理，可以设计出高效、安全且可扩展的基于 AI 的复杂应用程序。
**此仓库中的代理代码可用于将其实施到自己的解决方案/应用程序中。**

## 代理、LLMs 和 MCP 服务器之间的交互
这些组件的交互使开发强大、可扩展和安全的 AI 应用成为可能。以下是一个简化的场景，说明了这种交互：

```…

