humanus.cpp/server/mcp_tool_server.cpp

52 lines
1.3 KiB
C++
Raw Normal View History

2025-03-16 17:17:01 +08:00
/**
* @file mcp_server_main.cpp
2025-03-19 18:44:54 +08:00
* @brief Humanus MCP Server Implementation
2025-03-16 17:17:01 +08:00
*
2025-03-19 18:44:54 +08:00
* This file implements the Humanus MCP server that provides tool invocation functionality.
2025-03-17 16:35:11 +08:00
* Currently implements the PythonExecute tool.
2025-03-16 17:17:01 +08:00
*/
2025-03-19 18:44:54 +08:00
#include "mcp_server.h"
#include "mcp_tool.h"
#include "mcp_resource.h"
2025-03-16 17:17:01 +08:00
#include <iostream>
#include <string>
#include <memory>
#include <filesystem>
2025-03-17 16:35:11 +08:00
// Import Python execution tool
2025-03-16 17:17:01 +08:00
extern void register_python_execute_tool(mcp::server& server);
int main(int argc, char* argv[]) {
2025-04-12 21:18:35 +08:00
int port = 8895;
if (argc == 2) {
try {
port = std::stoi(argv[1]);
} catch (...) {
std::cerr << "Invalid port number: " << argv[1] << std::endl;
return 1;
}
}
2025-03-17 16:35:11 +08:00
// Create and configure server
mcp::server server("localhost", port);
2025-04-12 21:18:35 +08:00
server.set_server_info("humanus_tool", "0.1.0");
2025-03-16 17:17:01 +08:00
2025-03-17 16:35:11 +08:00
// Set server capabilities
2025-03-16 17:17:01 +08:00
mcp::json capabilities = {
{"tools", mcp::json::object()}
};
server.set_capabilities(capabilities);
2025-03-17 16:35:11 +08:00
// Register Python execution tool
2025-03-16 17:17:01 +08:00
register_python_execute_tool(server);
2025-03-17 16:35:11 +08:00
// Start server
std::cout << "Starting Humanus MCP server at localhost:" << port << "..." << std::endl;
2025-03-17 16:35:11 +08:00
std::cout << "Press Ctrl+C to stop server" << std::endl;
server.start(true); // Blocking mode
2025-03-16 17:17:01 +08:00
return 0;
2025-03-17 16:35:11 +08:00
}