Demo MCP Server
A learning-purpose MCP server providing tools for arithmetic calculation, current time retrieval, and text analysis.
README
Demo MCP Server
这是一个用于学习目的的简单 MCP (Model Context Protocol) Server 演示项目。
什么是 MCP?
MCP (Model Context Protocol) 是一个开放协议,允许 AI 应用程序(如 Claude)与外部工具和数据源进行通信。通过 MCP,你可以:
- 为 Claude 提供自定义工具
- 集成外部 API 和服务
- 访问本地数据源
- 扩展 Claude 的能力
这个演示 Server 提供的工具
这个 demo MCP server 提供了三个简单的工具:
- calculate - 执行基本算术运算(加、减、乘、除)
- get_current_time - 获取当前日期和时间
- analyze_text - 分析文本统计信息(字数、字符数等)
项目结构
.
├── demo_mcp_server.py # MCP server 主程序
├── pyproject.toml # Python 项目配置
├── claude_desktop_config.json # Claude Desktop 配置示例
└── README.md # 本文件
安装和运行
1. 安装依赖
使用 uv(推荐):
uv pip install -e .
或使用 pip:
pip install -e .
2. 测试 Server
你可以直接运行 server 来测试它:
demo-mcp-server
或者使用 Python 运行:
python demo_mcp_server.py
3. 配置 Claude Code 使用此 MCP Server
要配置 Claude Code 使用这个 MCP server,你需要编辑 Claude Code 的配置文件。
Claude Code 配置文件位置:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
在配置文件中添加以下内容:
{
"mcpServers": {
"demo-server": {
"command": "uv",
"args": [
"--directory",
"/Users/bytedance/workingspace/lzx-mcp",
"run",
"demo-mcp-server"
]
}
}
}
或者如果你使用的是系统 Python:
{
"mcpServers": {
"demo-server": {
"command": "demo-mcp-server"
}
}
}
注意:将 /Users/bytedance/workingspace/lzx-mcp 替换为你的实际项目路径。
4. 重启 Claude Code
配置完成后,重启 Claude Code 以加载新的 MCP server。
5. 使用 MCP 工具
重启后,你可以在 Claude Code 中这样使用:
请帮我计算 123 乘以 456
获取当前时间
分析这段文本的文字统计:Hello, this is a demo of the MCP server!
MCP Server 工作原理
核心概念
- Server(服务器): 提供 tools 和资源的程序
- Client(客户端): 使用这些 tools 的应用程序(如 Claude)
- Tools(工具): 可以被 AI 调用的函数
- Transport(传输): Server 和 client 之间的通信方式(stdio, SSE 等)
代码结构解释
# 1. 创建 Server 实例
app = Server("demo-mcp-server")
# 2. 列出可用工具
@app.list_tools()
async def list_tools() -> list[Tool]:
# 返回所有可用工具的描述
return [...]
# 3. 处理工具调用
@app.call_tool()
async def call_tool(name: str, arguments: dict):
# 根据 tool name 路由到相应的处理函数
...
# 4. 运行 server
async def main():
async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
await app.run(read_stream, write_stream, ...)
扩展建议
想要添加更多工具?只需:
- 在
list_tools()中添加新的 Tool 定义 - 在
call_tool()中添加对应的处理函数 - 实现具体的业务逻辑
示例:添加一个新的工具来获取天气信息
Tool(
name="get_weather",
description="Get current weather for a city",
inputSchema={
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"},
},
"required": ["city"],
},
)
参考资源
License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.