MCP server for tangled
1"""unit tests for tangled MCP server"""
2
3from fastmcp.client import Client
4
5from tangled_mcp.server import tangled_mcp
6
7
8class TestServerStructure:
9 """test that server exposes correct resources and tools"""
10
11 async def test_server_has_resources(self):
12 """test that server exposes the tangled_status resource"""
13 async with Client(tangled_mcp) as client:
14 resources = await client.list_resources()
15
16 assert len(resources) == 1
17 assert resources[0].name == "tangled_status"
18 assert str(resources[0].uri) == "tangled://status"
19
20 async def test_server_has_tools(self):
21 """test that server exposes expected tools"""
22 async with Client(tangled_mcp) as client:
23 tools = await client.list_tools()
24
25 assert len(tools) == 7
26
27 tool_names = {tool.name for tool in tools}
28 assert "list_repo_branches" in tool_names
29 assert "create_repo_issue" in tool_names
30 assert "update_repo_issue" in tool_names
31 assert "delete_repo_issue" in tool_names
32 assert "list_repo_issues" in tool_names
33 assert "list_repo_labels" in tool_names
34 assert "list_repo_pulls" in tool_names
35
36 async def test_list_repo_branches_tool_schema(self):
37 """test list_repo_branches tool has correct schema"""
38 async with Client(tangled_mcp) as client:
39 tools = await client.list_tools()
40
41 tool = next(t for t in tools if t.name == "list_repo_branches")
42
43 # check input schema
44 assert tool.inputSchema is not None
45 assert tool.inputSchema["type"] == "object"
46
47 properties = tool.inputSchema["properties"]
48
49 # required fields
50 assert "repo" in properties
51 assert properties["repo"]["type"] == "string"
52
53 # optional fields with defaults
54 assert "limit" in properties
55 assert properties["limit"]["type"] == "integer"
56 assert properties["limit"]["minimum"] == 1
57 assert properties["limit"]["maximum"] == 100
58 assert properties["limit"]["default"] == 50
59
60 # required parameters
61 assert tool.inputSchema["required"] == ["repo"]