Coverage for src/mcpadapt/auth/oauth.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-06 19:35 +0530

1"""OAuth token storage and utility implementations.""" 

2 

3from mcp.client.auth import TokenStorage 

4from mcp.shared.auth import OAuthClientInformationFull, OAuthToken 

5 

6 

7class InMemoryTokenStorage(TokenStorage): 

8 """Simple in-memory token storage implementation.""" 

9 

10 def __init__(self): 

11 """Initialize empty token storage.""" 

12 self._tokens: OAuthToken | None = None 

13 self._client_info: OAuthClientInformationFull | None = None 

14 

15 async def get_tokens(self) -> OAuthToken | None: 

16 """Get stored OAuth tokens. 

17  

18 Returns: 

19 Stored OAuth tokens or None if not available 

20 """ 

21 return self._tokens 

22 

23 async def set_tokens(self, tokens: OAuthToken) -> None: 

24 """Store OAuth tokens. 

25  

26 Args: 

27 tokens: OAuth tokens to store 

28 """ 

29 self._tokens = tokens 

30 

31 async def get_client_info(self) -> OAuthClientInformationFull | None: 

32 """Get stored OAuth client information. 

33  

34 Returns: 

35 Stored OAuth client information or None if not available 

36 """ 

37 return self._client_info 

38 

39 async def set_client_info(self, client_info: OAuthClientInformationFull) -> None: 

40 """Store OAuth client information. 

41  

42 Args: 

43 client_info: OAuth client information to store 

44 """ 

45 self._client_info = client_info