-
Notifications
You must be signed in to change notification settings - Fork 9
How to setup and test the MCP server with a dev certificate (TLS)
In order to create a self-signed certificate that can be trusted by your browser, first, create a configuration file named, e.g., openssl.cnf. An example of a minimal configuration file is shown below
[ req ]
default_bits = 2048
prompt = no
default_md = sha256
distinguished_name = dn
x509_extensions = v3_req
[ dn ]
CN = localhost
[ v3_req ]
subjectAltName = @alt_names
keyUsage = critical, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
[ alt_names ]
DNS.1 = localhost
IP.1 = 127.0.0.1
Then, run the command
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt -config openssl.cnf
The following two files will be generated:
-
server.keythat contains the private key -
server.crtthat contains the certificate.
Add the paths to these two files to the MCP configuration file by setting the two configuration variables
TLS_KEY_PATHTLS_CERT_PATH
In order to run Node.js applications that accept self-signed certificates, use the setting NODE_TLS_REJECT_UNAUTHORIZED=0 before the commands node or npx.
For instance, NODE_TLS_REJECT_UNAUTHORIZED=0 should be used in the following cases:
- in the command to run the MCP Inspector, when you wish to test an MCP server using a self-signed certificate in proxy mode, i.e.,
NODE_TLS_REJECT_UNAUTHORIZED=0 npx @modelcontextprotocol/inspector
- in the command to run the mcp-remote when the MCP server is using a self-signed certificate; if the mcp-remote is executed by Claude Desktop, add the following server configuration to its configuration file
~/Library/Application\ Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"Apache OFBiz mcp server": {
"command": "npx",
"args": ["-y", "mcp-remote", "https://localhost:3000/mcp"],
"env": {
"NODE_TLS_REJECT_UNAUTHORIZED": "0"
}
}
}
}
- in the command to run the MCP server when OFBiz is using a self-signed certificate, i.e.,
NODE_TLS_REJECT_UNAUTHORIZED=0 node ./build/server.js path_to_configuration_folder path_to_tools_folder
In order to use a browser to connect to an MCP server running over TLS with a self-signed certificate—for instance, to test the MCP server with the Inspector in ‘direct’ connection mode—you need to make the browser accept your self-signed certificate.
The recommended way to do this is to import the certificate into your Operating System's trust store.
On macOS, certificates are imported and trusted via Keychain Access as follows.
- Open Keychain Access
- Select System from the sidebar
- From the File menu, select ‘Import Items...’, then browse to your .crt certificate and click on 'Open'
- Double-click on the certificate, expand the 'Trust' section and set 'When using this certificate' to
Always Trust