-
Notifications
You must be signed in to change notification settings - Fork 235
feat: Add Docker support and configure for Cloud Run #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Python | ||
| __pycache__/ | ||
| *.pyc | ||
| *.pyo | ||
| *.pyd | ||
| .Python | ||
| build/ | ||
| develop-eggs/ | ||
| dist/ | ||
| downloads/ | ||
| eggs/ | ||
| .eggs/ | ||
| lib/ | ||
| lib64/ | ||
| parts/ | ||
| sdist/ | ||
| var/ | ||
| wheels/ | ||
| *.egg-info/ | ||
| .installed.cfg | ||
| *.egg | ||
| MANIFEST | ||
|
|
||
| # Git | ||
| .git/ | ||
| .gitignore | ||
|
|
||
| # Docker | ||
| .dockerignore | ||
| Dockerfile | ||
|
|
||
| # Testing | ||
| tests/ | ||
| noxfile.py | ||
|
|
||
| # GitHub | ||
| .github/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Use the official lightweight Python image. | ||
| # https://hub.docker.com/_/python | ||
| FROM python:3.11-slim | ||
|
|
||
| # Set the working directory in the container. | ||
| WORKDIR /app | ||
|
|
||
| # Copy the dependency file to the working directory. | ||
| COPY pyproject.toml . | ||
|
|
||
| # Install any dependencies. | ||
| RUN pip install --no-cache-dir -e . | ||
|
|
||
| # Copy the rest of the working directory contents into the container. | ||
| COPY . . | ||
|
|
||
| # Set the port that the container will listen on. | ||
| # This is the default port for Cloud Run. | ||
| ENV PORT=8080 | ||
| ENV HOST=0.0.0.0 | ||
|
|
||
| # Run the application. | ||
| CMD ["analytics-mcp"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
|
|
||
| """Entry point for the Google Analytics MCP server.""" | ||
|
|
||
| import os | ||
| from analytics_mcp.coordinator import mcp | ||
|
|
||
| # The following imports are necessary to register the tools with the `mcp` | ||
|
|
@@ -32,7 +33,11 @@ def run_server() -> None: | |
|
|
||
| Serves as the entrypoint for the 'runmcp' command. | ||
| """ | ||
| mcp.run() | ||
| # For Cloud Run, the server must listen on 0.0.0.0 and a port specified by | ||
| # the PORT environment variable. | ||
| host = os.environ.get("HOST", "127.0.0.1") | ||
| port = int(os.environ.get("PORT", "8000")) | ||
|
Comment on lines
+38
to
+39
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, |
||
| mcp.run(transport="streamable-http", host=host, port=port) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this require an upgrade to the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Should the host and port override go in the constructor call instead? |
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of hardcoding the defaults used by
mcphere (127,0.0.1 and 8000), could you make overriding the host and port only happen if the environment has theHOSTandPORTenv vars set?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turns out that FastMCP already handles host/port overrides via its own env vars
FAST_MCP_HOSTandFAST_MCP_PORT, respectively. See this comment in server.py.If you use those in Docker, you won't need this code that overrides the host and port at all.