openwebui-mcp-server 0.2.0__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.
- openwebui_mcp/__init__.py +1 -0
- openwebui_mcp/auth.py +30 -0
- openwebui_mcp/client.py +740 -0
- openwebui_mcp/main.py +44 -0
- openwebui_mcp/models.py +215 -0
- openwebui_mcp/server.py +704 -0
- openwebui_mcp_server-0.2.0.dist-info/METADATA +247 -0
- openwebui_mcp_server-0.2.0.dist-info/RECORD +11 -0
- openwebui_mcp_server-0.2.0.dist-info/WHEEL +4 -0
- openwebui_mcp_server-0.2.0.dist-info/entry_points.txt +2 -0
- openwebui_mcp_server-0.2.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Open WebUI MCP Server - Manage Open WebUI via MCP tools."""
|
openwebui_mcp/auth.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from contextvars import ContextVar
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
# Context variable to store the current user's token
|
|
6
|
+
_current_user_token: ContextVar[Optional[str]] = ContextVar("current_user_token", default=None)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def get_user_token() -> Optional[str]:
|
|
10
|
+
"""Get the current user's token from context or environment."""
|
|
11
|
+
token = _current_user_token.get()
|
|
12
|
+
if token:
|
|
13
|
+
return token
|
|
14
|
+
return os.getenv("WEBUI_API_KEY")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class AuthMiddleware:
|
|
18
|
+
"""ASGI middleware to extract Authorization header and set context variable."""
|
|
19
|
+
|
|
20
|
+
def __init__(self, app):
|
|
21
|
+
self.app = app
|
|
22
|
+
|
|
23
|
+
async def __call__(self, scope, receive, send):
|
|
24
|
+
if scope["type"] == "http":
|
|
25
|
+
headers = dict(scope.get("headers", []))
|
|
26
|
+
auth_header = headers.get(b"authorization", b"").decode()
|
|
27
|
+
if auth_header.startswith("Bearer "):
|
|
28
|
+
token = auth_header[7:]
|
|
29
|
+
_current_user_token.set(token)
|
|
30
|
+
await self.app(scope, receive, send)
|