listo-mcp-ip-guard
IP allowlist guard for Python MCP servers. Ships with OpenAI/ChatGPT egress IP ranges and Microsoft Azure public cloud ranges for ChatGPT developer mode. Zero production dependencies.
Install
pip install listo-mcp-ip-guard
Quick Start
from mcp_ip_guard import create_ip_guard
# Creates a guard with all OpenAI/ChatGPT IPs pre-loaded
guard = create_ip_guard()
# Check a raw IP
if guard.is_allowed("52.173.123.5"):
print("Allowed")
Options
guard = create_ip_guard(
# Include OpenAI/ChatGPT egress IPs (default: True)
include_openai_ranges=True,
# Include Azure public cloud IPs for ChatGPT developer mode (default: False)
include_azure_ranges=False,
# Add your own IPs/CIDR ranges
additional_ranges=[
"10.0.0.0/8", # CIDR range
"192.168.1.100", # Single IP (treated as /32)
],
# Allow localhost in non-production (default: True)
allow_localhost_in_dev=True,
# Number of trusted reverse proxies (default: 1)
# Uses X-Forwarded-For[-depth] to extract the client IP
trusted_proxy_depth=1,
# Log blocked IPs (default: False)
debug=False,
# Hook for telemetry / custom logging
on_blocked=lambda ip, path: print(f"Blocked {ip} on {path}"),
)
API
create_ip_guard(**options) -> IpGuard
Creates a new guard instance.
guard.is_allowed(ip: str) -> bool
Check if a raw IP address string is in the allowlist.
guard.get_client_ip(scope) -> str
Extract the client IP from an ASGI scope dict or Starlette/FastAPI Request. Uses X-Forwarded-For[-trusted_proxy_depth] to select the IP added by the outermost trusted proxy.
guard.get_client_ip_from_headers(remote_addr, x_forwarded_for, trusted_proxy_depth=1) -> str
Extract client IP from raw header values. Static method.
guard.check_request(client_ip, path) -> GuardResult
Check if a client IP is allowed. Fires the on_blocked callback if denied. Returns GuardResult(allowed=bool, client_ip=str).
guard.range_count -> int
Total number of parsed CIDR ranges in the allowlist.
OPENAI_IP_RANGES
The raw tuple of OpenAI/ChatGPT egress IP ranges in CIDR notation.
AZURE_IP_RANGES
Microsoft Azure public cloud IPv4 ranges (10,360 CIDRs). Lazy-loaded on first access.
ASGI Middleware (Starlette / FastAPI)
from starlette.applications import Starlette
from mcp_ip_guard.middleware import IpGuardMiddleware
app = Starlette(...)
app.add_middleware(
IpGuardMiddleware,
protected_paths=["/mcp", "/mcp/messages"],
)
With Azure ranges for developer mode:
app.add_middleware(
IpGuardMiddleware,
protected_paths=["/mcp", "/mcp/messages"],
include_azure_ranges=True,
)
The middleware guards both HTTP and WebSocket connections on the specified protected_paths. All other paths pass through unblocked. Paths are normalized (trailing slashes stripped) before matching.
With multi-proxy setup (e.g. CDN -> Load Balancer -> App):
app.add_middleware(
IpGuardMiddleware,
protected_paths=["/mcp", "/mcp/messages"],
trusted_proxy_depth=2, # skip the inner proxy's XFF entry
)
Usage with Python MCP Server
from mcp.server.fastmcp import FastMCP
from mcp_ip_guard import create_ip_guard
guard = create_ip_guard(
debug=True,
on_blocked=lambda ip, path: print(f"Blocked {ip} on {path}"),
)
mcp = FastMCP("my-server")
# In your custom HTTP handler or middleware:
client_ip = guard.get_client_ip(request)
result = guard.check_request(client_ip, request.url.path)
if not result.allowed:
return JSONResponse({"error": "Access denied"}, status_code=403)
ChatGPT Developer Mode
When connecting an MCP server directly to ChatGPT in developer mode, requests may come from Azure infrastructure IPs rather than the dedicated OpenAI egress IPs. Enable include_azure_ranges to allow these:
guard = create_ip_guard(include_azure_ranges=True)
This adds ~10,360 Azure IPv4 CIDR ranges to the allowlist. Only enable this when you need developer-mode compatibility — in production with ChatGPT's public integration, the default OpenAI ranges are sufficient.
Reverse Proxy Configuration
The guard extracts the client IP from the X-Forwarded-For header using trusted_proxy_depth to select the correct entry. The default (1) works for single-proxy deployments (e.g. Railway, Cloudflare, or a single load balancer).
| Deployment | Depth | XFF example | Extracted IP |
|---|---|---|---|
| Single proxy (Cloudflare -> App) | 1 | client, cloudflare |
cloudflare entry = client IP added by Cloudflare |
| Two proxies (CDN -> LB -> App) | 2 | client, cdn, lb |
cdn entry = client IP added by CDN |
| Direct (no proxy) | 1 | (empty) | Falls back to remote_addr |
Set trusted_proxy_depth to match the number of trusted reverse proxies in front of your application. An incorrect value means the guard checks the wrong IP.
Environment
ENVIRONMENT(orNODE_ENVas fallback) — When set to"production", localhost is blocked (unlessallow_localhost_in_dev=False).
IP Ranges Sources
- OpenAI — Published egress IPs (2026-02-21). Includes /28, /26, and /32 entries covering all ChatGPT outbound traffic to MCP servers.
- Azure — Microsoft Azure Service Tags – Public Cloud (2026-03-02). The
AzureCloudservice tag with 10,360 IPv4 CIDR ranges covering all Azure datacenter egress.
License
MIT
Metadata
Release files for listo-mcp-ip-guard 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| listo_mcp_ip_guard-0.3.0.tar.gz | 46.3 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| listo_mcp_ip_guard-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 91.6 kB
Release files / listo_mcp_ip_guard-0.3.0.tar.gz
| Download URL | listo_mcp_ip_guard-0.3.0.tar.gz |
|---|---|
| Size | 46.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
371fed465a81b95eb0913b3d53054b570c56e5c2e1efcd6dd72fca05b9c0ec6f
|
|
BLAKE2b-256 checksum How to use checksums |
b0f1f5e4edd59bfb2dd6fb88f0f56c7ba234e80b64cc09ee7123252769535641
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 4, 2026.
Transparency logRelease files / listo_mcp_ip_guard-0.3.0-py3-none-any.whl
| Download URL | listo_mcp_ip_guard-0.3.0-py3-none-any.whl |
|---|---|
| Size | 45.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
961b44bd929ad91c0ddb634ed9d8de549539cf54c902fe93d8831a5f9e399d06
|
|
BLAKE2b-256 checksum How to use checksums |
7b82cf33fb93005dcfddc05bddaf3380200f00eadcc82c48d5b184dc4c9ea7db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 4, 2026.
Transparency logSecurity for listo-mcp-ip-guard 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for listo_mcp_ip_guard-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.