Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion run/mcp-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
FROM python:3.14-slim

# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
COPY --from=ghcr.io/astral-sh/uv:0.13.10 /uv /uvx /bin/

# Install the project into /app
COPY . /app
Expand Down
2 changes: 1 addition & 1 deletion run/mcp-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ provides a fast, Pythonic way to build MCP servers and clients.

## Prerequisites

- Python 3.10+
- Python 3.14+
- Uv (for package and project management, see [docs for installation](https://docs.astral.sh/uv/getting-started/installation/))
- Google Cloud SDK (gcloud)

Expand Down
10 changes: 5 additions & 5 deletions run/mcp-server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ name = "mcp-server"
version = "0.1.0"
description = "Example of deploying an MCP server on Cloud Run"
readme = "README.md"
requires-python = ">=3.10"
requires-python = ">=3.14"
dependencies = [
"fastmcp==3.4.3",
"opentelemetry-api==1.40.0",
"opentelemetry-sdk==1.40.0",
"opentelemetry-exporter-otlp-proto-grpc==1.40.0",
"fastmcp==4.2.6",
"opentelemetry-api==1.45.2",
"opentelemetry-sdk==1.45.2",
"opentelemetry-exporter-otlp-proto-grpc==1.45.2",
"google-auth==2.62.0",
"grpcio==1.80.0",
"requests==2.34.2",
Expand Down
17 changes: 11 additions & 6 deletions run/mcp-server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,63 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# flake8: noqa
# [START cloudrun_mcpserver_otel]
from otel_setup import setup_opentelemetry

setup_opentelemetry("mcp-server")

# [START cloudrun_mcpserver]
import asyncio
import logging
import os

from fastmcp import FastMCP
from fastmcp import FastMCP

logger = logging.getLogger(__name__)
logging.basicConfig(format="[%(levelname)s]: %(message)s", level=logging.INFO)

mcp = FastMCP("MCP Server on Cloud Run")


@mcp.tool()
def add(a: int, b: int) -> int:
"""Use this to add two numbers together.

Args:
a: The first number.
b: The second number.

Returns:
The sum of the two numbers.
"""
logger.info(f">>> 🛠️ Tool: 'add' called with numbers '{a}' and '{b}'")
return a + b


@mcp.tool()
def subtract(a: int, b: int) -> int:
"""Use this to subtract two numbers.

Args:
a: The first number.
b: The second number.

Returns:
The difference of the two numbers.
"""
logger.info(f">>> 🛠️ Tool: 'subtract' called with numbers '{a}' and '{b}'")
return a - b


if __name__ == "__main__":
logger.info(f"🚀 MCP server started on port {os.getenv('PORT', 8080)}")
# Could also use 'sse' transport, host="0.0.0.0" required for Cloud Run.
asyncio.run(
mcp.run_async(
transport="streamable-http",
host="0.0.0.0",
port=os.getenv("PORT", 8080),
port=int(os.getenv("PORT", 8080)),
)
)

Expand Down
Loading