About Python Mcp Server Sample
A Python sample project that demonstrates building an MCP server with the MCP SDK and registering it in Cline. It is aimed at developers learning a basic server setup.
Key features
- 01Python project setup with uv
- 02MCP SDK installation
- 03FastMCP server scaffold
- 04Cline server registration example
Use cases
- 01Learning the Python MCP server setup flow
- 02Starting a small MCP server project
MCP support
Demonstrates creating an MCP server with the Python MCP SDK and configuring Cline to launch it.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEuvのインストール
curl -LsSf https://astral.sh/uv/install.sh | sh
Pythonプロジェクトを作成
# mcp-server-demoというPythonプロジェクトを作成
uv init mcp-server-demo
MCP SDKのインストール
# mcp-server-demoプロジェクト配下に移動
cd mcp-server-demo
# mcp-server-demoプロジェクトにmcp sdkをインストール
uv add "mcp[cli]"
MCPサーバの構築
server.pyファイルの作成(ファイル名はなんでもよい)
mv main.py server.py
server.pyに以下のように記述
from mcp.server.fastmcp import FastMCP
# Create an MCP server with debug enabled
mcp = FastMCP("Demo", debug=True)
# Add an addition tool
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b
# Add this part to run the server
if __name__ == "__main__":
# stdioトランスポートを使用
print("Starting MCP server in stdio mode")
mcp.run(transport="stdio")
ClineへのMCPサーバの登録
ClineのプロジェクトMCPファイルを以下のように編集
{
"mcpServers": {
"mcp-demo-server": {
"command": "uv",
"args": [
"--directory",
<path to mcp-server-demo>,
"run",
"server.py"
],
"alwaysAllow": [
"add"
],
"disabled": false
}
}
}
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.