Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ecb1dad

Browse files
Merge pull request #4 from caomengxuan666/dynamic_config
feat(config): Refactor configuration system and add hot reload feature
2 parents c43a8f5 + e557f94 commit ecb1dad

File tree

8 files changed

+532
-373
lines changed

8 files changed

+532
-373
lines changed

‎cmake/EnablePython.cmake‎

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ function(target_enable_python target_name)
55
find_package(Python COMPONENTS Interpreter Development)
66
if(Python_FOUND)
77
target_include_directories(${target_name} PUBLIC ${Python_INCLUDE_DIRS})
8-
if(WIN32)
9-
# On Windows, we need to link to python library
10-
# But we should avoid linking conflicts, so we use the imported targets
11-
if(TARGET Python::Python)
12-
target_link_libraries(${target_name} PUBLIC Python::Python)
13-
else()
14-
target_link_libraries(${target_name} PUBLIC ${Python_LIBRARIES})
15-
endif()
8+
# Link to python library on all platforms, not just Windows
9+
if(TARGET Python::Python)
10+
target_link_libraries(${target_name} PUBLIC Python::Python)
11+
else()
12+
target_link_libraries(${target_name} PUBLIC ${Python_LIBRARIES})
1613
endif()
1714
else()
1815
message(WARNING "Python not found. Disabling Python plugin support.")
@@ -30,14 +27,11 @@ function(enable_python)
3027
message(STATUS "Python include dirs: ${Python_INCLUDE_DIRS}")
3128
message(STATUS "Python libraries: ${Python_LIBRARIES}")
3229

33-
if(WIN32)
34-
# On Windows, link to python library for the main executable
35-
# But we should avoid linking conflicts, so we use the imported targets
36-
if(TARGET Python::Python)
37-
target_link_libraries(mcp-server++ PRIVATE Python::Python)
38-
else()
39-
target_link_libraries(mcp-server++ PRIVATE ${Python_LIBRARIES})
40-
endif()
30+
# Link to python library for the main executable on all platforms
31+
if(TARGET Python::Python)
32+
target_link_libraries(mcp-server++ PRIVATE Python::Python)
33+
else()
34+
target_link_libraries(mcp-server++ PRIVATE ${Python_LIBRARIES})
4135
endif()
4236
else()
4337
message(WARNING "Python not found. Disabling Python plugin support.")

‎config/config.hpp‎

Lines changed: 293 additions & 193 deletions
Large diffs are not rendered by default.

‎config/config_observer.hpp‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
namespace mcp {
4+
namespace config {
5+
struct GlobalConfig;
6+
class ConfigObserver {
7+
public:
8+
virtual ~ConfigObserver() = default;
9+
virtual void onConfigReloaded(const mcp::config::GlobalConfig &newConfig) = 0;
10+
};
11+
}// namespace config
12+
}// namespace mcp

‎scripts/format.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ def main():
119119
default_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) if len(sys.argv) <= 1 else sys.argv[1]
120120
root_dir = sys.argv[1] if len(sys.argv) > 1 else default_root
121121
suffixes = os.environ.get('SUFFIXES', '.h .cc .cpp .hpp .cxx .hxx .C').split()
122-
parallel_jobs = int(os.environ.get('PARALLEL_JOBS', multiprocessing.cpu_count()))
122+
123+
# Limit parallel jobs to avoid Windows multiprocessing limitations
124+
# Windows has a limit of 63 handles in WaitForMultipleObjects
125+
max_parallel_jobs = 60
126+
parallel_jobs = min(int(os.environ.get('PARALLEL_JOBS', multiprocessing.cpu_count())), max_parallel_jobs)
123127

124128
# Check for clang-format
125129
clang_format = find_clang_format()

‎src/business/python_plugin_instance.h‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace mcp::business {
3737
* @return True if virtual environment is enabled, false otherwise
3838
*/
3939
virtual bool use_virtual_env() const = 0;
40-
40+
4141
protected:
4242
/**
4343
* Detect Python version by trying common versions from 3.6 to 3.13
@@ -46,23 +46,22 @@ namespace mcp::business {
4646
std::string detect_python_version() const {
4747
// Try common Python versions from 3.13 down to 3.6
4848
static const std::vector<std::string> versions = {
49-
"3.13", "3.12", "3.11", "3.10", "3.9", "3.8", "3.7", "3.6"
50-
};
51-
49+
"3.13", "3.12", "3.11", "3.10", "3.9", "3.8", "3.7", "3.6"};
50+
5251
// In a real implementation, we would detect the actual Python version
5352
// For now, we default to "3.9" as a reasonable fallback
5453
// A more sophisticated implementation might check the filesystem or use Python API
5554
return "3.9";
5655
}
57-
56+
5857
#ifdef _MSC_VER
5958
/**
6059
* Secure way to get environment variable on Windows
6160
* @param name Environment variable name
6261
* @return Environment variable value or empty string if not found
6362
*/
64-
std::string get_env_var(const char* name) const {
65-
char* value = nullptr;
63+
std::string get_env_var(const char *name) const {
64+
char *value = nullptr;
6665
size_t len = 0;
6766
if (_dupenv_s(&value, &len, name) == 0 && value != nullptr) {
6867
std::string result(value);
@@ -77,7 +76,7 @@ namespace mcp::business {
7776
* @param name Environment variable name
7877
* @return Environment variable value or nullptr if not found
7978
*/
80-
const char* get_env_var(const char* name) const {
79+
const char *get_env_var(const char *name) const {
8180
return std::getenv(name);
8281
}
8382
#endif
@@ -95,17 +94,17 @@ namespace mcp::business {
9594
// Usually Python is in the PATH, so we can just use "python"
9695
return "python";
9796
#else
98-
return "/usr/bin/python3";// Default system Python path
97+
return "/usr/bin/python3";// Default system Python path
9998
#endif
10099
}
101100

102101
std::string get_python_path() const override {
103102
#ifdef _MSC_VER
104103
// On Windows, Python packages are typically available in the PATH
105104
// or can be found relative to the Python executable
106-
return "";// Empty string means use default Python path
105+
return "";// Empty string means use default Python path
107106
#else
108-
return "/usr/lib/python3/dist-packages";// System Python packages path
107+
return "/usr/lib/python3/dist-packages";// System Python packages path
109108
#endif
110109
}
111110

@@ -141,7 +140,7 @@ namespace mcp::business {
141140
*/
142141
class UvEnvConfig : public PythonEnvironmentConfig {
143142
public:
144-
explicit UvEnvConfig(const std::string& venv_path) : venv_path_(venv_path) {}
143+
explicit UvEnvConfig(const std::string &venv_path) : venv_path_(venv_path) {}
145144

146145
std::string get_python_interpreter_path() const override {
147146
return venv_path_ + "/bin/python";
@@ -181,6 +180,6 @@ namespace mcp::business {
181180
std::mutex cache_mutex_;
182181
};
183182

184-
}// namespace mcp::business
183+
}// namespace mcp::business
185184

186185
#endif// PYTHON_PLUGIN_INSTANCE_H

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /