---
title: "View source for AI Services/Mcp Server Deployment - DreamFactory Wiki"
source: "https://wiki.dreamfactory.com/index.php?action=edit&title=AI_Services%2FMcp_Server_Deployment"
canonical_url: "https://wiki.dreamfactory.com/index.php?action=edit&title=AI_Services%2FMcp_Server_Deployment"
converted_at: "2026-11-23T12:08:38.097Z"
format: "markdown"
converted_by: "html-to-md-ai"
---
[]()
	
	
	
	# View source for AI Services/Mcp Server Deployment

	
		
		← [AI Services/Mcp Server Deployment](/AI_Services/Mcp_Server_Deployment)
		
		
		
		[Jump to navigation](#mw-head)
		[Jump to search](#searchInput)
		You do not have permission to edit this page, for the following reason:

The action you have requested is limited to users in the group: [Users](/index.php?title=DreamFactory_Wiki:Users&action=edit&redlink=1).---

You can view and copy the source of this page.

{{#seo:
|title=Deploying the MCP Server - DreamFactory Documentation
|title_mode=replace
|description=Install, daemonize, and configure the DreamFactory MCP server, including running behind a reverse proxy or load balancer.
|keywords=MCP, Model Context Protocol, daemon, systemd, reverse proxy, load balancer, deployment, OAuth
|og:title=Deploying the MCP Server
|og:type=article
|og:site_name=DreamFactory Documentation
|og:description=Install, daemonize, and configure the DreamFactory MCP server, including running behind a reverse proxy or load balancer.
}}
'''Install, daemonize, and configure the DreamFactory MCP server, including running behind a reverse proxy or load balancer.'''

&lt;span id="deploying-the-mcp-server">&lt;/span>
= Deploying the MCP Server =

This guide covers installing and operating the MCP server on your DreamFactory host: the Node.js daemon, configuration, and running behind a reverse proxy.

* To create an MCP service in the admin interface, see [[AI_Services/Mcp_Service_Creation|Creating an MCP Server Service]].
* For the available tools, request format, and required headers, see [[AI_Services/Mcp_Service|MCP Server]].

&lt;span id="overview">&lt;/span>
== Overview ==

The MCP server runs in two parts on your DreamFactory host:

* '''PHP routes''' served by DreamFactory at &lt;code>/mcp/{service}&lt;/code>
* '''A Node.js daemon''' that handles the MCP protocol layer (the PHP side forwards to it)

Clients connect to &lt;code>https://&amp;lt;host&amp;gt;/mcp/{service}&lt;/code> — never directly to the daemon.

&lt;span id="prerequisites">&lt;/span>
== Prerequisites ==

A working DreamFactory installation, plus the following '''on the server''':

&lt;ul>
&lt;li>&lt;p>'''Node.js 20+ and npm''' — required to build and run the daemon. On Ubuntu:&lt;/p>
&lt;syntaxhighlight lang="bash">curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
node -v &amp;&amp; npm -v&lt;/syntaxhighlight>&lt;/li>
&lt;li>&lt;p>The &lt;code>dreamfactory/df-mcp-server&lt;/code> package (included in the commercial composer set).&lt;/p>&lt;/li>&lt;/ul>

Confirm the package and routes are present:

&lt;syntaxhighlight lang="bash">ls vendor/dreamfactory/df-mcp-server
php artisan route:list | grep '/mcp/'&lt;/syntaxhighlight>
&lt;span id="the-mcp-daemon">&lt;/span>
== The MCP daemon ==

The daemon lives under &lt;code>vendor/dreamfactory/df-mcp-server/daemon/&lt;/code> and listens on &lt;code>127.0.0.1:8006&lt;/code>.

Build it:

&lt;syntaxhighlight lang="bash">cd vendor/dreamfactory/df-mcp-server/daemon
npm install
npm run build&lt;/syntaxhighlight>
Run it via the shipped start script:

&lt;syntaxhighlight lang="bash">vendor/dreamfactory/df-mcp-server/scripts/start-daemon.sh&lt;/syntaxhighlight>
&lt;span id="daemonizing-for-production">&lt;/span>
=== Daemonizing for production ===

No systemd unit ships by default. Add one so the daemon starts on boot and restarts on crash — &lt;code>/etc/systemd/system/df-mcp-daemon.service&lt;/code>:

&lt;syntaxhighlight lang="ini">[Unit]
Description=DreamFactory MCP Daemon
After=network.target

[Service]
Type=simple
User=www-data
ExecStart=/opt/dreamfactory/vendor/dreamfactory/df-mcp-server/scripts/start-daemon.sh
Restart=always
RestartSec=5
StandardOutput=journal
StandardError=journal
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target&lt;/syntaxhighlight>
&lt;syntaxhighlight lang="bash">sudo systemctl daemon-reload
sudo systemctl enable --now df-mcp-daemon
sudo systemctl status df-mcp-daemon&lt;/syntaxhighlight>
&lt;span id="viewing-the-daemon-logs">&lt;/span>
=== Viewing the daemon logs ===

Because the unit sends output to the journal (&lt;code>StandardOutput=journal&lt;/code>), read the daemon's logs with &lt;code>journalctl&lt;/code>:

&lt;syntaxhighlight lang="bash">sudo journalctl -u df-mcp-daemon -f             # follow live
sudo journalctl -u df-mcp-daemon -n 100         # last 100 lines
sudo journalctl -u df-mcp-daemon --since "15 min ago"&lt;/syntaxhighlight>
{{Tip|1=Point &lt;code>ExecStart&lt;/code> at the shipped &lt;code>start-daemon.sh&lt;/code>, which runs the compiled &lt;code>dist/server.js&lt;/code>. Don't point it at &lt;code>tsx&lt;/code> — that's a dev-only dependency and is removed by a production &lt;code>npm install --omit=dev&lt;/code>.}}

{{Note|In the Docker/compose stack, the daemon starts automatically when &lt;code>ENABLE_MCP_DAEMON&lt;/code> is set, so no systemd unit is needed.}}
&lt;span id="configuration">&lt;/span>
== Configuration ==

Set these in your DreamFactory &lt;code>.env&lt;/code>:

{| class="wikitable"
|-
! Variable
! Set to
! Notes
|-
| &lt;code>APP_URL&lt;/code>
| &lt;code>https://df.example.com&lt;/code>
| The external URL clients use. Not &lt;code>http://localhost&lt;/code>.
|-
| &lt;code>DF_FRONTEND_URL&lt;/code>
| ''(optional)''
| Override only if the admin SPA is on a different host.
|-
| &lt;code>LOG_LEVEL&lt;/code>
| &lt;code>warning&lt;/code>
| Set to &lt;code>debug&lt;/code> while troubleshooting OAuth, then revert.
|}

{{Warning|&lt;code>APP_URL&lt;/code> must be the '''external HTTPS URL''' clients reach. It drives the OAuth discovery and callback URLs as well as server-side session validation. If it is left as &lt;code>http://localhost&lt;/code> (or any value clients can't reach), MCP authentication fails — typically as a login page that loops.}}

Verify the value actually in use:

&lt;syntaxhighlight lang="bash">php artisan tinker --execute="echo config('app.url');"&lt;/syntaxhighlight>
&lt;span id="applying-configuration-changes">&lt;/span>
== Applying configuration changes ==

DreamFactory caches configuration, so editing &lt;code>.env&lt;/code> alone is not enough:

&lt;syntaxhighlight lang="bash">php artisan config:clear            # required — .env is ignored while config is cached
php artisan config:cache            # only if you run cached config in production
sudo systemctl restart php8.5-fpm   # use your PHP version; also clears OPcache&lt;/syntaxhighlight>
* '''Don't''' run &lt;code>php artisan&lt;/code> as &lt;code>root&lt;/code> — it creates root-owned cache files that PHP-FPM can't read, causing 500s. Run it as a normal user. If it already happened, reset ownership to your web-server user, e.g. &lt;code>sudo chown -R www-data:www-data storage bootstrap/cache&lt;/code>.
* '''Don't''' rely on a PHP-FPM restart alone to apply &lt;code>.env&lt;/code> changes — run &lt;code>config:clear&lt;/code> first.
* Restart PHP-FPM after editing any vendor PHP file (OPcache won't pick it up otherwise).

&lt;span id="running-behind-a-reverse-proxy">&lt;/span>
== Running behind a reverse proxy ==

When a proxy (AWS ALB, nginx, Cloudflare) terminates TLS and forwards traffic to DreamFactory, the one thing you must do is set &lt;code>APP_URL&lt;/code> to the external HTTPS URL (see [[#configuration|Configuration]]). That is sufficient for most deployments.

After applying the change, confirm OAuth discovery advertises '''https''' URLs:

&lt;syntaxhighlight lang="bash">curl -s https://df.example.com/.well-known/oauth-authorization-server/mcp/&lt;service> \
  | jq -r '.issuer, .authorization_endpoint'&lt;/syntaxhighlight>
If those URLs come back as &lt;code>https://…&lt;/code>, no further proxy configuration is needed.

&lt;span id="only-if-discovery-still-shows-http">&lt;/span>
=== Only if discovery still shows &lt;code>http://&lt;/code> ===

This means the proxy's scheme isn't reaching PHP. Pass it through in your nginx site:

&lt;syntaxhighlight lang="nginx"># in the http { } block
map $http_x_forwarded_proto $fcgi_https { default off; https on; }

# in server { } -> location ~ \.php$ { }
fastcgi_param HTTPS $fcgi_https;&lt;/syntaxhighlight>
&lt;syntaxhighlight lang="bash">sudo nginx -t &amp;&amp; sudo systemctl reload nginx&lt;/syntaxhighlight>
For correct behavior across the rest of DreamFactory behind a proxy (redirects, secure cookies, client IPs in logs), also trust the proxy in &lt;code>app/Http/Middleware/TrustProxies.php&lt;/code>:

&lt;syntaxhighlight lang="php">protected $proxies = '*';   // or your load balancer / subnet CIDRs
protected $headers =
    Request::HEADER_X_FORWARDED_FOR  | Request::HEADER_X_FORWARDED_HOST |
    Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO;&lt;/syntaxhighlight>
&lt;span id="connecting-a-client">&lt;/span>
== Connecting a client ==

After [[AI_Services/Mcp_Service_Creation|creating an MCP service]], point your client at &lt;code>https://&amp;lt;host&amp;gt;/mcp/{service}&lt;/code>:

* '''No trailing slash''' — a trailing slash breaks OAuth discovery.
* '''Not''' &lt;code>/api/v2/...&lt;/code> — that is the REST API and returns &lt;code>400 No session token or API Key&lt;/code>.

Example VS Code &lt;code>mcp.json&lt;/code>:

&lt;syntaxhighlight lang="json">{
  "servers": {
    "df-poc": { "type": "http", "url": "https://df.example.com/mcp/poc" }
  }
}&lt;/syntaxhighlight>
{{Note|Native clients (VS Code, Cursor, Claude Desktop) receive the OAuth code on a rotating &lt;code>http://127.0.0.1:&amp;lt;port&amp;gt;/&lt;/code> listener. If you see &lt;code>redirect_uri is not registered for this client&lt;/code>, free up the client's preferred fixed port (VS Code uses &lt;code>33418&lt;/code>) and reconnect.}}

For tool calls and the full list of required headers, see [[AI_Services/Mcp_Service#required-headers|MCP Server]].

&lt;span id="troubleshooting">&lt;/span>
== Troubleshooting ==

Enable debug logging first — OAuth failures are otherwise silent. Set &lt;code>LOG_LEVEL=debug&lt;/code>, run &lt;code>config:clear&lt;/code>, then:

&lt;syntaxhighlight lang="bash">tail -f storage/logs/dreamfactory.log
sudo tail -f /var/log/nginx/access.log | grep -E "oauth-callback|user/session"&lt;/syntaxhighlight>
{| class="wikitable"
|-
! Symptom
! Fix
|-
| Login page loops or flickers
| Set &lt;code>APP_URL&lt;/code> to the external HTTPS URL, &lt;code>config:clear&lt;/code>, restart PHP-FPM
|-
| Discovery advertises &lt;code>http://&lt;/code> URLs
| Set &lt;code>APP_URL&lt;/code> + TrustProxies + nginx &lt;code>HTTPS&lt;/code> param
|-
| &lt;code>400 No session token or API Key&lt;/code>
| Client URL points at &lt;code>/api/v2/...&lt;/code> — use &lt;code>/mcp/{service}&lt;/code>
|-
| &lt;code>.well-known&lt;/code> returns 404
| Use the service-scoped path &lt;code>/.well-known/oauth-authorization-server/mcp/{service}&lt;/code>
|-
| &lt;code>redirect_uri is not registered&lt;/code>
| Rotating loopback port — free/reuse the client's fixed port and reconnect
|-
| 404 on all &lt;code>/mcp/*&lt;/code>
| Confirm the package is installed, then &lt;code>php artisan route:clear&lt;/code>
|-
| Config change has no effect
| Run &lt;code>config:clear&lt;/code> (not just a PHP-FPM restart); ensure cache files aren't root-owned
|}

&lt;span id="see-also">&lt;/span>
== See also ==

* [[AI_Services/Mcp_Service|MCP Server]] — protocol overview, tools, and request format
* [[AI_Services/Mcp_Service_Creation|Creating an MCP Server Service]]
* [[AI_Services/Mcp_Custom_Login_Page|Custom Login Page for MCP]]

[[Category:Mcp]]
[[Category:Model_Context_Protocol]]
[[Category:Ai_Integration]]
[[Category:Difficulty_Advanced]]
Templates used on this page:

- [Template:Note](/Template:Note) ([view source](/index.php?title=Template:Note&action=edit))
- [Template:Tip](/Template:Tip) ([view source](/index.php?title=Template:Tip&action=edit))
- [Template:Warning](/Template:Warning) ([view source](/index.php?title=Template:Warning&action=edit))

Return to [AI Services/Mcp Server Deployment](/AI_Services/Mcp_Server_Deployment).

Retrieved from "[https://wiki.dreamfactory.com/AI_Services/Mcp_Server_Deployment](https://wiki.dreamfactory.com/AI_Services/Mcp_Server_Deployment)"