mirror of
https://github.com/Sun-ZhenXing/mcp-template-python.git
synced 2026-03-24 11:48:05 +00:00
feat: update config & cors
This commit is contained in:
3
src/mcp_template_python/config/__init__.py
Normal file
3
src/mcp_template_python/config/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .app import settings
|
||||
|
||||
__all__ = ["settings"]
|
||||
46
src/mcp_template_python/config/app.py
Normal file
46
src/mcp_template_python/config/app.py
Normal 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()
|
||||
24
src/mcp_template_python/config/cors.py
Normal file
24
src/mcp_template_python/config/cors.py
Normal 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 '*'."""
|
||||
27
src/mcp_template_python/config/mcp.py
Normal file
27
src/mcp_template_python/config/mcp.py
Normal 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."""
|
||||
Reference in New Issue
Block a user