Add stdio MCP server for RollCalc

This commit is contained in:
2026-09-24 13:58:55 +02:00
parent defbf20202
commit bbaaaf31c5
5 changed files with 324 additions and 0 deletions
+116
View File
@@ -0,0 +1,116 @@
import sys
import types
import unittest
from unittest.mock import patch
import mcp_server
from roll_calculation import calculate_roll, get_article
from rollcalc_mcp_tools import (
analyze_transport_capacity_result,
calculate_roll_diameter_result,
get_article_result,
)
from transport_calculation import analyze_transport
class _FakeFastMCP:
def __init__(self, name):
self.name = name
self.tools = []
def tool(self):
def register(function):
self.tools.append(function)
return function
return register
class McpAdapterTests(unittest.TestCase):
def test_get_article_delegates_to_the_domain_for_success_not_found_and_conflict(self):
for arguments in (
{"article_number": "146900"},
{"article_number": "does-not-exist"},
{"article_number": "146900", "article_name_hint": "Other product"},
):
with self.subTest(arguments=arguments):
self.assertEqual(
get_article_result(**arguments),
get_article(**arguments),
)
def test_calculate_roll_diameter_delegates_for_normal_weighted_and_invalid_cases(self):
for arguments in (
{
"article_number": "146900",
"roll_length_m": 50.0,
"core_diameter_mm": 150.0,
},
{
"article_number": "146900",
"roll_length_m": 50.0,
"core_diameter_mm": 150.0,
"width_m": 5.8,
"area_weight_g_m2": 1767.2,
"include_roll_weight": True,
},
{"roll_length_m": -1.0, "core_diameter_mm": 150.0, "thickness_mm": 2.0},
):
with self.subTest(arguments=arguments):
self.assertEqual(
calculate_roll_diameter_result(**arguments),
calculate_roll(arguments),
)
def test_transport_tool_delegates_for_preset_custom_and_invalid_cases(self):
for arguments in (
{
"transport_preset": "container_20ft",
"roll_diameter_mm": 1000.0,
"core_diameter_mm": 150.0,
"roll_width_m": 2.0,
"roll_weight_kg": 1000.0,
"product_length_m": 50.0,
},
{
"length_m": 10.0,
"width_m": 5.0,
"height_m": 5.0,
"max_weight_kg": 10000.0,
"roll_diameter_mm": 1000.0,
"core_diameter_mm": 150.0,
"roll_width_m": 1.0,
"roll_weight_kg": 1000.0,
},
{"length_m": 0.0},
):
with self.subTest(arguments=arguments):
self.assertEqual(
analyze_transport_capacity_result(**arguments),
analyze_transport(arguments),
)
def test_server_registers_exactly_the_three_stdio_poc_tools(self):
mcp = types.ModuleType("mcp")
server = types.ModuleType("mcp.server")
fastmcp = types.ModuleType("mcp.server.fastmcp")
fastmcp.FastMCP = _FakeFastMCP
with patch.dict(sys.modules, {
"mcp": mcp,
"mcp.server": server,
"mcp.server.fastmcp": fastmcp,
}):
instance = mcp_server.create_server()
self.assertEqual(instance.name, "RollCalc")
self.assertEqual(
[tool.__name__ for tool in instance.tools],
[
"get_article",
"calculate_roll_diameter",
"analyze_transport_capacity",
],
)
if __name__ == "__main__":
unittest.main()