1111 pytest test/integration/test_agents.py -v
1212"""
1313
14+ import asyncio
1415import logging
1516import os
1617
18+ import pytest
19+ from fastmcp import (
20+ Client ,
21+ FastMCP ,
22+ )
23+ from fastmcp .exceptions import ToolError
24+
25+ from galaxy .agents .operations import AgentOperationsManager
26+ from galaxy .managers .context import ProvidesUserContext
1727from galaxy .util .unittest_utils import pytestmark_live_llm
28+ from galaxy .webapps .galaxy .api .mcp import get_mcp_app
1829from galaxy_test .base .populators import (
1930 DatasetPopulator ,
31+ TOOL_WITH_SHELL_COMMAND ,
2032 WorkflowPopulator ,
2133)
2234from galaxy_test .driver .integration_util import IntegrationTestCase
@@ -180,9 +192,6 @@ class TestAgentOperationsManagerEncoding(AgentIntegrationTestCase):
180192 """
181193
182194 def _make_ops (self ):
183- from galaxy .agents .operations import AgentOperationsManager
184- from galaxy .managers .context import ProvidesUserContext
185-
186195 class MinimalTrans (ProvidesUserContext ):
187196 def __init__ (self , app ):
188197 self ._app = app
@@ -285,8 +294,6 @@ def handle_galaxy_config_kwds(cls, config):
285294 config ["enable_beta_tool_formats" ] = True
286295
287296 def _get_mcp_server (self ):
288- from galaxy .webapps .galaxy .api .mcp import get_mcp_app
289-
290297 http_app = get_mcp_app (self ._app )
291298 return http_app .state .mcp_server
292299
@@ -302,8 +309,6 @@ def _setup_udt_user(self, email: str):
302309 return user , api_key
303310
304311 def _run_async (self , coro ):
305- import asyncio
306-
307312 loop = asyncio .new_event_loop ()
308313 try :
309314 return loop .run_until_complete (coro )
@@ -312,15 +317,11 @@ def _run_async(self, coro):
312317
313318 def test_mcp_server_initializes (self ):
314319 """MCP server creates a FastMCP instance when enabled."""
315- from fastmcp import FastMCP
316-
317320 mcp_server = self ._get_mcp_server ()
318321 assert isinstance (mcp_server , FastMCP )
319322
320323 def test_mcp_tools_registered (self ):
321324 """MCP server advertises all expected tools."""
322- from fastmcp import Client
323-
324325 mcp_server = self ._get_mcp_server ()
325326
326327 async def _list ():
@@ -350,8 +351,6 @@ async def _list():
350351
351352 def test_mcp_connect_with_valid_key (self ):
352353 """connect() succeeds with a valid API key and returns user + server info."""
353- from fastmcp import Client
354-
355354 mcp_server = self ._get_mcp_server ()
356355 api_key = self ._get_api_key ()
357356
@@ -367,10 +366,6 @@ async def _connect():
367366
368367 def test_mcp_connect_with_invalid_key (self ):
369368 """connect() rejects an invalid API key."""
370- import pytest
371- from fastmcp import Client
372- from fastmcp .exceptions import ToolError
373-
374369 mcp_server = self ._get_mcp_server ()
375370
376371 async def _connect ():
@@ -382,8 +377,6 @@ async def _connect():
382377
383378 def test_mcp_list_histories (self ):
384379 """list_histories() returns a valid response."""
385- from fastmcp import Client
386-
387380 mcp_server = self ._get_mcp_server ()
388381 api_key = self ._get_api_key ()
389382
@@ -398,8 +391,6 @@ async def _list():
398391
399392 def test_mcp_search_tools (self ):
400393 """search_tools() executes and returns a well-formed response."""
401- from fastmcp import Client
402-
403394 mcp_server = self ._get_mcp_server ()
404395 api_key = self ._get_api_key ()
405396
@@ -417,8 +408,6 @@ async def _search():
417408
418409 def test_mcp_list_user_tools_empty (self ):
419410 """list_user_tools() returns an empty list for a user with the role and no UDTs."""
420- from fastmcp import Client
421-
422411 mcp_server = self ._get_mcp_server ()
423412 _ , api_key = self ._setup_udt_user ("udt_list_user@test.com" )
424413
@@ -434,10 +423,6 @@ async def _list():
434423
435424 def test_mcp_create_user_tool (self ):
436425 """create_user_tool() persists a UDT and returns its uuid."""
437- from fastmcp import Client
438-
439- from galaxy_test .base .populators import TOOL_WITH_SHELL_COMMAND
440-
441426 mcp_server = self ._get_mcp_server ()
442427 _ , api_key = self ._setup_udt_user ("udt_create_user@test.com" )
443428
@@ -456,10 +441,6 @@ async def _create():
456441
457442 def test_mcp_delete_user_tool (self ):
458443 """delete_user_tool() deactivates a UDT so list_user_tools no longer returns it."""
459- from fastmcp import Client
460-
461- from galaxy_test .base .populators import TOOL_WITH_SHELL_COMMAND
462-
463444 mcp_server = self ._get_mcp_server ()
464445 _ , api_key = self ._setup_udt_user ("udt_delete_user@test.com" )
465446 populator = DatasetPopulator (self ._get_interactor (api_key = api_key ))
@@ -494,10 +475,6 @@ async def _flow():
494475
495476 def test_mcp_run_user_tool (self ):
496477 """run_user_tool() executes a UDT against an HDA input and produces an output."""
497- from fastmcp import Client
498-
499- from galaxy_test .base .populators import TOOL_WITH_SHELL_COMMAND
500-
501478 mcp_server = self ._get_mcp_server ()
502479 _ , api_key = self ._setup_udt_user ("udt_run_user@test.com" )
503480
0 commit comments