File size: 7,338 Bytes
0eed497
 
 
 
 
13e3e7d
0eed497
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2215271
0eed497
 
 
 
ccaec2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0eed497
1667edb
0eed497
ccaec2a
 
 
 
 
0eed497
ccaec2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2215271
 
ccaec2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0eed497
 
 
 
 
13e3e7d
 
0eed497
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13e3e7d
0eed497
13e3e7d
0eed497
 
 
 
 
 
 
 
 
13e3e7d
0eed497
13e3e7d
0eed497
 
 
 
 
 
 
ccaec2a
 
13e3e7d
0eed497
 
13e3e7d
0eed497
 
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
"""
Tests to verify that all MCP tools have the required annotations
(title, readOnlyHint, destructiveHint) per Anthropic Software Directory Policy §5.E.
"""

import asyncio
import os
import pathlib
import sys

sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1] / "src"))
os.environ.setdefault("API_KEY", "test")
os.environ.setdefault("ATHLETE_ID", "i1")

from intervals_mcp_server.mcp_instance import mcp  # noqa: E402

# Import all tool modules so they register with the mcp instance
import intervals_mcp_server.tools.activities  # noqa: E402, F401
import intervals_mcp_server.tools.events  # noqa: E402, F401
import intervals_mcp_server.tools.wellness  # noqa: E402, F401
import intervals_mcp_server.tools.custom_items  # noqa: E402, F401
import intervals_mcp_server.tools.athlete  # noqa: E402, F401
import intervals_mcp_server.tools.power_curves  # noqa: E402, F401
import intervals_mcp_server.tools.training_summary  # noqa: E402, F401
import intervals_mcp_server.tools.workout_library  # noqa: E402, F401


EXPECTED_ANNOTATIONS = {
    "get_activities": {"title": "Get Activities", "readOnlyHint": True, "destructiveHint": False},
    "get_activity_details": {
        "title": "Get Activity Details",
        "readOnlyHint": True,
        "destructiveHint": False,
    },
    "get_activity_intervals": {
        "title": "Get Activity Intervals",
        "readOnlyHint": True,
        "destructiveHint": False,
    },
    "get_activity_streams": {
        "title": "Get Activity Streams",
        "readOnlyHint": True,
        "destructiveHint": False,
    },
    "get_activity_messages": {
        "title": "Get Activity Messages",
        "readOnlyHint": True,
        "destructiveHint": False,
    },
    "add_activity_message": {
        "title": "Add Activity Message",
        "readOnlyHint": False,
        "destructiveHint": False,
    },
    "get_events": {"title": "Get Events", "readOnlyHint": True, "destructiveHint": False},
    "get_races": {"title": "Get Races", "readOnlyHint": True, "destructiveHint": False},
    "get_event_by_id": {"title": "Get Event by ID", "readOnlyHint": True, "destructiveHint": False},
    "add_or_update_event": {
        "title": "Add or Update Event",
        "readOnlyHint": False,
        "destructiveHint": False,
    },
    "delete_event": {"title": "Delete Event", "readOnlyHint": False, "destructiveHint": True},
    "delete_events_by_date_range": {
        "title": "Delete Events by Date Range",
        "readOnlyHint": False,
        "destructiveHint": True,
    },
    "get_wellness_data": {
        "title": "Get Wellness Data",
        "readOnlyHint": True,
        "destructiveHint": False,
    },
    "get_custom_items": {
        "title": "Get Custom Items",
        "readOnlyHint": True,
        "destructiveHint": False,
    },
    "get_custom_item_by_id": {
        "title": "Get Custom Item by ID",
        "readOnlyHint": True,
        "destructiveHint": False,
    },
    "create_custom_item": {
        "title": "Create Custom Item",
        "readOnlyHint": False,
        "destructiveHint": False,
    },
    "update_custom_item": {
        "title": "Update Custom Item",
        "readOnlyHint": False,
        "destructiveHint": False,
    },
    "delete_custom_item": {
        "title": "Delete Custom Item",
        "readOnlyHint": False,
        "destructiveHint": True,
    },
    "get_training_summary": {
        "title": "Get Training Summary",
        "readOnlyHint": True,
        "destructiveHint": False,
    },
    "get_athlete_zones": {
        "title": "Get Athlete Zones",
        "readOnlyHint": True,
        "destructiveHint": False,
    },
    "get_athlete_power_curves": {
        "title": "Get Athlete Power Curves",
        "readOnlyHint": True,
        "destructiveHint": False,
    },
    "get_workout_folders": {
        "title": "Get Workout Folders",
        "readOnlyHint": True,
        "destructiveHint": False,
    },
    "list_workouts": {"title": "List Workouts", "readOnlyHint": True, "destructiveHint": False},
    "get_workout": {"title": "Get Workout", "readOnlyHint": True, "destructiveHint": False},
    "create_workout": {
        "title": "Create Library Workout",
        "readOnlyHint": False,
        "destructiveHint": False,
    },
    "update_workout": {
        "title": "Update Library Workout",
        "readOnlyHint": False,
        "destructiveHint": False,
    },
    "schedule_workout": {
        "title": "Schedule Workout to Calendar",
        "readOnlyHint": False,
        "destructiveHint": False,
    },
}


def _get_tool_map() -> dict:
    """Build a mapping of tool name to Tool object from the mcp instance."""
    tools = asyncio.run(mcp.list_tools())
    return {tool.name: tool for tool in tools}


def test_all_tools_have_annotations():
    """Every registered tool must have annotations set."""
    tool_map = _get_tool_map()
    for tool_name in EXPECTED_ANNOTATIONS:
        assert tool_name in tool_map, f"Tool '{tool_name}' not found in registered tools"
        tool = tool_map[tool_name]
        assert tool.annotations is not None, f"Tool '{tool_name}' is missing annotations"


def test_all_tools_have_title():
    """Every registered tool must have a title annotation."""
    tool_map = _get_tool_map()
    for tool_name, expected in EXPECTED_ANNOTATIONS.items():
        tool = tool_map[tool_name]
        assert tool.annotations is not None
        assert tool.annotations.title == expected["title"], (
            f"Tool '{tool_name}' title mismatch: "
            f"expected '{expected['title']}', got '{tool.annotations.title}'"
        )


def test_all_tools_have_read_only_hint():
    """Every registered tool must have a readOnlyHint annotation."""
    tool_map = _get_tool_map()
    for tool_name, expected in EXPECTED_ANNOTATIONS.items():
        tool = tool_map[tool_name]
        assert tool.annotations is not None
        assert tool.annotations.read_only_hint == expected["readOnlyHint"], (
            f"Tool '{tool_name}' readOnlyHint mismatch: "
            f"expected {expected['readOnlyHint']}, got {tool.annotations.read_only_hint}"
        )


def test_all_tools_have_destructive_hint():
    """Every registered tool must have a destructiveHint annotation."""
    tool_map = _get_tool_map()
    for tool_name, expected in EXPECTED_ANNOTATIONS.items():
        tool = tool_map[tool_name]
        assert tool.annotations is not None
        assert tool.annotations.destructive_hint == expected["destructiveHint"], (
            f"Tool '{tool_name}' destructiveHint mismatch: "
            f"expected {expected['destructiveHint']}, got {tool.annotations.destructive_hint}"
        )


def test_no_tool_missing_annotations():
    """Ensure no registered tool is missing annotations entirely."""
    tool_map = _get_tool_map()
    for tool_name, tool in tool_map.items():
        assert tool.annotations is not None, f"Tool '{tool_name}' is missing annotations"
        assert tool.annotations.title is not None, f"Tool '{tool_name}' is missing title annotation"
        assert tool.annotations.read_only_hint is not None, (
            f"Tool '{tool_name}' is missing readOnlyHint annotation"
        )
        assert tool.annotations.destructive_hint is not None, (
            f"Tool '{tool_name}' is missing destructiveHint annotation"
        )