MCP Server Setup
How the Datasentinel MCP server is started, configured and secured with OAuth 2.1 in production, plus manual setup steps for sites upgrading from an older release.
This guide explains how to run the Datasentinel MCP server in production: how it is started, how it is configured, how clients authenticate, and (for sites upgrading from an older release) how to set it up by hand.
It is operations-focused. It covers how to run the server, not the tools it exposes. For what AI Connector does end to end, see the AI Connector overview. For what users experience when they sign in, see How authentication works.
At a glance
Entrypoint
datasentinel_mcp.py → mcp.run(transport=...)
Transport in production
streamable-http (set via DS_MCP_TRANSPORT)
Internal bind
DS_MCP_HOST (default 0.0.0.0) : DS_MCP_PORT (default 14311)
Public endpoint
nginx location /mcp → http://127.0.0.1:14311,
plus the OAuth locations (/.well-known/oauth-*, /authorize, /token, /register, /revoke, /oauth/login)
Public URL
https://<host name> by default;
DS_MCP_PUBLIC_URL, set on the datasentinel_mcp service, overrides it when the public name differs
Authentication
OAuth 2.1: the server is its own authorization server, users sign in with their platform login
OAuth state
/datasentinel/data/mcp_oauth/oauth.db (SQLite), must persist across restarts
systemd unit
/usr/lib/systemd/system/datasentinel_mcp.service
Start/stop scripts
scripts/backend_mcp_start.sh, scripts/backend_mcp_stop.sh
Manual setup on upgrade
If you are upgrading from a release that predates the MCP server (2026.10), the systemd unit, the service-control sudoers rules, and the nginx routes do not yet exist on your machine.
Set them up with the steps below. All paths use location /datasentinel/soft/datasentinel_backend.
Run the steps as a user with sudo. The service itself runs as the datasentinel user.
Grant the datasentinel user permission to manage the service
So the platform can stop, start, restart, and check the MCP service without a password prompt, grant the datasentinel group the matching systemctl rights. Add the lines below to /etc/sudoers.d/99-datasentinel-users. Edit the file with visudo so the syntax is validated before it is saved:
sudo visudo -f /etc/sudoers.d/99-datasentinel-users%datasentinel ALL=NOPASSWD: /bin/systemctl stop datasentinel_mcp
%datasentinel ALL=NOPASSWD: /bin/systemctl start datasentinel_mcp
%datasentinel ALL=NOPASSWD: /bin/systemctl status datasentinel_mcp
%datasentinel ALL=NOPASSWD: /bin/systemctl status datasentinel_mcp -l
%datasentinel ALL=NOPASSWD: /bin/systemctl restart datasentinel_mcpThese entries scope the datasentinel group to exactly the systemctl verbs it needs for the datasentinel_mcp service and nothing else.
Install the systemd service
Create /usr/lib/systemd/system/datasentinel_mcp.service:
[Unit]
Description=Datasentinel MCP Server
After=datasentinel_backend.service
[Service]
User=datasentinel
# MCP settings: see "How it is configured". Change them with a drop-in, not in this file.
Environment=DS_MCP_TRANSPORT=streamable-http
Environment=DS_MCP_HOST=0.0.0.0
Environment=DS_MCP_PORT=14311
Environment=DS_MCP_PUBLIC_URL=
Environment=DS_MCP_OAUTH_DIR=/datasentinel/data/mcp_oauth
Environment=DS_MCP_MAX_CONCURRENT_TOOLS=16
Environment=DS_API_VERIFY_TLS=
ExecStart=/datasentinel/soft/datasentinel_backend/scripts/backend_mcp_start.sh
ExecStop=/datasentinel/soft/datasentinel_backend/scripts/backend_mcp_stop.sh
KillSignal=SIGQUIT
Type=simple
Restart=on-failure
RestartSec=60s
[Install]
WantedBy=multi-user.targetReload systemd, enable at boot, and start:
sudo systemctl daemon-reload
sudo systemctl enable datasentinel_mcp
sudo systemctl start datasentinel_mcp
sudo systemctl status datasentinel_mcpAt this point the server is listening on 127.0.0.1:14311 but is not yet reachable through nginx.
Add the nginx location blocks
Edit the Datasentinel site file /etc/nginx/conf.d/datasentinel.conf.
Two things are added before the catch-all location / directive: the /mcp block, and the OAuth locations (the discovery documents, /authorize, /token, /register, /revoke, /oauth/login).
The OAuth routes are served at the root of the MCP application and cannot be moved under a prefix, which is why they need their own locations. None of them collides with a Grafana route.
The complete file, with the existing directives kept as they are and the new parts marked:
map $request_method $loggable {
default 1;
POST 0;
}
# --- NEW 2026.10: brute-force protection for the login form and the token endpoint -------------
limit_req_zone $binary_remote_addr zone=ds_oauth:1m rate=10r/m;
# --- END NEW 2026.10: brute-force protection -------------
server {
listen 443 ssl;
server_name default_server;
ssl_certificate /home/datasentinel/datasentinel/config/cert_datasentinel.pem;
ssl_certificate_key /home/datasentinel/datasentinel/config/key_datasentinel.pem;
access_log off;
client_max_body_size 100M;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
# --- existing Datasentinel services -------------------------------------------------
location /ds-api/pool {
proxy_set_header Host $remote_addr;
proxy_pass http://127.0.0.1:13300$request_uri;
}
location /ds-api {
proxy_set_header Host $remote_addr;
proxy_pass http://127.0.0.1:12324$request_uri;
}
# --- NEW 2026.10: MCP streamable-http endpoint and OAuth 2.1 discovery and authorization-server endpoints --------------------
location /mcp {
proxy_pass http://127.0.0.1:14311;
proxy_http_version 1.1;
proxy_buffering off;
proxy_cache off;
proxy_set_header Connection '';
proxy_set_header Host $host;
proxy_set_header Mcp-Session-Id $http_mcp_session_id;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
# /.well-known/oauth-protected-resource/mcp and /.well-known/oauth-authorization-server.
# ^~: a regex location on /.well-known (an ACME one, for example) must not take these requests.
location ^~ /.well-known/oauth- {
proxy_pass http://127.0.0.1:14311;
proxy_http_version 1.1;
proxy_set_header Host $host;
}
location = /authorize { # GET: starts the flow
proxy_pass http://127.0.0.1:14311;
proxy_http_version 1.1;
proxy_set_header Host $host;
}
location = /register { # POST: dynamic client registration
proxy_pass http://127.0.0.1:14311;
proxy_http_version 1.1;
proxy_set_header Host $host;
}
location = /revoke { # POST: optional
proxy_pass http://127.0.0.1:14311;
proxy_http_version 1.1;
proxy_set_header Host $host;
}
location = /oauth/login { # GET + POST: Datasentinel login form
limit_req zone=ds_oauth burst=5 nodelay;
proxy_pass http://127.0.0.1:14311;
proxy_http_version 1.1;
proxy_set_header Host $host;
}
location = /token { # POST: code / refresh exchange
limit_req zone=ds_oauth burst=5 nodelay;
proxy_pass http://127.0.0.1:14311;
proxy_http_version 1.1;
proxy_set_header Host $host;
}
# --- END NEW 2026.10: MCP streamable-http endpoint and OAuth 2.1
# --- Grafana frontend (catch-all) -----------------------
location / {
proxy_set_header Host $remote_addr;
proxy_pass http://127.0.0.1:3000$request_uri;
}
}
server {
listen 80;
server_name default_server;
access_log off;
return 301 https://$http_host$request_uri;
}location ~ /.well-known {
allow all;
root /tmp;
}Notes on the directives:
/mcp:proxy_buffering off/proxy_cache offlet streamed tool-call chunks reach the client immediately;proxy_set_header Connection ''preserves the upstream keep-alive stream; the one-hour timeouts exist because tool calls (reports, long queries) can run for minutes.The OAuth locations are ordinary short requests: no buffering or timeout overrides, and no URI part on
proxy_pass, so the request path reaches the MCP application unchanged.limit_reqon/oauth/loginand/tokenis the brute-force protection of the login form and the token endpoint (10 requests per minute per client address, burst of 5). It is not optional: the application has no lockout of its own.Authorizationis forwarded by nginx by default; do not strip it./tokenmust never answer a redirect, so keep it proxied directly.
If the public name of the platform is not the host name (a load balancer, a NAT, a DNS alias), set DS_MCP_PUBLIC_URL on the service with a systemd drop-in:
sudo systemctl edit datasentinel_mcpIn the editor, add:
[Service]
Environment=DS_MCP_PUBLIC_URL=https://<public-host>Do not set it in scripts/backend_mcp_start.sh: each upgrade replaces that script. See Change a setting.
Validate and reload:
sudo nginx -t
sudo systemctl reload nginx
sudo systemctl restart datasentinel_mcpVerify
Look at Verify the install.
To look at the answers yourself:
# service up
sudo systemctl status datasentinel_mcp
# internal listener: 401 with a WWW-Authenticate challenge is the healthy answer
curl -s -i http://127.0.0.1:14311/mcp | head -3
# end-to-end through nginx: the same challenge, then the two OAuth discovery documents
curl -s -i https://<public-host>/mcp | head -3
curl -s https://<public-host>/.well-known/oauth-protected-resource/mcp
curl -s https://<public-host>/.well-known/oauth-authorization-serverEvery URL in the two discovery documents, and the resource_metadata URL in the challenge, must start with the public origin clients use.
Fresh install
On a fresh Datasentinel install, the MCP server is provisioned automatically. You do not need to create anything by hand. This section just explains how it is started, how it is configured, and how it is secured so you can operate and troubleshoot it.
Verify the install
A health-check helper ships in scripts/mcp_check.sh. Run it on the platform host after a fresh install, after the manual setup on upgrade, and whenever you change a setting, the nginx configuration or the certificate:
It mints a token for the check user, then runs five checks and prints a readable summary:
Internal MCP server
Connects to the internal listener (http://localhost:14311/mcp), counts the tools and calls the platform status tool, which lists every platform service as running or stopped.
Nginx certificate
Describes the certificate nginx presents on the public URL: who it is issued to, who issued it, when it expires, and whether clients will trust it.
Public access through nginx
Connects to <public URL>/mcp through nginx, the way an assistant does.
OAuth routes on the internal MCP server
Probes every OAuth route on the internal listener: the two discovery documents, /mcp, /authorize, /register, /token, /revoke and /oauth/login.
OAuth routes through nginx
Probes the same routes on the public URL, which shows that nginx has a location for each of them.
The script finds the public URL the way the server does: DS_MCP_PUBLIC_URL from the environment or from the datasentinel_mcp unit, else https://<machine name>. The Public URL line of the output says which one was used.
The last line gives the verdict, and the exit code follows it:
OK
0
The five checks pass.
WARNING
0
The server works, but the certificate is not trusted (self-signed, unknown CA, or a name that does not match the public URL) or expires in less than 30 days. The output says what to do.
FAILED
1
The internal listener or the public URL cannot be reached, a platform service is stopped, the platform status is not OK, the certificate has expired, or an OAuth route does not answer as the MCP server should.
The OAuth route probes
Each probe is an incomplete request, sent on purpose: the server refuses it with its own error, so nothing is registered, issued or revoked. Only the MCP server's own answer passes. A failing route shows the reason on its line:
HTTP 404 - not routed to the MCP server
The nginx location of that route is missing, or another location took the request.
redirected to ...
Another location caught the request, usually the Grafana catch-all location /.
resource is ..., expected ...
issuer is ..., expected ...
A discovery document announces another host name than the public URL: check DS_MCP_PUBLIC_URL.
missing ...
The authorization server document lacks an endpoint.
no WWW-Authenticate header with resource_metadata
/mcp did not answer with the authentication challenge.
not an OAuth error answer from the MCP server
not the Datasentinel login page
Something other than the MCP server answered on that route.
The internal probes run first. A route that passes internally and fails through nginx is an nginx problem: see the nginx step of the manual setup.
Add --json to also print the raw answer of the platform status tool:
How it is started
The MCP server runs as a dedicated systemd service, datasentinel_mcp.service, which starts after the backend API service and stays up on failure:
The control flow is:
nginx terminates client traffic and proxies the /mcp path and the OAuth routes to the internal port 14311 (see the nginx step under Manual setup on upgrade). Clients therefore connect to the public nginx URL, never directly to 14311.
Everyday operation:
How it is configured
Configuration is entirely through environment variables read at process start. They are set by the Environment= lines of the datasentinel_mcp unit, which lists all of them. The start script sets none: each upgrade replaces it. An empty value (DS_MCP_PUBLIC_URL=, DS_API_VERIFY_TLS=) means the default shown below.
DS_MCP_TRANSPORT
streamable-http
Transport (sse only for local runs without nginx)
DS_MCP_HOST
0.0.0.0
Bind address for the MCP listener
DS_MCP_PORT
14311
Bind port for the MCP listener (nginx upstream)
DS_MCP_PUBLIC_URL
https://<host name>
The external HTTPS origin served by nginx, no path. Everything is derived from it: the OAuth discovery documents, the login page URL, and the server's own calls to the platform API. The default is the machine's fully qualified name, correct when nginx runs on the platform host under its own name. Set it only when the public name differs (load balancer, NAT, DNS alias).
DS_MCP_OAUTH_DIR
/datasentinel/data/mcp_oauth
Directory of the OAuth store (oauth.db), created on first start with owner-only permissions
DS_MCP_MAX_CONCURRENT_TOOLS
16
How many tool calls may run at once. Each one holds a database connection and builds its answer in memory. Raise it for a large fleet with many concurrent users. Lower it if the platform host is short of memory.
DS_API_VERIFY_TLS
empty (no verification)
1 (or true, yes) makes the server verify the nginx certificate on its own calls to the platform API. Use it only with a CA-signed certificate: the default nginx certificate is self-signed.
Change a setting
Do not edit the unit file: a new installation rewrites it. Put the change in a systemd drop-in instead. It survives upgrades and reinstallations:
In the editor, add only the lines to change. For example:
systemd saves the file as /etc/systemd/system/datasentinel_mcp.service.d/override.conf and reloads itself. Restart the service and check the values it runs with:
A platform installed with an older release may have a unit without Environment= lines. The server then runs on the defaults above, and a drop-in works the same way.
How clients authenticate
The server is protected by OAuth 2.1 and is its own authorization server. No token is configured on the server side, and the tools take no token argument.
Certificates
OAuth exposes the nginx certificate to consumers that did not see it before:
The user's browser, on the login page: a self-signed certificate shows a warning, which is survivable.
The assistant's own HTTP client, which fetches the discovery documents, registers and exchanges tokens. Claude Code and the other CLIs reject untrusted certificates: the machine running the assistant needs a certificate it trusts, either a CA-signed certificate on nginx or the internal CA installed on that machine. This applies equally to a headless server running a CLI over SSH.
Cloud-hosted assistants (Claude, ChatGPT, Microsoft Copilot) need the nginx endpoint reachable from the internet with a publicly trusted certificate; there is no workaround.
See Self-signed and untrusted TLS certificates for the per-assistant options.
Data directory
The OAuth state lives in one SQLite database, /datasentinel/data/mcp_oauth/oauth.db, created by the service on first start with owner-only permissions. It holds the registered clients, the hashed refresh tokens, and the sign-ins in progress.
It must survive restarts and upgrades. In Docker,
/datasentinel/datamust be a persistent volume.It is not part of the platform backup: the file is rebuilt by use. If it is lost, every assistant user signs in again on the login page (one browser step, no data lost) and assistants re-register by themselves.
Never copy
oauth.dbwhile the service runs: the database is in write-ahead-log mode and a raw copy of an open database is inconsistent. Stop the service first, or usesqlite3 oauth.db ".backup <file>".
To list the sessions held in this store, end them, or check the store's integrity, use the mcp_oauth_sessions.sh script described in Manage assistant sessions.
Logs
/datasentinel/log/mcp.log records every tool call and every authentication event, one line each, with the user's email and never a token value or a password: client registration, sign-in accepted or refused, tokens issued by code exchange or by refresh, tokens revoked, bearers rejected.
Every line carries session=<id>, the MCP session it belongs to, and the first tool call of a session prints session opened for <email>. To follow one session:
The HTTP access log of the OAuth routes is not in this file: it goes to the service output (journalctl -u datasentinel_mcp).
Last updated