test_server_contracts.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import inspect
  2. from app.core.mcp.servers import (
  3. CONTEXT_TOOL_NAMES,
  4. SCHEDULING_TOOL_NAMES,
  5. create_context_mcp,
  6. create_scheduling_mcp,
  7. )
  8. class FakeFastMCP:
  9. def __init__(self, name, **kwargs):
  10. self.name = name
  11. self.kwargs = kwargs
  12. self.tools = {}
  13. def tool(self):
  14. def register(function):
  15. self.tools[function.__name__] = function
  16. return function
  17. return register
  18. class Service:
  19. def __getattr__(self, name):
  20. return lambda *_args, **_kwargs: {"tool": name}
  21. def test_context_mcp_exposes_only_bounded_read_and_validation_tools():
  22. server = create_context_mcp(
  23. Service(),
  24. identity=object(),
  25. fastmcp_cls=FakeFastMCP,
  26. )
  27. assert set(server.tools) == CONTEXT_TOOL_NAMES
  28. assert server.kwargs["json_response"] is True
  29. assert not {"delete_flow", "read_business_rows"} & set(server.tools)
  30. def test_scheduling_mcp_exposes_only_compound_gateway_tools():
  31. server = create_scheduling_mcp(
  32. Service(),
  33. identity=object(),
  34. fastmcp_cls=FakeFastMCP,
  35. )
  36. assert set(server.tools) == SCHEDULING_TOOL_NAMES
  37. assert "delete_flow" not in server.tools
  38. assert "create_yaml" not in server.tools
  39. assert "configure_connection" not in server.tools
  40. assert "task_tokens" not in inspect.signature(server.tools["run_canary"]).parameters
  41. assert (
  42. "canary" not in inspect.signature(server.tools["promote_candidate"]).parameters
  43. )