-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathtest_definitions.py
More file actions
99 lines (74 loc) · 2.81 KB
/
test_definitions.py
File metadata and controls
99 lines (74 loc) · 2.81 KB
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
"""Unit tests for tool definition infrastructure."""
from enum import Enum
from typing import Any
from dbt_mcp.tools.definitions import GenericToolDefinition, generic_dbt_mcp_tool
from dbt_mcp.tools.register import generic_register_tools
from dbt_mcp.tools.toolsets import Toolset
class FakeToolName(Enum):
MY_TOOL = "my_tool"
def _make_tool(
meta: dict[str, Any] | None = None,
) -> GenericToolDefinition[FakeToolName]:
"""Helper to create a tool definition with optional meta."""
@generic_dbt_mcp_tool(
description="test tool",
name_enum=FakeToolName,
title="Test Tool",
read_only_hint=True,
meta=meta,
)
async def my_tool() -> str:
return "ok"
return my_tool
class TestMetaPassthrough:
"""Test that the meta field is preserved through all operations."""
def test_decorator_sets_meta(self):
meta = {"ui": {"resourceUri": "ui://test/app.html"}}
tool = _make_tool(meta=meta)
assert tool.meta == meta
def test_decorator_meta_defaults_to_none(self):
tool = _make_tool()
assert tool.meta is None
def test_adapt_context_preserves_meta(self):
meta = {"ui": {"resourceUri": "ui://test/app.html"}}
tool = _make_tool(meta=meta)
def mapper() -> None:
return None
adapted = tool.adapt_context(mapper)
assert adapted.meta == meta
def test_to_fastmcp_internal_tool_passes_meta(self):
meta = {"ui": {"resourceUri": "ui://test/app.html"}}
tool = _make_tool(meta=meta)
internal = tool.to_fastmcp_internal_tool()
assert internal.meta == meta
def test_to_fastmcp_internal_tool_none_meta(self):
tool = _make_tool()
internal = tool.to_fastmcp_internal_tool()
assert internal.meta is None
def test_register_tools_passes_meta(self, mock_fastmcp):
mock_mcp, _ = mock_fastmcp
meta = {"ui": {"resourceUri": "ui://test/app.html"}}
tool = _make_tool(meta=meta)
generic_register_tools(
mock_mcp,
[tool],
disabled_tools=set(),
enabled_tools=None,
enabled_toolsets=set(),
disabled_toolsets=set(),
tool_to_toolset={FakeToolName.MY_TOOL: Toolset.DISCOVERY},
)
assert mock_mcp.tool_kwargs["my_tool"]["meta"] == meta
def test_register_tools_passes_none_meta(self, mock_fastmcp):
mock_mcp, _ = mock_fastmcp
tool = _make_tool()
generic_register_tools(
mock_mcp,
[tool],
disabled_tools=set(),
enabled_tools=None,
enabled_toolsets=set(),
disabled_toolsets=set(),
tool_to_toolset={FakeToolName.MY_TOOL: Toolset.DISCOVERY},
)
assert mock_mcp.tool_kwargs["my_tool"]["meta"] is None