-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtest_sdk_mcp_server.py
More file actions
65 lines (51 loc) · 2.02 KB
/
test_sdk_mcp_server.py
File metadata and controls
65 lines (51 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""Tests for in-process SDK MCP server."""
import pytest
from open_agent_sdk.sdk_mcp_server import (
McpSdkServerConfig,
SdkMcpToolWrapper,
create_sdk_mcp_server,
is_sdk_server_config,
)
from open_agent_sdk.tools import BashTool, FileReadTool
from open_agent_sdk.types import ToolContext
class TestCreateSdkMcpServer:
def test_creates_config(self):
config = create_sdk_mcp_server("test-server", tools=[BashTool()])
assert isinstance(config, McpSdkServerConfig)
assert config.name == "test-server"
assert config.type == "sdk"
assert len(config.tools) == 1
def test_tool_name_prefix(self):
config = create_sdk_mcp_server("myserver", tools=[BashTool(), FileReadTool()])
names = [t.name for t in config.tools]
assert "mcp__myserver__Bash" in names
assert "mcp__myserver__Read" in names
def test_empty_tools(self):
config = create_sdk_mcp_server("empty")
assert config.tools == []
class TestSdkMcpToolWrapper:
@pytest.mark.asyncio
async def test_delegates_to_inner(self):
inner = BashTool()
wrapper = SdkMcpToolWrapper("server", inner)
assert wrapper.name == "mcp__server__Bash"
assert wrapper.description == inner.description
@pytest.mark.asyncio
async def test_call_delegates(self, tmp_path):
inner = FileReadTool()
wrapper = SdkMcpToolWrapper("server", inner)
test_file = tmp_path / "test.txt"
test_file.write_text("hello\n")
result = await wrapper.call(
{"file_path": str(test_file)},
ToolContext(cwd=str(tmp_path)),
)
assert "hello" in result.content
class TestIsSdkServerConfig:
def test_true_for_config(self):
config = create_sdk_mcp_server("test")
assert is_sdk_server_config(config) is True
def test_false_for_dict(self):
assert is_sdk_server_config({"type": "stdio"}) is False
def test_false_for_string(self):
assert is_sdk_server_config("not a config") is False