Workshop
MCP 工作坊

本项目是在 The Developers Life Weekend 活动的工作坊期间开发的,活动地点位于乌穆阿拉马 - 巴拉那州(线上)。
关于工作坊
本仓库包含分步指南、源代码和练习,用于构建您第一个基于 模型上下文协议(MCP) 的服务器。
在工作坊期间,我们介绍了:
MCP 协议的客户端-服务器架构;
为 LLM 创建和暴露工具(tools);
资源(resources)和动态提示词的管理;
将服务器连接到真实 AI 客户端。
主项目使用 Python 和 FastMCP 创建。它提供工具和资源来查询天气预报,并演示了一个在发送邀请前需要确认的操作。
Related MCP server: Weather MCP Server
要求
Python 3.14 或更高版本;
已安装 uv;
在 Auth0 中配置的应用程序;
可访问互联网以查询
https://wttr.in;兼容的 MCP 客户端,如 OpenCode 或 MCP Inspector。
项目使用 uv.lock 来保持依赖版本的可复现性。
安装
克隆仓库并进入项目文件夹:
git clone https://github.com/marcelomarkus/tdlw-workshop-mcp.git
cd tdlw-workshop-mcp同步依赖。该命令会自动创建或更新虚拟环境 .venv:
uv sync检查所选 Python 版本:
python --version
uv python findAuth0 配置
主服务器使用 Auth0Provider,需要以下环境变量:
变量 | 描述 |
| Auth0 实例的域名 |
| 应用程序的标识符 |
| 应用程序的密钥 |
| 在 Auth0 中配置的 API 标识符 |
从模板创建本地配置文件:
cp .env_example .env用真实值填写 .env:
AUTH_DOMAIN=https://seu-dominio.auth0.com
CLIENT_ID=seu-client-id
CLIENT_SECRET=seu-client-secret
AUDIENCE=https://sua-api.env 文件不会被 Python 自动加载。在启动服务器前导出变量:
set -a
source .env
set +a或者直接在同一个调用中定义它们:
AUTH_DOMAIN="https://seu-dominio.auth0.com" \
CLIENT_ID="seu-client-id" \
CLIENT_SECRET="seu-client-secret" \
AUDIENCE="https://sua-api" \
uv run main.py切勿共享 CLIENT_SECRET,也不要将其包含在提交中。
运行服务器
加载变量后,启动主服务器:
uv run main.pyMCP 端点可在以下地址访问:
http://127.0.0.1:8000/mcp在 MCP 客户端连接期间保持进程运行。要终止它,请按 Ctrl+C。
运行 MCP Inspector
MCP Inspector 提供了一个 Web 界面,用于测试工具、资源和提示词。
在第一个终端中,启动服务器:
set -a
source .env
set +a
uv run main.py在另一个终端中,运行 Inspector:
npx @modelcontextprotocol/inspector在浏览器中打开 http://localhost:6274 并配置:
字段 | 值 |
传输方式 |
|
URL |
|
点击 Connect 并测试可用的工具和资源。Auth0 变量需要存在于服务器进程的环境中。
通过 OpenCode 连接
opencode.json 文件已指向本地端点:
{
"mcp": {
"Workshop": {
"type": "remote",
"url": "http://127.0.0.1:8000/mcp"
}
}
}服务器运行后,在此项目中打开 OpenCode。
可用功能
工具
Tempo(cidade):查询某个城市的当前天气;Temperatura(cidade):查询某个城市的当前温度;Enviar_Convites(quantidade):请求确认并模拟发送,报告每个项目的进度。
天气查询使用 wttr.in/<cidade>?format=%t。
资源
workshop://oque-o-mcp-nao-e:关于 MCP 的介绍性文本;previsao://{cidade}:URI 中指定城市的天气预报。
提示词
exemplo_prompt(pergunta):指导在天气工具之间进行选择。
项目结构
.
├── main.py # Servidor MCP principal
├── mcp_com_api.py # Servidor MCP gerado a partir da API Petstore
├── exercises/ # Exercícios progressivos do workshop
│ ├── 01-mcp-server/
│ ├── 02-resources/
│ ├── 03-tools/
│ ├── 04-prompts/
│ ├── 05-Context/
│ ├── 06-auth/
│ └── 07-mcp-api/
├── slide/ # Material de apoio
│ └── TDLW-Umuarama.pdf
├── opencode.json # Configuração do OpenCode
├── pyproject.toml # Metadados e dependências
├── uv.lock # Versões resolvidas
└── .env_example # Modelo das variáveis do Auth0开发
您可以通过 VS Code 的调试模式或 uv 运行项目:
uv run main.py要检查模块的语法:
python -m compileall main.py mcp_com_api.py exercises故障排除
ModuleNotFoundError
执行 uv sync 并使用 uv run main.py 运行程序,避免在依赖仅安装在 .venv 中时使用全局 Python。
认证错误
检查四个 Auth0 变量是否已在服务器同一环境中导出,以及域名是否包含预期的协议。
天气查询失败
测试连接性:
curl "https://wttr.in/Sao%20Paulo?format=%t"8000 端口被占用
释放端口或在服务器和 opencode.json 中调整端口,保持两端地址一致。
文档和参考
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to fetch current weather conditions and forecasts for any city using the Open-Meteo API. Provides temperature, precipitation, and hourly forecast data through natural language queries.
- AlicenseNot gradedqualityDmaintenanceEnables LLMs to retrieve 24-hour weather forecasts and city information through natural language queries using city names or coordinates.MIT
- FlicenseAqualityDmaintenanceProvides weather information and time utilities for AI assistants, enabling them to fetch current weather for any city and get the current timestamp.246
- AlicenseNot gradedqualityCmaintenanceEnables LLMs to fetch real-time weather data for any city and perform basic arithmetic operations like addition.MIT
Related MCP Connectors
US weather & geo for AI agents: forecasts, alerts, earthquakes, elevation, geocoding. No keys.
Real-world data for agents: air quality, geocoding, quakes, holidays, web search
US weather, alerts, earthquakes and elevation for AI agents, from NWS/NOAA and USGS. No API keys.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/marcelomarkus/tdlw-workshop-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server