Skip to content

Commit 6287665

Browse files
committed
fix: cleanup
1 parent bcf1ddb commit 6287665

File tree

1 file changed

+6
-55
lines changed

1 file changed

+6
-55
lines changed

tests_integ/test_mcp_client.py

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ def start_comprehensive_mcp_server(transport: Literal["sse", "streamable-http"],
2929

3030
mcp = FastMCP("Comprehensive MCP Server", port=port)
3131

32-
# Tools
3332
@mcp.tool(description="Calculator tool which performs calculations")
3433
def calculator(x: int, y: int) -> int:
3534
return x + y
@@ -52,19 +51,12 @@ def greeting_prompt(name: str = "World") -> str:
5251
def math_prompt(operation: str = "addition", difficulty: str = "easy") -> str:
5352
return f"Create a {difficulty} {operation} math problem and solve it step by step."
5453

55-
# Resources (if supported by FastMCP - this is a placeholder for when resources are implemented)
56-
# @mcp.resource(description="A sample text resource")
57-
# def sample_resource() -> str:
58-
# return "This is a sample resource content"
59-
6054
mcp.run(transport=transport)
6155

6256

6357
def test_mcp_client():
6458
"""
65-
Comprehensive test for MCP client functionality including tools, prompts, and resources.
66-
67-
Test should yield output similar to the following for tools:
59+
Test should yield output similar to the following
6860
{'role': 'user', 'content': [{'text': 'add 1 and 2, then echo the result back to me'}]}
6961
{'role': 'assistant', 'content': [{'text': "I'll help you add 1 and 2 and then echo the result back to you.\n\nFirst, I'll calculate 1 + 2:"}, {'toolUse': {'toolUseId': 'tooluse_17ptaKUxQB20ySZxwgiI_w', 'name': 'calculator', 'input': {'x': 1, 'y': 2}}}]}
7062
{'role': 'user', 'content': [{'toolResult': {'status': 'success', 'toolUseId': 'tooluse_17ptaKUxQB20ySZxwgiI_w', 'content': [{'text': '3'}]}}]}
@@ -98,7 +90,6 @@ def test_mcp_client():
9890
assert any([block["name"] == "echo" for block in tool_use_content_blocks])
9991
assert any([block["name"] == "calculator" for block in tool_use_content_blocks])
10092

101-
# Test image generation tool
10293
image_prompt = """
10394
Generate a custom image, then tell me if the image is red, blue, yellow, pink, orange, or green.
10495
RESPOND ONLY WITH THE COLOR
@@ -179,64 +170,24 @@ def test_streamable_http_mcp_client():
179170
def transport_callback() -> MCPTransport:
180171
return streamablehttp_client(url="http://127.0.0.1:8001/mcp")
181172

182-
sse_mcp_client = MCPClient(transport_callback)
183-
with sse_mcp_client:
173+
streamable_http_client = MCPClient(transport_callback)
174+
with streamable_http_client:
184175
# Test tools
185-
agent = Agent(tools=sse_mcp_client.list_tools_sync())
176+
agent = Agent(tools=streamable_http_client.list_tools_sync())
186177
agent("add 1 and 2 using a calculator")
187178

188179
tool_use_content_blocks = _messages_to_content_blocks(agent.messages)
189180
assert any([block["name"] == "calculator" for block in tool_use_content_blocks])
190181

191182
# Test prompts
192-
prompts_result = sse_mcp_client.list_prompts_sync()
183+
prompts_result = streamable_http_client.list_prompts_sync()
193184
assert len(prompts_result.prompts) >= 2
194185

195-
greeting_result = sse_mcp_client.get_prompt_sync("greeting_prompt", {"name": "Charlie"})
186+
greeting_result = streamable_http_client.get_prompt_sync("greeting_prompt", {"name": "Charlie"})
196187
assert len(greeting_result.messages) > 0
197188
prompt_text = greeting_result.messages[0].content.text
198189
assert "Hello, Charlie!" in prompt_text
199190

200191

201192
def _messages_to_content_blocks(messages: List[Message]) -> List[ToolUse]:
202193
return [block["toolUse"] for message in messages for block in message["content"] if "toolUse" in block]
203-
204-
205-
@pytest.mark.asyncio
206-
async def test_mcp_client_async():
207-
"""Test MCP client async functionality with comprehensive server (tools, prompts, resources)."""
208-
server_thread = threading.Thread(
209-
target=start_comprehensive_mcp_server, kwargs={"transport": "sse", "port": 8005}, daemon=True
210-
)
211-
server_thread.start()
212-
time.sleep(2) # wait for server to startup completely
213-
214-
sse_mcp_client = MCPClient(lambda: sse_client("http://127.0.0.1:8005/sse"))
215-
216-
with sse_mcp_client:
217-
# Test sync prompts functionality
218-
prompts_result = sse_mcp_client.list_prompts_sync()
219-
assert len(prompts_result.prompts) >= 2
220-
221-
prompt_names = [prompt.name for prompt in prompts_result.prompts]
222-
assert "greeting_prompt" in prompt_names
223-
assert "math_prompt" in prompt_names
224-
225-
# Test get_prompt_sync
226-
greeting_result = sse_mcp_client.get_prompt_sync("greeting_prompt", {"name": "Bob"})
227-
assert len(greeting_result.messages) > 0
228-
prompt_text = greeting_result.messages[0].content.text
229-
assert "Hello, Bob!" in prompt_text
230-
assert "How are you today?" in prompt_text
231-
232-
# Test sync pagination for prompts
233-
prompts_with_pagination = sse_mcp_client.list_prompts_sync(pagination_token="test_token")
234-
assert len(prompts_with_pagination.prompts) >= 0
235-
236-
# Test async tools functionality (existing)
237-
tools_result = sse_mcp_client.list_tools_sync()
238-
assert len(tools_result) >= 2 # calculator and generate_custom_image
239-
240-
tool_names = [tool.tool_name for tool in tools_result]
241-
assert "calculator" in tool_names
242-
assert "generate_custom_image" in tool_names

0 commit comments

Comments
 (0)