This project includes two sides: a Python MCP server and a Python MCP client, both built using the Starlette framework and the MCP Streamable HTTP transport protocol. The MCP server also includes additional non-MCP routes for standard web functionality.
This project is a template for developing applications that use the Model Context Protocol (MCP) as a way to coordinate across clients and servers. The guide below will help you get started with the project, deploy it to Azure, and/or run it locally.
- Streamable HTTP transport protocol for MCP
- Starlette framework integration with custom routes
- Unified web application with both MCP and standard web endpoints
- Clean separation of concerns between MCP and web functionality
- Simple MCP client that can be used to test the MCP server endpoints
You have a few options for getting started with this template. The quickest way to get started is GitHub Codespaces, since it will setup all the tools for you, but you can also set it up locally.
You can run this template virtually by using GitHub Codespaces. The button will open a web-based VS Code instance in your browser:
-
Open the template (this may take several minutes):
-
Open a terminal window
-
Continue with the deploying steps
A related option is VS Code Dev Containers, which will open the project in your local VS Code using the Dev Containers extension:
-
Start Docker Desktop (install it if not already installed)
-
Open the project:
-
In the VS Code window that opens, once the project files show up (this may take several minutes), open a terminal window.
-
Continue with the deploying steps
If you're not using one of the above options for opening the project, then you'll need to:
-
Make sure the following tools are installed:
-
Clone this repository:
git clone https://github.com/pamelafox/python-mcp-starlette-client-server.git
-
Open the project folder
-
Create a Python virtual environment and activate it.
uv venv
-
Install the the MCP server packages:
uv pip install -e mcp_server
-
Install the MCP client packages:
uv pip install -e mcp_client
-
Continue with the deploying steps.
Note
Deploying to Azure will expose your MCP server to the public internet. Do not deploy this to production without securing it first, such as by using authentication and HTTPS.
-
Login to Azure:
az login
-
Install the container apps extension if you haven't already:
az extension add --name containerapp --upgrade
-
Store the following values in variables:
export RESOURCEGROUP="your-resource-group-name" export LOCATION="your-azure-region" # e.g., eastus, westus, etc. export CONTAINERAPPSENV="your-container-apps-environment-name"
Replace
your-resource-group-name
,your-azure-region
, andyour-container-apps-environment-name
with your desired values. -
Create a resource group:
az group create --name $RESOURCEGROUP --location $LOCATION
-
Create an Azure Container Apps environment:
az containerapp env create --name $CONTAINERAPPSENV --resource-group $RESOURCEGROUP --location $LOCATION
-
Run this command to deploy the application to Azure Container Apps:
az containerapp compose create --compose-file-path docker-compose.yaml -g $RESOURCEGROUP --environment $CONTAINERAPPSENV
-
Save the URL of the deployed server application:
DEPLOYED_SERVER_HOST=$(az containerapp show --name mcpserver --query properties.configuration.ingress.fqdn --resource-group $RESOURCEGROUP -o tsv)
-
Update the SERVER_URL environment variable of the client application to point to the deployed server URL:
az containerapp update --name mcpclient --resource-group $RESOURCEGROUP --set-env-vars SERVER_URL="https://$DEPLOYED_SERVER_HOST/mcp/"
-
Navigate to the mcpclient app in the Azure Portal and view the logs to see the client connecting to the server.
To run the MCP server and client in your local development environment, the easiest way is to use the provided Docker Compose file. This will set up both the MCP server and client in containers, and show the output in your terminal.
docker compose up
You can also run them each separately if you prefer, or run them without Docker, as described below.
Assuming you've run the steps to open the project, you can now run the app in your development environment:
To run the MCP server with Docker:
docker build -t mcp-server mcp-server
docker run -p 8000:8000 mcp-server
To run the MCP server without Docker:
cd mcp-server
uv run mcp-server
To use the MCP Dev Inspector to test the server:
uv run mcp dev mcp-server/src/mcp_server/weather.py
To run the MCP client with Docker:
docker build -t mcp-client mcp-client
docker run -e SERVER_URL=http://localhost:8000/mcp/ mcp-client
To run the MCP client without Docker:
cd mcp-client
uv run mcp-client