Skip to content

Commit e54b0e6

Browse files
committed
add openai end to end test
1 parent 30787eb commit e54b0e6

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

tests/mcp/test_mcp.py

+48-2
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ async def test_end_to_end_with_tool_use_anthropic(self, arithmetic_stdio_server)
319319
# Query that should use the multiply tool
320320
query = "I need to multiply 12 and 34. Can you use the multiply tool to help me?"
321321

322-
# Use mcp_chat instead of process_query to test the full client API
322+
# Use mcp_chat to test the full client API
323323
result, tool_outputs = await client.mcp_chat(query=query)
324324

325325
# Verify result
@@ -365,7 +365,7 @@ async def test_end_to_end_with_tool_use_gemini(self, arithmetic_stdio_server):
365365
# Query that should use the multiply tool
366366
query = "I need to multiply 12 and 34. Can you use the multiply tool to help me?"
367367

368-
# Use mcp_chat instead of process_query to test the full client API
368+
# Use mcp_chat to test the full client API
369369
result, tool_outputs = await client.mcp_chat(query=query)
370370

371371
# Verify result
@@ -396,3 +396,49 @@ async def test_end_to_end_with_tool_use_gemini(self, arithmetic_stdio_server):
396396
print("Cleaning up MCP client...")
397397
await client.cleanup()
398398
print("End-to-end tool use test with Gemini completed")
399+
400+
@pytest.mark.asyncio
401+
@pytest.mark.skipif(not os.environ.get("OPENAI_API_KEY"),
402+
reason="OPENAI_API_KEY environment variable not set")
403+
async def test_end_to_end_with_tool_use_openai(self, arithmetic_stdio_server):
404+
"""End-to-end test with tool use using OpenAI (requires API key and server)"""
405+
client = None
406+
try:
407+
print("Starting end-to-end tool use test with OpenAI...")
408+
# Initialize client with GPT-4
409+
client = await initialize_mcp_client(arithmetic_stdio_server, "o3-mini")
410+
411+
# Query that should use the multiply tool
412+
query = "I need to multiply 12 and 34. Can you use the multiply tool to help me?"
413+
414+
# Use mcp_chat to test the full client API
415+
result, tool_outputs = await client.mcp_chat(query=query)
416+
417+
# Verify result
418+
assert result is not None
419+
assert isinstance(result, str)
420+
print(f"End-to-end response from OpenAI: {result}")
421+
422+
# Check if the tool was used (using the returned tool_outputs)
423+
assert len(tool_outputs) > 0
424+
tool_used = False
425+
for tool in tool_outputs:
426+
print(f"Tool used: {tool['name']}")
427+
print(f"Tool args: {tool['args']}")
428+
print(f"Tool result: {tool['result']}")
429+
if tool['name'] == 'multiply':
430+
tool_used = True
431+
432+
assert tool_used, "Multiply tool was not used"
433+
434+
# Basic check for correct answer (408)
435+
assert "408" in result
436+
437+
except Exception as e:
438+
pytest.fail(f"End-to-end test with OpenAI failed: {str(e)}")
439+
finally:
440+
# Clean up client
441+
if client:
442+
print("Cleaning up MCP client...")
443+
await client.cleanup()
444+
print("End-to-end tool use test with OpenAI completed")

0 commit comments

Comments
 (0)