Skip to main content

General MCP Server

tip

This document applies to hosting any general locally running MCP Server.

For MCP Servers running in npx/uvx mode, the Cloud Development Platform provides one-click hosting capability. For details, refer to Hosting an Existing MCP Server / MCP Server Running in npx/uvx Mode.

Introduction

If you want to deploy a locally running MCP Server that only supports local operation to Cloud Development to provide remote MCP services, you can use Cloud Development's hosting feature for locally running MCP Server.

The hosted MCP Server has the following capabilities:

  • Remote Streamable HTTP access support
  • Support ApiKey authentication to protect the security of MCP Server code and key information
  • Support for access in MCP-supported clients such as Cursor
  • Support using in Cloud Development Agent to build complex automated Agents
  • You can submit for listing on the CloudBase MCP Marketplace, which after approval will allow more users to deploy and use it.

Hostable MCP Servers must meet the following conditions:

  • No restriction on languages/frameworks; Java/Python/GoLang/PHP are all acceptable
  • Stdio Transport with MCP support

We will use cloud hosting service to run your MCP Server, therefore your MCP Server must support Stdio Transport, meaning it supports transmitting data via Stdio.

In the container internal network, we use the cloudbase-mcp-transformer tool to convert the local MCP Server's Stdio into a remote MCP service, enabling remote access while supporting authorization/authentication/multiple sessions per service/multiple instances per service.

This article will use the MongoDB MCP from the community for demonstration.

Final code address: Sample Project for Hosting Local MCP on CloudBase Server

Preparations

  1. Before starting, please ensure you have activated the Cloud Development environment
  2. Have a local Node.js environment (recommended: Node.js LTS version) to run the @cloudbase/cli command for deploying cloud hosting services.

Create a Blank MCP Server

Create an MCP Server in CloudBase AI+, select Blank Template, and name the service according to your needs.

Prepare the code

Prepare a local MCP Server that supports commands like npx and uv. This article will demonstrate using MongoDB MCP.

You can download the Sample Project for Hosting Local MCP on CloudBase Server for testing.

It contains 3 files.

  • Dockerfile: The Dockerfile for the CloudBase MCP service
  • DOC.md: The showcase documentation for the MCP service (optional, but required when publishing the MCP service to CloudBase)
  • mcp-meta.json: The configuration file for the CloudBase MCP service (optional, but required when publishing the MCP service to CloudBase)

Write the Dockerfile

The Dockerfile content is as follows:

# Use the official Node.js Alpine image as the base
FROM node:20-alpine

# Configure the Tencent Cloud mirror source
RUN npm config set registry https://mirrors.cloud.tencent.com/npm/ \
&& yarn config set registry https://mirrors.cloud.tencent.com/npm/

# Configure the domestic mirror source for Alpine
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tencent.com/g' /etc/apk/repositories

# Install Python (automatically creates python/pip links)
RUN apk update \
&& apk add --no-cache python3 py3-pip \
&& apk add curl

# If your project is a python project, it is recommended to install it globally to enhance runtime performance
# For example, RUN pip3 install --break-system-packages mysql-mcp-server
RUN pip3 install --break-system-packages uv

## Install the required npm dependencies globally
## @cloudbase/mcp-transformer must be installed
## If your project is an npm package, it is recommended to install it globally to enhance runtime performance
RUN npm install -g @cloudbase/mcp-transformer@1.0.0-beta.18 mongo-mcp

# Expose fixed ports
EXPOSE 80

# Start Command
## Use the cloudbase-mcp-transformer command to convert Stdio to a remote MCP service
## --stdioCmd specifies the command to be transformed, which can reference environment variables such as $USER, $PASSWORD, $HOST, $PORT, $DATABASE
## When creating a cloud hosting service, users can specify environment variables
## If your project depends on environment variables, you need to declare them in mcp-meta.json
## --port specifies the port of the converted service, defaulting to 3000
CMD cloudbase-mcp-transformer stdioToStreamable --stdioCmd "mongodb-mcp mongodb://$USER:$PASSWORD@$HOST:$PORT/$DATABASE?authSource=admin ./" --port 80

After completing the Dockerfile, we can deploy the MCP Server to Cloud Hosting.

Deploy to the cloud

Deploy Code

# Ensure `@cloudbase/cli` is globally installed and you are logged in.
npm i -g @cloudbase/cli@latest
# Login
tcb login

Navigate to the directory containing the Dockerfile and run the following command to deploy. Enter the CloudBase environment id and CloudBase service name used in the Preparations section as prompted.

tcb cloudrun deploy

Configure Environment Variables

After deployment is complete, you can configure the environment variables required by the service in the cloud hosting service details page, such as USER, PASSWORD, HOST, PORT, DATABASE in the mongodb example.

If the service can run without depending on environment variables, you can skip this step.

Usage

After successful deployment, you can test in the CloudBase MCP Server details page. Navigate to the Tools tab to view available tools and make calls.

Read the following documentation to use the hosted MCP Server:

Publish to Marketplace

If you need to publish the MCP Server to the CloudBase MCP Marketplace, please refer to

FAQ

How to verify if the local MCP Server is functional?

First, run the MCP Server locally to verify its functionality.

Take Github MCP as an example, which provides the following configuration:

{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>"
}
}
}
}

This configuration note:

  • Run npx -y @modelcontextprotocol/server-github to start the MCP Server
  • Need to configure the environment variable GITHUB_PERSONAL_ACCESS_TOKEN

To facilitate local debugging, MCP officially provides the @modelcontextprotocol/inspector debugging tool. Run the following command to launch the graphical interface:

npx -y @modelcontextprotocol/inspector

After running, you can go to the debugging address based on the terminal output and follow these steps:

  1. Transport Type: Select STDIO
  2. Command: Enter npx
  3. Arguments: Enter -y @modelcontextprotocol/server-github
  4. Go to https://github.com/settings/tokens to create a Github Token
  5. Click Environment Variables, add GITHUB_PERSONAL_ACCESS_TOKEN: <Token> in the expanded list, and enter the newly created Github Token
  6. Click Connect, and once connected, you can test the tools it provides

After testing one or two tools locally, we can confirm that this MCP Server is functional. Next, let's start converting it to a remote MCP Server.

How to locally debug MCP Server to achieve the effect of converting it to a remote MCP

Converting an MCP Server in Stdio mode to Streamable HTTP mode is very straightforward. Simply run:

npx -y cross-env GITHUB_PERSONAL_ACCESS_TOKEN=<YOUR_TOKEN> \
npx -y @cloudbase/mcp-transformer stdioToStreamable \
--stdioCmd "npx -y @modelcontextprotocol/server-github" --noVerifyAccess

This command string is quite long. Let's break it down and explain the function of each part:

  • npx -y cross-env GITHUB_PERSONAL_ACCESS_TOKEN=<YOUR_TOKEN>: Set environment variables
  • npx -y @cloudbase/mcp-transformer stdioToStreamable: Run @cloudbase/mcp-transformer, a command-line tool we provide that offers a service to convert an MCP Server in Stdio mode to one running in Streamable HTTP mode. After execution, it will provide services by default at http://127.0.0.1:3000/messages
  • --stdioCmd "npx -y @modelcontextprotocol/server-github": The command to run the MCP Server in Stdio mode. @cloudbase/mcp-transformer will use this command to run the MCP Server in Stdio mode and provide an HTTP service, thereby converting it to an MCP Server running in Streamable HTTP mode
  • --noVerifyAccess: The parameter to skip authentication. The MCP Server running on cloud hosting can obtain the caller's identity. By default, it performs authentication based on the identity, only allowing calls from super administrators. When running locally here, skip authentication for convenience.

After running, return to the debugging interface and follow these steps:

  1. Transport Type: Select Streamable HTTP
  2. Fill in the URL as `http://127.0.0.1:3000/messages
  3. Click Connect, and once connected, you can test the tools it provides

If the test passes without errors, it indicates that we have successfully run the local MCP Server in Streamable HTTP mode, which can now be accessed remotely via URL.