MCP REST Demo Server

MCP REST Demo Server

A minimal demo MCP server exposing user management tools (list, get, create, update, delete users) over both stdio and HTTP/SSE transports, wrapping an Express REST API to illustrate local vs remote MCP connectivity.

Category
访问服务器

README

REST vs MCP Demo (stdio + HTTP/SSE)

A minimal, runnable demo of the difference between a plain REST API and MCP (Model Context Protocol) servers that wrap it — shown two ways: a local MCP server reached over stdio, and a remote-style MCP server reached over HTTP/SSE.

Architecture

Local (stdio) transport
------------------------
mcp-client-stdio.js  --spawns + talks MCP over stdio-->  mcp-server-stdio.js
                                                                |
                                                                | HTTP
                                                                v
                                                          server-rest.js
                                                        (Express API :3001)
                                                                ^
                                                                | HTTP
                                                                |
mcp-client-http.js  --connects over the network (SSE)-->  mcp-server-http.js
                                                              (listens :3002)
------------------------
Remote-style (HTTP/SSE) transport

Both MCP servers expose the exact same five tools and wrap the exact same REST API on port 3001. Only the transport between client and server differs:

mcp-server-stdio.js mcp-server-http.js
Transport stdio (stdin/stdout pipes) HTTP + Server-Sent Events
How the client finds it Client spawns it as a child process Client connects to a URL (http://localhost:3002/sse)
Server lifecycle Starts and dies with the client Runs independently, on its own — start it once and any number of clients can connect over time
Can client/server be on different machines? No — same machine, parent/child process Yes — this is exactly how a genuinely remote MCP server would be reached
Endpoints none (raw stdio) GET /sse (open stream), POST /messages (send requests)

The stdio version is what tools like Claude Desktop use for MCP servers installed locally on your machine. The HTTP/SSE version is the same idea as a hosted/remote MCP server — the kind you'd deploy once and let multiple clients (or multiple people) connect to over the network, the same way you'd deploy any web service.

Files

  • server-rest.js — the Express REST API for managing users (in-memory storage). Identical for both demos; you can hit it directly with Postman or curl. Runs on port 3001.
  • mcp-server-stdio.js — MCP server over stdio. Spawned directly by mcp-client-stdio.js.
  • mcp-client-stdio.js — spawns mcp-server-stdio.js, discovers its tools via tools/list, and runs the test sequence below.
  • mcp-server-http.js — MCP server over HTTP/SSE. Runs standalone on port 3002; you start it yourself, in its own terminal, before running the HTTP client.
  • mcp-client-http.js — connects to http://localhost:3002/sse over the network (no spawning), discovers tools via tools/list, and runs the identical test sequence.

Both MCP servers expose the same 5 tools:

  • list_users
  • get_user (parameter: id)
  • create_user (parameters: name, email)
  • update_user (parameters: id, name, email)
  • delete_user (parameter: id)

1. Install dependencies

npm install

2. Start the REST API

In one terminal (required for both demos below):

npm run rest

You should see:

[REST] User API listening on http://localhost:3001

Leave this running.

Try it with Postman / curl

curl http://localhost:3001/users

curl -X POST http://localhost:3001/users \
  -H "Content-Type: application/json" \
  -d '{"name":"John Doe","email":"john@example.com"}'

curl http://localhost:3001/users/1

curl -X PUT http://localhost:3001/users/1 \
  -H "Content-Type: application/json" \
  -d '{"name":"Jane Doe"}'

curl -X DELETE http://localhost:3001/users/1

Watch the REST terminal — every request logs there.

3. Run the stdio (local) demo

With the REST API still running, in another terminal:

npm run client-stdio

You don't need to start the MCP server yourself — mcp-client-stdio.js spawns mcp-server-stdio.js for you and talks to it over stdio.

If you want to see the stdio server run standalone (e.g. to try it from the MCP Inspector or Claude Desktop instead of the bundled client):

npm run mcp-stdio

On its own it just sits there waiting for a client to speak JSON-RPC on stdin — that's expected. Press Ctrl+C to stop it.

4. Run the HTTP/SSE (remote-style) demo

This one needs two terminals of its own, in order, because the HTTP server doesn't get spawned automatically — it's meant to represent a server running independently, somewhere else on the network.

Terminal 2 — start the HTTP MCP server (with the REST API from step 2 still running in terminal 1):

npm run mcp-http

You should see:

[MCP-HTTP ...] MCP HTTP/SSE server listening on http://localhost:3002
[MCP-HTTP ...] SSE endpoint:      GET  http://localhost:3002/sse
[MCP-HTTP ...] Messages endpoint: POST http://localhost:3002/messages

Leave this running too.

Terminal 3 — run the HTTP client:

npm run client-http

This connects to http://localhost:3002/sse (a plain network URL — no spawning involved) and runs the same test sequence as the stdio client.

Test sequence (identical for both transports)

  1. List all users (expect empty)
  2. Create user "John Doe"
  3. List all users again (shows John)
  4. Get John by ID
  5. Update John's name to "Jane Doe"
  6. Get the user again to verify the update
  7. Delete the user
  8. List all users one more time (expect empty)

Each step prints timing info and the raw tool result. You'll also see [MCP-SERVER] / [MCP-HTTP] log lines (the stdio server's logs are inherited into the client's terminal via stderr; the HTTP server's logs appear in its own terminal) and [REST] log lines in the REST terminal — so you can watch one logical operation flow through all three layers for either transport.

5. Talk to it in plain English (free mock version)

mock-ai-client.js is a free, no-API-key stand-in for a real AI client. There's no LLM involved — it's a handful of regexes that recognize a few plain-English phrasings and map them onto the same 5 MCP tools, discovered the same way (tools/list) as the other clients. It exists to show the shape of "natural language in → pick a tool → call it via MCP → REST API → result out" before spending anything on the real thing.

With the REST API running (step 2 above):

npm run mock-ai-client -- "list all users"

Or run it with no argument for an interactive prompt:

npm run mock-ai-client

Phrasings it understands:

  • list all users
  • create a user named <name> with email <email>
  • get user <id>
  • update user <id>'s name to <name>
  • update user <id>'s email to <email>
  • delete user <id>

Anything else prints a "didn't understand" message listing these examples — unlike a real LLM-backed client, it can't generalize to phrasings it doesn't recognize.

This is not the real thing. A genuine AI client would use the Anthropic Messages API's tool-use feature: hand Claude the same tools/list output (converted to Anthropic's tool format — just renaming inputSchema to input_schema, since MCP already uses JSON Schema), let Claude decide which tool to call and with what arguments based on your actual request, run it, and feed the result back. That requires a separate Anthropic API key (billed separately from any Claude subscription) and costs a small amount per request — a few cents at most for casual use with a cheap model like Claude Haiku 4.5. Ask if you want that version built.

What this demonstrates

  • The REST API works exactly like any normal HTTP service (Postman-testable), and is unchanged between both demos — both MCP servers wrap the same API.
  • Neither MCP client hardcodes a URL, HTTP verb, or JSON body shape — both discover tool names, descriptions, and parameters via tools/list.
  • stdio = local: the client owns the server's process lifecycle by spawning it directly. Simple, but client and server must be on the same machine.
  • HTTP/SSE = remote-capable: the server runs independently and listens on a port; the client just connects to a URL, the same way it would connect to a server hosted anywhere else on the network. Multiple clients can connect to the same running server over time.
  • Either way, the MCP server is a thin translation layer: each tool call becomes one HTTP call to the REST API, and the HTTP response becomes the tool result.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选