This repository was archived by the owner on May 26, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcp_devtools_cli.py
More file actions
69 lines (60 loc) · 2.25 KB
/
Copy pathmcp_devtools_cli.py
File metadata and controls
69 lines (60 loc) · 2.25 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
import uvicorn
import os
import argparse
import tomllib # Added tomllib import
def get_project_version() -> str:
"""
Reads the project version from pyproject.toml.
Assumes pyproject.toml is in the same directory as the script.
"""
script_dir = os.path.dirname(__file__)
# Construct path to pyproject.toml, assuming it's in the same directory
pyproject_path = os.path.join(script_dir, 'pyproject.toml')
if not os.path.exists(pyproject_path):
return "unknown"
try:
with open(pyproject_path, "rb") as f:
pyproject_data = tomllib.load(f)
version = pyproject_data.get("project", {}).get("version")
if version:
return str(version)
except Exception:
# Catch any errors during file reading or TOML parsing
pass
return "unknown"
def main():
"""
CLI entrypoint for the MCP DevTools server.
Conditionally enables reload based on an environment variable.
"""
parser = argparse.ArgumentParser(description="Run the MCP DevTools Server.")
parser.add_argument('-p', '--port', type=int, help='Port to run the server on.')
parser.add_argument('-v', '--version', action='version',
version=f'mcp-devtools v{get_project_version()}')
args = parser.parse_args()
# Use port from args, then .env, then default
# The server scripts create a .env file.
from dotenv import load_dotenv
load_dotenv()
port = args.port or int(os.getenv("MCP_PORT", 1337))
host = os.getenv("MCP_HOST", "127.0.0.1")
# Check for the reload environment variable.
# This will be 'false' by default when running via 'uvx'.
reload_enabled = os.getenv('MCP_DEVTOOLS_RELOAD', 'false').lower() in ('true', '1', 't')
# Get and print the server version
server_version = get_project_version()
print(f"MCP DevTools Server v{server_version}")
print(f"DevTools MCP server listening at http://{host}:{port}/sse")
if reload_enabled:
print("Auto-reloading is enabled.")
else:
print("Auto-reloading is disabled.")
uvicorn.run(
"server:app",
host=host,
port=port,
reload=reload_enabled, # Set reload conditionally
log_level="info"
)
if __name__ == "__main__":
main()