Skip to content

Remote MCP Server Configuration

Added in v1.8.0

Remote Model Context Protocol (MCP) server support is available starting in Coneshare v1.8.0.

Optional Component & Zero Idle Overhead

The Remote MCP Server is completely optional.

While the lightweight service container runs by default in the Docker stack, it binds exclusively to the host loopback interface (127.0.0.1:18999) and remains entirely inaccessible from external networks unless a system administrator explicitly configures Nginx to route traffic to it.

When not exposed or actively serving AI agent requests, the service sits idle and consumes virtually zero CPU and negligible memory. If your team does not use AI assistants or desktop agents, you can simply skip the /mcp/ and /.well-known/oauth-protected-resource Nginx configuration without impacting any standard Coneshare functionality.

Coneshare provides an official Remote MCP Server (coneshare-mcp) that enables both Web AI clients (such as ChatGPT, Claude, Gemini, and Grok via OAuth 2.1) and CLI / desktop clients (such as Claude Desktop, Claude Code CLI, Antigravity CLI agy, and Codex / VS Code via API keys) to interact directly with your Coneshare instance over secure HTTP/SSE streams.


Architectural Overview

The MCP server runs as a lightweight service in the Docker Compose stack, exposing an HTTP/SSE endpoint at path /mcp/sse.

+-------------------------------------------------------------+
|                      AI Agent Clients                       |
|  Web AI (OAuth 2.1)         |  CLI / Desktop (API Key)      |
|  ChatGPT, Claude, Gemini,   |  Claude Desktop, Claude Code, |
|  Grok                       |  Antigravity (agy), Codex     |
+-------------------------------------------------------------+
                              |
                              |  HTTPS / SSE
                              |  (Bearer <oauth_token> or cs_live_...)
                              v
+-------------------------------------------------------------+
|                     Nginx Reverse Proxy                     |
|    (Public Port 443 / SSL, SSE & .well-known Routing)       |
+-------------------------------------------------------------+
          |                                       |
          | /mcp/ &                               | / &
          | /.well-known/oauth-protected-resource | /.well-known/oauth-authorization-server
          v                                       v
+----------------------------------+    +---------------------+
|  Coneshare Remote MCP Server     |--->|  Coneshare Web      |
|  (Host :18999 -> Container :8001)|    |  (Django :8000)     |
+----------------------------------+    +---------------------+
  • Public Endpoint Path: https://your-domain.com/mcp/sse (Port 443 via Nginx)
  • OAuth Discovery Endpoints:
  • Protected Resource Metadata (RFC 9728): https://your-domain.com/.well-known/oauth-protected-resource (routed to coneshare_mcp)
  • Authorization Server Metadata (RFC 8414): https://your-domain.com/.well-known/oauth-authorization-server (routed to coneshare_web)
  • Host Loopback Port: 18999 (bound to 127.0.0.1:18999 by default)
  • MCP Container Port: 8001 (coneshare-mcp service)
  • Backend Internal Communication: Communicates directly over the Docker internal network (http://web:80/api/v1)
  • Authentication: Dual-mode, per-user authentication supporting OAuth 2.1 (Authorization Code + PKCE S256) for Web AI clients and Personal API Keys (cs_live_...) for CLI/desktop tools. No master API key is stored on the server.

Complete Nginx Reverse Proxy Configuration

Below is the full, production-ready Nginx configuration enabling standard Coneshare web traffic, the Remote MCP Server endpoint, and OAuth 2.1 discovery metadata over HTTPS:

# ------------------------------------------------------------------------------
# Coneshare Web App Upstream
# ------------------------------------------------------------------------------
upstream coneshare_web {
  server localhost:8999 fail_timeout=0;
}

# ------------------------------------------------------------------------------
# Remote MCP Server Upstream (maps to host loopback port 18999)
# ------------------------------------------------------------------------------
upstream coneshare_mcp {
  server localhost:18999 fail_timeout=0;
}

server {
    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;
    server_name coneshare.example.com; # managed by Certbot
    client_max_body_size 1G;

    # ------------------------------------------------------------------------------
    # OAuth 2.1 Protected Resource Metadata (RFC 9728)
    # Required for Web AI clients (ChatGPT, Claude, Gemini, Grok) using OAuth 2.1.
    # Optional if you only use CLI/desktop clients with static cs_live_... API keys.
    # ------------------------------------------------------------------------------
    location /.well-known/oauth-protected-resource {
        proxy_pass http://coneshare_mcp;

        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    # ------------------------------------------------------------------------------
    # Remote MCP Server Stream & Gateway (https://coneshare.example.com/mcp/sse)
    # ------------------------------------------------------------------------------
    location /mcp/ {
        proxy_pass http://coneshare_mcp;

        # Disable proxy buffering for long-lived Server-Sent Events (SSE) streams
        proxy_http_version 1.1;
        proxy_set_header Connection '';
        proxy_set_header Chunked_Transfer_Encoding off;
        proxy_buffering off;
        proxy_cache off;

        # Extended timeouts for persistent SSE connections (24 hours)
        proxy_read_timeout 86400s;
        proxy_send_timeout 86400s;

        # Forward real client IP and headers (including Authorization Bearer tokens)
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Authorization $http_authorization;

        proxy_redirect off;
    }

    # ------------------------------------------------------------------------------
    # Coneshare Web Application, REST API & OAuth 2.1 Authorization Server
    # (Serves /.well-known/oauth-authorization-server, /oauth/authorize, /api/v1/oauth/)
    # ------------------------------------------------------------------------------
    location / {
        try_files $uri @proxy_to_app;
    }

    location @proxy_to_app {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://coneshare_web;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/coneshare.example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/coneshare.example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

# ------------------------------------------------------------------------------
# HTTP to HTTPS Redirect
# ------------------------------------------------------------------------------
server {
    if ($host = coneshare.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    listen [::]:80;
    server_name coneshare.example.com;
    return 404; # managed by Certbot
}

Mandatory Nginx Directives Explained

When proxying MCP traffic for Web AI and CLI agents, four configuration requirements must be met:

  1. proxy_buffering off; and proxy_cache off;
    Nginx buffers response streams in memory by default. Disabling buffering ensures MCP tool responses and JSON-RPC message chunks are flushed immediately to connected AI clients without delay.

  2. proxy_read_timeout 86400s; and proxy_send_timeout 86400s;
    AI coding and chat sessions remain connected for extended periods. Setting the timeout to 24 hours prevents Nginx from prematurely closing idle SSE streams between tool invocations.

  3. proxy_set_header Authorization $http_authorization;
    The Coneshare MCP server is stateless and forwards incoming Bearer credentials (either an OAuth 2.1 access token or a static cs_live_... API key) from connection headers. If this header is omitted, tool calls will fail with 401 Unauthorized.

  4. location /.well-known/oauth-protected-resource
    Web AI clients use RFC 9728 discovery at /.well-known/oauth-protected-resource (or /.well-known/oauth-protected-resource/mcp/sse) to locate the Coneshare OAuth authorization server. Because this metadata is served by coneshare-mcp rather than the Django web container, it must be proxied to coneshare_mcp.


Application Configuration (app.env)

Ensure your /opt/coneshare/app.env file has SITE_DOMAIN set to your public Coneshare URL (for example https://your-domain.com or http://192.168.1.10) and includes the MCP server settings:

# ------------------------------------------------------------------------------
# Remote MCP Server (coneshare-mcp)
# ------------------------------------------------------------------------------
# Target REST API URL as seen from mcp_server container
CONESHARE_API_URL=http://web:80/api/v1

# Transport mode (streamable-http or sse)
MCP_TRANSPORT=streamable-http

# HTTP SSE endpoint path
MCP_PATH=/mcp/sse

# ------------------------------------------------------------------------------
# OAuth 2.1 Support (Required for Web AI Clients)
# ------------------------------------------------------------------------------
# Enable OAuth 2.1 Protected Resource metadata (RFC 9728) and Bearer verification (default: false).
# Required for Web AI clients; public MCP URL and OAuth issuer are derived from SITE_DOMAIN.
CONESHARE_OAUTH_ENABLED=true

# Optional: Comma-separated trusted OAuth client domain allowlist for DCR redirect URIs.
# Defaults to ChatGPT/OpenAI, Claude, Google/Gemini, and Grok web domains:
# OAUTH_ALLOWED_CLIENT_DOMAINS=.chatgpt.com,.openai.com,.claude.ai,.google.com,.googleusercontent.com,.grok.com,.x.ai

# Optional: Allow http://localhost:<port> loopback redirect URIs for local OAuth clients (default: false)
OAUTH_ALLOW_LOCALHOST_LOOPBACK=false

Derived from SITE_DOMAIN

Both the OAuth issuer (/.well-known/oauth-authorization-server) and the MCP protected-resource URL (${SITE_DOMAIN}/mcp/sse) are derived automatically from SITE_DOMAIN in app.env. Make sure SITE_DOMAIN matches the URL your clients use to access Coneshare (e.g. https://your-domain.com).

Restart the Service

After updating /opt/coneshare/app.env, restart the Coneshare services to apply the changes:

cd /opt/coneshare
./start.sh

Verifying the Deployment

After restarting Coneshare and reloading Nginx (sudo nginx -t && sudo nginx -s reload), verify both the MCP endpoint and OAuth discovery metadata:

1. Verify the MCP Endpoint

curl -i -N -H "Accept: text/event-stream" https://your-domain.com/mcp/sse

With CONESHARE_OAUTH_ENABLED=true configured in app.env, an unauthenticated request returns 401 Unauthorized with a WWW-Authenticate discovery challenge:

HTTP/1.1 401 Unauthorized
Server: nginx/...
Content-Type: application/json
WWW-Authenticate: Bearer resource_metadata="https://your-domain.com/.well-known/oauth-protected-resource/mcp/sse"

Why 401 Unauthorized confirms the setup is OK

Receiving 401 Unauthorized with the WWW-Authenticate: Bearer resource_metadata="..." header confirms that:

  1. Nginx successfully routed /mcp/ to coneshare_mcp on port 18999.
  2. coneshare-mcp is running with OAuth 2.1 middleware enabled and advertising the RFC 9728 metadata URL.

(Note: With the default CONESHARE_OAUTH_ENABLED=false—or if you leave OAuth disabled when using only static cs_live_... API keys—the same curl test returns 400 Bad Request with {"jsonrpc":"2.0","error":{"code":-32600,"message":"Bad Request: Missing session ID"}}.)

2. Verify OAuth Discovery Metadata (Web AI Clients)

curl -s https://your-domain.com/.well-known/oauth-protected-resource
curl -s https://your-domain.com/.well-known/oauth-authorization-server
  • The first endpoint (served by coneshare-mcp) should return JSON containing "resource": "https://your-domain.com/mcp/sse" and "authorization_servers": ["https://your-domain.com/"].
  • The second endpoint (served by the Django backend) should return JSON containing "authorization_endpoint": "https://your-domain.com/oauth/authorize", "token_endpoint", "registration_endpoint", and "code_challenge_methods_supported": ["S256"].

Connecting AI Clients

Choose the setup guide matching your client type:

Part 1: Web AI Clients (OAuth 2.1)

Web-based AI applications (ChatGPT, Claude, Gemini, and Grok) authenticate directly via OAuth 2.1 (Authorization Code + PKCE S256)—no manual API key copying is needed.

  1. In your AI client's Connectors / MCP Servers / Integrations settings, add a new remote MCP server with:
  2. MCP Server URL: https://your-domain.com/mcp/sse
  3. Authentication: OAuth (auto-discovered via /.well-known/oauth-protected-resource)
  4. When prompted, sign in to your Coneshare account in the browser.
  5. On the Coneshare consent screen (/oauth/authorize), review the client name, redirect destination, and requested permission scopes (read for read-only access or read + write for read-write access; destructive deletes, admin endpoints, and viewer analytics remain blocked for OAuth tokens), then click Authorize.

Trusted Client Domain Allowlist

By default, dynamic OAuth client registration (DCR) only accepts redirect URIs belonging to OpenAI / ChatGPT, Claude, Google / Gemini, and Grok (OAUTH_ALLOWED_CLIENT_DOMAINS).

To allow additional third-party web clients later, append their domains (comma-separated, e.g. .example.com) to OAUTH_ALLOWED_CLIENT_DOMAINS in app.env and restart Coneshare.


Part 2: CLI & Desktop Clients (API Key)

Local CLI tools and desktop clients can connect using a personal API key generated under Settings > API Keys in the Coneshare web interface.

No ALLOW_LOCALHOST_LOOPBACK Change Needed for API Keys

When using static cs_live_... API keys, keep OAUTH_ALLOW_LOCALHOST_LOOPBACK=false. You only need to set OAUTH_ALLOW_LOCALHOST_LOOPBACK=true if a native desktop or CLI client initiates an OAuth 2.1 flow with an http://localhost:<port> callback.

Add the server to claude_desktop_config.json:

{
  "mcpServers": {
    "coneshare": {
      "url": "https://your-domain.com/mcp/sse",
      "headers": {
        "Authorization": "Bearer cs_live_YOUR_API_KEY"
      }
    }
  }
}

Run the command in your terminal:

claude mcp add --transport sse coneshare https://your-domain.com/mcp/sse --header "Authorization: Bearer cs_live_YOUR_API_KEY"

Configure mcpServers in your configuration file:

{
  "mcpServers": {
    "coneshare": {
      "url": "https://your-domain.com/mcp/sse",
      "headers": {
        "Authorization": "Bearer cs_live_YOUR_API_KEY"
      }
    }
  }
}

Configure your IDE MCP settings:

{
  "mcpServers": {
    "coneshare": {
      "url": "https://your-domain.com/mcp/sse",
      "headers": {
        "Authorization": "Bearer cs_live_YOUR_API_KEY"
      }
    }
  }
}