|
5 | 5 | from unittest.mock import patch |
6 | 6 |
|
7 | 7 | import pytest |
| 8 | +from agents.mcp import MCPServerStdio |
| 9 | +from agents.mcp import MCPServerStreamableHttp |
8 | 10 | from agents.models.interface import Model |
9 | 11 | from agents.models.openai_chatcompletions import OpenAIChatCompletionsModel |
10 | 12 | from agents.models.openai_responses import OpenAIResponsesModel |
@@ -114,6 +116,57 @@ def test_from_dict_uses_default_without_instructions(self): |
114 | 116 | assert agent.agent.instructions == DEFAULT_INSTRUCTIONS |
115 | 117 |
|
116 | 118 |
|
| 119 | +class TestFromDictMcpServers: |
| 120 | + def test_url_creates_streamable_http_server(self): |
| 121 | + config = { |
| 122 | + "mcpServers": { |
| 123 | + "my-server": { |
| 124 | + "url": "http://localhost:8000/mcp", |
| 125 | + } |
| 126 | + }, |
| 127 | + } |
| 128 | + agent = OpenAIAgent.from_dict("test", config) |
| 129 | + assert len(agent.agent.mcp_servers) == 1 |
| 130 | + assert isinstance(agent.agent.mcp_servers[0], MCPServerStreamableHttp) |
| 131 | + |
| 132 | + def test_url_passes_headers(self): |
| 133 | + config = { |
| 134 | + "mcpServers": { |
| 135 | + "my-server": { |
| 136 | + "url": "http://localhost:8000/mcp", |
| 137 | + "headers": {"Authorization": "Bearer token"}, |
| 138 | + } |
| 139 | + }, |
| 140 | + } |
| 141 | + agent = OpenAIAgent.from_dict("test", config) |
| 142 | + server = agent.agent.mcp_servers[0] |
| 143 | + assert isinstance(server, MCPServerStreamableHttp) |
| 144 | + |
| 145 | + def test_command_creates_stdio_server(self): |
| 146 | + config = { |
| 147 | + "mcpServers": { |
| 148 | + "my-server": { |
| 149 | + "command": "npx", |
| 150 | + "args": ["-y", "some-mcp-server"], |
| 151 | + } |
| 152 | + }, |
| 153 | + } |
| 154 | + agent = OpenAIAgent.from_dict("test", config) |
| 155 | + assert len(agent.agent.mcp_servers) == 1 |
| 156 | + assert isinstance(agent.agent.mcp_servers[0], MCPServerStdio) |
| 157 | + |
| 158 | + def test_mixed_servers(self): |
| 159 | + config = { |
| 160 | + "mcpServers": { |
| 161 | + "remote": {"url": "http://localhost:8000/mcp"}, |
| 162 | + "local": {"command": "npx", "args": ["-y", "server"]}, |
| 163 | + }, |
| 164 | + } |
| 165 | + agent = OpenAIAgent.from_dict("test", config) |
| 166 | + types = {type(s) for s in agent.agent.mcp_servers} |
| 167 | + assert types == {MCPServerStreamableHttp, MCPServerStdio} |
| 168 | + |
| 169 | + |
117 | 170 | class TestHistoryTruncation: |
118 | 171 | def test_default_max_turns(self): |
119 | 172 | assert MAX_TURNS == 10 |
|
0 commit comments