diff --git a/src/fetch/Dockerfile b/src/fetch/Dockerfile deleted file mode 100644 index 7e8824c471..0000000000 --- a/src/fetch/Dockerfile +++ /dev/null @@ -1,36 +0,0 @@ -# Use a Python image with uv pre-installed -FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS uv - -# Install the project into `/app` -WORKDIR /app - -# Enable bytecode compilation -ENV UV_COMPILE_BYTECODE=1 - -# Copy from the cache instead of linking since it's a mounted volume -ENV UV_LINK_MODE=copy - -# Install the project's dependencies using the lockfile and settings -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 --frozen --no-install-project --no-dev --no-editable - -# Then, add the rest of the project source code and install it -# Installing separately from its dependencies allows optimal layer caching -ADD . /app -RUN --mount=type=cache,target=/root/.cache/uv \ - uv sync --frozen --no-dev --no-editable - -FROM python:3.12-slim-bookworm - -WORKDIR /app - -COPY --from=uv /root/.local /root/.local -COPY --from=uv --chown=app:app /app/.venv /app/.venv - -# Place executables in the environment at the front of the path -ENV PATH="/app/.venv/bin:$PATH" - -# when running the container, add --db-path and a bind mount to the host's db file -ENTRYPOINT ["mcp-server-fetch"] diff --git a/src/fetch/pyproject.toml b/src/fetch/pyproject.toml index bbee516a6b..8c3f255c83 100644 --- a/src/fetch/pyproject.toml +++ b/src/fetch/pyproject.toml @@ -15,6 +15,7 @@ classifiers = [ "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.10", ] + dependencies = [ "httpx<0.28", "markdownify>=0.13.1", @@ -23,6 +24,10 @@ dependencies = [ "pydantic>=2.0.0", "readabilipy>=0.2.0", "requests>=2.32.3", + # 👇 Added for Smithery HTTP hosting + "uvicorn>=0.30.0", + "starlette>=0.48.0", + "fastapi>=0.111.0", ] [project.scripts] diff --git a/src/fetch/smithery.yaml b/src/fetch/smithery.yaml new file mode 100644 index 0000000000..61c3d8aa11 --- /dev/null +++ b/src/fetch/smithery.yaml @@ -0,0 +1,9 @@ +name: fetch +type: server +runtime: python +startCommand: + - uv + - run + - python + - -m + - mcp_server_fetch diff --git a/src/fetch/src/mcp_server_fetch/__main__.py b/src/fetch/src/mcp_server_fetch/__main__.py index 318a21e789..3852dc40cf 100644 --- a/src/fetch/src/mcp_server_fetch/__main__.py +++ b/src/fetch/src/mcp_server_fetch/__main__.py @@ -1,5 +1,23 @@ -# __main__.py +import os +import uvicorn +from fastapi.middleware.cors import CORSMiddleware +import mcp +from mcp_server_fetch.server import serve +import asyncio -from mcp_server_fetch import main +def main(): + transport = os.getenv("MCP_TRANSPORT", "stdio") -main() + if transport in {"http", "streamable-http"}: + app = mcp.streamable_http_app() + app.add_middleware( + CORSMiddleware, + allow_origins=["*"], + allow_credentials=False, + allow_methods=["*"], + allow_headers=["*"], + ) + port = int(os.getenv("PORT", "8000")) + uvicorn.run(app, host="0.0.0.0", port=port) + else: + asyncio.run(serve())