feat: update config & cors

This commit is contained in:
Sun-ZhenXing
2025-10-02 16:20:15 +08:00
parent 477888de17
commit 0ffc5b69b4
13 changed files with 273 additions and 208 deletions

View File

@@ -0,0 +1,3 @@
from .app import settings
__all__ = ["settings"]

View File

@@ -0,0 +1,46 @@
from dotenv import load_dotenv
from pydantic_settings import BaseSettings, SettingsConfigDict
from mcp_template_python.config.cors import CORSSettings
from .mcp import MCPSettings
load_dotenv()
class AppSettings(BaseSettings):
"""
Configuration settings for the MCP template application.
"""
model_config = SettingsConfigDict(
env_prefix="APP_",
extra="allow",
)
mcp: MCPSettings = MCPSettings()
"""MCP settings, defaults to MCPSettings()."""
cors: CORSSettings = CORSSettings()
"""CORS settings, defaults to CORSSettings()."""
title: str = "MCP Template Application"
"""Title of the MCP application, defaults to 'MCP Template Application'."""
description: str = "A template application for MCP using FastAPI."
"""Description of the MCP application, defaults to 'A template application for MCP using FastAPI.'"""
default_host: str = "127.0.0.1"
"""Default host for the MCP server, defaults to 127.0.0.1."""
default_port: int = 3001
"""Default port for the MCP server, defaults to 3001."""
log_level: str = "INFO"
"""Logging level for the MCP server, defaults to 'info'."""
rich_console: bool = False
"""Enable rich console output, defaults to False."""
settings = AppSettings()

View File

@@ -0,0 +1,24 @@
from pydantic_settings import BaseSettings, SettingsConfigDict
class CORSSettings(BaseSettings):
"""
Configuration settings for CORS (Cross-Origin Resource Sharing).
"""
model_config = SettingsConfigDict(
env_prefix="CORS_",
extra="allow",
)
allow_origins: str = "*"
"""CORS allow origins, defaults to '*'."""
allow_credentials: bool = True
"""CORS allow credentials, defaults to True."""
allow_methods: str = "*"
"""CORS allow methods, defaults to '*'."""
allow_headers: str = "*"
"""CORS allow headers, defaults to '*'."""

View File

@@ -0,0 +1,27 @@
from pydantic_settings import BaseSettings, SettingsConfigDict
class MCPSettings(BaseSettings):
"""
Configuration settings for the MCP template application.
"""
model_config = SettingsConfigDict(
env_prefix="MCP_",
extra="allow",
)
default_mcp: str = "math"
"""Default MCP to be used by the application."""
instructions: str | None = None
"""Instructions to be used by the MCP server, defaults to None."""
enable_helpers_router: bool = True
"""Enable the helpers router for the MCP server."""
enable_sse: bool = True
"""Enable Server-Sent Events (SSE) for the MCP server."""
enable_streamable_http: bool = True
"""Enable streamable HTTP for the MCP server."""