Skip to content

Commit 7c561b1

Browse files
authored
Merge pull request #63 from papagala/main
Making the dockerfile and code ready for kagent.
2 parents 3715423 + 72de7f6 commit 7c561b1

File tree

4 files changed

+109
-4
lines changed

4 files changed

+109
-4
lines changed

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,19 @@ RUN m3 init mimic-iv-demo
2727

2828
# Lite: SQLite only
2929
FROM base AS lite
30+
ENV MCP_TRANSPORT=http \
31+
MCP_HOST=0.0.0.0 \
32+
MCP_PORT=3000 \
33+
MCP_PATH=/sse
34+
EXPOSE 3000
3035
CMD ["python", "-m", "m3.mcp_server"]
3136

3237
# BigQuery: add GCP client
3338
FROM base AS bigquery
3439
RUN pip install --no-cache-dir google-cloud-bigquery
40+
ENV MCP_TRANSPORT=http \
41+
MCP_HOST=0.0.0.0 \
42+
MCP_PORT=3000 \
43+
MCP_PATH=/sse
44+
EXPOSE 3000
3545
CMD ["python", "-m", "m3.mcp_server"]

Makefile

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Makefile for M3 Docker Image Build and Push
2+
DOCKER ?= docker
3+
IMAGE_NAME := m3-mimic-demo
4+
IMAGE_TAG ?= 0.4.0
5+
6+
# Prompt for registry only if not set
7+
ifndef DOCKER_REGISTRY
8+
DOCKER_REGISTRY := $(shell bash -c 'read -p "Enter Docker registry/username: " registry; echo $${registry}')
9+
endif
10+
11+
DOCKER_IMAGE := $(DOCKER_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)
12+
13+
DB_FILE := m3_data/databases/mimic_iv_demo.db
14+
15+
.PHONY: help
16+
help: ## Show help
17+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-20s %s\n", $$1, $$2}'
18+
19+
.PHONY: all
20+
all: download-db build push ## Complete workflow: download DB, build and push
21+
22+
.PHONY: login
23+
login: ## Login to Docker Hub
24+
@$(DOCKER) login docker.io
25+
26+
.PHONY: download-db
27+
download-db: ## Download MIMIC-IV demo database
28+
@uv sync
29+
@uv run m3 init mimic-iv-demo
30+
31+
.PHONY: build
32+
build: ## Build Docker image (lite version)
33+
@test -f $(DB_FILE) || { echo "Run 'make download-db' first"; exit 1; }
34+
@$(DOCKER) build --target lite -t $(DOCKER_IMAGE) -t $(DOCKER_REGISTRY)/$(IMAGE_NAME):lite .
35+
36+
.PHONY: build-bigquery
37+
build-bigquery: ## Build BigQuery version
38+
@test -f $(DB_FILE) || { echo "Run 'make download-db' first"; exit 1; }
39+
@$(DOCKER) build --target bigquery -t $(DOCKER_REGISTRY)/$(IMAGE_NAME):bigquery .
40+
41+
.PHONY: push
42+
push: ## Push Docker image to registry (run 'make login' first)
43+
@$(DOCKER) push $(DOCKER_IMAGE)
44+
@$(DOCKER) push $(DOCKER_REGISTRY)/$(IMAGE_NAME):lite
45+
46+
.PHONY: push-bigquery
47+
push-bigquery: ## Push BigQuery image (run 'make login' first)
48+
@$(DOCKER) push $(DOCKER_REGISTRY)/$(IMAGE_NAME):bigquery
49+
50+
.PHONY: test-image
51+
test-image: ## Test the built Docker image
52+
@$(DOCKER) run --rm $(DOCKER_IMAGE) python -c "import m3; print(f'M3 version: {m3.__version__}')"
53+
54+
.PHONY: clean
55+
clean: ## Remove database and raw files
56+
@rm -rf m3_data
57+
58+
.DEFAULT_GOAL := help

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,23 @@ m3-mcp-server
548548
- 🔐 **Enhanced Security**: Role-based access control, audit logging
549549
- 🌐 **Multi-tenant Support**: Organization-level data isolation
550550

551-
## Contributing
551+
## 🐳 Kubernetes Deployment
552+
553+
Deploy M3 on Kubernetes using Docker images with pre-loaded MIMIC-IV demo database:
554+
555+
```bash
556+
# Build and push Docker image
557+
make all # Will prompt for Docker registry/username
558+
559+
# Or specify registry directly
560+
make all DOCKER_REGISTRY=your-username DOCKER=podman
561+
```
562+
563+
The container uses StreamableHTTP transport on port 3000 with path `/sse`. Configure your MCP client to connect to the service endpoint (e.g., `http://m3.kagent.svc.cluster.local:3000/sse` for intra-cluster access).
564+
565+
Helm charts for deploying M3 are available in a separate repository.
566+
567+
## 🤝 Contributing
552568

553569
We welcome contributions! Please:
554570

src/m3/mcp_server.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,9 +682,30 @@ def get_race_distribution(limit: int = 10) -> str:
682682

683683

684684
def main():
685-
"""Main entry point for MCP server."""
686-
# Run the FastMCP server
687-
mcp.run()
685+
"""Main entry point for MCP server.
686+
687+
Runs FastMCP server in either STDIO mode (desktop clients) or HTTP mode
688+
(Kubernetes/web clients). Transport mode configured via environment variables.
689+
690+
Environment Variables:
691+
MCP_TRANSPORT: "stdio" (default), "sse", or "http"
692+
MCP_HOST: Host binding for HTTP mode (default: "0.0.0.0")
693+
MCP_PORT: Port for HTTP mode (default: 3000)
694+
MCP_PATH: SSE endpoint path for HTTP mode (default: "/sse")
695+
696+
Notes:
697+
HTTP/SSE mode uses streamable-http transport for containerized deployments
698+
where STDIO is unavailable. Binds to 0.0.0.0 for Kubernetes service mesh access.
699+
"""
700+
transport = os.getenv("MCP_TRANSPORT", "stdio").lower()
701+
702+
if transport in ("sse", "http"):
703+
host = os.getenv("MCP_HOST", "0.0.0.0")
704+
port = int(os.getenv("MCP_PORT", "3000"))
705+
path = os.getenv("MCP_PATH", "/sse")
706+
mcp.run(transport="streamable-http", host=host, port=port, path=path)
707+
else:
708+
mcp.run()
688709

689710

690711
if __name__ == "__main__":

0 commit comments

Comments
 (0)