diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7c56482 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.git +**/__pycache__/ +**/*.pyc +**/.venv/ diff --git a/mcp/Dockerfile b/mcp/Dockerfile new file mode 100644 index 0000000..05347c1 --- /dev/null +++ b/mcp/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.12-slim + +ENV PYTHONDONTWRITEBYTECODE=1 +ENV PYTHONUNBUFFERED=1 + +WORKDIR /app + +COPY mcp/requirements.txt /app/mcp/requirements.txt +RUN pip install --no-cache-dir -r /app/mcp/requirements.txt + +COPY . /app + +CMD ["python", "/app/mcp/server.py"] diff --git a/mcp/README.md b/mcp/README.md index c230c1e..df55b71 100644 --- a/mcp/README.md +++ b/mcp/README.md @@ -23,6 +23,17 @@ pip install -r C:\dev\infracloud\mcp\requirements.txt python C:\dev\infracloud\mcp\server.py ``` +### HTTP transport + +For container or VPS usage: + +```powershell +$env:INFRA_MCP_TRANSPORT="streamable-http" +$env:INFRA_MCP_HOST="0.0.0.0" +$env:INFRA_MCP_PORT="18000" +python C:\dev\infracloud\mcp\server.py +``` + ## Postgres Set `INFRA_MCP_POSTGRES_DSN` if you want the server to use Postgres for notes and SQL diagnostics. @@ -34,6 +45,14 @@ $env:INFRA_MCP_POSTGRES_DSN="postgresql://user:password@127.0.0.1:5432/infraclou python C:\dev\infracloud\mcp\server.py ``` +## Docker on echo + +The repo includes [docker-compose.echo.yml](C:\dev\infracloud\mcp\docker-compose.echo.yml) for running the MCP server on the echo VPS with: + +- `streamable-http` transport +- port `18000` +- Postgres database `infracloud_mcp` + ## Claude Desktop Use `claude_desktop_config.infracloud.json` as a base and merge it into your Claude Desktop MCP config. diff --git a/mcp/docker-compose.echo.yml b/mcp/docker-compose.echo.yml new file mode 100644 index 0000000..1d8e2bc --- /dev/null +++ b/mcp/docker-compose.echo.yml @@ -0,0 +1,13 @@ +services: + infracloud-mcp: + build: + context: .. + dockerfile: mcp/Dockerfile + container_name: infracloud-mcp + restart: unless-stopped + network_mode: host + environment: + INFRA_MCP_TRANSPORT: streamable-http + INFRA_MCP_HOST: 0.0.0.0 + INFRA_MCP_PORT: "18000" + INFRA_MCP_POSTGRES_DSN: postgresql://user:password@127.0.0.1:5432/infracloud_mcp diff --git a/mcp/server.py b/mcp/server.py index 8480a8e..be44381 100644 --- a/mcp/server.py +++ b/mcp/server.py @@ -18,6 +18,9 @@ CONTAINERS_ROOT = REPO_ROOT / "containers" DATABASES_ROOT = REPO_ROOT / "databases" K3S_ROOT = REPO_ROOT / "k3s" POSTGRES_DSN_ENV = "INFRA_MCP_POSTGRES_DSN" +TRANSPORT_ENV = "INFRA_MCP_TRANSPORT" +HOST_ENV = "INFRA_MCP_HOST" +PORT_ENV = "INFRA_MCP_PORT" DOC_ALLOWLIST = ( REPO_ROOT / "README.md", VPS_ROOT, @@ -52,6 +55,8 @@ mcp = FastMCP( "Do not assume paths like dev-scripts or docs/openproject if they do not exist. " "If Postgres is configured, prefer the MCP Postgres helpers for server-side persistence and diagnostics." ), + host=os.getenv(HOST_ENV, "127.0.0.1"), + port=int(os.getenv(PORT_ENV, "8000")), ) @@ -533,4 +538,4 @@ def list_operational_notes(scope: str | None = None, limit: int = 20) -> list[di if __name__ == "__main__": _ensure_mcp_tables() - mcp.run() + mcp.run(transport=os.getenv(TRANSPORT_ENV, "stdio"))