Skip to content

Commit 1ad9814

Browse files
committed
feat: Add documentation and scripts for local development environment setup
1 parent c83f0e4 commit 1ad9814

File tree

4 files changed

+149
-11
lines changed

4 files changed

+149
-11
lines changed

DEV_ENVIRONMENT.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# MCPM Local Development Environment
2+
3+
This document explains how to test MCPM CLI with local server data during development.
4+
5+
## Environment Variable Configuration
6+
7+
The MCPM CLI can now be configured to use a custom repository URL through the `MCPM_REPO_URL` environment variable.
8+
9+
### Default Behavior
10+
11+
By default, MCPM fetches server data from: `https://mcpm.sh/api/servers.json`
12+
13+
### Override with Environment Variable
14+
15+
You can override the repository URL by setting the `MCPM_REPO_URL` environment variable:
16+
17+
```bash
18+
# Use local file
19+
export MCPM_REPO_URL="file:///path/to/local/servers.json"
20+
21+
# Use local development server
22+
export MCPM_REPO_URL="http://localhost:4000/api/servers.json"
23+
24+
# Use custom remote URL
25+
export MCPM_REPO_URL="https://your-custom-api.com/servers.json"
26+
```
27+
28+
## Testing with Local Server Data
29+
30+
### Method 1: Manual Environment Variable
31+
32+
1. Generate local servers.json:
33+
34+
```bash
35+
./scripts/prepare.sh _dev
36+
```
37+
38+
2. Run CLI with local data:
39+
```bash
40+
MCPM_REPO_URL="file://${PWD}/_dev/api/servers.json" python3 test_cli.py search
41+
```
42+
43+
### Method 2: Helper Script (Recommended)
44+
45+
Use the provided helper script that automatically handles setup:
46+
47+
```bash
48+
# Make the script executable (first time only)
49+
chmod +x test_cli_local.sh
50+
51+
# Run any CLI command with local data
52+
./test_cli_local.sh search
53+
./test_cli_local.sh info figma
54+
./test_cli_local.sh search --table
55+
```
56+
57+
The helper script will:
58+
59+
- Automatically generate `_dev/api/servers.json` if it doesn't exist
60+
- Set the appropriate `MCPM_REPO_URL` environment variable
61+
- Run the CLI with local server data
62+
63+
## Supported URL Formats
64+
65+
- **HTTP/HTTPS URLs**: `https://api.example.com/servers.json`
66+
- **File URLs**: `file:///absolute/path/to/servers.json`
67+
68+
## Use Cases
69+
70+
1. **Testing local server definitions** before submitting to the registry
71+
2. **Development with offline environments**
72+
3. **Using custom/private server registries**
73+
4. **Testing API changes** without affecting production
74+
75+
## File Format
76+
77+
The local `servers.json` file should follow the same format as the remote API:
78+
79+
```json
80+
{
81+
"server-name": {
82+
"name": "server-name",
83+
"description": "Server description",
84+
"categories": ["category1"],
85+
"tags": ["tag1", "tag2"]
86+
// ... other server metadata
87+
}
88+
}
89+
```
90+
91+
This file is automatically generated from the individual JSON files in `mcp-registry/servers/` by the prepare script.

src/mcpm/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def print_logo():
4545
" ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ",
4646
"",
4747
f"v{__version__}",
48-
"Open Source. Forever Free.",
48+
"Melio MCP Installer",
4949
"Built with ❤️ by Path Integral Institute",
5050
]
5151

src/mcpm/utils/repository.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
logger = logging.getLogger(__name__)
1717

18-
# Default repository URL
19-
DEFAULT_REPO_URL = "https://mcpm.sh/api/servers.json"
18+
# Default repository URL - can be overridden with MCPM_REPO_URL environment variable
19+
DEFAULT_REPO_URL = os.environ.get("MCPM_REPO_URL", "https://mcpm.sh/api/servers.json")
2020

2121
# Default cache file path
2222
DEFAULT_CACHE_FILE = os.path.join(DEFAULT_CONFIG_DIR, "servers_cache.json")
@@ -91,16 +91,28 @@ def _fetch_servers(self, force_refresh: bool = False) -> Dict[str, Dict[str, Any
9191
return self.servers_cache
9292

9393
try:
94-
response = requests.get(self.repo_url)
95-
response.raise_for_status()
96-
self.servers_cache = response.json()
97-
self.last_refresh = datetime.now()
94+
# Handle file:// URLs for local development
95+
if self.repo_url.startswith("file://"):
96+
file_path = self.repo_url[7:] # Remove 'file://' prefix
97+
with open(file_path, "r", encoding="utf-8") as f:
98+
self.servers_cache = json.load(f)
99+
self.last_refresh = datetime.now()
100+
101+
# Save the updated cache to file
102+
self._save_cache_to_file()
103+
104+
return self.servers_cache
105+
else:
106+
response = requests.get(self.repo_url)
107+
response.raise_for_status()
108+
self.servers_cache = response.json()
109+
self.last_refresh = datetime.now()
98110

99-
# Save the updated cache to file
100-
self._save_cache_to_file()
111+
# Save the updated cache to file
112+
self._save_cache_to_file()
101113

102-
return self.servers_cache
103-
except requests.RequestException as e:
114+
return self.servers_cache
115+
except (requests.RequestException, FileNotFoundError, json.JSONDecodeError) as e:
104116
logger.error(f"Failed to fetch servers from {self.repo_url}: {e}")
105117
# Return empty dict if we can't fetch and have no cache
106118
return self.servers_cache or {}

test_cli_local.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# MCPM Local Development CLI Helper
4+
# This script runs the CLI using local server data from mcp-registry/servers
5+
6+
# Colors for output
7+
GREEN='\033[0;32m'
8+
BLUE='\033[0;34m'
9+
NC='\033[0m' # No Color
10+
11+
# Get the absolute path to the project directory
12+
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13+
14+
# Path to local servers.json file
15+
LOCAL_SERVERS_JSON="file://${PROJECT_DIR}/_dev/api/servers.json"
16+
17+
# Check if _dev/api/servers.json exists
18+
if [ ! -f "${PROJECT_DIR}/_dev/api/servers.json" ]; then
19+
echo -e "${BLUE}Local servers.json not found. Generating it now...${NC}"
20+
21+
# Run prepare script to generate local servers.json
22+
if ! ./scripts/prepare.sh _dev; then
23+
echo "❌ Failed to generate local servers.json file"
24+
exit 1
25+
fi
26+
27+
echo -e "${GREEN}✅ Local servers.json generated successfully!${NC}"
28+
fi
29+
30+
# Run the CLI with local repository URL
31+
echo -e "${BLUE}Running MCPM CLI with local server data...${NC}"
32+
echo -e "${BLUE}Repository URL: ${LOCAL_SERVERS_JSON}${NC}"
33+
echo ""
34+
35+
MCPM_REPO_URL="${LOCAL_SERVERS_JSON}" python3 test_cli.py "$@"

0 commit comments

Comments
 (0)