Coverage for mcpgateway/transports/base.py: 100%

1# -*- coding: utf-8 -*-

2"""Base Transport Interface.

3

4 Copyright 2025

5 SPDX-License-Identifier: Apache-2.0

6 Authors: Mihai Criveti

7

8 This module defines the base protocol for MCP transports.

9"""

10

11# Standard

12 from abc import ABC, abstractmethod

13 from typing import Any, AsyncGenerator, Dict

14

15

16 class Transport(ABC):

17 """Base class for MCP transport implementations."""

18

19 @abstractmethod

20 async def connect(self) -> None:

21 """Initialize transport connection."""

22

23 @abstractmethod

24 async def disconnect(self) -> None:

25 """Close transport connection."""

26

27 @abstractmethod

28 async def send_message(self, message: Dict[str, Any]) -> None:

29 """Send a message over the transport.

30

31 Args:

32 message: Message to send

33 """

34

35 @abstractmethod

36 async def receive_message(self) -> AsyncGenerator[Dict[str, Any], None]:

37 """Receive messages from the transport.

38

39 Yields:

40 Received messages

41 """

42

43 @abstractmethod

44 async def is_connected(self) -> bool:

45 """Check if transport is connected.

46

47 Returns:

48 True if connected

49 """