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

13 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-09 11:03 +0100

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

2"""Base Transport Interface. 

3 

4Copyright 2025 

5SPDX-License-Identifier: Apache-2.0 

6Authors: Mihai Criveti 

7 

8This module defines the base protocol for MCP transports. 

9""" 

10 

11# Standard 

12from abc import ABC, abstractmethod 

13from typing import Any, AsyncGenerator, Dict 

14 

15 

16class 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 """