Skip to content

Commit 9013595

Browse files
authored
Merge pull request #15 from John-Lin/fix/mcp-url-key
fix: use standard MCP config key "url" instead of "httpUrl"
2 parents e9e1f2e + da667c8 commit 9013595

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

bot/agents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ def truncate_history(self, chat_id: int) -> None:
9595
def from_dict(cls, name: str, config: dict[str, Any]) -> OpenAIAgent:
9696
mcp_servers: list[MCPServerStreamableHttp | MCPServerStdio] = []
9797
for mcp_srv in config.get("mcpServers", {}).values():
98-
if "httpUrl" in mcp_srv:
98+
if "url" in mcp_srv:
9999
mcp_servers.append(
100100
MCPServerStreamableHttp(
101101
client_session_timeout_seconds=MCP_SESSION_TIMEOUT_SECONDS,
102102
params={
103-
"url": mcp_srv["httpUrl"],
103+
"url": mcp_srv["url"],
104104
"headers": mcp_srv.get("headers", {}),
105105
},
106106
)

tests/test_agents.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from unittest.mock import patch
66

77
import pytest
8+
from agents.mcp import MCPServerStdio
9+
from agents.mcp import MCPServerStreamableHttp
810
from agents.models.interface import Model
911
from agents.models.openai_chatcompletions import OpenAIChatCompletionsModel
1012
from agents.models.openai_responses import OpenAIResponsesModel
@@ -114,6 +116,57 @@ def test_from_dict_uses_default_without_instructions(self):
114116
assert agent.agent.instructions == DEFAULT_INSTRUCTIONS
115117

116118

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+
117170
class TestHistoryTruncation:
118171
def test_default_max_turns(self):
119172
assert MAX_TURNS == 10

0 commit comments

Comments
 (0)