Skip to content
Merged
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
2 changes: 1 addition & 1 deletion mcp-example-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ USER 1100
EXPOSE 8000

# Start FastAPI via Uvicorn on HTTP
CMD ["fastmcp", "run", "src/main.py:app", "--transport", "streamable-http", "--port", "8000", "--host", "0.0.0.0"]
CMD ["fastmcp", "run", "src/main.py:app", "--transport", "streamable-http", "--port", "8000", "--host", "0.0.0.0"]
9 changes: 6 additions & 3 deletions mcp-proxy-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ RUN adduser --disabled-password --gecos '' --uid 1100 mcpuser

WORKDIR /app

# Install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --upgrade pip --root-user-action=ignore
RUN pip install --no-cache-dir -r requirements.txt --root-user-action=ignore

COPY src/main.py /app/main.py
# Copy source
COPY . .

# Change ownership to non-root user
RUN chown -R mcpuser:mcpuser /app \
Expand All @@ -44,4 +47,4 @@ USER 1100

EXPOSE 8080

ENTRYPOINT ["python", "/app/main.py"]
CMD ["fastmcp", "run", "src/main.py:app", "--transport", "streamable-http", "--port", "8000", "--host", "0.0.0.0"]
72 changes: 36 additions & 36 deletions mcp-proxy-server/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,47 @@ def safe(arg: str) -> bool:
and "\r" not in arg
)

def main():
proxy_url = os.environ.get("MCP_PROXY_URL")
if proxy_url:
if not validators.url(proxy_url):
bad("Invalid MCP_PROXY_URL: must be http(s) and a well-formed URL")
config = {
"mcpServers": {
"default": {
"url": proxy_url,
"transport": "http"
}
proxy_url = os.environ.get("MCP_PROXY_URL")
if proxy_url:
if not validators.url(proxy_url):
bad("Invalid MCP_PROXY_URL: must be http(s) and a well-formed URL")
config = {
"mcpServers": {
"default": {
"url": proxy_url,
"transport": "http"
}
}
else:
cmd = os.environ.get("MCP_COMMAND")
if not cmd:
bad("Must set either MCP_PROXY_URL or MCP_COMMAND environment variable")
raw_args = os.environ.get("MCP_ARGS", "")
args = shlex.split(raw_args) if raw_args else []
}
else:
cmd = os.environ.get("MCP_COMMAND")
if not cmd:
bad("Must set either MCP_PROXY_URL or MCP_COMMAND environment variable")
raw_args = os.environ.get("MCP_ARGS", "")
args = shlex.split(raw_args) if raw_args else []

if not safe(cmd):
bad("Unsafe command")
if len(args) > MAX_ARGS:
bad("Too many args")
for a in args:
if not safe(a):
bad(f"Unsafe arg: {a!r}")

config = {
"mcpServers": {
"default": {
"type": "stdio",
"command": cmd,
"args": args,
"env": dict(os.environ)
}
if not safe(cmd):
bad("Unsafe command")
if len(args) > MAX_ARGS:
bad("Too many args")
for a in args:
if not safe(a):
bad(f"Unsafe arg: {a!r}")

config = {
"mcpServers": {
"default": {
"type": "stdio",
"command": cmd,
"args": args,
"env": dict(os.environ)
}
}
}

app = FastMCP.as_proxy(config, name="MCP Proxy Server")
app.run(transport="streamable-http", host="0.0.0.0", port=8000)
app = FastMCP.as_proxy(config, name="MCP Proxy Server")

if __name__ == "__main__":
main()
app.settings.host = "127.0.0.1"
app.settings.port = 8000
app.run(transport="streamable-http")