Example MCP Server
平台与服务by mctx-ai
基于 mctx 的示例 MCP server,展示 tools、resources、prompts、progress 与 sampling 等能力。
什么是 Example MCP Server?
基于 mctx 的示例 MCP server,展示 tools、resources、prompts、progress 与 sampling 等能力。
README
Example App
The comprehensive reference implementation for @mctx-ai/app. Every framework capability in one well-commented file — clone it, study it, fork it as a template for your own App.
What This Example Demonstrates
src/index.ts covers every pattern the framework supports:
Tool Patterns
- Sync string return —
greet: receives args, returns a formatted string; demonstrates environment variable configuration viaGREETING - Object return —
calculate: returns a structured result object (auto-serialized to JSON); demonstrates input validation and error throwing - Generator with progress —
analyze: yields progress notifications viacreateProgress(); demonstratesGeneratorToolHandler - LLM sampling —
smart-answer: delegates to the client's LLM via theaskparameter; demonstrates graceful fallback when sampling is unavailable - User identity via ctx —
whoami: readsctx.userId, the stable mctx subscriber ID injected server-side by the platform; demonstrates graceful degradation outside mctx
Resource Patterns
- Static URI —
docs://readme: exact URI, no parameters, returns plain text - Dynamic URI template —
user://{userId}: extractsuserIdfrom the URI path, returns a JSON profile
Prompt Patterns
- Single-message —
code-review: returns a plain string that becomes one user message - Multi-message conversation —
debug: usesconversation()to build structured user/assistant dialogue
Infrastructure
- Tool annotation hints — every tool sets
readOnlyHint,destructiveHint,openWorldHint, andidempotentHintwith inline rationale explaining each choice - Structured logging —
log.info,log.debug,log.warning,log.error, andlog.noticethroughout - Environment variable configuration — reads
process.env.GREETINGlazily inside the handler (not at module scope) - Comprehensive test coverage —
src/index.test.tstests every tool, resource, and prompt via JSON-RPC 2.0 requests
Channel Events (Real-Time Push)
Ideal for real-time notifications, build status updates, background task completion alerts, and other events that don't require a response. See Usage in Conversation for example phrases.
- One-way push pattern —
ctx.emit()lets tools push real-time notifications into Claude Code sessions without the client polling. Handlers receive(args, ask, ctx)wherectx.emitsends events; the call is fire-and-forget and delivery to Claude Code happens asynchronously viactx.waitUntil()without blocking the tool response notifytool — dedicated demo of the channel pattern: receives a message string, emits it as anotificationevent withsource: example_servermeta, and returns a confirmation string to the callergreettool enhancement — fires agreetingevent as a side-effect every time someone is greeted, showing how emit integrates naturally into existing tools
Requirements: Channel events require the mctx thin client plugin and Claude Code with channel support. The environment variables
MCTX_EVENTS_ENDPOINT,MCTX_SERVER_ID, andMCTX_EVENTS_SECRETare auto-injected by mctx at runtime — developers do not set these manually. In local dev, these vars are absent andctx.emit()gracefully no-ops.
Usage in Conversation
Once connected to an MCP client, try phrases like these:
Greetings and identity
- "Greet Alice" — calls
greetwithname: "Alice" - "Who am I?" — calls
whoamito return your stable mctx user ID - "Greet the whole team" — calls
greetin a loop for each name
Math and analysis
- "What is 6 times 7?" — calls
calculatewithoperation: "multiply" - "Divide 10 by 0" — triggers the division-by-zero error path
- "Analyze quantum computing" — calls
analyzeand streams three progress phases
Q&A and LLM sampling
- "What is the capital of France?" — calls
smart-answer, which delegates to the client's LLM viaask - "Ask anything" — routes arbitrary questions through
smart-answer
Resources
- "Read the server docs" — reads
docs://readme - "Look up user 42" — reads
user://42
Prompts
- "Review my code" — invokes the
code-reviewprompt with a code snippet - "Help me debug this stack trace" — invokes the
debugprompt with an error and optional context
Channel Events
- "Send me a notification saying 'Build complete'" — calls
notify, which pushes the message as a real-time channel event into your Claude Code session - "Greet Alice" — calls
greetand also fires agreetingchannel event as a side-effect
Example Responses
greet(name: "Alice")
→ "Hello, Alice!"
whoami()
→ "Your mctx user ID is: user_abc123. This ID is stable across all your devices and sessions."
calculate(operation: "multiply", a: 6, b: 7)
→ { "operation": "multiply", "a": 6, "b": 7, "result": 42 }
analyze(topic: "quantum computing")
→ [progress: 1/3] → [progress: 2/3] → [progress: 3/3]
→ "Analysis of "quantum computing" complete. Found 42 insights across 7 categories."
smart-answer(question: "What is the capital of France?")
→ "Question: What is the capital of France?\n\nAnswer: Paris."
notify(message: "Build complete")
→ "Notification sent: \"Build complete\""
→ [channel event pushed to Claude Code session: type=notification, source=example_server]
(the channel event appears as a real-time notification in the Claude Code session)
Read URI: docs://readme
→ "Welcome to the example App built with @mctx-ai/app..."
Read URI: user://42
→ { "id": "42", "name": "User 42", "joined": "2024-01-01", "plan": "pro" }
code-review(code: "const x = eval(input)", language: "javascript")
→ "Please review this javascript for bugs, security issues, and improvements:..."
debug(error: "TypeError: Cannot read properties of undefined")
→ [user] "I'm seeing this error: TypeError: Cannot read..."
→ [assistant] "I will analyze the error and provide step-by-step debugging guidance."
Getting Started
Using as a Template
This repo is a GitHub template. Click Use this template on GitHub, then:
1. Clone your new repo
git clone https://github.com/your-username/your-repo.git
cd your-repo
2. Run the setup script
./setup.sh
setup.sh prompts for a project name and description, asks whether to keep the example code or start from a minimal skeleton, updates package.json, rewrites README.md with a clean starting point, installs dependencies, creates an initial git commit, and deletes itself.
3. Start developing
npm run dev
If you kept the examples, src/index.ts is unchanged — study the patterns and modify from there. If you started empty, you get a minimal skeleton with a single hello tool to build from.
Development Commands
Build
npm run build
Bundles src/index.ts to dist/index.js using esbuild (minified ESM output).
Dev server
npm run dev
# Test environment variables during dev:
GREETING="Howdy" npm run dev
Runs parallel watch mode: esbuild rebuilds on source changes, mctx-dev hot-reloads the server on rebuild.
Testing
npm test # Run all tests
npm test -- --watch # Watch mode
npm test src/index.test.ts # Specific file
npm test -- -t "greet" # Pattern match
Linting and formatting
npm run lint
npm run format
npm run format:check
Environment Variables
GREETING — Customizes the greeting in the greet tool (default: "Hello"). Set GREETING="Howdy" to get "Howdy, Alice!".
Channel event variables (auto-injected by mctx — do not set manually)
MCTX_EVENTS_ENDPOINT, MCTX_SERVER_ID, and MCTX_EVENTS_SECRET are injected by the mctx platform at runtime. ctx.emit() automatically detects and uses these variables with no developer configuration needed — the framework wires them up internally and passes a ready-to-use ctx to every handler. In local dev, these vars are absent and ctx.emit() gracefully no-ops, so your tools work the same locally as on mctx (without actually pushing channel events).
Project Structure
src/index.ts → Server implementation — all capabilities in one file
├─ Tools → greet, whoami, calculate, analyze, smart-answer, notify
├─ Resources → docs://readme (static), user://{userId} (dynamic)
├─ Prompts → code-review (single-message), debug (multi-message)
└─ Export → fetch handler for JSON-RPC 2.0 over HTTP
src/index.test.ts → Tests for every tool, resource, and prompt
dist/index.js → Bundled output (generated by esbuild, not committed on main)
Deployment Model
mctx does not run build commands. It serves dist/index.js from the release branch — no npm run build at deploy time.
dist/ is gitignored on main. The release pipeline (.github/workflows/release.yml) builds dist/index.js from source and commits it to release automatically. Source-only on main; built output on release.
Deployment trigger: mctx watches for version changes in package.json on the release branch. A version bump triggers a new deployment. A push with no version bump does not trigger deployment.
Conventional commits determine the version bump:
| Commit prefix | Bump |
|---|---|
feat!: or fix!: | Major |
feat: | Minor |
| Everything else | Patch |
This repo uses squash merging — PR title becomes the commit subject, so PR titles must follow conventional commit format.
Do not edit the release branch directly. Do not commit dist/index.js on main.
Making Your App Discoverable
Three package.json fields and README.md determine how developers find your App.
description— Appears in the MCP Community Registry (truncates at ~100–150 chars) and on your mctx.ai page. Front-load the most important information.homepage— Clickable link on your public mctx.ai page. Point it at your GitHub repo or docs site.README.md— Becomes the documentation on your mctx.ai page and is indexed by Context7 for AI assistant discovery. Lead with what the App does; the first ~4,000 characters are what AI assistants use to understand and recommend it.
Learn More
@mctx-ai/app— Framework documentation and API reference- docs.mctx.ai — Platform guides for deploying and managing your Apps
- mctx.ai — Host your App for free
- MCP Specification — The protocol spec this App implements
常见问题
Example MCP Server 是什么?
基于 mctx 的示例 MCP server,展示 tools、resources、prompts、progress 与 sampling 等能力。
相关 Skills
MCP构建
by anthropics
聚焦高质量 MCP Server 开发,覆盖协议研究、工具设计、错误处理与传输选型,适合用 FastMCP 或 MCP SDK 对接外部 API、封装服务能力。
✎ 想让 LLM 稳定调用外部 API,就用 MCP构建:从 Python 到 Node 都有成熟指引,帮你更快做出高质量 MCP 服务器。
Slack动图
by anthropics
面向Slack的动图制作Skill,内置emoji/消息GIF的尺寸、帧率和色彩约束、校验与优化流程,适合把创意或上传图片快速做成可直接发送的Slack动画。
✎ 帮你快速做出适配 Slack 的动图,内置约束规则和校验工具,少踩上传与播放坑,做表情包和演示都更省心。
MCP服务构建器
by alirezarezvani
从 OpenAPI 一键生成 Python/TypeScript MCP server 脚手架,并校验 tool schema、命名规范与版本兼容性,适合把现有 REST API 快速发布成可生产演进的 MCP 服务。
✎ 帮你快速搭建 MCP 服务与后端 API,脚手架完善、扩展顺手,尤其适合想高效验证服务能力的开发者。
相关 MCP Server
Slack 消息
编辑精选by Anthropic
Slack 是让 AI 助手直接读写你的 Slack 频道和消息的 MCP 服务器。
✎ 这个服务器解决了团队协作中需要 AI 实时获取 Slack 信息的痛点,特别适合开发团队让 Claude 帮忙汇总频道讨论或发送通知。不过,它目前只是参考实现,文档有限,不建议在生产环境直接使用——更适合开发者学习 MCP 如何集成第三方服务。
by netdata
io.github.netdata/mcp-server 是让 AI 助手实时监控服务器指标和日志的 MCP 服务器。
✎ 这个工具解决了运维人员需要手动检查系统状态的痛点,最适合 DevOps 团队让 Claude 自动分析性能数据。不过,它依赖 NetData 的现有部署,如果你没用过这个监控平台,得先花时间配置。
by d4vinci
Scrapling MCP Server 是专为现代网页设计的智能爬虫工具,支持绕过 Cloudflare 等反爬机制。
✎ 这个工具解决了爬取动态网页和反爬网站时的头疼问题,特别适合需要批量采集电商价格或新闻数据的开发者。不过,它依赖外部浏览器引擎,资源消耗较大,不适合轻量级任务。