-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathtest_tool_contracts.py
More file actions
148 lines (136 loc) · 4.09 KB
/
test_tool_contracts.py
File metadata and controls
148 lines (136 loc) · 4.09 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"""Tool contract tests for MCP tool signatures."""
from __future__ import annotations
import inspect
from basic_memory.mcp import tools
EXPECTED_TOOL_SIGNATURES: dict[str, list[str]] = {
"build_context": [
"url",
"project",
"workspace",
"depth",
"timeframe",
"page",
"page_size",
"max_related",
"output_format",
],
"canvas": ["nodes", "edges", "title", "directory", "project", "workspace"],
"cloud_info": [],
"create_memory_project": ["project_name", "project_path", "set_default", "output_format"],
"delete_note": ["identifier", "is_directory", "project", "workspace", "output_format"],
"delete_project": ["project_name"],
"edit_note": [
"identifier",
"operation",
"content",
"project",
"workspace",
"section",
"find_text",
"expected_replacements",
"output_format",
],
"fetch": ["id"],
"list_directory": ["dir_name", "depth", "file_name_glob", "project", "workspace"],
"list_memory_projects": ["output_format", "workspace"],
"list_workspaces": ["output_format"],
"move_note": [
"identifier",
"destination_path",
"destination_folder",
"is_directory",
"project",
"workspace",
"output_format",
],
"read_content": ["path", "project", "workspace"],
"read_note": [
"identifier",
"project",
"workspace",
"page",
"page_size",
"output_format",
"include_frontmatter",
],
"release_notes": [],
"recent_activity": [
"type",
"depth",
"timeframe",
"page",
"page_size",
"project",
"workspace",
"output_format",
],
"schema_diff": ["note_type", "project", "workspace", "output_format"],
"schema_infer": ["note_type", "threshold", "project", "workspace", "output_format"],
"schema_validate": ["note_type", "identifier", "project", "workspace", "output_format"],
"search": ["query"],
"search_notes": [
"query",
"project",
"workspace",
"page",
"page_size",
"search_type",
"output_format",
"note_types",
"entity_types",
"after_date",
"metadata_filters",
"tags",
"status",
"min_similarity",
],
"view_note": ["identifier", "project", "workspace", "page", "page_size"],
"write_note": [
"title",
"content",
"directory",
"project",
"workspace",
"tags",
"note_type",
"metadata",
"overwrite",
"output_format",
],
}
TOOL_FUNCTIONS: dict[str, object] = {
"build_context": tools.build_context,
"canvas": tools.canvas,
"cloud_info": tools.cloud_info,
"create_memory_project": tools.create_memory_project,
"delete_note": tools.delete_note,
"delete_project": tools.delete_project,
"edit_note": tools.edit_note,
"fetch": tools.fetch,
"list_directory": tools.list_directory,
"list_memory_projects": tools.list_memory_projects,
"list_workspaces": tools.list_workspaces,
"move_note": tools.move_note,
"read_content": tools.read_content,
"read_note": tools.read_note,
"release_notes": tools.release_notes,
"recent_activity": tools.recent_activity,
"schema_diff": tools.schema_diff,
"schema_infer": tools.schema_infer,
"schema_validate": tools.schema_validate,
"search": tools.search,
"search_notes": tools.search_notes,
"view_note": tools.view_note,
"write_note": tools.write_note,
}
def _signature_params(tool_obj: object) -> list[str]:
params = []
for param in inspect.signature(tool_obj).parameters.values():
if param.name == "context":
continue
params.append(param.name)
return params
def test_mcp_tool_signatures_are_stable():
assert set(TOOL_FUNCTIONS.keys()) == set(EXPECTED_TOOL_SIGNATURES.keys())
for tool_name, tool_obj in TOOL_FUNCTIONS.items():
assert _signature_params(tool_obj) == EXPECTED_TOOL_SIGNATURES[tool_name]