Skip to content

Commit 3be2fe8

Browse files
committed
feat(vefaas): add vefaas_cli_sdk module and refactor deploy workflow
## Summary This is a major refactoring of the veFaaS MCP Server to introduce a new vefaas_cli_sdk module ported from vefaas-cli, providing better project detection, deployment workflow, and configuration management. ## New Components ### vefaas_cli_sdk module (new) - **deploy.py**: Core deployment logic - VeFaaSClient: Unified API client with error handling - Package directory with .vefaasignore support - Static site deployment with Caddyfile generation - Full deployment workflow (create/update function, build, release, poll status) - **detector.py**: Project detection module - Auto-detect framework (Next.js, Vite, FastAPI, Flask, Streamlit, etc.) - Detect runtime, build command, start command, and port - Support for Node.js, Python, and static site projects - **config.py**: Configuration management - Read/write .vefaas/config.json (vefaas-cli compatible) - Read/write vefaas.yaml (legacy MCP format) - Region-aware configuration linking ## Tool Changes ### deploy_application (enhanced) - Now the PRIMARY deployment tool - one command to deploy - Handles full workflow: detect → build → package → upload → create/update → release - Region-aware configuration: only uses cached IDs if region matches - Explicit build_command validation for non-Python runtimes - Clear error messages with actionable next_action guidance ### detect_project (enhanced) - Uses new detector module for accurate framework detection - Returns comprehensive project configuration ### get_function_detail / pull_function_code (enhanced) - Better error handling for optional fields - Returns SourceType for early validation ### Removed tools - create_vefaas_application (merged into deploy_application) - poll_vefaas_application_status (handled internally) - list_vefaas_application_templates (no longer needed) - get_vefaas_application_template (no longer needed) ## Test Updates - Added tests for new vefaas_cli_sdk module - Updated existing tests for refactored tools - Added region-aware deployment tests ## Dependencies - Added 'pathspec' for .vefaasignore pattern matching - Added 'pyyaml' for YAML config file support
1 parent 65743a3 commit 3be2fe8

File tree

9 files changed

+3067
-894
lines changed

9 files changed

+3067
-894
lines changed

server/mcp_server_vefaas_function/pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dependencies = [
99
"volcengine-python-sdk>=3.0.8",
1010
"requests==2.32.3",
1111
"pyzipper==0.3.6",
12+
"pathspec>=0.12.0",
1213
]
1314

1415
[project.scripts]
@@ -20,3 +21,6 @@ build-backend = "hatchling.build"
2021

2122
[tool.hatch.metadata]
2223
allow-direct-references = true
24+
25+
[tool.autopep8]
26+
max_line_length = 240

server/mcp_server_vefaas_function/src/mcp_server_vefaas_function/sign.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
Service = "apig"
3939
Version = "2021-03-03"
4040
Region = "cn-beijing"
41-
Host = "iam.volcengineapi.com"
41+
Host = "open.volcengineapi.com"
4242
ContentType = "application/x-www-form-urlencoded"
4343

4444
AK_KEY = "VOLCENGINE_ACCESS_KEY"
@@ -62,7 +62,7 @@ def norm_query(params):
6262
if type(params[key]) == list:
6363
for k in params[key]:
6464
query = (
65-
query + quote(key, safe="-_.~") + "=" + quote(k, safe="-_.~") + "&"
65+
query + quote(key, safe="-_.~") + "=" + quote(k, safe="-_.~") + "&"
6666
)
6767
else:
6868
query = (query + quote(key, safe="-_.~") + "=" + quote(params[key], safe="-_.~") + "&")
@@ -82,7 +82,7 @@ def hash_sha256(content: str):
8282

8383

8484
# 第二步:签名请求函数
85-
def request(method, date, query, header, ak, sk, token, action, body, region = None, timeout=None):
85+
def request(method, date, query, header, ak, sk, token, action, body, region=None, timeout=None):
8686
# 第三步:创建身份证明。其中的 Service 和 Region 字段是固定的。ak 和 sk 分别代表
8787
# AccessKeyID 和 SecretAccessKey。同时需要初始化签名结构体。一些签名计算时需要的属性也在这里处理。
8888
# 初始化身份证明结构体
@@ -99,7 +99,8 @@ def request(method, date, query, header, ak, sk, token, action, body, region = N
9999

100100
if action in ['CodeUploadCallback', 'CreateDependencyInstallTask', 'GetDependencyInstallTaskStatus',
101101
'GetDependencyInstallTaskLogDownloadURI', "ListApplicationTemplates", "GetApplicationTemplateDetail", "GetRevision",
102-
"CreateApplication", "GetApplication", "ReleaseApplication", "ListTriggers", "GetApplicationRevisionLog", "ListTemplates", "GetTemplateDetail"]:
102+
"CreateApplication", "GetApplication", "ReleaseApplication", "ListTriggers", "GetApplicationRevisionLog", "ListTemplates", "GetTemplateDetail",
103+
"GenTempTosObjectUrl", "ListApplications", "CreateFunction", "UpdateFunction", "GetFunction", "Release", "GetReleaseStatus"]:
103104
credential["service"] = "vefaas"
104105

105106
content_type = ContentType
@@ -150,11 +151,11 @@ def request(method, date, query, header, ak, sk, token, action, body, region = N
150151
"x-content-sha256:" + x_content_sha256,
151152
"x-date:" + x_date,
152153
]
153-
),
154-
"",
155-
signed_headers_str,
156-
x_content_sha256,
157-
]
154+
),
155+
"",
156+
signed_headers_str,
157+
x_content_sha256,
158+
]
158159
)
159160

160161
# 打印正规化的请求用于调试比对
@@ -195,13 +196,13 @@ def request(method, date, query, header, ak, sk, token, action, body, region = N
195196
def get_authorization_credentials(ctx: Context = None) -> tuple[str, str, str]:
196197
"""
197198
Gets authorization credentials from either environment variables or request headers.
198-
199+
199200
Args:
200201
ctx: The server context object
201-
202+
202203
Returns:
203204
tuple: (access_key, secret_key, session_token)
204-
205+
205206
Raises:
206207
ValueError: If authorization information is missing or invalid
207208
"""
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates
2+
# SPDX-License-Identifier: MIT
3+
4+
"""veFaaS CLI SDK - Ported capabilities from vefaas-cli (TypeScript)"""
5+
6+
from .detector import auto_detect, DetectionResult
7+
from .deploy import (
8+
DeployConfig,
9+
DeployResult,
10+
VeFaaSClient,
11+
deploy_application,
12+
get_console_url,
13+
get_application_console_url,
14+
extract_access_url_from_cloud_resource,
15+
wait_for_function_release,
16+
wait_for_application_deploy,
17+
wait_for_dependency_install,
18+
)
19+
from .config import (
20+
VefaasConfig,
21+
FunctionConfig,
22+
TriggerConfig,
23+
read_config,
24+
write_config,
25+
get_linked_ids,
26+
get_linked_region,
27+
)
28+
29+
__all__ = [
30+
# Detector
31+
"auto_detect",
32+
"DetectionResult",
33+
# Deploy
34+
"DeployConfig",
35+
"DeployResult",
36+
"VeFaaSClient",
37+
"deploy_application",
38+
"get_console_url",
39+
"get_application_console_url",
40+
"extract_access_url_from_cloud_resource",
41+
"wait_for_function_release",
42+
"wait_for_application_deploy",
43+
"wait_for_dependency_install",
44+
# Config
45+
"VefaasConfig",
46+
"FunctionConfig",
47+
"TriggerConfig",
48+
"read_config",
49+
"write_config",
50+
"get_linked_ids",
51+
"get_linked_region",
52+
]

0 commit comments

Comments
 (0)