About Add API key to .env file
This minimal Python MCP example is for developers learning how an MCP system runs. It includes a client and task-list server, with MCP servers specified in a configuration file.
Key features
- 01Python client and server example
- 02Configure MCP servers with JSON
- 03Use an API key with an LLM service
- 04Task-list server
Use cases
- 01Learn the basic operation of an MCP client and server
- 02Configure the client to connect to the task-list MCP server
MCP support
The example includes an MCP client and task-list server, with server targets specified in server.json.
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 READMEThe simplest mcp project
本项目实现了最小的mcp项目,方便理解整个MCP系统的运行,
项目使用了deepseek的api_key,请在.env文件中添加你的api_key
如果使用其他LLM服务,请在env文件中添加相应的API_KEY,请选择支持MCP服务的LLM服务
文件结构
├── .env
├── .gitignore
├── client/client.py
├── client/server.json
├── server/tasklist.py
├── pyproject.toml
|── tasks.csv
|── README.md
创建虚拟环境
uv venv
# Activate virtual environment
# On Windows:
.venv\Scripts\activate
# On Unix or MacOS:
source .venv/bin/activate
安装依赖
## 使用openai格式来访问
uv add mcp openai python-dotenv
创建.env文件
touch .env
Add API key to .env file
echo "OPENAI_API_KEY=your_api_key" >> .env
echo "OPENAI_BASE_URL="https://api.deepseek.com/v1"" >> .env
echo "OPENAI_MODEL="deepseek-chat" >> .env
编辑server.json文件来指定mcp-server
{
"servers": [
{
"command": "uv",
"args": ["run","../server/tasklist.py"],
"env": null
},
{
"command": "uv",
"args": ["run","../server/weather.py"],
"env": null
},
{
"command": "npx",
"args": ["-y","../server/stock.js"],
"env": null
}
]
}
运行mcp-demo
cd client
uv run client.py server.json
然后输入用户query即可
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.