Update script: add --limit argument, progress logging, and JSON string conversion for capabilities
Browse files- scripts/mcp_clients_job.py +41 -8
scripts/mcp_clients_job.py
CHANGED
|
@@ -9,14 +9,15 @@
|
|
| 9 |
"""
|
| 10 |
Scheduled job to extract and update MCP clients dataset.
|
| 11 |
This script runs via HF Jobs to keep the dataset fresh.
|
|
|
|
|
|
|
|
|
|
| 12 |
"""
|
| 13 |
|
| 14 |
import sys
|
| 15 |
-
from datetime import datetime
|
| 16 |
-
|
| 17 |
-
# Import the extraction logic
|
| 18 |
-
import argparse
|
| 19 |
import json
|
|
|
|
|
|
|
| 20 |
|
| 21 |
from datasets import Dataset, Features, Value
|
| 22 |
|
|
@@ -40,16 +41,25 @@ def create_dataset_from_clients(clients_list):
|
|
| 40 |
features = Features({
|
| 41 |
'name': Value('string'),
|
| 42 |
'version': Value('string'),
|
| 43 |
-
'capabilities': Value('
|
| 44 |
'last_seen': Value('string'),
|
| 45 |
})
|
| 46 |
|
| 47 |
records = []
|
| 48 |
for client in clients_list:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
records.append({
|
| 50 |
'name': client['name'],
|
| 51 |
'version': client['version'],
|
| 52 |
-
'capabilities':
|
| 53 |
'last_seen': client['last_seen'],
|
| 54 |
})
|
| 55 |
|
|
@@ -57,7 +67,14 @@ def create_dataset_from_clients(clients_list):
|
|
| 57 |
|
| 58 |
|
| 59 |
def main():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
print(f"[{datetime.now().isoformat()}] Starting MCP clients extraction...", file=sys.stderr)
|
|
|
|
|
|
|
| 61 |
|
| 62 |
unique_clients = {}
|
| 63 |
|
|
@@ -68,11 +85,23 @@ def main():
|
|
| 68 |
total_rows = 0
|
| 69 |
skipped_deletes = 0
|
| 70 |
skipped_other = 0
|
|
|
|
| 71 |
|
| 72 |
for batch in sessions_ds.iter(batch_size=1000):
|
| 73 |
batch_len = len(batch['name'])
|
| 74 |
total_rows += batch_len
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
for i in range(batch_len):
|
| 77 |
method_name = batch['methodName'][i] if 'methodName' in batch else None
|
| 78 |
|
|
@@ -107,7 +136,11 @@ def main():
|
|
| 107 |
'last_seen': time_str
|
| 108 |
}
|
| 109 |
|
|
|
|
|
|
|
|
|
|
| 110 |
print(f"[{datetime.now().isoformat()}] Processing complete: {total_rows:,} rows", file=sys.stderr)
|
|
|
|
| 111 |
print(f"Skipped {skipped_deletes:,} deletes, {skipped_other:,} non-initialize events", file=sys.stderr)
|
| 112 |
print(f"Found {len(unique_clients):,} unique client configurations", file=sys.stderr)
|
| 113 |
|
|
@@ -123,11 +156,11 @@ def main():
|
|
| 123 |
dataset = create_dataset_from_clients(sorted_clients)
|
| 124 |
|
| 125 |
dataset.push_to_hub(
|
| 126 |
-
repo_id=
|
| 127 |
commit_message=f"Update MCP clients dataset ({datetime.now().strftime('%Y-%m-%d %H:%M')})",
|
| 128 |
)
|
| 129 |
|
| 130 |
-
print(f"[{datetime.now().isoformat()}] Successfully pushed {len(sorted_clients):,} clients to
|
| 131 |
|
| 132 |
|
| 133 |
if __name__ == '__main__':
|
|
|
|
| 9 |
"""
|
| 10 |
Scheduled job to extract and update MCP clients dataset.
|
| 11 |
This script runs via HF Jobs to keep the dataset fresh.
|
| 12 |
+
|
| 13 |
+
Usage:
|
| 14 |
+
uv run mcp_clients_job.py [--limit N]
|
| 15 |
"""
|
| 16 |
|
| 17 |
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
import json
|
| 19 |
+
import argparse
|
| 20 |
+
from datetime import datetime
|
| 21 |
|
| 22 |
from datasets import Dataset, Features, Value
|
| 23 |
|
|
|
|
| 41 |
features = Features({
|
| 42 |
'name': Value('string'),
|
| 43 |
'version': Value('string'),
|
| 44 |
+
'capabilities': Value('string'), # Store as JSON string for consistency
|
| 45 |
'last_seen': Value('string'),
|
| 46 |
})
|
| 47 |
|
| 48 |
records = []
|
| 49 |
for client in clients_list:
|
| 50 |
+
# Convert capabilities to JSON string for consistency
|
| 51 |
+
caps = client['capabilities']
|
| 52 |
+
if isinstance(caps, dict):
|
| 53 |
+
caps = json.dumps(caps, sort_keys=True)
|
| 54 |
+
elif caps is None:
|
| 55 |
+
caps = ''
|
| 56 |
+
else:
|
| 57 |
+
caps = str(caps)
|
| 58 |
+
|
| 59 |
records.append({
|
| 60 |
'name': client['name'],
|
| 61 |
'version': client['version'],
|
| 62 |
+
'capabilities': caps,
|
| 63 |
'last_seen': client['last_seen'],
|
| 64 |
})
|
| 65 |
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
def main():
|
| 70 |
+
parser = argparse.ArgumentParser(description="Extract and update MCP clients dataset")
|
| 71 |
+
parser.add_argument("--limit", type=int, default=None, help="Limit processing to N rows (for testing)")
|
| 72 |
+
parser.add_argument("--repo-id", default="evalstate/mcp-clients", help="Target repository ID")
|
| 73 |
+
args = parser.parse_args()
|
| 74 |
+
|
| 75 |
print(f"[{datetime.now().isoformat()}] Starting MCP clients extraction...", file=sys.stderr)
|
| 76 |
+
if args.limit:
|
| 77 |
+
print(f"[{datetime.now().isoformat()}] LIMIT MODE: Will process at most {args.limit:,} rows", file=sys.stderr)
|
| 78 |
|
| 79 |
unique_clients = {}
|
| 80 |
|
|
|
|
| 85 |
total_rows = 0
|
| 86 |
skipped_deletes = 0
|
| 87 |
skipped_other = 0
|
| 88 |
+
start_time = datetime.now()
|
| 89 |
|
| 90 |
for batch in sessions_ds.iter(batch_size=1000):
|
| 91 |
batch_len = len(batch['name'])
|
| 92 |
total_rows += batch_len
|
| 93 |
|
| 94 |
+
# Progress indicator every 100k rows
|
| 95 |
+
if total_rows % 100000 == 0:
|
| 96 |
+
elapsed = (datetime.now() - start_time).total_seconds()
|
| 97 |
+
rate = total_rows / elapsed if elapsed > 0 else 0
|
| 98 |
+
print(f"[{datetime.now().isoformat()}] Progress: {total_rows:,} rows processed "
|
| 99 |
+
f"({rate:.0f} rows/sec), {len(unique_clients):,} unique clients found", file=sys.stderr)
|
| 100 |
+
|
| 101 |
+
if args.limit and total_rows >= args.limit:
|
| 102 |
+
print(f"[{datetime.now().isoformat()}] Reached limit of {args.limit:,} rows", file=sys.stderr)
|
| 103 |
+
break
|
| 104 |
+
|
| 105 |
for i in range(batch_len):
|
| 106 |
method_name = batch['methodName'][i] if 'methodName' in batch else None
|
| 107 |
|
|
|
|
| 136 |
'last_seen': time_str
|
| 137 |
}
|
| 138 |
|
| 139 |
+
elapsed = (datetime.now() - start_time).total_seconds()
|
| 140 |
+
rate = total_rows / elapsed if elapsed > 0 else 0
|
| 141 |
+
|
| 142 |
print(f"[{datetime.now().isoformat()}] Processing complete: {total_rows:,} rows", file=sys.stderr)
|
| 143 |
+
print(f"Rate: {rate:.0f} rows/sec, elapsed: {elapsed:.1f} seconds", file=sys.stderr)
|
| 144 |
print(f"Skipped {skipped_deletes:,} deletes, {skipped_other:,} non-initialize events", file=sys.stderr)
|
| 145 |
print(f"Found {len(unique_clients):,} unique client configurations", file=sys.stderr)
|
| 146 |
|
|
|
|
| 156 |
dataset = create_dataset_from_clients(sorted_clients)
|
| 157 |
|
| 158 |
dataset.push_to_hub(
|
| 159 |
+
repo_id=args.repo_id,
|
| 160 |
commit_message=f"Update MCP clients dataset ({datetime.now().strftime('%Y-%m-%d %H:%M')})",
|
| 161 |
)
|
| 162 |
|
| 163 |
+
print(f"[{datetime.now().isoformat()}] Successfully pushed {len(sorted_clients):,} clients to {args.repo_id}", file=sys.stderr)
|
| 164 |
|
| 165 |
|
| 166 |
if __name__ == '__main__':
|