mcp-use 1.3.12__py3-none-any.whl → 1.3.13__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mcp-use might be problematic. Click here for more details.

Files changed (101) hide show
  1. mcp_use/__init__.py +1 -1
  2. mcp_use/adapters/.deprecated +0 -0
  3. mcp_use/adapters/__init__.py +18 -7
  4. mcp_use/adapters/base.py +12 -185
  5. mcp_use/adapters/langchain_adapter.py +12 -219
  6. mcp_use/agents/adapters/__init__.py +10 -0
  7. mcp_use/agents/adapters/base.py +193 -0
  8. mcp_use/agents/adapters/langchain_adapter.py +228 -0
  9. mcp_use/agents/base.py +1 -1
  10. mcp_use/agents/managers/__init__.py +19 -0
  11. mcp_use/agents/managers/base.py +36 -0
  12. mcp_use/agents/managers/server_manager.py +131 -0
  13. mcp_use/agents/managers/tools/__init__.py +15 -0
  14. mcp_use/agents/managers/tools/base_tool.py +19 -0
  15. mcp_use/agents/managers/tools/connect_server.py +69 -0
  16. mcp_use/agents/managers/tools/disconnect_server.py +43 -0
  17. mcp_use/agents/managers/tools/get_active_server.py +29 -0
  18. mcp_use/agents/managers/tools/list_servers_tool.py +53 -0
  19. mcp_use/agents/managers/tools/search_tools.py +328 -0
  20. mcp_use/agents/mcpagent.py +16 -14
  21. mcp_use/agents/remote.py +14 -1
  22. mcp_use/auth/.deprecated +0 -0
  23. mcp_use/auth/__init__.py +19 -4
  24. mcp_use/auth/bearer.py +11 -12
  25. mcp_use/auth/oauth.py +11 -620
  26. mcp_use/auth/oauth_callback.py +16 -207
  27. mcp_use/client/__init__.py +1 -0
  28. mcp_use/client/auth/__init__.py +6 -0
  29. mcp_use/client/auth/bearer.py +23 -0
  30. mcp_use/client/auth/oauth.py +629 -0
  31. mcp_use/client/auth/oauth_callback.py +214 -0
  32. mcp_use/client/client.py +356 -0
  33. mcp_use/client/config.py +106 -0
  34. mcp_use/client/connectors/__init__.py +20 -0
  35. mcp_use/client/connectors/base.py +470 -0
  36. mcp_use/client/connectors/http.py +304 -0
  37. mcp_use/client/connectors/sandbox.py +332 -0
  38. mcp_use/client/connectors/stdio.py +109 -0
  39. mcp_use/client/connectors/utils.py +13 -0
  40. mcp_use/client/connectors/websocket.py +257 -0
  41. mcp_use/client/exceptions.py +31 -0
  42. mcp_use/client/middleware/__init__.py +50 -0
  43. mcp_use/client/middleware/logging.py +31 -0
  44. mcp_use/client/middleware/metrics.py +314 -0
  45. mcp_use/client/middleware/middleware.py +266 -0
  46. mcp_use/client/session.py +162 -0
  47. mcp_use/client/task_managers/__init__.py +20 -0
  48. mcp_use/client/task_managers/base.py +145 -0
  49. mcp_use/client/task_managers/sse.py +84 -0
  50. mcp_use/client/task_managers/stdio.py +69 -0
  51. mcp_use/client/task_managers/streamable_http.py +86 -0
  52. mcp_use/client/task_managers/websocket.py +68 -0
  53. mcp_use/client.py +12 -344
  54. mcp_use/config.py +20 -97
  55. mcp_use/connectors/.deprecated +0 -0
  56. mcp_use/connectors/__init__.py +46 -20
  57. mcp_use/connectors/base.py +12 -455
  58. mcp_use/connectors/http.py +13 -300
  59. mcp_use/connectors/sandbox.py +13 -306
  60. mcp_use/connectors/stdio.py +13 -104
  61. mcp_use/connectors/utils.py +15 -8
  62. mcp_use/connectors/websocket.py +13 -252
  63. mcp_use/exceptions.py +33 -18
  64. mcp_use/managers/.deprecated +0 -0
  65. mcp_use/managers/__init__.py +56 -17
  66. mcp_use/managers/base.py +13 -31
  67. mcp_use/managers/server_manager.py +13 -119
  68. mcp_use/managers/tools/__init__.py +45 -15
  69. mcp_use/managers/tools/base_tool.py +5 -16
  70. mcp_use/managers/tools/connect_server.py +5 -67
  71. mcp_use/managers/tools/disconnect_server.py +5 -41
  72. mcp_use/managers/tools/get_active_server.py +5 -26
  73. mcp_use/managers/tools/list_servers_tool.py +5 -51
  74. mcp_use/managers/tools/search_tools.py +17 -321
  75. mcp_use/middleware/.deprecated +0 -0
  76. mcp_use/middleware/__init__.py +89 -50
  77. mcp_use/middleware/logging.py +14 -26
  78. mcp_use/middleware/metrics.py +30 -303
  79. mcp_use/middleware/middleware.py +39 -246
  80. mcp_use/session.py +13 -149
  81. mcp_use/task_managers/.deprecated +0 -0
  82. mcp_use/task_managers/__init__.py +48 -20
  83. mcp_use/task_managers/base.py +13 -140
  84. mcp_use/task_managers/sse.py +13 -79
  85. mcp_use/task_managers/stdio.py +13 -64
  86. mcp_use/task_managers/streamable_http.py +15 -81
  87. mcp_use/task_managers/websocket.py +13 -63
  88. mcp_use/telemetry/events.py +58 -0
  89. mcp_use/telemetry/telemetry.py +71 -1
  90. mcp_use/types/.deprecated +0 -0
  91. mcp_use/types/sandbox.py +13 -18
  92. {mcp_use-1.3.12.dist-info → mcp_use-1.3.13.dist-info}/METADATA +59 -34
  93. mcp_use-1.3.13.dist-info/RECORD +109 -0
  94. mcp_use-1.3.12.dist-info/RECORD +0 -64
  95. mcp_use-1.3.12.dist-info/licenses/LICENSE +0 -21
  96. /mcp_use/{observability → agents/observability}/__init__.py +0 -0
  97. /mcp_use/{observability → agents/observability}/callbacks_manager.py +0 -0
  98. /mcp_use/{observability → agents/observability}/laminar.py +0 -0
  99. /mcp_use/{observability → agents/observability}/langfuse.py +0 -0
  100. {mcp_use-1.3.12.dist-info → mcp_use-1.3.13.dist-info}/WHEEL +0 -0
  101. {mcp_use-1.3.12.dist-info → mcp_use-1.3.13.dist-info}/entry_points.txt +0 -0
@@ -1,214 +1,23 @@
1
- """OAuth callback server implementation."""
1
+ # mcp_use/auth/oauth_callback.py
2
+ import warnings
2
3
 
3
- import asyncio
4
- from dataclasses import dataclass
4
+ from typing_extensions import deprecated
5
5
 
6
- import anyio
7
- import uvicorn
8
- from starlette.applications import Starlette
9
- from starlette.requests import Request
10
- from starlette.responses import HTMLResponse
11
- from starlette.routing import Route
6
+ from mcp_use.client.auth.oauth_callback import CallbackResponse as _CallbackResponse
7
+ from mcp_use.client.auth.oauth_callback import OAuthCallbackServer as _OAuthCallbackServer
12
8
 
13
- from ..logging import logger
9
+ warnings.warn(
10
+ "mcp_use.auth.oauth_callback is deprecated. "
11
+ "Use mcp_use.client.auth.oauth_callback. "
12
+ "This import will be removed in version 1.4.0",
13
+ DeprecationWarning,
14
+ stacklevel=2,
15
+ )
14
16
 
15
17
 
16
- @dataclass
17
- class CallbackResponse:
18
- """Response data from OAuth callback."""
18
+ @deprecated("Use mcp_use.client.auth.oauth_callback.OAuthCallbackServer")
19
+ class OAuthCallbackServer(_OAuthCallbackServer): ...
19
20
 
20
- code: str | None = None # Authorization code (success)
21
- state: str | None = None # CSRF protection token
22
- error: str | None = None # Errors code (if failed)
23
- error_description: str | None = None
24
- error_uri: str | None = None
25
21
 
26
-
27
- class OAuthCallbackServer:
28
- """Local server to handle OAuth callback."""
29
-
30
- def __init__(self, port: int):
31
- """Initialize the callback server.
32
-
33
- Args:
34
- port: Port to listen on.
35
- """
36
- self.port = port
37
- self.redirect_uri: str | None = None
38
- # Thread safe way to pass callback data to the main OAuth flow
39
- self.response_queue: asyncio.Queue[CallbackResponse] = asyncio.Queue(maxsize=1)
40
- self.server: uvicorn.Server | None = None
41
- self._shutdown_event = anyio.Event()
42
-
43
- async def start(self) -> str:
44
- """Start the callback server and return the redirect URI."""
45
- app = self._create_app()
46
-
47
- # Create the server
48
- config = uvicorn.Config(
49
- app,
50
- host="127.0.0.1",
51
- port=self.port,
52
- log_level="error", # Suppress uvicorn logs
53
- )
54
- self.server = uvicorn.Server(config)
55
-
56
- # Start server in background
57
- self._server_task = asyncio.create_task(self.server.serve())
58
-
59
- # Wait a moment for server to start
60
- await asyncio.sleep(0.1)
61
-
62
- self.redirect_uri = f"http://localhost:{self.port}/callback"
63
- return self.redirect_uri
64
-
65
- async def wait_for_code(self, timeout: float = 300) -> CallbackResponse:
66
- """Wait for the OAuth callback with a timeout (default 5 minutes)."""
67
- try:
68
- response = await asyncio.wait_for(self.response_queue.get(), timeout=timeout)
69
- return response
70
- except TimeoutError:
71
- raise TimeoutError(f"OAuth callback not received within {timeout} seconds") from None
72
- finally:
73
- await self.shutdown()
74
-
75
- async def shutdown(self):
76
- """Shutdown the callback server."""
77
- self._shutdown_event.set()
78
- if self.server:
79
- self.server.should_exit = True
80
- if hasattr(self, "_server_task"):
81
- try:
82
- await asyncio.wait_for(self._server_task, timeout=5.0)
83
- except TimeoutError:
84
- self._server_task.cancel()
85
-
86
- def _create_app(self) -> Starlette:
87
- """Create the Starlette application."""
88
-
89
- async def callback(request: Request) -> HTMLResponse:
90
- """Handle the OAuth callback."""
91
- params = request.query_params
92
-
93
- # Extract OAuth parameters
94
- response = CallbackResponse(
95
- code=params.get("code"),
96
- state=params.get("state"),
97
- error=params.get("error"),
98
- error_description=params.get("error_description"),
99
- error_uri=params.get("error_uri"),
100
- )
101
-
102
- # Log the callback response
103
- logger.debug(
104
- f"OAuth callback received: error={response.error}, error_description={response.error_description}"
105
- )
106
- if response.code:
107
- logger.debug("OAuth callback received authorization code")
108
- else:
109
- logger.error(f"OAuth callback error: {response.error} - {response.error_description}")
110
-
111
- # Put response in queue
112
- try:
113
- self.response_queue.put_nowait(response)
114
- except asyncio.QueueFull:
115
- pass # Ignore if queue is already full
116
-
117
- # Return success page
118
- if response.code:
119
- html = self._success_html()
120
- else:
121
- html = self._error_html(response.error, response.error_description)
122
-
123
- return HTMLResponse(content=html)
124
-
125
- routes = [Route("/callback", callback)]
126
- return Starlette(routes=routes)
127
-
128
- def _success_html(self) -> str:
129
- """HTML response for successful authorization."""
130
- return """
131
- <!DOCTYPE html>
132
- <html>
133
- <head>
134
- <title>Authorization Successful</title>
135
- <style>
136
- body {
137
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
138
- display: flex;
139
- justify-content: center;
140
- align-items: center;
141
- height: 100vh;
142
- margin: 0;
143
- background-color: #f5f5f5;
144
- }
145
- .container {
146
- text-align: center;
147
- padding: 2rem;
148
- background: white;
149
- border-radius: 8px;
150
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
151
- }
152
- h1 { color: #22c55e; margin-bottom: 0.5rem; }
153
- p { color: #666; margin-top: 0.5rem; }
154
- .icon { font-size: 48px; margin-bottom: 1rem; }
155
- </style>
156
- </head>
157
- <body>
158
- <div class="container">
159
- <div class="icon">✅</div>
160
- <h1>Authorization Successful!</h1>
161
- <p>You can now close this window and return to your application.</p>
162
- </div>
163
- <script>
164
- // Auto-close after 3 seconds
165
- setTimeout(() => window.close(), 3000);
166
- </script>
167
- </body>
168
- </html>
169
- """
170
-
171
- def _error_html(self, error: str | None, description: str | None) -> str:
172
- """HTML response for authorization error."""
173
- error_msg = error or "Unknown error"
174
- desc_msg = description or "Authorization was not completed successfully."
175
-
176
- return f"""
177
- <!DOCTYPE html>
178
- <html>
179
- <head>
180
- <title>Authorization Error</title>
181
- <style>
182
- body {{
183
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
184
- display: flex;
185
- justify-content: center;
186
- align-items: center;
187
- height: 100vh;
188
- margin: 0;
189
- background-color: #f5f5f5;
190
- }}
191
- .container {{
192
- text-align: center;
193
- padding: 2rem;
194
- background: white;
195
- border-radius: 8px;
196
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
197
- max-width: 500px;
198
- }}
199
- h1 {{ color: #ef4444; margin-bottom: 0.5rem; }}
200
- .error {{ color: #dc2626; font-weight: 600; margin: 1rem 0; }}
201
- .description {{ color: #666; margin-top: 0.5rem; }}
202
- .icon {{ font-size: 48px; margin-bottom: 1rem; }}
203
- </style>
204
- </head>
205
- <body>
206
- <div class="container">
207
- <div class="icon">❌</div>
208
- <h1>Authorization Error</h1>
209
- <p class="error">{error_msg}</p>
210
- <p class="description">{desc_msg}</p>
211
- </div>
212
- </body>
213
- </html>
214
- """
22
+ @deprecated("Use mcp_use.client.auth.oauth_callback.CallbackResponse")
23
+ class CallbackResponse(_CallbackResponse): ...
@@ -0,0 +1 @@
1
+ from .client import MCPClient
@@ -0,0 +1,6 @@
1
+ """Authentication support for MCP clients."""
2
+
3
+ from .bearer import BearerAuth
4
+ from .oauth import OAuth
5
+
6
+ __all__ = ["BearerAuth", "OAuth"]
@@ -0,0 +1,23 @@
1
+ """Bearer token authentication support."""
2
+
3
+ from collections.abc import Generator
4
+
5
+ import httpx
6
+ from pydantic import BaseModel, SecretStr
7
+
8
+ from mcp_use.telemetry.telemetry import telemetry
9
+
10
+
11
+ class BearerAuth(httpx.Auth, BaseModel):
12
+ """Bearer token authentication for HTTP requests."""
13
+
14
+ token: SecretStr
15
+
16
+ def __init__(self, **data):
17
+ super().__init__(**data)
18
+
19
+ @telemetry("auth_bearer")
20
+ def auth_flow(self, request: httpx.Request) -> Generator[httpx.Request, httpx.Response, None]:
21
+ """Apply bearer token authentication to the request."""
22
+ request.headers["Authorization"] = f"Bearer {self.token.get_secret_value()}"
23
+ yield request