Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
93 lines (76 loc) · 2.39 KB
/
Copy pathmain.py
File metadata and controls
93 lines (76 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python3
"""
OPNsense MCP Server entry point.
This module provides a simple entry point for running the OPNsense MCP server.
It redirects to the actual MCP server implementation in opnsense_mcp.server.
"""
import argparse
import os
from typing import Any
from opnsense_mcp.utils.logging import setup_logging
def build_http_server() -> Any:
"""Build the FastMCP server for an HTTP transport, bearer auth enforced.
Both checks run before the server is built, so a misconfigured container
exits instead of listening.
"""
from opnsense_mcp.fastmcp_server import build_mcp_server
from opnsense_mcp.server import (
http_auth_from_env,
require_live_credentials_or_mock_flag,
)
auth = http_auth_from_env()
require_live_credentials_or_mock_flag()
mcp = build_mcp_server()
mcp.auth = auth
return mcp
def main() -> None:
"""
Start the OPNsense MCP Server.
Supports stdio (default) and streamable-http transports.
"""
parser = argparse.ArgumentParser(description="OPNsense MCP Server")
parser.add_argument("--log-file", type=str, help="Path to log file (optional)")
parser.add_argument(
"--log-level",
type=str,
default="INFO",
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
help="Logging level",
)
parser.add_argument(
"--transport",
type=str,
default="stdio",
choices=["stdio", "streamable-http", "http", "sse"],
help="MCP transport protocol (default: stdio)",
)
parser.add_argument(
"--host",
type=str,
default="0.0.0.0",
help="Host to bind for HTTP transport (default: 0.0.0.0)",
)
parser.add_argument(
"--port",
type=int,
default=8765,
help="Port to bind for HTTP transport (default: 8765)",
)
args = parser.parse_args()
setup_logging(args.log_file, args.log_level)
os.environ["PYTHONUNBUFFERED"] = "1"
os.environ["PYTHONIOENCODING"] = "utf-8"
if args.transport == "stdio":
os.environ["MCP_TRANSPORT"] = "stdio"
from opnsense_mcp.server import main as mcp_main
mcp_main()
else:
mcp = build_http_server()
mcp.run(
transport=args.transport,
host=args.host,
port=args.port,
show_banner=False,
)
if __name__ == "__main__":
main()