24
24
25
25
pytestmark = pytest .mark .anyio
26
26
27
+
27
28
@pytest .fixture
28
29
def mcp_url ():
29
30
return os .environ .get ("MCP_GRAFANA_URL" , DEFAULT_MCP_URL )
@@ -81,7 +82,9 @@ async def test_loki(model: str, mcp_client: ClientSession):
81
82
# Verify Loki datasource exists
82
83
loki_datasources = [ds for ds in datasources_data if ds .get ("type" ) == "loki" ]
83
84
assert len (loki_datasources ) > 0 , "No Loki datasource found"
84
- print (f"\n Found Loki datasource: { loki_datasources [0 ]['name' ]} (uid: { loki_datasources [0 ]['uid' ]} )" )
85
+ print (
86
+ f"\n Found Loki datasource: { loki_datasources [0 ]['name' ]} (uid: { loki_datasources [0 ]['uid' ]} )"
87
+ )
85
88
86
89
# Call the LLM including the tool call result.
87
90
response = await acompletion (
@@ -149,7 +152,9 @@ async def test_loki_container_labels(model: str, mcp_client: ClientSession):
149
152
# Verify Loki datasource exists
150
153
loki_datasources = [ds for ds in datasources_data if ds .get ("type" ) == "loki" ]
151
154
assert len (loki_datasources ) > 0 , "No Loki datasource found"
152
- print (f"\n Found Loki datasource: { loki_datasources [0 ]['name' ]} (uid: { loki_datasources [0 ]['uid' ]} )" )
155
+ print (
156
+ f"\n Found Loki datasource: { loki_datasources [0 ]['name' ]} (uid: { loki_datasources [0 ]['uid' ]} )"
157
+ )
153
158
154
159
# Call the LLM including the tool call result.
155
160
response = await acompletion (
@@ -165,10 +170,7 @@ async def test_loki_container_labels(model: str, mcp_client: ClientSession):
165
170
response ,
166
171
mcp_client ,
167
172
"list_loki_label_values" ,
168
- {
169
- "datasourceUid" : "loki" ,
170
- "labelName" : "container"
171
- },
173
+ {"datasourceUid" : "loki" , "labelName" : "container" },
172
174
)
173
175
)
174
176
@@ -219,8 +221,12 @@ async def assert_and_handle_tool_call(
219
221
220
222
if expected_args :
221
223
for key , value in expected_args .items ():
222
- assert key in arguments , f"Missing required argument '{ key } ' in tool call"
223
- assert arguments [key ] == value , f"Argument '{ key } ' has wrong value. Expected: { value } , Got: { arguments [key ]} "
224
+ assert key in arguments , (
225
+ f"Missing required argument '{ key } ' in tool call"
226
+ )
227
+ assert arguments [key ] == value , (
228
+ f"Argument '{ key } ' has wrong value. Expected: { value } , Got: { arguments [key ]} "
229
+ )
224
230
result = await mcp_client .call_tool (tool_call .function .name , arguments )
225
231
# Assume each tool returns a single text content for now
226
232
assert len (result .content ) == 1
0 commit comments