Test registering and running a basic function.
(self)
| 19 | |
| 20 | class 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.""" |
nothing calls this directly
no test coverage detected