Coverage for mcpgateway/transports/base.py: 100%
13 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-22 12:53 +0100
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-22 12:53 +0100
1# -*- coding: utf-8 -*-
2"""Base Transport Interface.
4Copyright 2025
5SPDX-License-Identifier: Apache-2.0
6Authors: Mihai Criveti
8This module defines the base protocol for MCP transports.
9"""
11from abc import ABC, abstractmethod
12from typing import Any, AsyncGenerator, Dict
15class Transport(ABC):
16 """Base class for MCP transport implementations."""
18 @abstractmethod
19 async def connect(self) -> None:
20 """Initialize transport connection."""
22 @abstractmethod
23 async def disconnect(self) -> None:
24 """Close transport connection."""
26 @abstractmethod
27 async def send_message(self, message: Dict[str, Any]) -> None:
28 """Send a message over the transport.
30 Args:
31 message: Message to send
32 """
34 @abstractmethod
35 async def receive_message(self) -> AsyncGenerator[Dict[str, Any], None]:
36 """Receive messages from the transport.
38 Yields:
39 Received messages
40 """
42 @abstractmethod
43 async def is_connected(self) -> bool:
44 """Check if transport is connected.
46 Returns:
47 True if connected
48 """