|
10 | 10 | import time
|
11 | 11 | from collections.abc import Generator
|
12 | 12 |
|
13 |
| -import anyio |
14 | 13 | import pytest
|
15 | 14 | import uvicorn
|
16 | 15 | from pydantic import AnyUrl
|
|
20 | 19 | from mcp.client.sse import sse_client
|
21 | 20 | from mcp.client.streamable_http import streamablehttp_client
|
22 | 21 | from mcp.server.fastmcp import FastMCP
|
| 22 | +from mcp.server.fastmcp.resources import FunctionResource |
23 | 23 | from mcp.shared.context import RequestContext
|
24 | 24 | from mcp.types import (
|
25 | 25 | CreateMessageRequestParams,
|
26 | 26 | CreateMessageResult,
|
27 | 27 | GetPromptResult,
|
28 | 28 | InitializeResult,
|
29 | 29 | ReadResourceResult,
|
| 30 | + SamplingMessage, |
30 | 31 | TextContent,
|
31 | 32 | TextResourceContents,
|
32 | 33 | )
|
@@ -123,8 +124,6 @@ def echo(message: str) -> str:
|
123 | 124 | # Tool with sampling capability
|
124 | 125 | @mcp.tool(description="A tool that uses sampling to generate content")
|
125 | 126 | async def sampling_tool(prompt: str, ctx: Context) -> str:
|
126 |
| - from mcp.types import SamplingMessage, TextContent |
127 |
| - |
128 | 127 | await ctx.info(f"Requesting sampling for prompt: {prompt}")
|
129 | 128 |
|
130 | 129 | # Request sampling from the client
|
@@ -161,10 +160,6 @@ async def notification_tool(message: str, ctx: Context) -> str:
|
161 | 160 | return f"Sent notifications and logs for: {message}"
|
162 | 161 |
|
163 | 162 | # Resource - static
|
164 |
| - from pydantic import AnyUrl |
165 |
| - |
166 |
| - from mcp.server.fastmcp.resources import FunctionResource |
167 |
| - |
168 | 163 | def get_static_info() -> str:
|
169 | 164 | return "This is static resource content"
|
170 | 165 |
|
@@ -293,7 +288,7 @@ def run_streamable_http_server(server_port: int) -> None:
|
293 | 288 | server.run()
|
294 | 289 |
|
295 | 290 |
|
296 |
| -def run_comprehensive_streamable_http_server(server_port: int) -> None: |
| 291 | +def run_everything_streamable_http_server(server_port: int) -> None: |
297 | 292 | """Run the comprehensive StreamableHTTP server with all features."""
|
298 | 293 | _, app = make_everything_fastmcp_streamable_http_app()
|
299 | 294 | server = uvicorn.Server(
|
@@ -492,7 +487,6 @@ async def test_fastmcp_stateless_streamable_http(
|
492 | 487 | assert tool_result.content[0].text == f"Echo: test_{i}"
|
493 | 488 |
|
494 | 489 |
|
495 |
| -# Fixtures for comprehensive servers |
496 | 490 | @pytest.fixture
|
497 | 491 | def everything_server_port() -> int:
|
498 | 492 | """Get a free port for testing the comprehensive server."""
|
@@ -557,12 +551,12 @@ def everything_server(everything_server_port: int) -> Generator[None, None, None
|
557 | 551 |
|
558 | 552 |
|
559 | 553 | @pytest.fixture()
|
560 |
| -def comprehensive_streamable_http_server( |
| 554 | +def everything_streamable_http_server( |
561 | 555 | everything_http_server_port: int,
|
562 | 556 | ) -> Generator[None, None, None]:
|
563 | 557 | """Start the comprehensive StreamableHTTP server in a separate process."""
|
564 | 558 | proc = multiprocessing.Process(
|
565 |
| - target=run_comprehensive_streamable_http_server, |
| 559 | + target=run_everything_streamable_http_server, |
566 | 560 | args=(everything_http_server_port,),
|
567 | 561 | daemon=True,
|
568 | 562 | )
|
@@ -858,7 +852,7 @@ async def message_handler(message):
|
858 | 852 |
|
859 | 853 | @pytest.mark.anyio
|
860 | 854 | async def test_fastmcp_all_features_streamable_http(
|
861 |
| - comprehensive_streamable_http_server: None, everything_http_server_url: str |
| 855 | + everything_streamable_http_server: None, everything_http_server_url: str |
862 | 856 | ) -> None:
|
863 | 857 | """Test all MCP features work correctly with StreamableHTTP transport."""
|
864 | 858 |
|
|
0 commit comments