fix(ci): fix black/ruff failures, add CoC and PR template
- Fix Python formatting (sync no longer strips blank lines from .py files) - Remove test_community_build.py (tests private sync module) - Fix ruff warnings in test files - Add CODE_OF_CONDUCT.md - Add .github/PULL_REQUEST_TEMPLATE.md Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ Each endpoint has specific plugin types, scopes, and access requirements.
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class EndpointType(Enum):
|
||||
"""Types of MCP endpoints"""
|
||||
|
||||
@@ -25,6 +26,7 @@ class EndpointType(Enum):
|
||||
PROJECT = "project" # Dynamic per-project endpoint
|
||||
CUSTOM = "custom"
|
||||
|
||||
|
||||
@dataclass
|
||||
class EndpointConfig:
|
||||
"""
|
||||
@@ -90,6 +92,7 @@ class EndpointConfig:
|
||||
return True # Empty set = all scopes
|
||||
return scope in self.allowed_scopes
|
||||
|
||||
|
||||
# Predefined endpoint configurations
|
||||
ENDPOINT_CONFIGS = {
|
||||
# Admin endpoint - all tools, requires Master API Key
|
||||
@@ -305,12 +308,14 @@ ENDPOINT_CONFIGS = {
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def get_endpoint_config(endpoint_type: EndpointType) -> EndpointConfig:
|
||||
"""Get configuration for a specific endpoint type"""
|
||||
if endpoint_type not in ENDPOINT_CONFIGS:
|
||||
raise ValueError(f"Unknown endpoint type: {endpoint_type}")
|
||||
return ENDPOINT_CONFIGS[endpoint_type]
|
||||
|
||||
|
||||
def create_project_endpoint_config(
|
||||
project_id: str, plugin_type: str, site_alias: str | None = None
|
||||
) -> EndpointConfig:
|
||||
|
||||
@@ -21,6 +21,7 @@ if TYPE_CHECKING:
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MCPEndpointFactory:
|
||||
"""
|
||||
Factory for creating scoped MCP endpoints.
|
||||
|
||||
@@ -24,6 +24,7 @@ from .config import EndpointConfig
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class AuthContext:
|
||||
"""Authentication context for a request"""
|
||||
@@ -35,6 +36,7 @@ class AuthContext:
|
||||
is_oauth_token: bool = False
|
||||
client_ip: str | None = None
|
||||
|
||||
|
||||
class EndpointAuthMiddleware(Middleware):
|
||||
"""
|
||||
Authentication middleware for multi-endpoint architecture.
|
||||
@@ -256,6 +258,7 @@ class EndpointAuthMiddleware(Middleware):
|
||||
duration_ms = int((time.time() - start_time) * 1000)
|
||||
logger.warning(f"Tool {tool_name} failed: {error} (duration={duration_ms}ms)")
|
||||
|
||||
|
||||
class EndpointRateLimitMiddleware(Middleware):
|
||||
"""
|
||||
Rate limiting middleware for multi-endpoint architecture.
|
||||
@@ -285,6 +288,7 @@ class EndpointRateLimitMiddleware(Middleware):
|
||||
# Proceed with request
|
||||
return await call_next(context)
|
||||
|
||||
|
||||
class EndpointAuditMiddleware(Middleware):
|
||||
"""
|
||||
Audit logging middleware for multi-endpoint architecture.
|
||||
@@ -333,6 +337,7 @@ class EndpointAuditMiddleware(Middleware):
|
||||
)
|
||||
raise
|
||||
|
||||
|
||||
def create_endpoint_middleware(endpoint_config: EndpointConfig) -> list:
|
||||
"""
|
||||
Create middleware stack for an endpoint.
|
||||
|
||||
@@ -21,6 +21,7 @@ from .factory import MCPEndpointFactory
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class EndpointInfo:
|
||||
"""Information about a registered endpoint"""
|
||||
@@ -33,6 +34,7 @@ class EndpointInfo:
|
||||
plugin_types: list[str]
|
||||
require_master_key: bool
|
||||
|
||||
|
||||
class EndpointRegistry:
|
||||
"""
|
||||
Central registry for all MCP endpoints.
|
||||
@@ -199,9 +201,11 @@ class EndpointRegistry:
|
||||
logger.info(f"Total: {len(self._endpoints)} endpoints")
|
||||
logger.info("=" * 60)
|
||||
|
||||
|
||||
# Singleton instance
|
||||
_registry: EndpointRegistry | None = None
|
||||
|
||||
|
||||
def get_endpoint_registry() -> EndpointRegistry:
|
||||
"""Get the global endpoint registry instance"""
|
||||
global _registry
|
||||
@@ -211,6 +215,7 @@ def get_endpoint_registry() -> EndpointRegistry:
|
||||
)
|
||||
return _registry
|
||||
|
||||
|
||||
def initialize_endpoint_registry(factory: MCPEndpointFactory) -> EndpointRegistry:
|
||||
"""
|
||||
Initialize the global endpoint registry.
|
||||
|
||||
Reference in New Issue
Block a user