MCPcopy Create free account
hub / github.com/PrefectHQ/fastmcp / test_basic_function

Method test_basic_function

tests/tools/tool/test_tool.py:21–57  ·  view source on GitHub ↗

Test registering and running a basic function.

(self)

Source from the content-addressed store, hash-verified

19
20class TestToolFromFunction:
21 def test_basic_function(self):
22 """Test registering and running a basic function."""
23
24 def add(a: int, b: int) -> int:
25 """Add two numbers."""
26 return a + b
27
28 tool = Tool.from_function(add)
29
30 assert tool.model_dump(exclude_none=True) == snapshot(
31 {
32 "name": "add",
33 "description": "Add two numbers.",
34 "tags": set(),
35 "parameters": {
36 "additionalProperties": False,
37 "properties": {
38 "a": {"type": "integer"},
39 "b": {"type": "integer"},
40 },
41 "required": ["a", "b"],
42 "type": "object",
43 },
44 "output_schema": {
45 "properties": {"result": {"type": "integer"}},
46 "required": ["result"],
47 "type": "object",
48 "x-fastmcp-wrap-result": True,
49 },
50 "fn": HasName("add"),
51 "task_config": {
52 "mode": "forbidden",
53 "poll_interval": timedelta(seconds=5),
54 },
55 "run_in_thread": True,
56 }
57 )
58
59 def test_meta_parameter(self):
60 """Test that meta parameter is properly handled."""

Callers

nothing calls this directly

Calls 2

snapshotFunction · 0.85
from_functionMethod · 0.45

Tested by

no test coverage detected