mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-09 15:19:10 +02:00
Improve methods on server and registration
This commit is contained in:
parent
8c30fc5f2c
commit
c032d0cb06
2 changed files with 72 additions and 56 deletions
|
|
@ -1,13 +1,25 @@
|
|||
from mcp.shared.memory import (
|
||||
create_connected_server_and_client_session as client_session,
|
||||
)
|
||||
from fastmcp.server import FastMCP
|
||||
from fastmcp import FastMCP
|
||||
|
||||
|
||||
class TestServer:
|
||||
async def test_create_server(self):
|
||||
server = FastMCP()
|
||||
assert server.name == "FastMCP"
|
||||
mcp = FastMCP()
|
||||
assert mcp.name == "FastMCP"
|
||||
|
||||
async def test_add_tool_decorator(self):
|
||||
mcp = FastMCP()
|
||||
|
||||
@mcp.tool
|
||||
def add(x: int, y: int) -> int:
|
||||
return x + y
|
||||
|
||||
async with client_session(mcp._mcp_server) as client:
|
||||
tools = await client.list_tools()
|
||||
assert len(tools.tools) == 1
|
||||
assert tools.tools[0].name == "add"
|
||||
|
||||
|
||||
def tool_fn(x: int, y: int) -> int:
|
||||
|
|
@ -16,22 +28,22 @@ def tool_fn(x: int, y: int) -> int:
|
|||
|
||||
class TestServerTools:
|
||||
async def test_add_tool(self):
|
||||
server = FastMCP()
|
||||
server.add_tool(tool_fn)
|
||||
server.add_tool(tool_fn)
|
||||
assert len(server._tool_manager.list_tools()) == 1
|
||||
mcp = FastMCP()
|
||||
mcp.add_tool(tool_fn)
|
||||
mcp.add_tool(tool_fn)
|
||||
assert len(mcp._tool_manager.list_tools()) == 1
|
||||
|
||||
async def test_list_tools(self):
|
||||
server = FastMCP()
|
||||
server.add_tool(tool_fn)
|
||||
async with client_session(server._mcp_server) as client:
|
||||
mcp = FastMCP()
|
||||
mcp.add_tool(tool_fn)
|
||||
async with client_session(mcp._mcp_server) as client:
|
||||
tools = await client.list_tools()
|
||||
assert len(tools.tools) == 1
|
||||
|
||||
async def test_call_tool(self):
|
||||
server = FastMCP()
|
||||
server.add_tool(tool_fn)
|
||||
async with client_session(server._mcp_server) as client:
|
||||
mcp = FastMCP()
|
||||
mcp.add_tool(tool_fn)
|
||||
async with client_session(mcp._mcp_server) as client:
|
||||
result = await client.call_tool("my_tool", {"arg1": "value"})
|
||||
assert "error" not in result
|
||||
assert len(result.content) > 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue