Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions cmake/EnablePython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ function(target_enable_python target_name)
find_package(Python COMPONENTS Interpreter Development)
if(Python_FOUND)
target_include_directories(${target_name} PUBLIC ${Python_INCLUDE_DIRS})
if(WIN32)
# On Windows, we need to link to python library
# But we should avoid linking conflicts, so we use the imported targets
if(TARGET Python::Python)
target_link_libraries(${target_name} PUBLIC Python::Python)
else()
target_link_libraries(${target_name} PUBLIC ${Python_LIBRARIES})
endif()
# Link to python library on all platforms, not just Windows
if(TARGET Python::Python)
target_link_libraries(${target_name} PUBLIC Python::Python)
else()
target_link_libraries(${target_name} PUBLIC ${Python_LIBRARIES})
endif()
else()
message(WARNING "Python not found. Disabling Python plugin support.")
Expand All @@ -30,14 +27,11 @@ function(enable_python)
message(STATUS "Python include dirs: ${Python_INCLUDE_DIRS}")
message(STATUS "Python libraries: ${Python_LIBRARIES}")

if(WIN32)
# On Windows, link to python library for the main executable
# But we should avoid linking conflicts, so we use the imported targets
if(TARGET Python::Python)
target_link_libraries(mcp-server++ PRIVATE Python::Python)
else()
target_link_libraries(mcp-server++ PRIVATE ${Python_LIBRARIES})
endif()
# Link to python library for the main executable on all platforms
if(TARGET Python::Python)
target_link_libraries(mcp-server++ PRIVATE Python::Python)
else()
target_link_libraries(mcp-server++ PRIVATE ${Python_LIBRARIES})
endif()
else()
message(WARNING "Python not found. Disabling Python plugin support.")
Expand Down
486 changes: 293 additions & 193 deletions config/config.hpp

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions config/config_observer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

namespace mcp {
namespace config {
struct GlobalConfig;
class ConfigObserver {
public:
virtual ~ConfigObserver() = default;
virtual void onConfigReloaded(const mcp::config::GlobalConfig &newConfig) = 0;
};
}// namespace config
}// namespace mcp
6 changes: 5 additions & 1 deletion scripts/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ def main():
default_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) if len(sys.argv) <= 1 else sys.argv[1]
root_dir = sys.argv[1] if len(sys.argv) > 1 else default_root
suffixes = os.environ.get('SUFFIXES', '.h .cc .cpp .hpp .cxx .hxx .C').split()
parallel_jobs = int(os.environ.get('PARALLEL_JOBS', multiprocessing.cpu_count()))

# Limit parallel jobs to avoid Windows multiprocessing limitations
# Windows has a limit of 63 handles in WaitForMultipleObjects
max_parallel_jobs = 60
parallel_jobs = min(int(os.environ.get('PARALLEL_JOBS', multiprocessing.cpu_count())), max_parallel_jobs)

# Check for clang-format
clang_format = find_clang_format()
Expand Down
25 changes: 12 additions & 13 deletions src/business/python_plugin_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace mcp::business {
* @return True if virtual environment is enabled, false otherwise
*/
virtual bool use_virtual_env() const = 0;

protected:
/**
* Detect Python version by trying common versions from 3.6 to 3.13
Expand All @@ -46,23 +46,22 @@ namespace mcp::business {
std::string detect_python_version() const {
// Try common Python versions from 3.13 down to 3.6
static const std::vector<std::string> versions = {
"3.13", "3.12", "3.11", "3.10", "3.9", "3.8", "3.7", "3.6"
};

"3.13", "3.12", "3.11", "3.10", "3.9", "3.8", "3.7", "3.6"};

// In a real implementation, we would detect the actual Python version
// For now, we default to "3.9" as a reasonable fallback
// A more sophisticated implementation might check the filesystem or use Python API
return "3.9";
}

#ifdef _MSC_VER
/**
* Secure way to get environment variable on Windows
* @param name Environment variable name
* @return Environment variable value or empty string if not found
*/
std::string get_env_var(const char* name) const {
char* value = nullptr;
std::string get_env_var(const char *name) const {
char *value = nullptr;
size_t len = 0;
if (_dupenv_s(&value, &len, name) == 0 && value != nullptr) {
std::string result(value);
Expand All @@ -77,7 +76,7 @@ namespace mcp::business {
* @param name Environment variable name
* @return Environment variable value or nullptr if not found
*/
const char* get_env_var(const char* name) const {
const char *get_env_var(const char *name) const {
return std::getenv(name);
}
#endif
Expand All @@ -95,17 +94,17 @@ namespace mcp::business {
// Usually Python is in the PATH, so we can just use "python"
return "python";
#else
return "/usr/bin/python3"; // Default system Python path
return "/usr/bin/python3";// Default system Python path
#endif
}

std::string get_python_path() const override {
#ifdef _MSC_VER
// On Windows, Python packages are typically available in the PATH
// or can be found relative to the Python executable
return ""; // Empty string means use default Python path
return "";// Empty string means use default Python path
#else
return "/usr/lib/python3/dist-packages"; // System Python packages path
return "/usr/lib/python3/dist-packages";// System Python packages path
#endif
}

Expand Down Expand Up @@ -141,7 +140,7 @@ namespace mcp::business {
*/
class UvEnvConfig : public PythonEnvironmentConfig {
public:
explicit UvEnvConfig(const std::string& venv_path) : venv_path_(venv_path) {}
explicit UvEnvConfig(const std::string &venv_path) : venv_path_(venv_path) {}

std::string get_python_interpreter_path() const override {
return venv_path_ + "/bin/python";
Expand Down Expand Up @@ -181,6 +180,6 @@ namespace mcp::business {
std::mutex cache_mutex_;
};

} // namespace mcp::business
}// namespace mcp::business

#endif// PYTHON_PLUGIN_INSTANCE_H
Loading
Loading