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
29 changes: 29 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Docker ignore file to reduce build context size
**/__pycache__/
*.pyc
*.pyo
*.pyd
.Python
*.so
.git
.gitignore
.github
.vscode
.idea
*.md
!README.md
.env
.env.*
.env.example
*.log
.coverage
.pytest_cache
.mypy_cache
dist/
build/
*.egg-info/
docker-compose.yml
Dockerfile*
*.tar
*.zip
.venv/
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM python:3.13-alpine3.22 AS builder

RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir uv

WORKDIR /app

RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --locked --no-install-project --no-dev

COPY . /app

RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --locked --no-dev


FROM python:3.13-alpine3.22
ENV PYTHONUNBUFFERED=1

RUN apk add --no-cache ca-certificates \
&& addgroup -g 1000 appuser \
&& adduser -D -u 1000 -G appuser appuser

COPY --from=builder --chown=appuser:appuser /app /app

WORKDIR /app

USER appuser

ENV PATH="/app/.venv/bin:$PATH"

CMD ["python", "-u", "server.py"]
45 changes: 45 additions & 0 deletions Dockerfile.mcpo
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM python:3.13-alpine3.22 AS builder

RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir uv

WORKDIR /app

RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --locked --no-install-project --no-dev \
&& uv pip install mcpo

COPY . /app

RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --locked --no-dev \
&& uv pip install mcpo


FROM python:3.13-alpine3.22
ENV PYTHONUNBUFFERED=1

RUN apk add --no-cache ca-certificates \
&& addgroup -g 1000 appuser \
&& adduser -D -u 1000 -G appuser appuser

COPY --from=builder --chown=appuser:appuser /app /app

WORKDIR /app

USER appuser

ENV PATH="/app/.venv/bin:$PATH"

HEALTHCHECK \
--interval=30s \
--timeout=10s \
--start-period=30s \
--retries=3 \
CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:8000/openapi.json || exit 1

EXPOSE 8000

CMD ["sh", "-c", "if [ -n \"$MCPO_API_KEY\" ]; then exec mcpo --api-key \"$MCPO_API_KEY\" -- python -u server.py; else exec mcpo -- python -u server.py; fi"]
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ This is a simple read-only [Model Context Protocol](https://modelcontextprotocol
> Show me all configuration changes to the core router in the last month
```

## Docker Usage

This repository provides two Dockerfiles:

- `Dockerfile`: Standard image for running the NetBox MCP server. Use this for most deployments, for example in Claude Desktop or VS Code.
- `Dockerfile.mcpo`: Image with [mcpo](https://github.com/open-webui/mcpo) included, mainly for integration with OpenWebUI or other MCP Orchestrators that require the OpenAPI-compatible HTTP MCP server.

To build and run the standard image:

```sh
docker build -t netbox-mcp-server:main .
docker run --rm -e NETBOX_URL=... -e NETBOX_TOKEN=... -p 8000:8000 netbox-mcp-server:main
```

To build and run the mcpo-enabled image (for OpenWebUI):

```sh
docker build -f Dockerfile.mcpo -t netbox-mcp-server:mcpo .
docker run --rm -e NETBOX_URL=... -e NETBOX_TOKEN=... -e MCPO_API_KEY=... -p 8000:8000 netbox-mcp-server:mcpo
```

> Use the `MCPO_API_KEY` environment variable if want to set a API KEY.


## Development

Contributions are welcome! Please open an issue or submit a PR.
Expand Down