Coverage for mcpgateway / plugins / framework / external / unix / server / runtime.py: 100%

24 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-09 03:05 +0000

1# -*- coding: utf-8 -*- 

2"""Location: ./mcpgateway/plugins/framework/external/unix/server/runtime.py 

3Copyright 2025 

4SPDX-License-Identifier: Apache-2.0 

5Authors: Teryl Taylor 

6 

7Entry point for running the Unix socket plugin server. 

8 

9Usage: 

10 python -m mcpgateway.plugins.framework.external.unix.server.runtime 

11 

12Environment variables: 

13 PLUGINS_CONFIG_PATH: Path to plugin configuration file 

14 PLUGINS_UNIX_SOCKET_PATH: Path for Unix socket (default: /tmp/mcpgateway-plugins.sock) 

15 

16Examples: 

17 Run with default settings: 

18 

19 $ PLUGINS_CONFIG_PATH=plugins/config.yaml python -m mcpgateway.plugins.framework.external.unix.server.runtime 

20 

21 Run with custom socket path: 

22 

23 $ PLUGINS_UNIX_SOCKET_PATH=/tmp/my-plugins.sock python -m mcpgateway.plugins.framework.external.unix.server.runtime 

24""" 

25 

26# Standard 

27import asyncio 

28import logging 

29import os 

30import sys 

31 

32# First-Party 

33from mcpgateway.plugins.framework.external.unix.server.server import run_server 

34from mcpgateway.plugins.framework.settings import get_settings 

35 

36# Configure logging 

37logging.basicConfig( 

38 level=logging.INFO, 

39 format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", 

40 stream=sys.stderr, # Log to stderr to keep stdout clean for coordination 

41) 

42 

43logger = logging.getLogger(__name__) 

44 

45 

46async def run() -> None: 

47 """Main entry point for the Unix socket server.""" 

48 s = get_settings() 

49 config_path = s.config_path or os.path.join(".", "resources", "plugins", "config.yaml") 

50 socket_path = s.unix_socket_path or "/tmp/mcpgateway-plugins.sock" # nosec B108 - configurable via env var 

51 

52 logger.info("Starting Unix socket plugin server") 

53 logger.info(" Config: %s", config_path) 

54 logger.info(" Socket: %s", socket_path) 

55 

56 await run_server(config_path=config_path, socket_path=socket_path) 

57 

58 

59def main() -> None: 

60 """CLI entry point.""" 

61 try: 

62 asyncio.run(run()) 

63 except KeyboardInterrupt: 

64 logger.info("Server interrupted") 

65 except Exception as e: 

66 logger.exception("Server error: %s", e) 

67 sys.exit(1) 

68 

69 

70if __name__ == "__main__": 

71 main()