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
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-09 11:03 +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"""
11# Standard
12from abc import ABC, abstractmethod
13from typing import Any, AsyncGenerator, Dict
16class Transport(ABC):
17 """Base class for MCP transport implementations."""
19 @abstractmethod
20 async def connect(self) -> None:
21 """Initialize transport connection."""
23 @abstractmethod
24 async def disconnect(self) -> None:
25 """Close transport connection."""
27 @abstractmethod
28 async def send_message(self, message: Dict[str, Any]) -> None:
29 """Send a message over the transport.
31 Args:
32 message: Message to send
33 """
35 @abstractmethod
36 async def receive_message(self) -> AsyncGenerator[Dict[str, Any], None]:
37 """Receive messages from the transport.
39 Yields:
40 Received messages
41 """
43 @abstractmethod
44 async def is_connected(self) -> bool:
45 """Check if transport is connected.
47 Returns:
48 True if connected
49 """