generated from personal-projects/leo-claude-mktplace
Issue #19 - Foundation for Sprint 01: Core Architecture Correction Changes: - Renamed package directory: gitea_http_wrapper -> gitea_mcp_remote - Updated config/settings.py: - Made gitea_repo optional (allow None) - Added mcp_auth_mode field (default: "optional") - Changed HTTP defaults: 0.0.0.0:8080 (was 127.0.0.1:8000) - Removed get_gitea_mcp_env() method (no longer needed) - Updated all import paths throughout codebase - Updated filtering/filter.py: Changed ValueError to warning when both enabled_tools and disabled_tools are specified - Updated test files with new import paths - Updated test_filtering.py to test warning instead of ValueError - Updated pyproject.toml, pytest.ini, and README.md references All modules preserved - only import paths and configuration updated. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
109 lines
3.2 KiB
Python
109 lines
3.2 KiB
Python
"""Configuration settings for Gitea MCP HTTP transport."""
|
|
|
|
from pathlib import Path
|
|
from typing import Optional
|
|
|
|
from pydantic import Field, field_validator
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class GiteaSettings(BaseSettings):
|
|
"""Configuration settings loaded from environment or .env file."""
|
|
|
|
model_config = SettingsConfigDict(
|
|
env_file=".env",
|
|
env_file_encoding="utf-8",
|
|
case_sensitive=False,
|
|
extra="ignore",
|
|
)
|
|
|
|
# Gitea Configuration
|
|
gitea_url: str = Field(
|
|
...,
|
|
description="Gitea instance URL (e.g., https://git.example.com)",
|
|
)
|
|
gitea_token: str = Field(
|
|
...,
|
|
description="Gitea API token for authentication",
|
|
)
|
|
gitea_owner: str = Field(
|
|
...,
|
|
description="Default repository owner/organization",
|
|
)
|
|
gitea_repo: str | None = Field(
|
|
default=None,
|
|
description="Default repository name (optional)",
|
|
)
|
|
|
|
# HTTP Server Configuration
|
|
http_host: str = Field(
|
|
default="0.0.0.0",
|
|
description="HTTP server bind address",
|
|
)
|
|
http_port: int = Field(
|
|
default=8080,
|
|
ge=1,
|
|
le=65535,
|
|
description="HTTP server port",
|
|
)
|
|
|
|
# Authentication Configuration
|
|
auth_token: Optional[str] = Field(
|
|
default=None,
|
|
description="Bearer token for HTTP authentication (optional)",
|
|
)
|
|
mcp_auth_mode: str = Field(
|
|
default="optional",
|
|
description="MCP authentication mode: 'required', 'optional', or 'none'",
|
|
)
|
|
|
|
# Tool Filtering Configuration
|
|
enabled_tools: Optional[str] = Field(
|
|
default=None,
|
|
description="Comma-separated list of enabled tools (optional, enables all if not set)",
|
|
)
|
|
disabled_tools: Optional[str] = Field(
|
|
default=None,
|
|
description="Comma-separated list of disabled tools (optional)",
|
|
)
|
|
|
|
@field_validator("gitea_url")
|
|
@classmethod
|
|
def validate_gitea_url(cls, v: str) -> str:
|
|
"""Ensure Gitea URL is properly formatted."""
|
|
if not v.startswith(("http://", "https://")):
|
|
raise ValueError("gitea_url must start with http:// or https://")
|
|
return v.rstrip("/")
|
|
|
|
@property
|
|
def enabled_tools_list(self) -> Optional[list[str]]:
|
|
"""Parse enabled_tools into a list."""
|
|
if not self.enabled_tools:
|
|
return None
|
|
return [tool.strip() for tool in self.enabled_tools.split(",") if tool.strip()]
|
|
|
|
@property
|
|
def disabled_tools_list(self) -> Optional[list[str]]:
|
|
"""Parse disabled_tools into a list."""
|
|
if not self.disabled_tools:
|
|
return None
|
|
return [tool.strip() for tool in self.disabled_tools.split(",") if tool.strip()]
|
|
|
|
|
|
def load_settings(env_file: Optional[Path] = None) -> GiteaSettings:
|
|
"""
|
|
Load settings from environment or .env file.
|
|
|
|
Args:
|
|
env_file: Optional path to .env file. If not provided, searches for .env in current directory.
|
|
|
|
Returns:
|
|
GiteaSettings instance with loaded configuration.
|
|
|
|
Raises:
|
|
ValidationError: If required settings are missing or invalid.
|
|
"""
|
|
if env_file:
|
|
return GiteaSettings(_env_file=env_file)
|
|
return GiteaSettings()
|