@@ -803,6 +803,41 @@ function registerResources() {
803803 ) ;
804804}
805805
806+ /**
807+ * Starts the PM2 MCP server, exposing PM2 controls and state as Model Context Protocol resources.
808+ *
809+ * @param {Object } [options={}] - Configuration options for the MCP server.
810+ * @param {'http'|'stdio' } [options.transportType='http'] - The transport type to use ('http' or 'stdio').
811+ * @param {number } [options.port=0] - The port to listen on (for HTTP transport).
812+ * @param {string } [options.host='127.0.0.1'] - The host to bind to (for HTTP transport).
813+ * @param {string } [options.path] - The path for UNIX socket (for HTTP transport).
814+ * @param {Object } [options.env] - Environment variables to set (merged into process.env).
815+ * @param {boolean } [options.attachProcessHandlers=true] - Whether to register process signal handlers.
816+ * @param {...any } [options.other] - Other options passed to the transport/server.
817+ *
818+ * @returns {Promise<Object> } Resolves to an object containing:
819+ * - {McpServer} server: The MCP server instance.
820+ * - {Object} transport: The transport instance (HTTP or stdio).
821+ * - {http.Server|null} httpServer: The HTTP server instance (if applicable).
822+ * - {Object} address: The address information for the server.
823+ *
824+ * @example
825+ * // Start MCP server with default options
826+ * const { server, transport, httpServer, address } = await startMcpServer();
827+ *
828+ * // Start MCP server on custom port
829+ * const { server } = await startMcpServer({ port: 8080 });
830+ *
831+ * // Start MCP server with custom environment variables
832+ * await startMcpServer({ env: { PM2_HOME: '/custom/path' } });
833+ *
834+ * @sideEffects
835+ * - Modifies process.env if options.env is provided.
836+ * - May register process signal handlers if options.attachProcessHandlers is true.
837+ * - Starts network listeners (HTTP or stdio) as specified.
838+ *
839+ * @throws {Error } If the server fails to start or required resources are unavailable.
840+ */
806841async function startMcpServer ( options = { } ) {
807842 const { transport, httpServer, address } = createTransport ( options ) ;
808843
0 commit comments