Spaces:
Running
Running
File size: 2,414 Bytes
3acddf3 224caf9 3acddf3 224caf9 3acddf3 224caf9 3acddf3 f6c5553 3acddf3 81e8514 3acddf3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | # from pathlib import Path
# from typing import TYPE_CHECKING, Any
# import pytest
# import fastmcp
# from fastmcp import FastMCP
# if TYPE_CHECKING:
# pass
# USERS = [
# {"id": "1", "name": "Alice", "active": True},
# {"id": "2", "name": "Bob", "active": True},
# {"id": "3", "name": "Charlie", "active": False},
# ]
# @pytest.fixture
# def fastmcp_server():
# server = FastMCP("TestServer")
# # --- Tools ---
# @server.tool
# def greet(name: str) -> str:
# """Greet someone by name."""
# return f"Hello, {name}!"
# @server.tool
# def add(a: int, b: int) -> int:
# """Add two numbers together."""
# return a + b
# @server.tool
# def error_tool():
# """This tool always raises an error."""
# raise ValueError("This is a test error")
# # --- Resources ---
# @server.resource(uri="resource://wave")
# def wave() -> str:
# return "👋"
# @server.resource(uri="data://users")
# async def get_users() -> list[dict[str, Any]]:
# return USERS
# @server.resource(uri="data://user/{user_id}")
# async def get_user(user_id: str) -> dict[str, Any] | None:
# return next((user for user in USERS if user["id"] == user_id), None)
# # --- Prompts ---
# @server.prompt
# def welcome(name: str) -> str:
# return f"Welcome to FastMCP, {name}!"
# return server
# @pytest.fixture
# async def stdio_client():
# # Find the stdio.py script path
# base_dir = Path(__file__).parent
# stdio_script = base_dir / "test_servers" / "stdio.py"
# if not stdio_script.exists():
# raise FileNotFoundError(f"Could not find stdio.py script at {stdio_script}")
# client = fastmcp.Client(
# transport=fastmcp.client.transports.StdioTransport(
# command="python",
# args=[str(stdio_script)],
# )
# )
# async with client:
# print("READY")
# yield client
# print("DONE")
# class TestRunServerStdio:
# async def test_run_server_stdio(
# self, fastmcp_server: FastMCP, stdio_client: fastmcp.Client
# ):
# print("TEST")
# tools = await stdio_client.list_tools()
# print("TEST 2")
# assert tools == 1
# class TestRunServerSSE:
#
# async def test_run_server_sse(self, fastmcp_server: FastMCP):
# pass
|