remote-mcp

remote-mcp

A minimal MCP server exposed over HTTP with bearer token authentication, providing echo and get_server_time tools to demonstrate transport and auth mechanics.

Category
访问服务器

README

Remote MCP Server — HTTP transport + authentication

A minimal MCP server exposed over the network (HTTP) instead of stdio, with bearer token authentication — the two things that change the moment an MCP server leaves your own laptop.

This project is intentionally simple (two trivial tools: echo and get_server_time) so the lesson is entirely about transport and auth mechanics, not new business logic — you already know RAG, tool use, and MCP fundamentals from Projects 2-5.

The core concept

Every previous project used stdio transport: Claude Code launches your script as its own child process and talks to it over stdin/stdout. Only whoever can start a process on your machine can ever reach it — there's no meaningful "who's allowed to call this" question, because nothing outside your machine can even see it.

HTTP transport is fundamentally different: the server runs as an independent, long-lived network service, reachable by URL. Once that's true, anyone who can reach the port can send it requests — so authentication stops being optional.

# stdio (every previous project) — implicitly private, no auth needed
mcp.run()

# HTTP (this project) — network-reachable, auth now required
mcp.run(transport="http", host="0.0.0.0", port=8000)

Verified live: the actual authentication boundary

This was tested against a real running server process, not simulated — three real HTTP requests, three real outcomes:

--- Attempt with NO auth token ---
Correctly rejected: HTTPStatusError: Client error '401 Unauthorized'

--- Attempt with WRONG auth token ---
Correctly rejected: HTTPStatusError: Client error '401 Unauthorized'

--- Attempt with CORRECT auth token ---
Tools discovered: ['get_server_time', 'echo']
Echo result: Server received: hello from a real HTTP client
Server time: 2026-08-13T22:07:47.826826

Notice the wrong-token case: it fails identically to no-token-at-all — proof the server is genuinely validating the token's value, not just checking that some header is present.

Setup

pip install -r requirements.txt
$env:REMOTE_MCP_TOKEN = "pick-any-secret-string-here"

Run it locally

python remote_server.py

You'll see it start a real Uvicorn web server, listening at http://0.0.0.0:8000/mcp — this is a genuinely different kind of process than every previous project's script, which just ran, did something, and exited.

Connect a client (from a second terminal, while the server is running)

import asyncio
from fastmcp import Client

async def main():
    async with Client("http://localhost:8000/mcp", auth="pick-any-secret-string-here") as client:
        result = await client.call_tool("echo", {"message": "hello"})
        print(result.data)

asyncio.run(main())

Connecting Claude Code to a remote HTTP server

Unlike previous projects (claude mcp add name -- python script.py, which tells Claude Code to launch the process), an HTTP server is already running independently — you point Claude Code at its URL instead:

claude mcp add remote-demo --transport http https://your-deployed-url.com/mcp

(Exact syntax for passing the bearer token alongside this may vary by Claude Code version — check claude mcp add --help for the current auth-header flag.)

Actually deploying this off your laptop

Running python remote_server.py locally proves the mechanism works, but it's still only reachable from your own machine (localhost). To make it genuinely reachable by others, you need to run it on a machine that's always on and has a public address — a small cloud host, not your laptop.

Simplest free options for a small Python service like this:

  • Render (render.com) — free tier, connects directly to a GitHub repo, auto-deploys on push. Set REMOTE_MCP_TOKEN as an environment variable in their dashboard (never commit it to the repo).
  • Railway (railway.app) — similar free-tier flow, GitHub-connected.
  • Fly.io — free tier, more control but a bit more setup (a fly.toml config file, in addition to your requirements.txt).

All three follow roughly the same shape: connect your GitHub repo → they detect it's Python → they run something equivalent to python remote_server.py on a real server with a real public URL → you set REMOTE_MCP_TOKEN as a secret in their dashboard, not in code.

This step is deliberately left as your next hands-on exercise, since the actual mechanics (transport + auth) are already verified above — picking a host, connecting a GitHub repo, and setting an environment variable in a web dashboard is a different, more click-through-y skill than anything code-related, and it's worth doing yourself rather than following a script blindly.

Design notes

  • StaticTokenVerifier is explicitly for development/testing only — tokens are stored in plain text in server memory. A real production deployment would use JWTVerifier against a real identity provider (Auth0, Okta, your company's SSO), not a single shared secret string. This project uses the static version deliberately, to isolate the concept (HTTP needs auth) from the complexity (real OAuth/JWT flows) — worth knowing the limitation, not just the pattern.
  • host="0.0.0.0" vs "localhost" matters. localhost only accepts connections from the same machine — binding to it would defeat the purpose of this whole exercise. 0.0.0.0 means "accept connections on any network interface," which is what actually makes remote access possible once deployed.
  • The wrong-token test is the important one, not the no-token test. A server that merely checks "is a token present" without validating its value would still pass a naive test but be completely insecure — this project's verification specifically confirms invalid credentials are rejected, not just missing ones.

What's next

  • Deploy to Render/Railway/Fly.io and re-run the same three-case auth test against the real public URL instead of localhost.
  • Swap StaticTokenVerifier for JWTVerifier against a real identity provider — the production-grade version of this same concept.
  • Point Claude Desktop (not just Claude Code) at the deployed URL, to confirm the server truly doesn't care which client connects — the same client-independence property from Project 4, now proven over a real network instead of a local subprocess.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选