|
1 | 1 | import inspect |
2 | 2 | from pathlib import Path |
3 | 3 |
|
| 4 | +from fastmcp.client.auth.bearer import BearerAuth |
| 5 | +from fastmcp.client.auth.oauth import OAuthClientProvider |
4 | 6 | from fastmcp.client.client import Client |
5 | 7 | from fastmcp.client.transports import ( |
6 | 8 | SSETransport, |
@@ -136,3 +138,60 @@ def add(a: int, b: int) -> int: |
136 | 138 | result_2 = await client.call_tool("test_2_add", {"a": 1, "b": 2}) |
137 | 139 | assert result_1[0].text == "3" # type: ignore[attr-dict] |
138 | 140 | assert result_2[0].text == "3" # type: ignore[attr-dict] |
| 141 | + |
| 142 | + |
| 143 | +async def test_remote_config_default_no_auth(): |
| 144 | + config = { |
| 145 | + "mcpServers": { |
| 146 | + "test_server": { |
| 147 | + "url": "http://localhost:8000", |
| 148 | + } |
| 149 | + } |
| 150 | + } |
| 151 | + client = Client(config) |
| 152 | + assert isinstance(client.transport.transport, StreamableHttpTransport) |
| 153 | + assert client.transport.transport.auth is None |
| 154 | + |
| 155 | + |
| 156 | +async def test_remote_config_with_auth_token(): |
| 157 | + config = { |
| 158 | + "mcpServers": { |
| 159 | + "test_server": { |
| 160 | + "url": "http://localhost:8000", |
| 161 | + "auth": "test_token", |
| 162 | + } |
| 163 | + } |
| 164 | + } |
| 165 | + client = Client(config) |
| 166 | + assert isinstance(client.transport.transport, StreamableHttpTransport) |
| 167 | + assert isinstance(client.transport.transport.auth, BearerAuth) |
| 168 | + assert client.transport.transport.auth.token.get_secret_value() == "test_token" |
| 169 | + |
| 170 | + |
| 171 | +async def test_remote_config_sse_with_auth_token(): |
| 172 | + config = { |
| 173 | + "mcpServers": { |
| 174 | + "test_server": { |
| 175 | + "url": "http://localhost:8000/sse", |
| 176 | + "auth": "test_token", |
| 177 | + } |
| 178 | + } |
| 179 | + } |
| 180 | + client = Client(config) |
| 181 | + assert isinstance(client.transport.transport, SSETransport) |
| 182 | + assert isinstance(client.transport.transport.auth, BearerAuth) |
| 183 | + assert client.transport.transport.auth.token.get_secret_value() == "test_token" |
| 184 | + |
| 185 | + |
| 186 | +async def test_remote_config_with_oauth_literal(): |
| 187 | + config = { |
| 188 | + "mcpServers": { |
| 189 | + "test_server": { |
| 190 | + "url": "http://localhost:8000", |
| 191 | + "auth": "oauth", |
| 192 | + } |
| 193 | + } |
| 194 | + } |
| 195 | + client = Client(config) |
| 196 | + assert isinstance(client.transport.transport, StreamableHttpTransport) |
| 197 | + assert isinstance(client.transport.transport.auth, OAuthClientProvider) |
0 commit comments