1. Service_type do not set after add server
2. Issue relate pricing when "Update from OpenAPI"
3. Failed to set SQLAlchemy cache for key Error
4. Request Body Logging in Internal Service
5. Deleted API Key Remains Valid for 5 Minutes
This commit is contained in:
Liujian committed 2025-12-05 10:27:19 +09:00
1 parent 284880a170
commit 1846aafc1e
10 files changed
+75 -83

No files matched your search

+2 -2
View File
@@ -1,11 +1,11 @@
{
"version": "v1.1",
"releaseDate": "2025-10-17",
"releaseDate": "2025-12-07",
"description": "This is the latest release of the application.",
"downloads": {
"program": {
"xpack_mcp_market": {
"version": "v1.1.1",
"version": "v1.1.5",
"docker": "xpackai/xpack-mcp-market",
"tar": "xpack-mcp-market.tar.gz",
"url": "https://public.eolinker.com/xpack/images/xpack-mcp-market.${VERSION}.${ARCH}.tar.gz"
@@ -2,7 +2,6 @@ import logging
import uuid
import json
import re
from datetime import datetime, timezone
from sqlalchemy.orm import Session
from typing import Optional, Tuple, List
from services.admin_service.repositories.mcp_service_repository import McpServiceRepository
@@ -143,10 +142,7 @@ class McpManagerService:
existing_service.short_description = temp_service.short_description
existing_service.long_description = temp_service.long_description
existing_service.headers = temp_service.headers
# existing_service.auth_method = AuthMethod(temp_service.auth_method.value)
existing_service.base_url = temp_service.base_url
# existing_service.auth_header = temp_service.auth_header
# existing_service.auth_token = temp_service.auth_token
existing_service.charge_type = ChargeType(temp_service.charge_type.value)
existing_service.price = temp_service.price
existing_service.input_token_price = temp_service.input_token_price
@@ -239,7 +235,8 @@ class McpManagerService:
else:
# If provided as string, store directly
existing_service.tags = body["tags"]
if not existing_service.service_type:
existing_service.service_type = "openapi"
# Commit changes
self.db.commit()
self.db.refresh(existing_service)
@@ -369,6 +366,7 @@ class McpManagerService:
mcp_service.charge_type = ChargeType.FREE # Default to free
mcp_service.price = 0.0
mcp_service.enabled = 0 # Default disabled, requires manual activation by user
mcp_service.service_type = "openapi"
# Save service
self.mcp_service_repository.create(mcp_service)
@@ -433,15 +431,13 @@ class McpManagerService:
temp_service.slug_name = existing_service.slug_name # Keep original slug_name
temp_service.short_description = openapi_data.description or existing_service.short_description
temp_service.long_description = openapi_data.description or existing_service.long_description
# temp_service.auth_method = TempAuthMethod(existing_service.auth_method.value) # Keep original auth method
temp_service.base_url = existing_service.base_url # Keep original base_url
# temp_service.auth_header = existing_service.auth_header
# temp_service.auth_token = existing_service.auth_token
temp_service.headers = existing_service.headers # Keep original headers
temp_service.charge_type = TempChargeType(existing_service.charge_type.value) # Keep original charge type
temp_service.price = existing_service.price # Keep original price
temp_service.enabled = existing_service.enabled # Keep original enabled status
temp_service.tags = existing_service.tags # Keep original tags
# temp_service.service_type = existing_service.service_type # Keep original service type
# Save temporary service record
self.temp_mcp_service_repository.create(temp_service)
@@ -488,18 +484,17 @@ class McpManagerService:
"headers": json.loads(temp_service.headers) if temp_service.headers else [],
"charge_type": temp_service.charge_type.value if temp_service.charge_type else None,
"price": str(float(temp_service.price)) if temp_service.price and temp_service.charge_type == ChargeType.PER_CALL else "0.00",
"input_token_price": str(float(temp_service.input_token_price)) if temp_service.input_token_price and temp_service.charge_type == ChargeType.PER_TOKEN else "0.00",
"input_token_price": str(float(temp_service.input_token_price)) if temp_service.input_token_price and temp_service.charge_type.value == ChargeType.PER_TOKEN else "0.00",
"output_token_price": str(float(temp_service.output_token_price)) if temp_service.output_token_price and temp_service.charge_type == ChargeType.PER_TOKEN else "0.00",
"enabled": temp_service.enabled,
"tags": parse_tags_to_array(temp_service.tags),
"apis": apis_list,
}
return result
except Exception as e:
logger.error(f"Failed to update service from OpenAPI: {str(e)}")
raise ValueError(f"Failed to update service from OpenAPI: {str(e)}")
raise ValueError(f"Failed to update service from OpenAPI.")
def get_public_services_paginated(self, keyword: str, page: int = 1, page_size: int = 10) -> Tuple[List[dict], int]:
"""Get public services list with pagination, returns formatted data with API info"""
@@ -5,6 +5,8 @@ from services.common.models.user_apikey import UserApiKey
from services.common.database import SessionLocal
from datetime import datetime
from services.admin_service.repositories.user_apikey_repository import UserApiKeyRepository
from services.common.utils.cache_utils import CacheUtils
from services.common.redis_keys import RedisKeys
logger = logging.getLogger(__name__)
@@ -31,6 +33,10 @@ class UserApiKeyService:
if not user_apikey or user_apikey.user_id != user_id:
return None
self.user_apikey_repository.delete(id)
try:
CacheUtils.delete_cache(RedisKeys.user_apikey_key(user_apikey.apikey))
except Exception:
pass
return user_apikey
def get_by_user_id(self, user_id: str) -> List[UserApiKey]:
@@ -16,7 +16,7 @@ class McpServiceRepository:
def get_by_id(self, service_id: str, force_update: bool = False) -> Optional[McpService]:
"""
Get single MCP service by service ID
Get single MCP service by service ID
"""
cache_key = f"xpack:mcp_service:id:{service_id}"
if not force_update:
@@ -67,7 +67,7 @@ class McpToolService:
logger.info(f"Sending HTTP request: {method} {url}")
logger.debug(f"Query parameters: {query_params}")
logger.debug(f"Request body: {request_body}")
# logger.debug(f"Request body: {request_body}")
async with create_mcp_http_client(headers=headers) as client:
if method == "GET":
+2 -2
View File
@@ -307,7 +307,7 @@ class HttpRequestBuilder:
request_body[param_name] = arguments[param_name]
if request_body:
logger.debug(f"Built request body from parameters: {request_body}")
# logger.debug(f"Built request body from parameters: {request_body}")
return request_body
else:
# If not a parameters list, try to parse as JSON schema object
@@ -322,7 +322,7 @@ class HttpRequestBuilder:
request_body[prop_name] = arguments[prop_name]
if request_body:
logger.debug(f"Built request body from schema: {request_body}")
# logger.debug(f"Built request body from schema: {request_body}")
return request_body
except json.JSONDecodeError:
logger.warning(f"Failed to parse request body schema as JSON")
+14 -1
View File
@@ -1,4 +1,17 @@
from sqlalchemy.orm import DeclarativeBase
from enum import Enum as PyEnum
class Base(DeclarativeBase):
pass
pass
class AuthMethod(PyEnum):
FREE = "free"
APIKEY = "apikey"
TOKEN = "token"
class ChargeType(PyEnum):
FREE = "free"
PER_CALL = "per_call"
PER_TOKEN = "per_token"
+2 -21
View File
@@ -1,21 +1,8 @@
from sqlalchemy import String, Enum, Numeric, Integer, DateTime
from sqlalchemy.sql import func
from sqlalchemy.orm import Mapped, mapped_column
from enum import Enum as PyEnum
from datetime import datetime
from services.common.models.base import Base
class AuthMethod(PyEnum):
FREE = "free"
APIKEY = "apikey"
TOKEN = "token"
class ChargeType(PyEnum):
FREE = "free"
PER_CALL = "per_call"
PER_TOKEN = "per_token"
from services.common.models.base import Base,ChargeType
class McpService(Base):
@@ -31,14 +18,7 @@ class McpService(Base):
slug_name: Mapped[str] = mapped_column(String(255), unique=True, nullable=False, comment="Unique slug name for the service")
short_description: Mapped[str] = mapped_column(String, nullable=False, comment="Short description of the service")
long_description: Mapped[str] = mapped_column(String, nullable=True, comment="Detailed description of the service (Markdown format)")
# auth_method: Mapped[AuthMethod] = mapped_column(
# Enum(AuthMethod, values_callable=lambda obj: [e.value for e in obj]),
# nullable=False,
# comment="Authentication method: free, apikey, token",
# )
base_url: Mapped[str] = mapped_column(String(512), nullable=True, comment="api url")
# auth_header: Mapped[str] = mapped_column(String(255), nullable=True, comment="Authentication header name")
# auth_token: Mapped[str] = mapped_column(String(255), nullable=True, comment="Authentication token value")
headers: Mapped[str] = mapped_column(String, nullable=True, comment="Additional headers for requests (JSON Array format)")
charge_type: Mapped[ChargeType] = mapped_column(
Enum(ChargeType, values_callable=lambda obj: [e.value for e in obj]),
@@ -54,6 +34,7 @@ class McpService(Base):
)
enabled: Mapped[int] = mapped_column(Integer, nullable=True, comment="Service status: 0=disabled, 1=enabled")
tags: Mapped[str] = mapped_column(String, nullable=True, comment="Tags")
service_type: Mapped[str] = mapped_column(String(255), nullable=True, comment="Service type",default="openapi")
created_at: Mapped[datetime] = mapped_column(
DateTime,
nullable=True,
+1 -21
View File
@@ -1,23 +1,10 @@
from sqlalchemy import String, Enum, Numeric, Integer, DateTime
from sqlalchemy.sql import func
from sqlalchemy.orm import Mapped, mapped_column
from enum import Enum as PyEnum
from services.common.models.base import Base
from services.common.models.base import Base,ChargeType
from datetime import datetime
class AuthMethod(PyEnum):
FREE = "free"
APIKEY = "apikey"
TOKEN = "token"
class ChargeType(PyEnum):
FREE = "free"
PER_CALL = "per_call"
PER_TOKEN = "per_token"
class TempMcpService(Base):
__tablename__ = "temp_mcp_service"
@@ -31,15 +18,8 @@ class TempMcpService(Base):
slug_name: Mapped[str] = mapped_column(String(255), unique=True, nullable=False, comment="Unique slug name for the service")
short_description: Mapped[str] = mapped_column(String, nullable=False, comment="Short description of the service")
long_description: Mapped[str] = mapped_column(String, nullable=True, comment="Detailed description of the service (Markdown format)")
# auth_method: Mapped[AuthMethod] = mapped_column(
# Enum(AuthMethod, values_callable=lambda obj: [e.value for e in obj]),
# nullable=False,
# comment="Authentication method: free, apikey, token",
# )
base_url: Mapped[str] = mapped_column(String(512), nullable=True, comment="api url")
headers: Mapped[str] = mapped_column(String, nullable=True, comment="Additional headers for requests (JSON Array format)")
# auth_header: Mapped[str] = mapped_column(String(255), nullable=True, comment="Authentication header name")
# auth_token: Mapped[str] = mapped_column(String(255), nullable=True, comment="Authentication token value")
charge_type: Mapped[ChargeType] = mapped_column(
Enum(ChargeType, values_callable=lambda obj: [e.value for e in obj]),
nullable=False,
+40 -23
View File
@@ -1,5 +1,8 @@
from typing import get_origin, get_args
from enum import Enum as PyEnum
from decimal import Decimal
from datetime import datetime
from sqlalchemy import DateTime, Numeric
class SqlalchemyUtils:
@@ -7,10 +10,13 @@ class SqlalchemyUtils:
@staticmethod
def model_to_dict(model):
result = {column.name: getattr(model, column.name) for column in model.__table__.columns}
# Normalize Enum values to primitive for safe serialization
for key, value in list(result.items()):
if isinstance(value, PyEnum):
result[key] = value.value
elif isinstance(value, Decimal):
result[key] = str(value)
elif isinstance(value, datetime):
result[key] = value.isoformat()
return result
@staticmethod
@@ -27,31 +33,42 @@ class SqlalchemyUtils:
"""
instance = model_class()
# Get all column names for the model
column_names = {column.name for column in model_class.__table__.columns}
# Map column definitions by name for type-aware restoration
columns_by_name = {column.name: column for column in model_class.__table__.columns}
# Set attributes that exist in both the dictionary and the model
for key, value in data_dict.items():
if key in column_names and hasattr(instance, key):
# Attempt to restore Enum types from strings using type annotations
annotations = getattr(model_class, "__annotations__", {})
ann = annotations.get(key)
target_type = None
if ann is not None:
origin = get_origin(ann)
if origin is None:
target_type = ann
else:
args = get_args(ann)
if args:
target_type = args[0]
column = columns_by_name.get(key)
if not column:
continue
if isinstance(target_type, type) and issubclass(target_type, PyEnum) and isinstance(value, str):
try:
value = target_type(value)
except Exception:
pass
# Restore Enum from string using annotations if available
annotations = getattr(model_class, "__annotations__", {})
ann = annotations.get(key)
target_type = None
if ann is not None:
origin = get_origin(ann)
if origin is None:
target_type = ann
else:
args = get_args(ann)
if args:
target_type = args[0]
if isinstance(target_type, type) and issubclass(target_type, PyEnum) and isinstance(value, str):
try:
value = target_type(value)
except Exception:
pass
setattr(instance, key, value)
# Restore Numeric and DateTime types from JSON-friendly forms
try:
if isinstance(column.type, Numeric) and value is not None:
if not isinstance(value, Decimal):
value = Decimal(str(value))
elif isinstance(column.type, DateTime) and isinstance(value, str):
value = datetime.fromisoformat(value)
except Exception:
pass
setattr(instance, key, value)
return instance