-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_env.py
130 lines (109 loc) · 4.55 KB
/
setup_env.py
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python3
"""
Environment Setup Script for MCP Tool Kit
This script helps you set up environment variables for the MCP Tool Kit
by creating or updating a .env file in the repository.
Usage:
python setup_env.py
"""
import os
import sys
from pathlib import Path
def main():
print("MCP Tool Kit Environment Setup")
print("==============================")
print("This script will help you set up environment variables for the MCP Tool Kit.")
print("It will create or update a .env file in the repository root.")
print()
# Check if .env file exists
env_file = Path(".env")
existing_vars = {}
if env_file.exists():
print(f"Found existing .env file at {env_file.absolute()}")
# Parse existing variables
with open(env_file, 'r') as f:
for line in f:
line = line.strip()
if line and not line.startswith('#') and '=' in line:
key, value = line.split('=', 1)
existing_vars[key.strip()] = value.strip()
print(f"Found {len(existing_vars)} existing variables.")
print()
update = input(
"Do you want to update the existing .env file? (y/n): ").lower()
if update != 'y':
print("Setup canceled. Existing .env file was not modified.")
return
# Define required environment variables with descriptions
env_vars = {
"BRAVE_API_KEY": {
"description": "API key for Brave Search functionality",
"required": True,
"default": existing_vars.get("BRAVE_API_KEY", ""),
"example": "YOUR_BRAVE_API_KEY",
"url": "https://brave.com/search/api/"
},
"NEWS_API_KEY": {
"description": "API key for NewsAPI functionality",
"required": True,
"default": existing_vars.get("NEWS_API_KEY", ""),
"example": "YOUR_NEWS_API_KEY",
"url": "https://newsapi.org/"
},
"FRED_API_KEY": {
"description": "API key for FRED economic data API",
"required": True,
"default": existing_vars.get("FRED_API_KEY", ""),
"example": "YOUR_FRED_API_KEY",
"url": "https://fred.stlouisfed.org/docs/api/api_key.html"
},
"STREAMLIT_APPS_DIR": {
"description": "Directory for Streamlit applications",
"required": False,
"default": existing_vars.get("STREAMLIT_APPS_DIR", os.path.expanduser("~/streamlit_apps")),
"example": "/path/to/streamlit/apps"
},
"MCP_FILESYSTEM_DIRS": {
"description": "Comma-separated list of directories that can be accessed by filesystem tools",
"required": False,
"default": existing_vars.get("MCP_FILESYSTEM_DIRS", os.path.expanduser("~")),
"example": "/path/to/dir1,/path/to/dir2"
},
}
# Collect values from user
new_values = {}
print("\nPlease enter values for the following environment variables:")
print("(Press Enter to use default or existing value shown in brackets)")
print()
for key, info in env_vars.items():
default = info["default"]
default_display = f"[{default}]" if default else ""
# Show URL for API keys that need to be obtained
url_info = f" (Get it from: {info['url']})" if "url" in info else ""
while True:
prompt = f"{key}: {info['description']}{url_info} {default_display}: "
value = input(prompt).strip()
# Use default if empty
if not value and default:
value = default
# Validate required fields
if info["required"] and not value:
print(f"Error: {key} is required.")
continue
new_values[key] = value
break
# Write to .env file
print("\nWriting environment variables to .env file...")
with open(env_file, 'w') as f:
f.write("# Environment variables for MCP Tool Kit\n")
f.write("# Generated by setup_env.py\n\n")
for key, info in env_vars.items():
if key in new_values and new_values[key]:
f.write(f"# {info['description']}\n")
f.write(f"{key}={new_values[key]}\n\n")
print(
f"Environment setup complete. Configuration saved to {env_file.absolute()}")
print("\nYou can manually edit this file at any time to update your configuration.")
print("Remember to restart the MCP server after changing environment variables.")
if __name__ == "__main__":
main()