Coverage for /home/admin/Documents/AI/applications/lexigram-dev/lexigram/experimental/ai/lexigram-ai-mcp/src/lexigram/ai/mcp/transport/base.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-25 07:19 +0800

1"""Base transport for MCP server.""" 

2 

3from __future__ import annotations 

4 

5from abc import ABC, abstractmethod 

6from typing import Any 

7 

8 

9class AbstractTransport(ABC): 

10 """Abstract base class for MCP transport implementations. 

11 

12 A transport handles the I/O layer - reading requests and 

13 writing responses. The MCP server is transport-agnostic. 

14 """ 

15 

16 @abstractmethod 

17 async def start(self) -> None: 

18 """Start the transport.""" 

19 

20 @abstractmethod 

21 async def stop(self) -> None: 

22 """Stop the transport.""" 

23 

24 @abstractmethod 

25 async def send(self, message: dict[str, Any]) -> None: 

26 """Send a message through the transport. 

27 

28 Args: 

29 message: JSON-RPC message to send. 

30 """ 

31 

32 @abstractmethod 

33 async def receive(self) -> dict[str, Any] | None: 

34 """Receive a message from the transport. 

35 

36 Returns: 

37 Parsed JSON-RPC message, or None if no message available. 

38 """ 

39 

40 

41__all__ = ["AbstractTransport"]