Skip to main content
Glama
MCP Test Server

MCP Test Server

by sonixz
README.md
# MCP Test Server

A tiny local [MCP](https://modelcontextprotocol.io) server to test MCP clients and tunnels against.
Four read-only tools, Streamable HTTP on `127.0.0.1` only, no keys, no account, no cloud.

| Tool | Returns |
| --- | --- |
| `ping` | `pong`, a fresh `call_id`, a UTC `timestamp`, and your optional `correlation_id` |
| `echo` | the `text` you sent (up to 1,000 characters) and its length |
| `status` | name, version, `ready: true`, uptime |
| `diagnostics` | a fresh `request_id` and non-sensitive facts about **this application** (versions, endpoint, negotiated protocol, call counts) |

It reads no file, makes no outbound network call, and never returns environment variables,
headers, client addresses, keys or tokens. `diagnostics` describes the application only: it cannot
tell you whether a tunnel in front of it is healthy (ask the tunnel client for that).

Built on the official MCP Python SDK (`mcp==2.3.0`). It answers both 2025 clients (`initialize`
handshake) and 2026-07-28 clients, statelessly.

## Quickstart

Needs Python 3.12 or later and git.

**Linux / WSL**

```sh
git clone https://github.com/sonixz/mcp-test-server.git && cd mcp-test-server
python3 -m venv .venv
.venv/bin/pip install --require-hashes -r requirements.txt && .venv/bin/pip install --no-deps -e .
.venv/bin/mcp-test-server                # serves http://127.0.0.1:8711/mcp
```

**Windows (PowerShell)**

```powershell
git clone https://github.com/sonixz/mcp-test-server.git; cd mcp-test-server
py -3.12 -m venv .venv
.venv\Scripts\pip install --require-hashes -r requirements.txt; .venv\Scripts\pip install --no-deps -e .
.venv\Scripts\mcp-test-server            # serves http://127.0.0.1:8711/mcp
```

Or let a script do the same: `scripts/run.sh` (Linux/WSL) or `scripts\run.ps1` (Windows). Both
create `.venv` on first run and pass their arguments on, e.g. `scripts/run.sh --port 9000`.

The server prints:

```text
mcp-test-server 0.1.0 serving MCP on http://127.0.0.1:8711/mcp
liveness (not an MCP test): http://127.0.0.1:8711/healthz
MCP smoke test: mcp-test-server smoke --port 8711
```

**Port:** `--port N` or `MCP_TEST_SERVER_PORT=N` (default `8711`). If the port is taken, it says so
and exits with code 2. **Host:** fixed to `127.0.0.1`; there is no option to change it.

**Keep it running in the background (Linux / WSL, needs tmux):**

```sh
scripts/background.sh start        # 127.0.0.1:8711, survives the terminal that started it
scripts/background.sh status       # pid, uptime, listener owner, /healthz
scripts/background.sh stop
```

It uses a tmux server of its own (socket `mcp-test-server`, session `mcp-test-server-8711`) and
keeps its PID and log in `~/.local/state/mcp-test-server/`, outside the repository. It refuses to
start a duplicate when the port is already taken. It does not survive a reboot or `wsl --shutdown`.

**WSL and Windows are two sides.** Run the server and whatever connects to it (the smoke test, a
tunnel client) on the same side. Windows can usually reach a WSL `127.0.0.1` port, but do not
build a test on that.

## Smoke test (the real MCP check)

In a second terminal, with the server running:

```sh
.venv/bin/mcp-test-server smoke                 # Windows: .venv\Scripts\mcp-test-server smoke
```

It connects with the official MCP client twice, once per protocol era, lists the tools and calls
each one. Expected output (ids and uptimes differ):

```text
MCP smoke test against http://127.0.0.1:8711/mcp (correlation_id=smoke-1a2b3c4d5e6f)
[legacy] PASS tools/list  diagnostics, echo, ping, status
[legacy] PASS ping  correlation_id=smoke-1a2b3c4d5e6f call_id=…32 hex…
[legacy] PASS echo  'hello from mcp-test-server smoke'
[legacy] PASS status  version=0.1.0 uptime=4.5s
[legacy] PASS diagnostics  request_id=…32 hex… protocol=2025-11-25
[modern] PASS tools/list  diagnostics, echo, ping, status
[modern] PASS ping  …
[modern] PASS echo  …
[modern] PASS status  …
[modern] PASS diagnostics  request_id=…32 hex… protocol=2026-07-28
RESULT ok
```

Exit code `0` means every check passed, `1` means at least one failed. Options: `--port`, `--url`,
`--mode legacy|modern|both`, `--correlation-id ID`.

The server log shows the same ids, so a call can be matched end to end:

```text
… INFO mcp_test_server tool=ping call_id=… correlation_id=smoke-1a2b3c4d5e6f
```

### What is *not* an MCP test

- `curl http://127.0.0.1:8711/mcp` (an HTTP GET) answers **405** on purpose. MCP talks by POSTing
  JSON-RPC messages; a GET proves only that something listens.
- `GET /healthz` answers `{"status":"ok"}`: the HTTP listener is up. It says nothing about MCP.

Only the smoke test (or another real MCP client calling the tools) proves the server works.

## Use it as a tunnel target: MCP Tunnel Manager → OpenAI tunnel → ChatGPT

> **NOT YET E2E VALIDATED.** Nothing below has been run end to end with ChatGPT. The steps that
> need OpenAI need the owner's own OpenAI account and keys and a real test later. This repository
> invents no OpenAI screen, URL, field name or token.

The full, checkable procedure, with what to expect and what to capture at each step, is in
**[docs/E2E-CHATGPT.md](docs/E2E-CHATGPT.md)**. In short:

1. **Local (validated):** start this server and run the smoke test until `RESULT ok`.
2. **Tunnel (not validated):** point OpenAI's official tunnel client (or MCP Tunnel Manager, which
   drives it) at the MCP server URL `http://127.0.0.1:8711/mcp` (Streamable HTTP). The tunnel
   client's own health page says whether the *tunnel* is up; `diagnostics` here says only that the
   *application* is up.
3. **ChatGPT (not validated):** add the tunnel as a custom MCP server the way OpenAI's current
   documentation says, then ask ChatGPT to call `ping` with a correlation id you choose and look for
   that id in this server's log.

Agents working on MCP Tunnel Manager: see [docs/FOR-MCP-TUNNEL-MANAGER.md](docs/FOR-MCP-TUNNEL-MANAGER.md).

## Develop

```sh
.venv/bin/pip install --require-hashes -r requirements-dev.txt && .venv/bin/pip install --no-deps -e .
.venv/bin/ruff check . && .venv/bin/ruff format --check .
.venv/bin/mypy --strict src
.venv/bin/pytest
```

Tests cover the four tools and their schemas (in-process client) and the real CLI in a subprocess,
reached over Streamable HTTP by the official client on both protocol eras, plus the refusals: a
foreign `Host` (421), a foreign `Origin` (403), `GET /mcp` (405), and no listener beyond loopback.

Dependencies are pinned in `pyproject.toml` and locked with hashes in `requirements*.txt`
(regenerate with `uv pip compile`, see [CONTRIBUTING.md](CONTRIBUTING.md)).

## Project

[Architecture](docs/ARCHITECTURE.md) · [Decisions](DECISIONS.md) · [Status](STATUS.md) ·
[Backlog](BACKLOG.md) · [Security](SECURITY.md) · [Devlog](devlog/index.html) · work happens in
loops ([LOOP.md](LOOP.md)).

License: [MIT](LICENSE).