mirror of
https://github.com/vastsa/FileCodeBox.git
synced 2026-11-22 06:57:56 +08:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c5d7c2b7e |
No files matched your search
@@ -1,3 +1,3 @@
|
||||
{
|
||||
".": "2.8.3"
|
||||
".": "2.7.1"
|
||||
}
|
||||
+1
-1
@@ -54,7 +54,7 @@ RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
|
||||
echo 'Asia/Shanghai' > /etc/timezone
|
||||
|
||||
# 从构建阶段复制编译好的前端主题
|
||||
COPY --from=frontend-builder /build/FileCodeBox/themes/2024 ./themes/2024
|
||||
COPY --from=frontend-builder /build/fronted-2024/dist ./themes/2024
|
||||
COPY --from=frontend-builder /build/fronted-2023/dist ./themes/2023
|
||||
|
||||
# 安装系统安全更新 + Python 依赖
|
||||
|
||||
@@ -40,7 +40,6 @@ class ConfigService:
|
||||
"max_save_seconds",
|
||||
"onedrive_proxy",
|
||||
"open_upload",
|
||||
"mcp_require_token",
|
||||
"port",
|
||||
"s3_proxy",
|
||||
"server_port",
|
||||
|
||||
@@ -1,231 +0,0 @@
|
||||
"""Stateless MCP Streamable HTTP endpoint for quick share uploads."""
|
||||
import base64
|
||||
import binascii
|
||||
import html
|
||||
import io
|
||||
import json
|
||||
from typing import Any
|
||||
from urllib.parse import quote, urlsplit
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Request, UploadFile
|
||||
from starlette.datastructures import Headers
|
||||
from starlette.responses import JSONResponse, Response
|
||||
|
||||
from apps.base.auth import _require_admin_payload
|
||||
from apps.base.file_validation import validate_file_type, validate_upload_file
|
||||
from apps.base.services import FileUploadService, validate_file_size
|
||||
from apps.base.utils import ip_limit, validate_expire_style
|
||||
from core.settings import settings
|
||||
from core.utils import sanitize_filename
|
||||
|
||||
router = APIRouter(tags=["MCP"])
|
||||
|
||||
MCP_PROTOCOL_VERSION = "2025-03-26"
|
||||
TEXT_SHARE_MAX_BYTES = 222 * 1024
|
||||
MAX_MCP_BODY_BYTES = 64 * 1024 * 1024
|
||||
|
||||
|
||||
def _jsonrpc_error(request_id, code: int, message: str) -> dict:
|
||||
return {"jsonrpc": "2.0", "id": request_id, "error": {"code": code, "message": message}}
|
||||
|
||||
|
||||
def _jsonrpc_result(request_id, result: dict) -> dict:
|
||||
return {"jsonrpc": "2.0", "id": request_id, "result": result}
|
||||
|
||||
|
||||
def _validate_origin(request: Request) -> None:
|
||||
"""Reject browser cross-site POSTs before parsing any upload tool."""
|
||||
origin = request.headers.get("origin")
|
||||
fetch_site = request.headers.get("sec-fetch-site", "").lower()
|
||||
if fetch_site == "cross-site":
|
||||
raise HTTPException(status_code=403, detail="跨站请求已拒绝")
|
||||
if not origin:
|
||||
return # Native MCP clients do not send Origin and use no ambient cookies.
|
||||
try:
|
||||
parsed = urlsplit(origin)
|
||||
host = request.headers.get("host", "").lower()
|
||||
if (
|
||||
parsed.scheme not in {"http", "https"}
|
||||
or not parsed.netloc
|
||||
or parsed.netloc.lower() != host
|
||||
or parsed.username is not None
|
||||
or parsed.password is not None
|
||||
or parsed.path not in {"", "/"}
|
||||
or parsed.query
|
||||
or parsed.fragment
|
||||
):
|
||||
raise ValueError("origin mismatch")
|
||||
except (ValueError, TypeError):
|
||||
raise HTTPException(status_code=403, detail="跨站请求已拒绝")
|
||||
|
||||
|
||||
async def _read_limited_body(request: Request) -> bytes:
|
||||
max_size = min(
|
||||
MAX_MCP_BODY_BYTES,
|
||||
max(1024 * 1024, int(settings.upload_size * 4 / 3) + 256 * 1024),
|
||||
)
|
||||
declared_size = request.headers.get("content-length")
|
||||
if declared_size:
|
||||
try:
|
||||
if int(declared_size) > max_size:
|
||||
raise HTTPException(status_code=413, detail="MCP 请求体过大")
|
||||
except ValueError:
|
||||
raise HTTPException(status_code=400, detail="Content-Length 无效")
|
||||
body = bytearray()
|
||||
async for chunk in request.stream():
|
||||
body.extend(chunk)
|
||||
if len(body) > max_size:
|
||||
raise HTTPException(status_code=413, detail="MCP 请求体过大")
|
||||
return bytes(body)
|
||||
|
||||
|
||||
def _tool_definitions() -> list[dict]:
|
||||
return [
|
||||
{
|
||||
"name": "share_text",
|
||||
"description": "将文本快速上传到 FileCodeBox 并创建分享链接。",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"text": {"type": "string", "description": "要分享的文本"},
|
||||
"expire_value": {"type": "integer", "minimum": 1, "default": 1},
|
||||
"expire_style": {"type": "string", "enum": ["day", "hour", "minute", "forever", "count"], "default": "day"},
|
||||
},
|
||||
"required": ["text"],
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "share_file",
|
||||
"description": "将 Base64 编码的文件上传到 FileCodeBox 并创建分享链接。",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"filename": {"type": "string", "description": "文件名"},
|
||||
"content_base64": {"type": "string", "description": "文件内容的标准 Base64 编码"},
|
||||
"content_type": {"type": "string", "default": "application/octet-stream"},
|
||||
"expire_value": {"type": "integer", "minimum": 1, "default": 1},
|
||||
"expire_style": {"type": "string", "enum": ["day", "hour", "minute", "forever", "count"], "default": "day"},
|
||||
},
|
||||
"required": ["filename", "content_base64"],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def _share_result(request: Request, code: str, name: str) -> dict:
|
||||
base_url = str(request.base_url).rstrip("/")
|
||||
share_url = f"{base_url}/#/?code={quote(code, safe='')}"
|
||||
markdown_name = html.escape(name).replace("[", "\\[").replace("]", "\\]")
|
||||
return {
|
||||
"code": code,
|
||||
"name": name,
|
||||
"url": share_url,
|
||||
"markdown": f"[{markdown_name}]({share_url})",
|
||||
}
|
||||
|
||||
|
||||
async def _call_tool(request: Request, tool_name: str, arguments: dict) -> dict:
|
||||
authorization = request.headers.get("authorization", "")
|
||||
if settings.mcp_require_token or not settings.open_upload:
|
||||
_require_admin_payload(authorization)
|
||||
ip = ip_limit["upload"](request)
|
||||
|
||||
if tool_name == "share_text":
|
||||
text = arguments.get("text")
|
||||
if not isinstance(text, str):
|
||||
raise ValueError("text 必须是字符串")
|
||||
if len(text.encode("utf-8")) > TEXT_SHARE_MAX_BYTES:
|
||||
raise ValueError("内容过多,请改用文件分享")
|
||||
expire_value = int(arguments.get("expire_value", 1))
|
||||
expire_style = str(arguments.get("expire_style", "day"))
|
||||
if expire_value < 1:
|
||||
raise ValueError("expire_value 必须大于 0")
|
||||
validate_expire_style(expire_style)
|
||||
code = await FileUploadService.create_text_share(text, expire_value, expire_style)
|
||||
ip_limit["upload"].add_ip(ip)
|
||||
return _share_result(request, code, "Text")
|
||||
|
||||
if tool_name == "share_file":
|
||||
filename = arguments.get("filename")
|
||||
encoded_content = arguments.get("content_base64")
|
||||
content_type = str(arguments.get("content_type", "application/octet-stream"))
|
||||
if not isinstance(filename, str) or not filename.strip():
|
||||
raise ValueError("filename 不能为空")
|
||||
if not isinstance(encoded_content, str):
|
||||
raise ValueError("content_base64 必须是字符串")
|
||||
try:
|
||||
content = base64.b64decode(encoded_content, validate=True)
|
||||
except (ValueError, binascii.Error):
|
||||
raise ValueError("content_base64 不是有效的标准 Base64")
|
||||
safe_name = await sanitize_filename(filename.rsplit("/", 1)[-1].rsplit("\\", 1)[-1])
|
||||
validate_file_type(safe_name, content_type)
|
||||
upload = UploadFile(filename=safe_name, file=io.BytesIO(content), size=len(content), headers=Headers({"content-type": content_type}))
|
||||
size = await validate_file_size(upload, settings.upload_size)
|
||||
await validate_upload_file(upload)
|
||||
expire_value = int(arguments.get("expire_value", 1))
|
||||
expire_style = str(arguments.get("expire_style", "day"))
|
||||
if expire_value < 1:
|
||||
raise ValueError("expire_value 必须大于 0")
|
||||
validate_expire_style(expire_style)
|
||||
share = await FileUploadService.create_file_share(upload, size=size, expire_value=expire_value, expire_style=expire_style)
|
||||
ip_limit["upload"].add_ip(ip)
|
||||
return _share_result(request, share["code"], share["name"])
|
||||
|
||||
raise LookupError(f"未知工具:{tool_name}")
|
||||
|
||||
|
||||
@router.post("/mcp", include_in_schema=False)
|
||||
async def mcp_endpoint(request: Request):
|
||||
_validate_origin(request)
|
||||
media_type = request.headers.get("content-type", "").split(";", 1)[0].strip().lower()
|
||||
if media_type != "application/json":
|
||||
raise HTTPException(status_code=415, detail="MCP 请求必须使用 application/json")
|
||||
try:
|
||||
message = json.loads(await _read_limited_body(request))
|
||||
except (json.JSONDecodeError, UnicodeDecodeError):
|
||||
return JSONResponse(_jsonrpc_error(None, -32700, "Parse error"), status_code=400)
|
||||
if not isinstance(message, dict) or message.get("jsonrpc") != "2.0" or not isinstance(message.get("method"), str):
|
||||
return JSONResponse(_jsonrpc_error(message.get("id") if isinstance(message, dict) else None, -32600, "Invalid Request"), status_code=400)
|
||||
|
||||
request_id = message.get("id")
|
||||
method = message["method"]
|
||||
if request_id is None and method.startswith("notifications/"):
|
||||
return Response(status_code=202)
|
||||
result: dict[str, Any] = {}
|
||||
try:
|
||||
if method == "initialize":
|
||||
result = {
|
||||
"protocolVersion": MCP_PROTOCOL_VERSION,
|
||||
"capabilities": {"tools": {"listChanged": False}},
|
||||
"serverInfo": {"name": "filecodebox", "version": "1.0.0"},
|
||||
}
|
||||
elif method == "ping":
|
||||
result = {}
|
||||
elif method == "tools/list":
|
||||
result = {"tools": _tool_definitions()}
|
||||
elif method == "tools/call":
|
||||
params = message.get("params")
|
||||
if not isinstance(params, dict) or not isinstance(params.get("name"), str):
|
||||
return JSONResponse(_jsonrpc_error(request_id, -32602, "Invalid params"))
|
||||
arguments = params.get("arguments", {})
|
||||
if not isinstance(arguments, dict):
|
||||
return JSONResponse(_jsonrpc_error(request_id, -32602, "Invalid params"))
|
||||
try:
|
||||
tool_value = await _call_tool(request, params["name"], arguments)
|
||||
result = {"content": [{"type": "text", "text": json.dumps(tool_value, ensure_ascii=False)}], "structuredContent": tool_value}
|
||||
except LookupError as exc:
|
||||
return JSONResponse(_jsonrpc_error(request_id, -32602, str(exc)))
|
||||
except HTTPException as exc:
|
||||
if exc.status_code in {401, 403}:
|
||||
raise
|
||||
result = {"content": [{"type": "text", "text": str(exc.detail)}], "isError": True}
|
||||
except (TypeError, ValueError) as exc:
|
||||
result = {"content": [{"type": "text", "text": str(exc)}], "isError": True}
|
||||
else:
|
||||
return JSONResponse(_jsonrpc_error(request_id, -32601, "Method not found"))
|
||||
return JSONResponse(_jsonrpc_result(request_id, result), headers={"MCP-Protocol-Version": MCP_PROTOCOL_VERSION})
|
||||
except HTTPException as exc:
|
||||
return JSONResponse(
|
||||
_jsonrpc_error(request_id, -32001 if exc.status_code == 401 else -32003, str(exc.detail)),
|
||||
status_code=exc.status_code,
|
||||
)
|
||||
@@ -194,8 +194,6 @@ async def post_file_metadata(
|
||||
return APIResponse(detail=build_file_metadata(file_code))
|
||||
|
||||
|
||||
|
||||
|
||||
@share_api.get("/select/")
|
||||
async def get_code_file(code: str, ip: str = Depends(ip_limit["error"])):
|
||||
file_storage: FileStorageInterface = storages[settings.file_storage]()
|
||||
|
||||
@@ -48,7 +48,6 @@ DEFAULT_CONFIG: dict[str, Any] = {
|
||||
"jwt_secret": "",
|
||||
"admin_session_expire": ADMIN_SESSION_EXPIRE_DEFAULT,
|
||||
"open_upload": 1,
|
||||
"mcp_require_token": 0,
|
||||
"upload_size": 1024 * 1024 * 10,
|
||||
"allowed_file_types": ["*"],
|
||||
"expire_style": ["day", "hour", "minute", "forever", "count"],
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
version: "3"
|
||||
services:
|
||||
file-code-box:
|
||||
image: lanol/filecodebox:2.8.3 # x-release-please-version
|
||||
image: lanol/filecodebox:2.7.1 # x-release-please-version
|
||||
volumes:
|
||||
- fcb-data:/app/data:rw
|
||||
# NAS 已有文件:把共享目录挂到 /app/data/local,即可在后台「本地分享」里生成提取码,无需再上传
|
||||
|
||||
@@ -1,33 +1,5 @@
|
||||
# Changelog
|
||||
|
||||
## [2.8.3](https://github.com/vastsa/FileCodeBox/compare/v2.8.2...v2.8.3) (2026-10-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* remove HTML preview endpoint ([65f4929](https://github.com/vastsa/FileCodeBox/commit/65f4929d405408e1c9e58127e0097f8b78b1819f))
|
||||
|
||||
## [2.8.2](https://github.com/vastsa/FileCodeBox/compare/v2.8.1...v2.8.2) (2026-10-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* type MCP protocol results ([da374b4](https://github.com/vastsa/FileCodeBox/commit/da374b459537ee079e1d03da121a935c8fb18f0e))
|
||||
|
||||
## [2.8.1](https://github.com/vastsa/FileCodeBox/compare/v2.8.0...v2.8.1) (2026-10-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* restore lint and Docker theme build ([2f5eab1](https://github.com/vastsa/FileCodeBox/commit/2f5eab18b1ab28fcb4f416248076ce574998d718))
|
||||
|
||||
## [2.8.0](https://github.com/vastsa/FileCodeBox/compare/v2.7.1...v2.8.0) (2026-10-10)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add MCP quick share and safe HTML preview ([63e72c1](https://github.com/vastsa/FileCodeBox/commit/63e72c145576d169265e4fa8cf373e33531a06a0))
|
||||
|
||||
## [2.7.1](https://github.com/vastsa/FileCodeBox/compare/v2.7.0...v2.7.1) (2026-09-19)
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
## [Unreleased]
|
||||
|
||||
<!-- Current release: 2.8.3 x-release-please-version -->
|
||||
<!-- Current release: 2.7.1 x-release-please-version -->
|
||||
|
||||
### Added
|
||||
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ docker run -d --restart unless-stopped \
|
||||
--log-opt max-size=10m \
|
||||
--log-opt max-file=3 \
|
||||
--name filecodebox \
|
||||
lanol/filecodebox:2.8.3 # x-release-please-version
|
||||
lanol/filecodebox:2.7.1 # x-release-please-version
|
||||
```
|
||||
|
||||
Open `http://localhost:12345` and complete the first-run setup.
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ docker run -d --restart unless-stopped \
|
||||
--log-opt max-size=10m \
|
||||
--log-opt max-file=3 \
|
||||
--name filecodebox \
|
||||
lanol/filecodebox:2.8.3 # x-release-please-version
|
||||
lanol/filecodebox:2.7.1 # x-release-please-version
|
||||
```
|
||||
|
||||
打开 `http://localhost:12345`,按引导完成首次初始化。
|
||||
|
||||
@@ -28,7 +28,6 @@ from apps.base.tasks import (
|
||||
delete_expire_files,
|
||||
)
|
||||
from apps.base.views import share_api, chunk_api, presign_api
|
||||
from apps.base.mcp import router as mcp_router
|
||||
from core.database import db_startup_lock, get_db_config, init_db
|
||||
from core.errors import StorageError
|
||||
from core.logger import get_log_level_name, is_access_log_enabled, logger
|
||||
@@ -140,7 +139,6 @@ app.include_router(presign_api)
|
||||
app.include_router(presign_api, prefix="/api")
|
||||
app.include_router(admin_api)
|
||||
app.include_router(pages_router)
|
||||
app.include_router(mcp_router)
|
||||
|
||||
# 404 时返回主题首页(index 兼任 exception handler 与 GET / 路由)
|
||||
app.add_exception_handler(404, not_found_handler)
|
||||
|
||||
@@ -32,7 +32,7 @@ docker run -d --restart unless-stopped \
|
||||
--log-opt max-size=10m \
|
||||
--log-opt max-file=3 \
|
||||
--name filecodebox \
|
||||
lanol/filecodebox:2.8.3 # x-release-please-version
|
||||
lanol/filecodebox:2.7.1 # x-release-please-version
|
||||
```
|
||||
|
||||
访问 `http://localhost:12345`,完成首次初始化。生产环境建议固定版本号;`latest` 指向最新正式版。
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ docker run -d --restart unless-stopped \
|
||||
--log-opt max-size=10m \
|
||||
--log-opt max-file=3 \
|
||||
--name filecodebox \
|
||||
lanol/filecodebox:2.8.3 # x-release-please-version
|
||||
lanol/filecodebox:2.7.1 # x-release-please-version
|
||||
```
|
||||
|
||||
Open `http://localhost:12345` and complete first-run setup. Pin a version in production; `latest` tracks the newest stable release.
|
||||
|
||||
+102
-82
@@ -836,88 +836,108 @@ uvicorn==0.53.0 \
|
||||
--hash=sha256:a9356f0cb89b3b8621529c5d5eebd69bfe154f4c3f68b4cf2de47e45fa855c2e \
|
||||
--hash=sha256:e8dca71ec86dce5f04e333f0d56cdedf942446e6643b9cea1af0d6d3a02cb03e
|
||||
# via -r requirements.txt
|
||||
wrapt==1.17.3 \
|
||||
--hash=sha256:02b551d101f31694fc785e58e0720ef7d9a10c4e62c1c9358ce6f63f23e30a56 \
|
||||
--hash=sha256:042ec3bb8f319c147b1301f2393bc19dba6e176b7da446853406d041c36c7828 \
|
||||
--hash=sha256:0610b46293c59a3adbae3dee552b648b984176f8562ee0dba099a56cfbe4df1f \
|
||||
--hash=sha256:0b02e424deef65c9f7326d8c19220a2c9040c51dc165cddb732f16198c168396 \
|
||||
--hash=sha256:0b1831115c97f0663cb77aa27d381237e73ad4f721391a9bfb2fe8bc25fa6e77 \
|
||||
--hash=sha256:0ed61b7c2d49cee3c027372df5809a59d60cf1b6c2f81ee980a091f3afed6a2d \
|
||||
--hash=sha256:0f5f51a6466667a5a356e6381d362d259125b57f059103dd9fdc8c0cf1d14139 \
|
||||
--hash=sha256:16ecf15d6af39246fe33e507105d67e4b81d8f8d2c6598ff7e3ca1b8a37213f7 \
|
||||
--hash=sha256:1f0b2f40cf341ee8cc1a97d51ff50dddb9fcc73241b9143ec74b30fc4f44f6cb \
|
||||
--hash=sha256:1f23fa283f51c890eda8e34e4937079114c74b4c81d2b2f1f1d94948f5cc3d7f \
|
||||
--hash=sha256:223db574bb38637e8230eb14b185565023ab624474df94d2af18f1cdb625216f \
|
||||
--hash=sha256:249f88ed15503f6492a71f01442abddd73856a0032ae860de6d75ca62eed8067 \
|
||||
--hash=sha256:24c2ed34dc222ed754247a2702b1e1e89fdbaa4016f324b4b8f1a802d4ffe87f \
|
||||
--hash=sha256:273a736c4645e63ac582c60a56b0acb529ef07f78e08dc6bfadf6a46b19c0da7 \
|
||||
--hash=sha256:281262213373b6d5e4bb4353bc36d1ba4084e6d6b5d242863721ef2bf2c2930b \
|
||||
--hash=sha256:30ce38e66630599e1193798285706903110d4f057aab3168a34b7fdc85569afc \
|
||||
--hash=sha256:33486899acd2d7d3066156b03465b949da3fd41a5da6e394ec49d271baefcf05 \
|
||||
--hash=sha256:343e44b2a8e60e06a7e0d29c1671a0d9951f59174f3709962b5143f60a2a98bd \
|
||||
--hash=sha256:373342dd05b1d07d752cecbec0c41817231f29f3a89aa8b8843f7b95992ed0c7 \
|
||||
--hash=sha256:3af60380ba0b7b5aeb329bc4e402acd25bd877e98b3727b0135cb5c2efdaefe9 \
|
||||
--hash=sha256:3e62d15d3cfa26e3d0788094de7b64efa75f3a53875cdbccdf78547aed547a81 \
|
||||
--hash=sha256:41b1d2bc74c2cac6f9074df52b2efbef2b30bdfe5f40cb78f8ca22963bc62977 \
|
||||
--hash=sha256:423ed5420ad5f5529db9ce89eac09c8a2f97da18eb1c870237e84c5a5c2d60aa \
|
||||
--hash=sha256:46acc57b331e0b3bcb3e1ca3b421d65637915cfcd65eb783cb2f78a511193f9b \
|
||||
--hash=sha256:4da9f45279fff3543c371d5ababc57a0384f70be244de7759c85a7f989cb4ebe \
|
||||
--hash=sha256:507553480670cab08a800b9463bdb881b2edeed77dc677b0a5915e6106e91a58 \
|
||||
--hash=sha256:53e5e39ff71b3fc484df8a522c933ea2b7cdd0d5d15ae82e5b23fde87d44cbd8 \
|
||||
--hash=sha256:54a30837587c6ee3cd1a4d1c2ec5d24e77984d44e2f34547e2323ddb4e22eb77 \
|
||||
--hash=sha256:5531d911795e3f935a9c23eb1c8c03c211661a5060aab167065896bbf62a5f85 \
|
||||
--hash=sha256:55cbbc356c2842f39bcc553cf695932e8b30e30e797f961860afb308e6b1bb7c \
|
||||
--hash=sha256:59923aa12d0157f6b82d686c3fd8e1166fa8cdfb3e17b42ce3b6147ff81528df \
|
||||
--hash=sha256:5a03a38adec8066d5a37bea22f2ba6bbf39fcdefbe2d91419ab864c3fb515454 \
|
||||
--hash=sha256:5a7b3c1ee8265eb4c8f1b7d29943f195c00673f5ab60c192eba2d4a7eae5f46a \
|
||||
--hash=sha256:5d4478d72eb61c36e5b446e375bbc49ed002430d17cdec3cecb36993398e1a9e \
|
||||
--hash=sha256:5ea5eb3c0c071862997d6f3e02af1d055f381b1d25b286b9d6644b79db77657c \
|
||||
--hash=sha256:604d076c55e2fdd4c1c03d06dc1a31b95130010517b5019db15365ec4a405fc6 \
|
||||
--hash=sha256:656873859b3b50eeebe6db8b1455e99d90c26ab058db8e427046dbc35c3140a5 \
|
||||
--hash=sha256:65d1d00fbfb3ea5f20add88bbc0f815150dbbde3b026e6c24759466c8b5a9ef9 \
|
||||
--hash=sha256:6b538e31eca1a7ea4605e44f81a48aa24c4632a277431a6ed3f328835901f4fd \
|
||||
--hash=sha256:6fd1ad24dc235e4ab88cda009e19bf347aabb975e44fd5c2fb22a3f6e4141277 \
|
||||
--hash=sha256:70d86fa5197b8947a2fa70260b48e400bf2ccacdcab97bb7de47e3d1e6312225 \
|
||||
--hash=sha256:7171ae35d2c33d326ac19dd8facb1e82e5fd04ef8c6c0e394d7af55a55051c22 \
|
||||
--hash=sha256:73d496de46cd2cdbdbcce4ae4bcdb4afb6a11234a1df9c085249d55166b95116 \
|
||||
--hash=sha256:7425ac3c54430f5fc5e7b6f41d41e704db073309acfc09305816bc6a0b26bb16 \
|
||||
--hash=sha256:74afa28374a3c3a11b3b5e5fca0ae03bef8450d6aa3ab3a1e2c30e3a75d023dc \
|
||||
--hash=sha256:758895b01d546812d1f42204bd443b8c433c44d090248bf22689df673ccafe00 \
|
||||
--hash=sha256:79573c24a46ce11aab457b472efd8d125e5a51da2d1d24387666cd85f54c05b2 \
|
||||
--hash=sha256:7e18f01b0c3e4a07fe6dfdb00e29049ba17eadbc5e7609a2a3a4af83ab7d710a \
|
||||
--hash=sha256:88547535b787a6c9ce4086917b6e1d291aa8ed914fdd3a838b3539dc95c12804 \
|
||||
--hash=sha256:88bbae4d40d5a46142e70d58bf664a89b6b4befaea7b2ecc14e03cedb8e06c04 \
|
||||
--hash=sha256:8cccf4f81371f257440c88faed6b74f1053eef90807b77e31ca057b2db74edb1 \
|
||||
--hash=sha256:9baa544e6acc91130e926e8c802a17f3b16fbea0fd441b5a60f5cf2cc5c3deba \
|
||||
--hash=sha256:a36692b8491d30a8c75f1dfee65bef119d6f39ea84ee04d9f9311f83c5ad9390 \
|
||||
--hash=sha256:a47681378a0439215912ef542c45a783484d4dd82bac412b71e59cf9c0e1cea0 \
|
||||
--hash=sha256:a7c06742645f914f26c7f1fa47b8bc4c91d222f76ee20116c43d5ef0912bba2d \
|
||||
--hash=sha256:a9a2203361a6e6404f80b99234fe7fb37d1fc73487b5a78dc1aa5b97201e0f22 \
|
||||
--hash=sha256:ab232e7fdb44cdfbf55fc3afa31bcdb0d8980b9b95c38b6405df2acb672af0e0 \
|
||||
--hash=sha256:ad85e269fe54d506b240d2d7b9f5f2057c2aa9a2ea5b32c66f8902f768117ed2 \
|
||||
--hash=sha256:af338aa93554be859173c39c85243970dc6a289fa907402289eeae7543e1ae18 \
|
||||
--hash=sha256:afd964fd43b10c12213574db492cb8f73b2f0826c8df07a68288f8f19af2ebe6 \
|
||||
--hash=sha256:b32888aad8b6e68f83a8fdccbf3165f5469702a7544472bdf41f582970ed3311 \
|
||||
--hash=sha256:c31eebe420a9a5d2887b13000b043ff6ca27c452a9a22fa71f35f118e8d4bf89 \
|
||||
--hash=sha256:caea3e9c79d5f0d2c6d9ab96111601797ea5da8e6d0723f77eabb0d4068d2b2f \
|
||||
--hash=sha256:cf30f6e3c077c8e6a9a7809c94551203c8843e74ba0c960f4a98cd80d4665d39 \
|
||||
--hash=sha256:d40770d7c0fd5cbed9d84b2c3f2e156431a12c9a37dc6284060fb4bec0b7ffd4 \
|
||||
--hash=sha256:d8a210b158a34164de8bb68b0e7780041a903d7b00c87e906fb69928bf7890d5 \
|
||||
--hash=sha256:dc4a8d2b25efb6681ecacad42fca8859f88092d8732b170de6a5dddd80a1c8fa \
|
||||
--hash=sha256:df7d30371a2accfe4013e90445f6388c570f103d61019b6b7c57e0265250072a \
|
||||
--hash=sha256:e01375f275f010fcbf7f643b4279896d04e571889b8a5b3f848423d91bf07050 \
|
||||
--hash=sha256:e1a4120ae5705f673727d3253de3ed0e016f7cd78dc463db1b31e2463e1f3cf6 \
|
||||
--hash=sha256:e228514a06843cae89621384cfe3a80418f3c04aadf8a3b14e46a7be704e4235 \
|
||||
--hash=sha256:e405adefb53a435f01efa7ccdec012c016b5a1d3f35459990afc39b6be4d5056 \
|
||||
--hash=sha256:e6b13af258d6a9ad602d57d889f83b9d5543acd471eee12eb51f5b01f8eb1bc2 \
|
||||
--hash=sha256:e6f40a8aa5a92f150bdb3e1c44b7e98fb7113955b2e5394122fa5532fec4b418 \
|
||||
--hash=sha256:e71d5c6ebac14875668a1e90baf2ea0ef5b7ac7918355850c0908ae82bcb297c \
|
||||
--hash=sha256:ed7c635ae45cfbc1a7371f708727bf74690daedc49b4dba310590ca0bd28aa8a \
|
||||
--hash=sha256:f38e60678850c42461d4202739f9bf1e3a737c7ad283638251e79cc49effb6b6 \
|
||||
--hash=sha256:f66eb08feaa410fe4eebd17f2a2c8e2e46d3476e9f8c783daa8e09e0faa666d0 \
|
||||
--hash=sha256:f9b2601381be482f70e5d1051a5965c25fb3625455a2bf520b5a077b22afb775 \
|
||||
--hash=sha256:fbd3c8319de8e1dc79d346929cd71d523622da527cca14e0c1d257e31c2b8b10 \
|
||||
--hash=sha256:fd341868a4b6714a5962c1af0bd44f7c404ef78720c7de4892901e540417111c
|
||||
wrapt==2.4.1 \
|
||||
--hash=sha256:03b5598edd435373278731d0d53449ce7a9626bc48d5548e4a71124ee3e526a1 \
|
||||
--hash=sha256:094a606d0bf1c4b847b3a743d22fc69cb164015b8c70cf6f20a534d30889ed47 \
|
||||
--hash=sha256:0aacc1af512e040fb0b3c4593a8bded9aaa04235025f08a54eda9d8c1103d3c6 \
|
||||
--hash=sha256:0c974c36e8205255a3947dad9c2fe000431b57dd522946e56c192174a7f92a0f \
|
||||
--hash=sha256:0cbee8d00840ac89846f6567c75506260a15fbb4dc74de180678fafe09458d47 \
|
||||
--hash=sha256:0f5990f5db090f069fcd577cc61cc8d463db73cde132abba9033b0a264fc06d0 \
|
||||
--hash=sha256:1e84ec5d89a0a07a0ef6bcd343f5c8ecdc95601d71de3058cdc63274e86c193c \
|
||||
--hash=sha256:1f1851be0e593d65e68d7c1bc9d3b971e19fefa219f617e490d75e80e467ee14 \
|
||||
--hash=sha256:1fe758b9c2d49138231ec3efabd106fec665f86fec50b3d02d7edd75f08a69ca \
|
||||
--hash=sha256:20327e162ef7953fae56b31a43ca457f94ed1fc7a206d01e3d5c8412d1b91572 \
|
||||
--hash=sha256:2286e8e4a937966706463d1bcea30dfefee529e6e73e097a18e9e066a07ae6c2 \
|
||||
--hash=sha256:24389748f0b9d5b67e478fad4fc8b3f1108422ef80716e48eead6cebcebbff08 \
|
||||
--hash=sha256:28cb1c2713b4377bf03ddcb3e76d8216e4bb334199066c6122be7eed2f72de8c \
|
||||
--hash=sha256:2945f4bce1518e09eb25458dbd09800f7aa3fee81a5a5cefe66c4e82fe8cb69c \
|
||||
--hash=sha256:2b21924949dedc3ac63725e09b9b0a130e771975f03432789344ed3422c46008 \
|
||||
--hash=sha256:2cedb743dbdfb9b6d4f11acd8cb6329460264429777e81ea2e86b1b72ea503af \
|
||||
--hash=sha256:2e2e694057bcfd46f43e28f7b50fad8f5fec7113cc6445fdf251219539a08f28 \
|
||||
--hash=sha256:2f725af353bb3319c528ee69dbff838599426974288b281a3258d5397b18cb63 \
|
||||
--hash=sha256:2f86e328c482bc5383b4eda5094be0bed3617fc3076aa9225ff1a9eb6372de9b \
|
||||
--hash=sha256:30d11c289b013bf384ff1a1a6553f150d0b855901708a9bef667a5680f8247c9 \
|
||||
--hash=sha256:3152b2e94d733a9bd70dbd1c95f148266f079a70e9ffca2a9c5dc421ade1b4e6 \
|
||||
--hash=sha256:355e766371657ceca791041b82a7943aa3c8a0d879359c112e63bf3c1c8cfea7 \
|
||||
--hash=sha256:3593b43fabab6b59fe77e38f7e40974aae120c30cea3fd1ceaea6621ee96be00 \
|
||||
--hash=sha256:37ff91b390400463ecd4d080ea823314510b6843ac53e6e35cc09bba1805d466 \
|
||||
--hash=sha256:38819761401baa2d11916d7265b82f23265f8fe5a31c431dd7c24a8863c65f88 \
|
||||
--hash=sha256:3bc7ab495e564449f39db2f54c1033d7190c944736d525f3bd06cefaf0134df0 \
|
||||
--hash=sha256:3bfc6907ebed560d2d3f677c3b17bf6199679163b6c6e475035c9dca497d1697 \
|
||||
--hash=sha256:3d5c8f3b4eae814213d4097f134be03aeb23816e6358213454ec5e62e8449fb6 \
|
||||
--hash=sha256:42d01574bd4bcafc3476e77a95c6c0dd6167101991401325fc5591e2db21a91d \
|
||||
--hash=sha256:432f402f9b6014403cacf9fd18a6bf089c77964330eae951a155131ab0414f5d \
|
||||
--hash=sha256:47c267617551e906de72f6e7265aa3bce84c63d44513d2d2e735e943422aa0a2 \
|
||||
--hash=sha256:4935ad7324d8637715f7cefc35ad65be80900f91d1631947b01bf70651daa328 \
|
||||
--hash=sha256:4d48f1720569b4f6e2df97783fd270554abc4c6ebd74b2e5f15e5110283aaf78 \
|
||||
--hash=sha256:4dc92697444ee380544fbb43c86612d8486529aadf917c22b5524141d4af074c \
|
||||
--hash=sha256:52e474424ea1863199e8635a3915b279164929e71b81af97f2105cab1ce78ef2 \
|
||||
--hash=sha256:53e15cd74bd6b84d7fa90b93dda7334d85f4641fae97632de8aa61d268dfd145 \
|
||||
--hash=sha256:55f36bb1461f93beaf18d818e568b5de343dd8fade7456773d201a38ee723bd3 \
|
||||
--hash=sha256:5a54744b1193505f19016194979b773ee3754a199e9ad90db18f2e9a18fffa16 \
|
||||
--hash=sha256:5c0217b8c12952bf4d137a19ff2c61cc9b626f52c09c43f0289769c9f5f808aa \
|
||||
--hash=sha256:5d83e412665aeb1e854eefbf1564d0d67872d9994b502a0bce96e6ff7f4970b7 \
|
||||
--hash=sha256:68a403adbeb4dd2654d6d108e43e69f0f90e6d34cb7588e0e6589109f6985e67 \
|
||||
--hash=sha256:69fa244ddc1f9c3e8d390e169ebbf018eee53c2e05bda61c980418df89585ccf \
|
||||
--hash=sha256:6b9df84f0a96763159cccb8e3b0ed83cc950c7c8bf82d6e45428372a805b3224 \
|
||||
--hash=sha256:6f32a45d0e883918387aabf5384952e5a93ae40be0a6fb5f1eddc8281af4c714 \
|
||||
--hash=sha256:6f5577fdc702427698c81c8c9c3b8479cbecb3dfd0f697be8c1d09c89f5838cc \
|
||||
--hash=sha256:7033c3c5eb7cd301d9bea8a01660fbe9561c9a3a069d1733e9a712917def0aa2 \
|
||||
--hash=sha256:707d2bef68deddd0fc74a81103d91b286a69ac5a9ff0f0a6dad66f8787e86697 \
|
||||
--hash=sha256:730195aa58afaa7dbb5d351e8728cec6763be2605ef82eec9f134950e3c8618e \
|
||||
--hash=sha256:78af62413095d0a57077606654ce85e273deda8e2bfa28fdb04257b962d94ef2 \
|
||||
--hash=sha256:7aaff952dd6930fc87b52d44bf72ac8426e45e90058fe0f2da446889738eff44 \
|
||||
--hash=sha256:7c89bdfe72c2b96bbe431764a90a25723570a896b605d08e08bca6fe150b8a33 \
|
||||
--hash=sha256:7cb3035b332bc9d21478600ba82c7c71e2d074ed9b4e76364297f54598792227 \
|
||||
--hash=sha256:7e86fbc2ac8a363ea04abf631fad82720e16b17a25020f32dbe9b24a2ed2b0e3 \
|
||||
--hash=sha256:7ff549316d94c404999f96bb0a6993222566231ff4bede1b6f68908d1958a08f \
|
||||
--hash=sha256:80afa3b7010e82899044a2a189c468a0cd8c89980398a59ba3b96b451a6dc5e9 \
|
||||
--hash=sha256:8342f332dada211f64b74609e332d727b13315e9a83177f7918bf68c59f815f2 \
|
||||
--hash=sha256:898513db90d55a4ed3009312d41c12932b8163edbae3535280046d47aaff774f \
|
||||
--hash=sha256:8c4b44e4be7680fc496816e824b6ed134d781c4da296e44b75399196e5c248f1 \
|
||||
--hash=sha256:8d67b916f2f777a6d31067e842598e059f1a0e29022c86454564fc9efb9a0c19 \
|
||||
--hash=sha256:8e82a1669d63b79a2b53041bbb6ea096b5763cab3ca698ed7ac244b3acb7cd51 \
|
||||
--hash=sha256:8ec7aeb92e956810eedc268fe75f8c11f05d6c3d864d0995a53eb6623b3b6a51 \
|
||||
--hash=sha256:9356dbb59199a0e4709de35fa4a1ac1a88ef6da99711a397f5b009233faff326 \
|
||||
--hash=sha256:96a5023fa63ca2f095f7776c8bfaa1694547577f762646c375abafd8f8ae649b \
|
||||
--hash=sha256:9ecdeb8a1ec13397421e6f925412186bd87ab86d63517e6825b6d7bccf781f26 \
|
||||
--hash=sha256:a0c3b217332cf0c4df085fec41c126bf7507d6c1ca0efb3ba8d2b3fd234d4e73 \
|
||||
--hash=sha256:a1e4870d3368c6c918f38e308d5dcea970ea5b908ce889c21412f3a517ebf0c3 \
|
||||
--hash=sha256:a23b89621cfeb3329b1a290596bf402e61d7d5a647a65ca8ea735e48771b71d4 \
|
||||
--hash=sha256:a524ca32f0bcdde2b728d9f81f9527d4dd24b13f15d180f05d08cdc01d1cebe0 \
|
||||
--hash=sha256:a7ce62ee24eddb76c317ec790c44f4fbe9f34ee0a5dae37b30c65a2b8f3e3604 \
|
||||
--hash=sha256:ac1939ccf3e1c33f463706fbf52db5075f5eefb6042bcc1f9cf48c2c20ef478c \
|
||||
--hash=sha256:b0d38d9cc23e9781e6584f303e5c5a9f0d45b85de92ad45678c4dde8d49d9535 \
|
||||
--hash=sha256:b0ee076be124406a7f97ca663c4a3ba32b6bcdd9102ca82497feaca79e9cb33c \
|
||||
--hash=sha256:b19e71c914c435d2c5652caea386c9bf2807979e957183f5bb06d5ed5fa8b55e \
|
||||
--hash=sha256:b4e7efdd476ac631a0181551fd9aace844765ea3ce2b5133b194fae4421e8ad0 \
|
||||
--hash=sha256:b6ea396edcfb305698f44ef0a47b9adaca15d30386ce093ca606844f776d7236 \
|
||||
--hash=sha256:b78dd8d058468156003ee8c212dab334b6eea18cd9c5db3b81f6c90a9408afcc \
|
||||
--hash=sha256:b86bfe741840cec6d8d5858b1eb53a325f564f08d7e6fb5694981961edcec230 \
|
||||
--hash=sha256:ba66eccadd4b857a845e309c08457bb71fa8300000e508e3a86cd695bf9c7515 \
|
||||
--hash=sha256:bc67d4872af5ab2dc1b88904097b92ac00e7658fdf010dee36807807fe882ac4 \
|
||||
--hash=sha256:be6cdd7121adc89a6f52e3c2f4e26a2d4dcdc1c0fde47e3156234db8939e4cdc \
|
||||
--hash=sha256:c15c4ede3fde08723cabab0a892d4b75d35b5a6f0a51c84e6542ac0bdc0507aa \
|
||||
--hash=sha256:c2ab24ed5d3a19f31fb815419a61b27904b5b0222eaacac5e1853d5361035df8 \
|
||||
--hash=sha256:c57abea6aa7de8c584b32958d8f606a08d659d3a5a1296ba2038ea9c185a417e \
|
||||
--hash=sha256:c6c35541cc729964c65c2b9b1f9cf317811039abc2da13b4557f20f21cdc292b \
|
||||
--hash=sha256:d2d6f9abaa52de05090a2b4a4c1d0e858a268c4de69eec277506af9fbcccff91 \
|
||||
--hash=sha256:d60702ebc914d0bb01aa48f5c1785ceaaaa505e0a841b444a69d6ceb5de4097e \
|
||||
--hash=sha256:de5d2d7f12557c9e994b4037330efa5700fccb9f2b9df0bd4ccf384eaf73c254 \
|
||||
--hash=sha256:e0a518cac3e789443af54fc77f23e66f17d80192c281b160b42058f11fabccc5 \
|
||||
--hash=sha256:e32c5951c36fed88b6c603dc0bab209a62dc3217bd8762413634725fe28f2f3c \
|
||||
--hash=sha256:e59f1d5db7bba65f57a2b121eea839214465e878d957d9ab29ad039279ec2a66 \
|
||||
--hash=sha256:e5b347c2184906daedae9a2f9fac67cf02c61f7b6498f09cafdcdd6b404ea9be \
|
||||
--hash=sha256:e78c0f6d66a564bab245faf170d55595df6fc237117b99d97fd838678f0906f0 \
|
||||
--hash=sha256:eb7c0f8bdd21e954bad89d554cfb7431c2f8179842853f199841ab90cbebe914 \
|
||||
--hash=sha256:ebf3b703752b53366fd02b7fbd8c447428e0349c9af3fc17c7a05076dbdd749a \
|
||||
--hash=sha256:edd03758a7578526642508b8833d43496fdfba0f64e0025dfca153a7c1777735 \
|
||||
--hash=sha256:ee437bd7fd050823ef731aad20e968ca8fe670b95e1841f5d201bfdbad4a4e96 \
|
||||
--hash=sha256:ef19a2590b195ac294deff8ee350a027a479afdd2ef2170ce3900af92406e110 \
|
||||
--hash=sha256:f1556a96b20d5bfdc9cb5dcd0a3ec65cbbac8a4eebcd3cd34efdc91c9519f660 \
|
||||
--hash=sha256:fb5b3f94258bcf71db902795f4a71151c7a74d9fe21fffa00752d2bd286866f8 \
|
||||
--hash=sha256:fd6390aab9e8aa40c52eff3c180f098e8d9f5894b1fd4c4fd2c207067b33ed16 \
|
||||
--hash=sha256:fdc997819a6df4c65bdb0a1c5601c98b479ee34cc2f94ffa98a767034ad6366d
|
||||
# via aiobotocore
|
||||
yarl==1.24.5 \
|
||||
--hash=sha256:0055afc45e864b92729ac7600e2d102c17bef060647e74bca75fa84d66b9ff36 \
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from apps.base.models import KeyValue
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mcp_initialize_and_list_tools(initialized_client):
|
||||
init_response = await initialized_client.post(
|
||||
"/mcp",
|
||||
json={"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {}},
|
||||
)
|
||||
assert init_response.status_code == 200
|
||||
assert init_response.json()["result"]["capabilities"]["tools"]
|
||||
|
||||
tools_response = await initialized_client.post(
|
||||
"/mcp", json={"jsonrpc": "2.0", "id": 2, "method": "tools/list"}
|
||||
)
|
||||
assert tools_response.status_code == 200
|
||||
assert {tool["name"] for tool in tools_response.json()["result"]["tools"]} == {
|
||||
"share_text",
|
||||
"share_file",
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mcp_rejects_cross_origin_requests(initialized_client):
|
||||
response = await initialized_client.post(
|
||||
"/mcp",
|
||||
json={"jsonrpc": "2.0", "id": 3, "method": "tools/list"},
|
||||
headers={"origin": "https://attacker.invalid"},
|
||||
)
|
||||
assert response.status_code == 403
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mcp_token_can_be_required(initialized_client):
|
||||
from core.settings import settings
|
||||
|
||||
record = await KeyValue.filter(key="settings").first()
|
||||
config = dict(record.value)
|
||||
config["mcp_require_token"] = 1
|
||||
record.value = config
|
||||
await record.save()
|
||||
settings.user_config = config
|
||||
|
||||
response = await initialized_client.post(
|
||||
"/mcp",
|
||||
json={
|
||||
"jsonrpc": "2.0",
|
||||
"id": 4,
|
||||
"method": "tools/call",
|
||||
"params": {"name": "share_text", "arguments": {"text": "private"}},
|
||||
},
|
||||
)
|
||||
assert response.status_code == 401
|
||||
from apps.admin.dependencies import create_token
|
||||
|
||||
token = create_token({"is_admin": True})
|
||||
authorized = await initialized_client.post(
|
||||
"/mcp",
|
||||
headers={"authorization": f"Bearer {token}"},
|
||||
json={
|
||||
"jsonrpc": "2.0",
|
||||
"id": 6,
|
||||
"method": "tools/call",
|
||||
"params": {"name": "share_text", "arguments": {"text": "private"}},
|
||||
},
|
||||
)
|
||||
assert authorized.status_code == 200
|
||||
assert "/#/?code=" in authorized.json()["result"]["structuredContent"]["url"]
|
||||
Reference in new issue
Block a user