demo-server
A minimal MCP server demonstrating tools, resources, and prompts. It includes an add tool, a greeting resource, and a greet_user prompt for tutorial purposes.
README
MCP Tutorial
A minimal Model Context Protocol (MCP) tutorial built with the
MCP Python SDK (mcp[cli]). It contains a small
FastMCP server and shows how to make Claude Code aware of it through project configuration — without
running claude mcp add.
Contents
- The server
- Prerequisites
- Running the server standalone
- Registering the server with a client
- Approving servers and auto-approving tools (Claude Code)
- Debugging with the MCP Inspector
- Configuration reference
The server
The example server lives in examples/snippets/servers/fastmcp_quickstart.py
and exposes one of each MCP primitive:
| Primitive | Name | Description |
|---|---|---|
| Tool | add(a, b) |
Adds two numbers |
| Resource | greeting://{name} |
Returns a personalized greeting |
| Prompt | greet_user(name, style) |
Generates a greeting prompt |
Prerequisites
- uv for running the project
- Dependencies are declared in
pyproject.toml(mcp[cli]>=1.28.0)
Install dependencies:
uv sync
Running the server standalone
To run the server directly over streamable HTTP (listens on http://localhost:8000/mcp):
uv run examples/snippets/servers/fastmcp_quickstart.py
This is only required for the HTTP transport option below. With the stdio option, Claude Code launches the server for you, so you don't need to run this manually.
Registering the server with a client
Each MCP client discovers servers from its own config file. The server configuration is nearly identical across clients — the differences are which file holds it and the top-level key name:
| Client | Config file | Top-level key |
|---|---|---|
| Claude Code | .mcp.json |
mcpServers |
| GitHub Copilot | .vscode/mcp.json |
servers |
Both files are committed to the repo, so anyone who clones it gets the same server configuration.
Claude Code
Claude Code learns about project-scoped MCP servers from a .mcp.json file at the repository root.
This file is the declarative equivalent of claude mcp add — it's committed to the repo, so anyone who
clones it gets the same server configuration.
Pick one of the two transport options below.
Option A — stdio (Claude Code launches the server)
Because the server lives in this project, you can let Claude Code spawn it on demand. There's no port and nothing to keep running separately.
{
"mcpServers": {
"demo-server": {
"command": "uv",
"args": ["run", "examples/snippets/servers/fastmcp_quickstart.py"]
}
}
}
Note: For stdio, the server script must use the stdio transport. FastMCP uses stdio by default when you call
mcp.run()with no arguments, so change the last line of the script tomcp.run()(or run a stdio-specific entry point).
Option B — HTTP transport
If you'd rather run the server yourself as a long-running HTTP process, point .mcp.json at its URL
instead. First start the server (see Running the server standalone),
then use:
{
"mcpServers": {
"demo-server": {
"type": "http",
"url": "http://localhost:8000/mcp"
}
}
}
With this option the server must already be running before Claude Code connects.
Note: For HTTP, the server script must use the streamable HTTP transport. In
fastmcp_quickstart.pythe defaultmcp.run()is commented alongsidemcp.run(transport="streamable-http")— swap the active line so the script runs over HTTP:if __name__ == "__main__": mcp.run(transport="streamable-http") # mcp.run() # default transport is stdio
Reload and verify
-
Restart Claude Code (or run
/mcpin an interactive session). -
From the terminal, check status with:
claude mcp list claude mcp get demo-server -
The server should report ✔ Connected and expose the
addtool, thegreeting://{name}resource, and thegreet_userprompt.
GitHub Copilot (VS Code)
VS Code discovers workspace MCP servers from .vscode/mcp.json. Note the top-level
key is servers (not mcpServers), and each entry declares its transport with type.
Pick one of the two transport options below.
stdio
VS Code launches the server for you — no port, nothing to keep running separately:
{
"servers": {
"demo-server": {
"type": "stdio",
"command": "uv",
"args": ["run", "examples/snippets/servers/fastmcp_quickstart.py"]
}
}
}
Note: As with Claude Code, the script must use the stdio transport (
mcp.run()).
HTTP transport
Run the server yourself first (see Running the server standalone), then point VS Code at its URL:
{
"servers": {
"demo-server": {
"type": "http",
"url": "http://localhost:8000/mcp"
}
}
}
Note: For HTTP, the script must use
mcp.run(transport="streamable-http")(see the Claude Code HTTP note).
Start and verify
- Open
.vscode/mcp.json— VS Code shows a Start action above each server entry. You can also run MCP: List Servers from the Command Palette to start/stop/inspect them. - Open the Copilot Chat view and switch to Agent mode (tools are only available in agent mode).
- Click the tools (🛠) icon to confirm
demo-serveris listed, then ask Copilot to use theaddtool.
Approving servers and auto-approving tools (Claude Code)
Claude Code has two independent safety gates for project MCP servers, both configured in
.claude/settings.json (shared, committed) or .claude/settings.local.json (personal, git-ignored):
- Server approval — whether a server from
.mcp.jsonis allowed to load at all. - Tool-call approval — whether Claude may run a server's tools without prompting you each time.
This section walks through both, using the lifespan-demo server (which exposes the query_db tool) as
the example.
Step 1 — Approve the server
Servers declared in .mcp.json start as ⏸ Pending approval as a safety measure — a cloned repo can't
auto-run servers without your consent. Grant approval declaratively with enabledMcpjsonServers instead
of clicking through the interactive prompt:
{
"enabledMcpjsonServers": ["demo-server", "lifespan-demo"]
}
Or trust every server defined in .mcp.json at once:
{
"enableAllProjectMcpServers": true
}
After this, the server loads and its tools become visible — but Claude will still ask permission each time it wants to call one.
Step 2 — Auto-approve tool calls
To stop the per-call prompts, add a permissions.allow rule. The MCP rule format is:
| Rule | Matches |
|---|---|
mcp__lifespan-demo |
Every tool from the lifespan-demo server |
mcp__lifespan-demo__query_db |
Only the query_db tool |
Note: the tool part does not support
*wildcards — use the server-only form (mcp__<server>) to cover all tools, or name a specific tool (mcp__<server>__<tool>).
Combined with Step 1, .claude/settings.json looks like:
{
"enabledMcpjsonServers": ["demo-server", "lifespan-demo"],
"permissions": {
"allow": ["mcp__lifespan-demo"]
}
}
Reload Claude Code (restart or /mcp), then ask:
Use the query_db tool to run
SELECT * FROM users
It runs without a permission prompt and returns Result of 'SELECT * FROM users'.
Scope tip: keep server approval (
enabledMcpjsonServers) in the sharedsettings.jsonso teammates get the server, but consider putting auto-approval (permissions.allow) insettings.local.jsonif you don't want to silently grant tool execution to everyone who clones the repo.
Debugging with the MCP Inspector
The MCP Inspector is an interactive, browser-based tool for poking at a server directly — without wiring it into Claude Code or Copilot. It's the quickest way to call tools by hand and watch logs and progress notifications live.
Launch it against any server in this repo:
uv run mcp dev examples/snippets/servers/<server_file>.py
uv run mcp dev examples/snippets/servers/basic_tool.py
What this does:
uv runruns inside the project virtualenv (somcpand your deps are available).mcp devstarts the server over stdio and attaches the Inspector to it.- It prints a
localhostURL — open it in a browser.
The Inspector uses two ports: 6274 (the web UI) and 6277 (the proxy). In the UI you can:
- List and call tools — e.g. run
long_running_taskwith atask_nameandsteps. - Browse resources and prompts.
- Watch logs and progress notifications live — the best way to see
Contextcalls (ctx.info,ctx.debug,ctx.report_progress) as they happen.
Requires Node.js. The Inspector is a Node package (
@modelcontextprotocol/inspector) launched vianpx; the first run downloads it.Auth token. Recent versions print a URL that includes a session token, e.g.
http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=…— use that full link from the terminal.Port already in use?
❌ Proxy Server PORT IS IN USE at port 6277means an Inspector is already running — just open http://localhost:6274, or stop the existing one first. It's a long-running process; stop it withCtrl-C.
Configuration reference
| File | Purpose | Committed? |
|---|---|---|
.mcp.json |
Declares the project MCP server for Claude Code | Yes (shared) |
.vscode/mcp.json |
Declares the workspace MCP server for Copilot | Yes (shared) |
.claude/settings.json |
Approves servers + auto-approves tools for the team | Yes (shared) |
.claude/settings.local.json |
Approves servers + auto-approves tools just for you | No (git-ignored) |
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。