11"""Happy path integration tests for AWS MCP Server at https://aws-mcp.us-east-1.api.aws/mcp."""
22
33import fastmcp
4+ import json
45import logging
56import pytest
67from fastmcp .client .client import CallToolResult
7-
88from tests .integ .test_proxy_simple_mcp_server import get_text_content
9- import json
109
1110
1211logger = logging .getLogger (__name__ )
1312
1413
15- @pytest .mark .asyncio (loop_scope = " module" )
14+ @pytest .mark .asyncio (loop_scope = ' module' )
1615async def test_aws_mcp_ping (aws_mcp_client : fastmcp .Client ):
1716 """Test ping to AWS MCP Server."""
1817 await aws_mcp_client .ping ()
1918
20- @pytest .mark .asyncio (loop_scope = "module" )
19+
20+ @pytest .mark .asyncio (loop_scope = 'module' )
2121async def test_aws_mcp_list_tools (aws_mcp_client : fastmcp .Client ):
2222 """Test list tools from AWS MCP Server."""
2323 tools = await aws_mcp_client .list_tools ()
2424
25- assert len (tools ) > 0 , f" AWS MCP Server should have tools (got { len (tools )} )"
25+ assert len (tools ) > 0 , f' AWS MCP Server should have tools (got { len (tools )} )'
2626
2727
2828def verify_response_content (response : CallToolResult ):
@@ -37,16 +37,17 @@ def verify_response_content(response: CallToolResult):
3737 Raises:
3838 AssertionError: If response indicates an error or has empty content
3939 """
40- assert (
41- response . is_error is False
42- ), f"is_error returned true. Returned response body: { response } ."
43- assert len (response .content ) > 0 , f" Empty result list in response. Response: { response } "
40+ assert response . is_error is False , (
41+ f' is_error returned true. Returned response body: { response } .'
42+ )
43+ assert len (response .content ) > 0 , f' Empty result list in response. Response: { response } '
4444
4545 response_text = get_text_content (response )
46- assert len (response_text ) > 0 , f" Empty response text. Response: { response } "
46+ assert len (response_text ) > 0 , f' Empty response text. Response: { response } '
4747
4848 return response_text
4949
50+
5051def verify_json_response (response : CallToolResult ):
5152 """Verify that a tool call response is successful and contains valid JSON data.
5253
@@ -63,76 +64,77 @@ def verify_json_response(response: CallToolResult):
6364 try :
6465 response_data = json .loads (response_text )
6566 except json .JSONDecodeError :
66- raise AssertionError (f" Response text is not valid JSON. Response text: { response_text } " )
67+ raise AssertionError (f' Response text is not valid JSON. Response text: { response_text } ' )
6768
68- assert len (response_data ) > 0 , f" Empty JSON content in response. Response: { response } "
69+ assert len (response_data ) > 0 , f' Empty JSON content in response. Response: { response } '
6970
7071
7172@pytest .mark .parametrize (
72- " tool_name,params" ,
73+ ' tool_name,params' ,
7374 [
74- (" aws___list_regions" , {}),
75- (" aws___suggest_aws_commands" , {" query" : " how to list my lambda functions" }),
76- (" aws___search_documentation" , {" search_phrase" : " S3 bucket versioning" }),
75+ (' aws___list_regions' , {}),
76+ (' aws___suggest_aws_commands' , {' query' : ' how to list my lambda functions' }),
77+ (' aws___search_documentation' , {' search_phrase' : ' S3 bucket versioning' }),
7778 (
78- " aws___recommend" ,
79- {" url" : " https://docs.aws.amazon.com/lambda/latest/dg/lambda-invocation.html" },
79+ ' aws___recommend' ,
80+ {' url' : ' https://docs.aws.amazon.com/lambda/latest/dg/lambda-invocation.html' },
8081 ),
8182 (
82- " aws___read_documentation" ,
83- {" url" : " https://docs.aws.amazon.com/lambda/latest/dg/lambda-invocation.html" },
83+ ' aws___read_documentation' ,
84+ {' url' : ' https://docs.aws.amazon.com/lambda/latest/dg/lambda-invocation.html' },
8485 ),
8586 (
86- " aws___get_regional_availability" ,
87- {" resource_type" : " cfn" , " region" : " us-east-1" },
87+ ' aws___get_regional_availability' ,
88+ {' resource_type' : ' cfn' , ' region' : ' us-east-1' },
8889 ),
89- (" aws___call_aws" , {" cli_command" : " aws s3 ls" , " max_results" : 10 }),
90+ (' aws___call_aws' , {' cli_command' : ' aws s3 ls' , ' max_results' : 10 }),
9091 ],
9192 ids = [
92- " list_regions" ,
93- " suggest_aws_commands" ,
94- " search_documentation" ,
95- " recommend" ,
96- " read_documentation" ,
97- " get_regional_availability" ,
98- " call_aws" ,
93+ ' list_regions' ,
94+ ' suggest_aws_commands' ,
95+ ' search_documentation' ,
96+ ' recommend' ,
97+ ' read_documentation' ,
98+ ' get_regional_availability' ,
99+ ' call_aws' ,
99100 ],
100101)
101- @pytest .mark .asyncio (loop_scope = " module" )
102+ @pytest .mark .asyncio (loop_scope = ' module' )
102103async def test_aws_mcp_tools (aws_mcp_client : fastmcp .Client , tool_name : str , params : dict ):
103104 """Test AWS MCP tools with minimal valid params."""
104105 response = await aws_mcp_client .call_tool (tool_name , params )
105106 verify_json_response (response )
106107
107108
108- @pytest .mark .asyncio (loop_scope = " module" )
109+ @pytest .mark .asyncio (loop_scope = ' module' )
109110async def test_aws_mcp_tools_retrieve_agent_sop (aws_mcp_client : fastmcp .Client ):
110111 """Test aws___retrieve_agent_sop by retrieving the list of available SOPs."""
111-
112112 # Step 1: Call retrieve_agent_sop with empty params to get list of available SOPs
113- list_sops_response = await aws_mcp_client .call_tool (" aws___retrieve_agent_sop" )
113+ list_sops_response = await aws_mcp_client .call_tool (' aws___retrieve_agent_sop' )
114114
115115 list_sops_response_text = verify_response_content (list_sops_response )
116116
117117 # Parse SOP names from text (format: "* sop_name : description")
118118 sop_names = []
119- for line in list_sops_response_text .split (" \n " ):
119+ for line in list_sops_response_text .split (' \n ' ):
120120 line = line .strip ()
121- if line .startswith ("*" ) and ":" in line :
121+ if line .startswith ('*' ) and ':' in line :
122122 # Extract the SOP name between '*' and ':'
123- sop_name = line .split ("*" , 1 )[1 ].split (":" , 1 )[0 ].strip ()
123+ sop_name = line .split ('*' , 1 )[1 ].split (':' , 1 )[0 ].strip ()
124124 if sop_name :
125125 sop_names .append (sop_name )
126126
127- assert (
128- len ( sop_names ) > 0
129- ), f"No SOPs found in response. Response: { list_sops_response_text [: 200 ] } ..."
130- logger .info (f" Found { len (sop_names )} SOPs: { sop_names } " )
127+ assert len ( sop_names ) > 0 , (
128+ f'No SOPs found in response. Response: { list_sops_response_text [: 200 ] } ...'
129+ )
130+ logger .info (' Found %d SOPs: %s' , len (sop_names ), sop_names )
131131
132132 # Step 2: Test retrieving the first SOP
133133 test_script = sop_names [0 ]
134- logger .info (f" Testing with SOP: { test_script } " )
134+ logger .info (' Testing with SOP: %s' , test_script )
135135
136- response = await aws_mcp_client .call_tool ("aws___retrieve_agent_sop" , {"sop_name" : test_script })
136+ response = await aws_mcp_client .call_tool (
137+ 'aws___retrieve_agent_sop' , {'sop_name' : test_script }
138+ )
137139
138140 verify_response_content (response )
0 commit comments