-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
104 lines (91 loc) · 4.06 KB
/
Copy pathconfig.py
File metadata and controls
104 lines (91 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""
Configuration management for the MSInsight MCP server.
All settings can be overridden via environment variables with the
MSINSIGHT_ prefix, or by placing a .env file in the mcp/ directory.
Example .env:
MSINSIGHT_CPP_BACKEND_HOST=192.168.1.100
MSINSIGHT_CPP_BACKEND_PORT=9000
MSINSIGHT_MCP_TRANSPORT=sse
MSINSIGHT_MCP_PORT=8765
"""
from typing import Literal, Optional, List
from pydantic import Field
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
model_config = {"env_prefix": "MSINSIGHT_", "env_file": ".env", "extra": "ignore"}
# ------------------------------------------------------------------
# C++ backend connection
# ------------------------------------------------------------------
cpp_backend_host: str = Field("localhost", description="C++ backend WebSocket host")
cpp_backend_port: int = Field(9000, description="C++ backend WebSocket port")
cpp_reconnect_interval: float = Field(
3.0, description="Seconds to wait between reconnect attempts"
)
cpp_request_timeout: float = Field(
30.0, description="Seconds to wait for a C++ backend response"
)
cpp_keepalive_interval: float = Field(
15.0,
description=(
"Seconds of idle time before sending a heartCheck keep-alive to the "
"C++ backend. Prevents the server's idleTimeout from closing the "
"WebSocket connection. Set to 0 to disable."
),
)
cpp_auto_start_binary: str = Field(
r"C:\Program Files (x86)\MindStudio Insight\resources\profiler\server\profiler_server.exe",
description="Path to the C++ backend executable to auto-start. If empty, auto-start is disabled."
)
cpp_log_path: str = Field(
r"C:\Users\Administrator\.mindstudio_insight",
description="Path to the C++ backend log directory."
)
cpp_mock_mode: bool = Field(
False,
description="Return deterministic mock C++ backend responses without starting or connecting to the backend."
)
# ------------------------------------------------------------------
# MCP server
# ------------------------------------------------------------------
mcp_transport: Literal["stdio", "sse", "websocket"] = Field(
"stdio",
description=(
"Transport for the MCP protocol interface. "
"'stdio' for Claude Desktop / local CLI; "
"'sse' for HTTP+SSE (LangChain remote); "
"'websocket' for raw WebSocket."
),
)
mcp_host: str = Field("0.0.0.0", description="Bind host (sse / websocket modes)")
mcp_port: int = Field(8765, description="Bind port (sse / websocket modes)")
# ------------------------------------------------------------------
# Logging
# ------------------------------------------------------------------
log_level: str = Field("INFO", description="Logging level (DEBUG/INFO/WARNING/ERROR)")
log_file: str = Field("mcp_server.log", description="Path to the rotating log file")
# ------------------------------------------------------------------
# Path security (防止路径注入攻击)
# ------------------------------------------------------------------
path_security_enabled: bool = Field(
True,
description="Enable path security validation for file operations"
)
allowed_dirs: Optional[List[str]] = Field(
None,
description=(
"List of allowed directories for file access. "
"If None, uses platform-specific defaults (user home, Documents, etc.). "
"Example: ['D:\\data', 'C:\\Users\\admin\\profiling']"
)
)
allow_relative_paths: bool = Field(
False,
description="Allow relative paths (not recommended for security)"
)
# ------------------------------------------------------------------
# Derived helpers
# ------------------------------------------------------------------
@property
def cpp_backend_url(self) -> str:
return f"ws://{self.cpp_backend_host}:{self.cpp_backend_port}/"
settings = Settings()