mcp-demo
A demo MCP server showcasing every MCP capability with fake logic, including tools, resources, prompts, progress, cancellation, elicitation, sampling, roots, and subscriptions, over Streamable HTTP, HTTP+SSE, and stdio transports.
README
mcp-demo
A demo Model Context Protocol server built with TypeScript + Hono + Bun, showcasing every MCP capability with fake logic — nothing here does anything real.
See docs/architecture.md for the session model and module split. Run
bun run typecheckto type-check the project.
Run it
bun install
# terminal 1 — the server (http://localhost:3000, MCP endpoints at /mcp and /sse)
bun run dev
# terminal 2 — scripted walkthrough of every capability (no LLM needed),
# pick a transport:
bun run client # Streamable HTTP (current standard)
bun run client:sse # legacy HTTP+SSE (deprecated, kept for education)
bun run client:stdio # stdio (client spawns src/transports/stdio.ts itself)
# or explore interactively with the MCP Inspector
bun run inspect # Streamable HTTP → http://localhost:3000/mcp, SSE → /sse
bunx @modelcontextprotocol/inspector bun run src/transports/stdio.ts # stdio
bun run dev uses --hot reload. Set PORT=4000 to change the port, MCP_URL to point the client elsewhere.
Transports
All three MCP transports are implemented — the same server capabilities are exposed over each:
| Transport | Status | Endpoint / entry | Docs |
|---|---|---|---|
| Streamable HTTP | current standard (2025-03-26) | POST/GET/DELETE /mcp |
docs/streamable-http.md |
| HTTP+SSE | legacy (2024-11-05), deprecated | GET /sse + POST /messages |
docs/sse.md |
| stdio | current, for local servers | src/transports/stdio.ts (stdin/stdout) |
docs/stdio.md |
Capability map
| MCP capability | Where it's demonstrated |
|---|---|
| Tools | echo (input schema, structured outputSchema, annotations), roll-dice — src/server/tools.ts |
| Progress | long-task streams notifications/progress when the client passes a progressToken (client uses the onprogress option) |
| Cancellation | long-task honors the request AbortSignal (notifications/cancelled) |
| Elicitation | ask-user calls elicitation/create to request structured user input via the client |
| Sampling | ai-summarize calls sampling/createMessage to use the client's LLM |
| Roots | explore-roots calls roots/list to read client-exposed filesystem roots |
| Resources (static) | demo://about, demo://config |
| Resource templates | demo://greeting/{name}, demo://users/{id} (with list + complete callbacks) |
| Subscriptions | demo://live/stats mutates every 3s; subscribers get notifications/resources/updated |
| Prompts | code-review, commit-message (multi-message / few-shot) |
| Completion | completable() prompt args + resource template variables (completion/complete) |
| Logging | emit-logs sends every level via notifications/message; the SDK filters per-session after logging/setLevel |
| List-changed | toggle-bonus enables/disables a bonus tool/resource/prompt → notifications/{tools,resources,prompts}/list_changed — src/server/bonus.ts |
| Ping | client.ping() in the demo client |
| Sessions & resumability | Stateful Mcp-Session-Id sessions in src/transports/http.ts, in-memory event store for Last-Event-ID replay, DELETE teardown |
Layout
src/
server/ the MCP server itself — one module per capability family
index.ts createMcpServer(): wires the capability modules together
tools.ts echo, roll-dice, long-task, ask-user, ai-summarize, explore-roots, emit-logs
resources.ts static + templated + live subscribable resources
prompts.ts code-review, commit-message (completable args)
bonus.ts bonus tool/resource/prompt + toggle-bonus (demonstrates list_changed)
subscriptions.ts per-session resource-subscribe tracking + live-stats ticker
data.ts fake in-memory data
transports/ the wire layers that expose the same server over the network/process boundary
http.ts Hono app: /mcp (Streamable HTTP) + /sse + /messages (legacy SSE), /health — main entry
sse.ts HonoSseTransport: Bun-native implementation of the legacy HTTP+SSE wire protocol
stdio.ts stdio entry point (server over stdin/stdout)
utils.ts helpers shared by server and client (sleep, errorMessage)
client/
demo.ts thin orchestrator: pick transport → connect → run → teardown
walkthrough.ts runWalkthrough(): one step per MCP capability
handlers.ts createDemoClient(): fake sampling/elicitation/roots + notification logging
helpers.ts step/show/toolText/resourceText formatters
docs/
architecture.md session model, module split, how to add a capability
streamable-http.md / sse.md / stdio.md — how each transport works and why MCP uses it
See docs/architecture.md for the full session model and how the pieces fit.
Notes / gotchas encountered
- The server is stateful: each
initializegets its ownMcpServer+StreamableHTTPTransport, so subscriptions and log levels are per-session. resources/subscribeis not handled by the SDK — the server tracks subscribed URIs itself (src/server/subscriptions.ts).- Log-level filtering only applies when
sendLoggingMessage(params, sessionId)is given the session id. - Don't override the client's
ProgressNotificationSchemahandler if you want the per-requestonprogresscallback — the SDK's internal handler is what routes to it. - The demo client fakes
sampling/elicitation/rootsresponses, so the full walkthrough runs without an LLM. In the Inspector, sampling needs a real model API key; elicitation shows a form dialog.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。