MCPcopy Index your code
hub / github.com/modelcontextprotocol/python-sdk / InMemoryTokenStorage

Class InMemoryTokenStorage

tests/interaction/auth/_harness.py:104–126  ·  view source on GitHub ↗

A `TokenStorage` that holds tokens and client info as instance attributes. Tests pre-seed `client_info` (via the constructor or by assignment) to drive the pre-registered path, and read both attributes after the flow to assert what the SDK persisted.

Source from the content-addressed store, hash-verified

102
103
104class InMemoryTokenStorage:
105 """A `TokenStorage` that holds tokens and client info as instance attributes.
106
107 Tests pre-seed `client_info` (via the constructor or by assignment) to drive the
108 pre-registered path, and read both attributes after the flow to assert what the SDK
109 persisted.
110 """
111
112 def __init__(self, *, client_info: OAuthClientInformationFull | None = None) -> None:
113 self.tokens: OAuthToken | None = None
114 self.client_info: OAuthClientInformationFull | None = client_info
115
116 async def get_tokens(self) -> OAuthToken | None:
117 return self.tokens
118
119 async def set_tokens(self, tokens: OAuthToken) -> None:
120 self.tokens = tokens
121
122 async def get_client_info(self) -> OAuthClientInformationFull | None:
123 return self.client_info
124
125 async def set_client_info(self, client_info: OAuthClientInformationFull) -> None:
126 self.client_info = client_info
127
128
129class HeadlessOAuth:

Calls

no outgoing calls