
PrivateGPT
STDIOModel Context Protocol server for privateGPT integration with secure AI communication
Model Context Protocol server for privateGPT integration with secure AI communication
A Model Context Protocol (MCP) server implementation that allows you to use privateGPT as an agent for your preferred MCP client. This enables seamless integration between privateGPT's powerful capabilities and any MCP-compatible application.
MCP is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications. Just as USB-C provides a standardized way to connect your devices to various peripherals and accessories, MCP provides a standardized way to connect AI models to different data sources and tools.
MCP helps you build agents and complex workflows on top of LLMs. LLMs frequently need to integrate with data and tools, and MCP provides:
At its core, MCP follows a client-server architecture where a host application can connect to multiple servers:
This server provides a bridge between MCP clients and the privateGPT API, allowing you to:
An agent in relation to LLMs (Large Language Models) and MCP servers is a specialized software component that acts as an intermediary between language models and applications. It handles tasks such as processing requests, interacting with the LLM via MCP, managing workflows, ensuring security and efficiency within the overall system, and much more. By utilizing agents, complex AI-based applications can be designed to be effective, secure, and scalable. The code for agents in this repository can be used to implement it into own solutions / applications.
The interaction of these components enables the development of powerful, scalable, and secure AI applications. Below is a simplified scenario that illustrates this interaction:
In any application handling sensitive data, security is paramount. This server manages two critical sets of credentials:
Storing these passwords in plaintext poses significant security risks, including unauthorized access and potential data breaches. To mitigate these risks, it is essential to encrypt these passwords and handle only their ciphertext within the system.
The following security features are implemented to ensure data protection and secure communication between the client application and server. These features cover encryption, decryption, key management, and transport security.
Enabling TLS between client and server is essential to ensure data privacy, security, and communication integrity. It not only protects sensitive information but also helps meet compliance requirements and increases user trust.
Passwords can be encrypted using RSA (Rivest–Shamir–Adleman) public-key cryptography. This ensures that sensitive data, such as user passwords, are never transmitted in plaintext.
RSA_PKCS1_PADDING
to enhance security and prevent known padding attacks.id_rsa_public.pem
) by executing node security/generate_encrypted_password.js ~/.ssh/id_rsa_public.pem
and hand out the encrpyted password to the client.id_rsa_public.pem
) by using the keygen
- Function. Therefore the function has to be enabled in the server's config (privateGPT.env.json
). Important: Using this function also means transmitting data via the network. Therefore, make sure that the data traffic is secure and cannot be intercepted.To secure data communication and encryption processes, the following key management principles are followed:
id_rsa.pub
).id_rsa_public.pem
).id_rsa
).chmod 600
).Decryption is exclusively performed on the server using the private key:
Tokens are used to authenticate requests and ensure only authorized users can access the system:
To prevent misuse of the system, key generation (keygen
) is restricted:
ALLOW_KEYGEN
) to enable or disable key generation.keygen
, store_user
, and edit_source
are only accessible to authorized roles.Functions
object).The server configuration contains several security-related options:
All security-related events are logged for monitoring and troubleshooting:
The implemented security features ensure:
These measures collectively provide a secure environment for client-server communication and data handling.
The privateGPT Server offers a robust set of features designed to provide efficient, flexible, and secure communication with the Model Context Protocol (MCP). Below is an overview of the key features and functionalities available in the server.
.env
configuration file.assignableGroups
for enhanced privacy.privateGPT.env.json.example
file to privateGPT.env.json
e.g. with cp .\privateGPT.env.json.example .\privateGPT.env.json
privateGPT.env.json
file.Refer to the API Documentation for detailed usage instructions and examples for each endpoint.
The privateGPT Server is a powerful tool for managing structured communication and data in a customizable environment. Tailor its features to your needs for maximum efficiency and control.
git clone https://github.com/privateGPT-dev/MCP-Server-for-MAS-Developments.git cd MCP-Server-for-MAS-Developments
Now you have to choose: Manually or automatic.
Manually step-by-step Installation
npm
, for example:sudo apt install npm
npm install
npm run build
or Automatic Installation
InstallMPCServer.sh
executable (Linux):sudo chmod +x InstallMPCServer.sh
./InstallMPCServer.sh
This section provides detailed explanations for the Proxy_Config
settings used in the system.
Use Proxy
If a Proxy is used, you have to define a Header for authentication at the Proxy.
Key | Description | Example Value |
---|---|---|
USE_PROXY | Determines whether the application should route | true |
requests through a proxy server. |
Example configuration of a HAProxy's backend. Only request contaning 1234567890ABCDEFHIJ
in the header will be accepted:
backend mcpserver.mydomain.com acl valid_header req.hdr(X-Custom-Header) -m str "1234567890ABCDEFHIJ" http-request deny unless valid_header http-request del-header X-Custom-Header server stable 172.16.123.4:443 ssl verify none
Header Encryption
Key | Description | Example Value |
---|---|---|
HEADER_ENCRYPTED | Indicates if the custom proxy access header is encrypted. | true |
"true"
: The access header is encrypted. Use the encryption tool in the security folder on the server to encrypt the Header."false"
: The access header is plain text.Access Header
The custom header value used for proxy authentication or access control. If HEADER_ENCRYPTED
is "true"
, this value must be decrypted before use.
Key | Description | Example Value |
---|---|---|
ACCESS_HEADER | Used for proxy authentication or access control. | 123abc.. |
ACCESS_HEADER
is properly secured if HEADER_ENCRYPTED
is set to "true"
.For secure certificate authentification, create a .env
file with your privateGPT credentials, for example privateGPT.env.json
Settings can be adjusted in the .env
file to customize the server and its functionalities.
Generate the certificates (if you haven't ssh certificates use ssh-keygen -t rsa
), .pem files are needed:
ssh-keygen -p -m PEM -f ~/.ssh/id_rsa ssh-keygen -f ~/.ssh/id_rsa.pub -e -m PEM > ~/.ssh/id_rsa_public.pem
After this process, you can create Ciphertext from passwords by using the Encrypted Password Encryption Tool and test the cipher with the Encrypted Password Decryption Tool.
You will find the descriptionof how it works in the Security
section of this document.
Next, you should provide the SSL/TLS certificates server.crt
and server.key
to ensure that communication with clients and agents is encrypted.
If you want to use self-signed certificates, you can generate them by executing f.e. the following command:
openssl req -x509 -newkey rsa:2048 -nodes -keyout server.key -out server.crt -days 365 -subj "/CN=localhost"
Note: Clients and agents can detect that the server uses self-signed certificates, as these are potentially insecure compared to official certificates where the organisation is checked and more. However, clients and agents can accept communication with these certificates with the appropriate parameter (see description of the respective client and agent parameters).
Below is a sample .env
configuration file for the privateGPT server, including descriptions for each setting.
Customize these values to fit your environment and requirements.
Server Port
Key | Description | Example Value |
---|---|---|
PORT | The port on which the MCP server runs. | 5000 |
Language
The system supports out-of-the-box: de
, en
, pt
, es
, nl
, fr
.
Every Language can be easily added by modifying the privateGPT-messages.js
. This file should be stored after the modification in /src
as well as in /dist
.
Key | Description | Example Value |
---|---|---|
LANGUAGE | The language for the server's system messages (en or de ). | "de" |
SSL Validation
Key | Description | Example Value |
---|---|---|
SSL_VALIDATE | Use "false" only if the server's certificate cannot be validated by the client. | "false" |
Encryption
Key | Description | Example Value |
---|---|---|
PW_ENCRYPTION | If set to "true" the server only accepts passwords in Ciphertext. | "false" |
PUBLIC_KEY | Specifies the file system path to the server's public PEM file used for RSA. | "~/.ssh/id_rsa_public.pem" |
PRIVATE_KEY | Specifies the file system path to the server's private key file used for RSA. | "~/.ssh/id_rsa_public.pem" |
SSL/TLS
Key | Description | Example Value |
---|---|---|
ENABLE_TLS | If set to "true" the server only provides TLS encrypted communication with clients and agents. | "true" |
SSL_KEY_PATH | Specifies the file system path to the server's SSL/TLS Key file used for SSL/TLS. | "~/.ssh/certs/server.key" |
SSL_CERT_PATH | Specifies the file system path to the server's certificate used for SSL/TLS. | "~/.ssh/certs/server.crt" |
Restrictions
Key | Description | Example Value |
---|---|---|
RESTRICTED_GROUPS | Setting true prevents client access to assignableGroups . | true |
ENABLE_OPEN_AI_COMP_API | Setting true allows the compatibility mode for OpenAI API. | false |
Logging
Key | Description | Example Value |
---|---|---|
WRITTEN_LOGFILE | Enable logfile. If set to false , no logfile logs/server.log will be written. If this option is set to ‘true’, the log can be retrieved via `http:// | true |
LOG_IPs | Log IP's of the cleints/agents. If it is set to false , this information is replaced by ***** and cannot be restored. | false |
ANONYMOUS_MODE | Deactivate everything that has to do with logging. No communication, errors or similar are written/saved or displayed. | false |
Feature Activation/Deactivation
Control the availability of individual server functions. Set the corresponding value to true
to enable the function, or false
to disable it. Disabled functions will return a message indicating they are not available.
Key | Description | Example Value |
---|---|---|
ENABLE_LOGIN | Enables or disables the login function. | true |
ENABLE_LOGOUT | Enables or disables the logout function. | true |
ENABLE_CHAT | Enables or disables the chat functionality. | true |
ENABLE_CONTINUE_CHAT | Enables or disables continuing a chat. | true |
ENABLE_GET_CHAT_INFO | Enables or disables retrieving chat information. | true |
ENABLE_DELETE_ALL_CHATS | Enables or disables retrieving chat information. | true |
ENABLE_DELETE_CHAT | Enables or disables retrieving chat information. | true |
ENABLE_LIST_GROUPS | Enables or disables listing groups. | true |
ENABLE_STORE_GROUP | Enables or disables creating a group. | true |
ENABLE_DELETE_GROUP | Enables or disables deleting a group. | false |
ENABLE_CREATE_SOURCE | Enables or disables creating a source. | true |
ENABLE_EDIT_SOURCE | Enables or disables editing a source. | true |
ENABLE_DELETE_SOURCE | Enables or disables deleting a source. | true |
ENABLE_GET_SOURCE | Enables or disables retrieving a source. | true |
ENABLE_LIST_SOURCES | Enables or disables listing sources. | true |
ENABLE_STORE_USER | Enables or disables creating a user. | true |
ENABLE_EDIT_USER | Enables or disables editing a user. | false |
ENABLE_DELETE_USER | Enables or disables deleting a user. | false |
ENABLE_REACTIVATE_USER | Enables or disables reactivating a user. | false |
.env
file to true
..env
file to false
.
Example .env
entry:
{ "privateGPT_Url": { "PRIVATE_GPT_API_URL": "https://<YOUR_privateGPT_URL>/api/v1", "API_URL": "https://<YOUR_privateGPT_URL>/api/v1" }, "Proxy_Config": { "USE_PROXY": "true", "HEADER_ENCRYPTED": "true", "ACCESS_HEADER": "Example: BptfJBeRGLbZas+..." }, "Server_Config": { "PORT": 5000, "LANGUAGE": "en", "SSL_VALIDATE": "false", "PW_ENCRYPTION": "true", "ALLOW_KEYGEN": "false", "PUBLIC_KEY": "~/.ssh/id_rsa_public.pem", "PRIVATE_KEY": "~/.ssh/id_rsa", "ENABLE_TLS": "true", "SSL_KEY_PATH": "~/.ssh/certs/server.key", "SSL_CERT_PATH": "~/.ssh/certs/server.crt" }, "Restrictions": { "RESTRICTED_GROUPS": false, "ENABLE_OPEN_AI_COMP_API": true }, "Logging": { "WRITTEN_LOGFILE": true, "LOG_IPs": true, "ANONYMOUS_MODE": false }, "Functions": { "ENABLE_LOGIN": true, "ENABLE_LOGOUT": true, "ENABLE_CHAT": true, "ENABLE_CONTINUE_CHAT": true, "ENABLE_GET_CHAT_INFO": true, "ENABLE_DELETE_ALL_CHATS": true, "ENABLE_DELETE_CHAT": true, "ENABLE_LIST_GROUPS": true, "ENABLE_STORE_GROUP": true, "ENABLE_DELETE_GROUP": true, "ENABLE_CREATE_SOURCE": true, "ENABLE_EDIT_SOURCE": true, "ENABLE_DELETE_SOURCE": true, "ENABLE_GET_SOURCE": true, "ENABLE_LIST_SOURCES": true, "ENABLE_STORE_USER": true, "ENABLE_EDIT_USER": false, "ENABLE_DELETE_USER": false, "ENABLE_REACTIVATE_USER": true } }
Start the server:
node dist/index.js
The server will start and listen on stdio for MCP commands.
The server handles various error scenarios:
Errors are mapped to appropriate MCP error codes and include detailed messages for debugging.
Generate a password for the client and/or the server's Proxy_Config->Password entry:
node security/generate_encrypted_password.js ~/.ssh/id_rsa_public.pem
To check the encrytion use:
node security/generate_decrypted_password.js ~/.ssh/id_rsa
See the sections Encrypted Password Generation Tool
and Encrypted Password Decryption Tool
below for further information
The Encrypted Password Generation Tool is a Node.js script designed to securely encrypt user passwords using RSA public-key cryptography. This tool ensures that sensitive password data remains protected during transmission and storage by leveraging robust encryption mechanisms. It is an essential component for systems requiring secure password handling and transmission between clients and servers.
RSA_PKCS1_PADDING
, the script encrypts the entered password.id_rsa_public.pem
) used for encrypting the password.rm -rf node_modules package-lock.json npm cache clean --force npm install
Prepare Your RSA Public Key:
Ensure you have your RSA public key (id_rsa_public.pem
) stored securely on your MCP server.
Run the Script, you will find it at the security
directory of the MCP server:
Execute the script using Node.js, providing the path to your public key as a command-line argument.
node encrypt_password.js /path/to/your/id_rsa_public.pem
Example:
node security/encrypt_password.js ~/.ssh/id_rsa_public.pem
Enter Your Password: When prompted, input your password securely.
Please enter your password: ********
View the Encrypted Password: The script will output the encrypted password in Base64 format.
Encrypted Password: <Your_Encrypted_Password>
The Encrypted Password Decryption Tool is a Node.js script designed to securely decrypt encrypted passwords using RSA private-key cryptography. This tool ensures that sensitive password data remains protected during transmission and storage by leveraging robust encryption and decryption mechanisms. To verify or decrypt an encrypted password, use the private key. This is helpful to ensure that the encryption was performed correctly.
id_rsa
) on your MCP server used for decrypting the password.Prepare Your RSA Private Key:
Ensure you have your RSA private key (id_rsa
) stored securely on your machine.
Run the Script, you will find it at the security
directory of the MCP server::**
Execute the script using Node.js, providing the path to your private key as a command-line argument.
node decrypt_password.js /path/to/your/id_rsa
Example:
node decrypt_password.js ~/.ssh/id_rsa
Enter the Encrypted Password: When prompted, input the encrypted password in Base64 format.
Please enter the encrypted password: <Your_Encrypted_Password>
View the Decrypted Password: The script will output the decrypted plaintext password.
Decrypted Password: your_plaintext_password
This will decrypt the encrypted password and display the original value.
~/.ssh/id_rsa_public.pem
(public key) and ~/.ssh/id_rsa
(private key) files exist and have the correct permissions.This repository contains the MCP Server and all related client implementations.
Below you will find a complete directory structure as listed from the project root, including:
clients
(C# .Net, C++, Go, Java, JavaScript, PHP, Python),dist
,docs
,logs
,security
,src
,tests
,ver
,
and all subfolders/files.Note:
This is a direct directory listing with minimal commentary.
MCP-Server-for-MAS-Developments/ ├── dist │ └── public │ ├── index.html │ └── privateGPT-mcp-logo.png ├── docs │ └── images │ ├── alternative mcp client.png │ ├── mcp-general-architecture.png │ └── privateGPT-MCP.png ├── logs ├── security │ ├── generate_decrypted_password.js │ └── generate_encrypted_password.js ├── src │ ├── index.js │ ├── logger.js │ ├── privateGPT-messages.js │ ├── public │ │ ├── index.html │ │ └── privateGPT-mcp-logo.png │ ├── services │ │ └── privateGPT-service.ts │ └── types │ └── api.ts ├── tests ├── ver │ ├── index_np.js │ └── index_proxy_np.js └── clients ├── C# .Net │ ├── 1.0 mcp_login │ │ ├── bin │ │ │ └── Debug │ │ │ └── net9.0 │ │ ├── obj │ │ │ └── Debug │ │ │ └── net9.0 │ │ ├── mcp_login.csproj │ │ └── Program.cs │ ├── 1.1 mcp_logout │ │ ├── bin │ │ │ └── Debug │ │ │ └── net9.0 │ │ ├── obj │ │ │ └── Debug │ │ │ └── net9.0 │ │ ├── mcp_logout.csproj │ │ └── Program.cs │ ├── 2.0 mcp_chat │ │ ├── bin │ │ │ └── Debug │ │ │ └── net9.0 │ │ ├── obj │ │ │ └── Debug │ │ │ └── net9.0 │ │ ├── mcp_chat.csproj │ │ └── Program.cs │ ├── 2.1 mcp_continue_chat │ ├── 2.2 mcp_get_chat_info │ ├── 3.0 mcp_create_source │ ├── 3.1 mcp_get_source │ ├── 3.2 mcp_list_sources │ ├── 3.3 mcp_edit_source │ ├── 3.4 mcp_delete_source │ ├── 4.0 mcp_list_groups │ ├── 4.1 mcp_store_group │ ├── 4.2 mcp_delete_group │ ├── 5.0 mcp_store_user │ ├── 5.1 mcp_edit_user │ ├── 5.2 mcp_delete_user │ ├── Code Archiv │ │ ├── mcp_chat.cs │ │ ├── mcp_continue_chat.cs │ │ ├── ... │ │ └── mcp_store_user.cs │ └── README.md (14,924 bytes) ├── C++ │ ├── 1.0 mcp_login │ │ ├── MCPLoginClient.cpp │ │ └── MCPLoginClient.exe │ ├── 1.1 mcp_logout │ ├── 2.0 mcp_chat │ ├── 2.1 mcp_continue_chat │ ├── 2.2 mcp_get_chat_info │ ├── 3.0 mcp_create_source │ ├── 3.1 mcp_get_source │ ├── 3.2 mcp_list_sources │ ├── 3.3 mcp_edit_source │ ├── 3.4 mcp_delete_source │ ├── 4.0 mcp_list_groups │ ├── 4.1 mcp_store_group │ ├── 4.2 mcp_delete_group │ ├── 5.0 mcp_store_user │ ├── 5.1 mcp_edit_user │ ├── 5.2 mcp_delete_user │ ├── 9.0 mcp_keygen │ └── README.md (15,109 bytes) ├── Go │ ├── 1.0 mcp_login │ │ ├── MCPLoginClient.go │ │ └── MCPLoginClient.exe │ ├── 1.1 mcp_logout │ ├── 2.0 mcp_chat │ ├── 2.1 mcp_continue_chat │ ├── 2.2 mcp_get_chat_info │ ├── 3.0 mcp_create_source │ ├── 3.1 mcp_get_source │ ├── 3.2 mcp_list_sources │ ├── 3.3 mcp_edit_source │ ├── 3.4 mcp_delete_source │ ├── 4.0 mcp_list_groups │ ├── 4.1 mcp_store_group │ ├── 4.2 mcp_delete_group │ ├── 5.0 mcp_store_user │ ├── 5.1 mcp_edit_user │ ├── 5.2 mcp_delete_user │ ├── 9.0 mcp_keygen │ └── README.md (14,903 bytes) ├── Java │ ├── 1.0 mcp_login │ │ ├── json-20241224.jar │ │ ├── MCPLoginClient.class │ │ └── MCPLoginClient.java │ ├── 1.1 mcp_logout │ ├── 2.0 mcp_chat │ ├── 2.1 mcp_continue_chat │ ├── 2.2 mcp_get_chat_info │ ├── 3.0 mcp_create_source │ ├── 3.1 mcp_get_source │ ├── 3.2 mcp_list_sources │ ├── 3.3 mcp_edit_source │ ├── 3.4 mcp_delete_source │ ├── 4.0 mcp_list_groups │ ├── 4.1 mcp_store_group │ ├── 4.2 mcp_delete_group │ ├── 5.0 mcp_store_user │ ├── 5.1 mcp_edit_user │ ├── 5.2 mcp_delete_user │ └── README.md (16,208 bytes) ├── JavaScript │ ├── 1.0 mcp_login │ │ └── MCPLoginClient.js │ ├── 1.1 mcp_logout │ ├── 2.0 mcp_chat │ ├── 2.1 mcp_continue_chat │ ├── 2.2 mcp_get_chat_info │ ├── 3.0 mcp_create_source │ ├── 3.1 mcp_get_source │ ├── 3.2 mcp_list_sources │ ├── 3.3 mcp_edit_source │ ├── 3.4 mcp_delete_source │ ├── 4.0 mcp_list_groups │ ├── 4.1 mcp_store_group │ ├── 4.2 mcp_delete_group │ ├── 5.0 mcp_store_user │ ├── 5.1 mcp_edit_user │ ├── 5.2 mcp_delete_user │ ├── 9.0 mcp_keygen │ └── README.md (15,692 bytes) ├── PHP │ ├── 1.0 mcp_login │ │ └── MCPLoginClient.php │ ├── 1.1 mcp_logout │ ├── 2.0 mcp_chat │ ├── 2.1 mcp_continue_chat │ ├── 2.2 mcp_get_chat_info │ ├── 3.0 mcp_create_source │ ├── 3.1 mcp_get_source │ ├── 3.2 mcp_list_sources │ ├── 3.3 mcp_edit_source │ ├── 3.4 mcp_delete_source │ ├── 4.0 mcp_list_groups │ ├── 4.1 mcp_store_group │ ├── 4.2 mcp_delete_group │ ├── 5.0 mcp_store_user │ ├── 5.1 mcp_edit_user │ ├── 5.2 mcp_delete_user │ ├── 9.0 mcp_keygen │ └── README.md (15,636 bytes) └── Python ├── 1.0 mcp_login │ └── MCPLoginClient.py ├── 1.1 mcp_logout ├── 2.0 mcp_chat ├── 2.1 mcp_continue_chat ├── 2.2 mcp_get_chat_info ├── 3.0 mcp_create_source ├── 3.1 mcp_get_source ├── 3.2 mcp_list_sources ├── 3.3 mcp_edit_source ├── 3.4 mcp_delete_source ├── 4.0 mcp_list_groups ├── 4.1 mcp_store_group ├── 4.2 mcp_delete_group ├── 5.0 mcp_store_user ├── 5.1 mcp_edit_user ├── 5.2 mcp_delete_user ├── 9.0 mcp_keygen └── README.md (15,630 bytes)
This project is licensed under the MIT License - see the LICENSE file for details.