Task 01 - Run MCP server locally
Introduction
In this task, you will set up and run the MCP Weather Mock server on your local machine (or in a GitHub Codespace). This server is a simple Python-based MCP server that exposes weather-related tools using the Model Context Protocol.
Description
You will create a Python virtual environment, install the required dependencies, and start the MCP server. The server uses FastMCP with Streamable HTTP transport, which means it exposes an HTTP endpoint that MCP clients can connect to.
Success Criteria
- The MCP server is running and accessible at
http://localhost:8000. - The MCP endpoint is available at
http://localhost:8000/mcp.
Learning Resources
Key Tasks
01: Navigate to the project directory
Open a terminal and navigate to the MCP Weather Mock server directory.
Expand this section to view the solution
cd src/01-mcp-weather-mock
02: Create and activate a Python virtual environment
Create a virtual environment to isolate the project dependencies.
Expand this section to view the solution
Create the virtual environment:
python -m venv .venv
Activate it based on your operating system:
Linux / macOS / Codespace:
source .venv/bin/activate
Windows (PowerShell):
.venv\Scripts\Activate.ps1
Windows (Command Prompt):
.venv\Scripts\activate.bat
03: Install dependencies
Install the required Python packages.
Expand this section to view the solution
pip install -r requirements.txt
This installs the mcp package (version 1.26.0) which includes FastMCP, Starlette, and uvicorn.
04: Run the MCP server
Start the MCP server.
Expand this section to view the solution
python main.py
You should see output similar to:
INFO: Started server process
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
The server is now running and the MCP endpoint is available at http://localhost:8000/mcp.
Keep this terminal open and the server running. You will need it for the next tasks. Open a new terminal for subsequent commands.
05: (Codespace only) Open port for access
If you are running in a GitHub Codespace, you need to make port 8000 accessible.
Expand this section to view the solution
- In VS Code, open the Ports panel (click on the Ports tab in the bottom panel, or go to View > Terminal and select the Ports tab).
- You should see port 8000 listed automatically (Codespaces detects running servers).
- If port 8000 is not listed, click Add Port and enter
8000. - Click on the Visibility column for port 8000 and change it to Public (this is required for external tools like MCP Inspector to access the server).
- Copy the Forwarded Address URL (e.g.,
https://<codespace-name>-8000.app.github.dev). You will use this URL instead ofhttp://localhost:8000in subsequent tasks.
Remember to use the Codespace forwarded URL (e.g.,
https://<codespace-name>-8000.app.github.dev/mcp) instead ofhttp://localhost:8000/mcpwhen testing from external tools in a Codespace environment.