Roar AI
Mulai gratis
Resources

How to build and host a remote MCP server

Build a remote MCP server that ChatGPT, Claude, Cursor and VS Code can connect to, secure it, and host it on a public HTTPS address, with a working example.

In short
  • A remote MCP server is a small web app with one endpoint. AI assistants send it requests over HTTPS to list its tools and call them.
  • The current version of the protocol, dated 28 July 2026, is stateless: each request stands alone, so the server scales like any ordinary web app.
  • To be usable it needs three things: a public HTTPS address, a way to check who is calling, and hosting that lets streamed responses through.

The Model Context Protocol (MCP) is the open standard AI assistants use to work with other software. An MCP server tells an assistant what it can do, as a list of tools, and does those things when the assistant asks. A local server runs on your own computer and talks to one assistant. A remote server runs on the internet, so anyone you allow can connect it to ChatGPT, Claude, Cursor or VS Code by its address.

This guide covers what a remote MCP server has to do, a minimal working example in TypeScript, how to secure it, and what to look for in hosting. If MCP itself is new to you, start with Claude connectors and MCP, explained.

What a remote MCP server has to do

The protocol defines two ways for an assistant to reach a server: stdio, for a local process, and Streamable HTTP, for a server on the network. The older HTTP-plus-SSE transport is deprecated, so new remote servers should use Streamable HTTP.

A Streamable HTTP server exposes a single endpoint, such as https://notes.example.com/mcp, that accepts POST requests. Each request carries one JSON-RPC message, such as "list your tools" or "call this tool with these arguments", and the server answers with JSON or, for longer work, with a stream of events in the same response.

The current revision of the specification, dated 28 July 2026, made that model stateless. There are no sessions to keep and no separate stream to hold open: every request names its protocol version and says what it needs. A server can therefore run as several copies behind a load balancer, or restart at any time, without losing anything. If a tool needs to remember something between calls, it returns a handle that the assistant passes back in the next call.

The specification also asks servers to check the Origin header of each request and refuse ones they do not expect, which stops a web page in someone's browser from calling the server on their behalf.

A minimal server in TypeScript

The official SDKs cover TypeScript, Python, C#, Go, Rust, Ruby and several other languages. Version 2 of the TypeScript SDK implements the 2026 specification, and a server with one tool looks like this:

import { createServer } from 'node:http';
import { createMcpHandler, McpServer } from '@modelcontextprotocol/server';
import { toNodeHandler } from '@modelcontextprotocol/node';
import * as z from 'zod/v4';

const handler = createMcpHandler(() => {
  const server = new McpServer({ name: 'notes', version: '1.0.0' });

  server.registerTool(
    'add-note',
    { description: 'Save a short note', inputSchema: z.object({ text: z.string() }) },
    async ({ text }) => ({ content: [{ type: 'text', text: `Saved: ${text}` }] }),
  );

  return server;
});

createServer(toNodeHandler(handler)).listen(Number(process.env.PORT) || 3000);

The handler builds a fresh server for each request, which is what lets it scale without shared state. Each tool has a name, a description the assistant reads to decide when to use it, and a schema for its arguments. The SDK's documentation has the current details, including how to serve it through Express, Hono or Fastify. In Python, the official mcp package offers the same shape with a decorator on each tool.

This example does no authentication and no Origin checking. Both belong in front of the handler before the server is public.

Securing it

A remote server is reachable by anyone who knows its address, so it needs a way to tell who is calling.

A token in a header is the simplest approach and suits a server for yourself or your team. The server keeps a long random secret, and each client sends it as Authorization: Bearer <token>; anything without it gets a 401. Claude's custom connectors, Claude Code, Cursor and VS Code all let you add a header like this when you connect a server.

OAuth is what the specification describes for servers that many people sign in to. The server acts as an OAuth 2.1 resource server: it publishes metadata saying which authorization server issues its tokens, answers an unauthenticated request with a 401 that points to that metadata, and accepts only tokens issued for it. The assistant then sends each person through a normal sign-in page. ChatGPT's custom MCP servers document OAuth as the way to sign in.

Whichever you choose, keep the token or client secret out of your code: store it as an environment variable on the host.

Hosting it

Any host that runs a web app can run an MCP server, but four things decide whether assistants can use it:

  • A public HTTPS address. ChatGPT and Claude only connect to servers on public HTTPS, and Claude expects the standard port, 443.
  • Streamed responses that arrive as they are sent. A long tool call answers with a stream of events. A proxy that holds the whole response back until it finishes breaks it; sending the header X-Accel-Buffering: no asks proxies not to.
  • Prompt answers. Assistants and proxies give up on a request that has not started answering within a minute or two. Send long work's progress as a stream, or return quickly and let the assistant check back.
  • Room to scale. Because the protocol is stateless, adding a second copy of the server needs no shared memory between them.

Connecting it to an assistant

  • Claude: add it as a custom connector under Settings › Connectors, with OAuth or a header. Custom connectors are available on every Claude plan, with one on the free plan.
  • Claude Code: claude mcp add --transport http notes https://notes.example.com/mcp --header "Authorization: Bearer your-token".
  • Cursor: add it to .cursor/mcp.json with its url and any headers.
  • VS Code: add it to .vscode/mcp.json with "type": "http", its url and any headers.
  • ChatGPT: custom MCP servers with full tool use are available on Business, Enterprise and Edu plans, added from the plugins settings with OAuth.

Hosting an MCP server on Roar AI

Roar AI hosts an MCP server like any other web app. Upload the folder, ask your AI assistant to publish it, or connect its GitHub repository, and it comes up on its own HTTPS address on roarai.app, or on your own domain. Streamed responses pass straight through.

  • Keep the token secret. Add it as an environment variable, and the server reads it from there.
  • Leave the app's sign-in page off. Assistants cannot get past a sign-in page meant for people, so keep the app open and let the server's own token or OAuth decide who gets in.
  • Use AI inside your tools. Every app on Roar AI is given its own key for 200+ AI models, in ROAR_API_KEY and ROAR_BASE_URL, so a tool can call a model without a separate provider account.
  • Check the logs when a tool fails. The app's logs show what your server prints, so log each tool call and its errors.

To try it, deploy the example above from the hosting page, add your token, and connect the address to Claude Code with the command above.

Questions people ask

What is a remote MCP server?

A remote MCP server is a web service that AI assistants connect to over HTTPS to use its tools. Unlike a local server, which runs on your own computer for one assistant, a remote server runs online, so ChatGPT, Claude, Cursor and VS Code can all reach it by its address.

Is SSE still supported for MCP?

The HTTP-plus-SSE transport from the first version of MCP is deprecated. New servers should use Streamable HTTP, which can still send a stream of events in the response to a single request.

Do I need OAuth for an MCP server?

Not always. The specification makes authorization optional and describes OAuth for servers that many people sign in to. For a server used by you or your team, a secret token sent in a header is simpler, and Claude, Claude Code, Cursor and VS Code all support it.

Can ChatGPT connect to my MCP server?

Yes, on ChatGPT's Business, Enterprise and Edu plans, which can add custom MCP servers with full tool use. The server needs a public HTTPS address, and OpenAI documents OAuth as the way to sign in.

Where can I host an MCP server?

Any host that gives a web app a public HTTPS address and lets streamed responses through. Roar AI hosts it like any other app, on its own address, with a key for 200+ AI models already set for your tools to use.

Start building
in minutes

Get a key, call any model, ship your app. Pay in your local currency.