fastmcp icon indicating copy to clipboard operation
fastmcp copied to clipboard

When I was deploying the SSE server, I encountered an issue that seems to be related to the passing of parameters.

Open Wall-cn opened this issue 7 months ago • 4 comments

This is my code:

`from fastmcp import FastMCP

Create a basic server instance

mcp = FastMCP(name="MyAssistantServer")

You can also add instructions for how to interact with the server

mcp_with_instructions = FastMCP( name="HelpfulAssistant", instructions="This server provides data analysis tools. Call get_average() to analyze numerical data." )

@mcp.tool() def multiply(a: float, b: float) -> float: """Multiplies two numbers together.""" return a * b

@mcp.resource("data://config") def get_config() -> dict: """Provides the application configuration.""" return {"theme": "dark", "version": "1.0"}

@mcp.resource("users://{user_id}/profile") def get_user_profile(user_id: int) -> dict: """Retrieves a user's profile by ID.""" # The {user_id} in the URI is extracted and passed to this function return {"id": user_id, "name": f"User {user_id}", "status": "active"}

@mcp.prompt() def analyze_data(data_points: list[float]) -> str: """Creates a prompt asking for analysis of numerical data.""" formatted_data = ", ".join(str(point) for point in data_points) return f"Please analyze these data points: {formatted_data}"

if name == "main": # This code only runs when the file is executed directly

# Basic run with default settings (stdio transport)
#mcp.run()

# Or with specific transport and parameters
mcp.run(transport="sse", host="127.0.0.1", port=9000)`

My fastmcp version:

FastMCP version: 2.2.0 MCP version: 1.6.0 Python version: 3.12.3 Platform: Linux-6.11.0-21-generic-x86_64-with-glibc2.39 FastMCP root path: ~/fastmcp/lib/python3.12

Error info

Traceback (most recent call last): File "/mnt/ai_data/mymcp/03.py", line 42, in <module> mcp.run(transport="sse", host="127.0.0.1", port=9000) File "/home/wall/fastmcp/lib/python3.12/site-packages/fastmcp/server/server.py", line 262, in run anyio.run(self.run_async, transport, **transport_kwargs) TypeError: run() got an unexpected keyword argument 'host'

Wall-cn avatar Apr 18 '25 06:04 Wall-cn

Would you try this api run_sse_async? I can bring on the SSE server with it.

if name == "main": import asyncio asyncio.run(main_mcp_server.run_sse_async(host="localhost", port=8080, log_level="debug"))

nightowl54321 avatar Apr 18 '25 07:04 nightowl54321

Would you try this api run_sse_async? I can bring on the SSE server with it.

if name == "main": import asyncio asyncio.run(main_mcp_server.run_sse_async(host="localhost", port=8080, log_level="debug"))

Oh, this one works fine. It seems like mcp.run doesn't work properly.

Wall-cn avatar Apr 18 '25 07:04 Wall-cn

ran into same issue here . Also SSE server does not even run with mcp.run in my case. Got fixed with run_sse_async. Is anyone working on the fix?

sandipan1 avatar Apr 19 '25 15:04 sandipan1

At https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/server.py#L262 the library incorrectly tries to pass host and port as keyword arguments directly to the anyio.run function, which doesn't accept them in that manner.

You can patch it by wrapping it with mcp proxy for now -- for example

# https://github.com/sparfenyuk/mcp-proxy
# Could also use the custom docker image
# https://github.com/sparfenyuk/mcp-proxy?tab=readme-ov-file#extending-the-container-image
FROM python:3.12-slim-bookworm

COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

# Create a working directory
WORKDIR /app

# Copy the application files
COPY ./pyproject.toml ./uv.lock ./

# Install the dependencies
RUN uv sync --frozen --no-cache

# Expose the port mcp-proxy will listen on for SSE connections
EXPOSE 9712

ENV FASTMCP_LOG_LEVEL=ERROR

ENTRYPOINT ["/bin/uvx", "mcp-proxy", "--sse-port=9712", "--sse-host=0.0.0.0"]

# https://github.com/awslabs/mcp/tree/main/src/aws-documentation-mcp-server
CMD ["/bin/uvx", "awslabs.aws-documentation-mcp-server@latest"]

wsargent avatar Apr 19 '25 17:04 wsargent

@wsargent is correct and the test for this failed because it mocked out the kwargs. PR to fix shortly.

jlowin avatar Apr 21 '25 00:04 jlowin