-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEXTRACT_AND_REPLACE_RETURN.py
More file actions
172 lines (130 loc) · 4.69 KB
/
EXTRACT_AND_REPLACE_RETURN.py
File metadata and controls
172 lines (130 loc) · 4.69 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env python3
"""
EXTRACT ALL TOOLS AND REPLACE return STATEMENT
"""
from pathlib import Path
print("=" * 80)
print("EXTRACT ALL TOOLS AND REPLACE return STATEMENT")
print("=" * 80)
print()
server_file = Path("/root/clawd/lore_mcp_server/mcp_server/server.py")
print(f"Server file: {server_file}")
print()
# Read server.py file
print("Reading server.py file...")
print()
with open(server_file, 'r') as f:
content = f.read()
# Count Tool( occurrences
tool_count = content.count('Tool(')
print(f"✅ Tool( occurrences: {tool_count}")
# Find all Tool definitions (extract entire Tool(...) block)
print("Extracting all Tool(...) definitions...")
print()
tools = []
start = 0
while True:
# Find Tool(
pos = content.find('Tool(', start)
if pos == -1:
break
# Find closing )
end = content.find(')', pos)
if end == -1:
break
# Find matching ) for multiline Tool definition
open_parens = 0
for i in range(pos, len(content)):
if content[i] == '(':
open_parens += 1
elif content[i] == ')':
open_parens -= 1
if open_parens == 0:
end = i
break
# Extract Tool definition
tool_def = content[pos:end + 1]
tools.append(tool_def)
print(f" Tool {len(tools)}: {tool_def[:80]}...")
start = end + 1
print(f"✅ Extracted {len(tools)} Tool(...) definitions")
# Find return [ in list_tools() function (around line 27557)
print("Finding return [ in list_tools() function...")
print()
list_tools_pos = content.find('async def list_tools()')
if list_tools_pos == -1:
print("❌ Error: Could not find 'async def list_tools()'")
exit(1)
print(f"✅ Found 'async def list_tools()' at position {list_tools_pos}")
# Find return [ within function (next 100 lines)
return_pos = content.find('return [', list_tools_pos)
if return_pos == -1:
print("❌ Error: Could not find 'return [' in list_tools()")
exit(1)
print(f"✅ Found 'return [' at position {return_pos}")
# Find closing ] for return statement
closing_pos = content.find(']', return_pos)
if closing_pos == -1:
print("❌ Error: Could not find closing ] for return statement")
exit(1)
print(f"✅ Found closing ] at position {closing_pos}")
# Extract old return statement
old_return = content[return_pos:closing_pos + 1]
print(f"Old return statement: {old_return[:100]}")
print(f"Old tools in return: {old_return.count('Tool(')}")
# Generate new return statement with all 1495 tools
print("Generating new return statement with all 1495 tools...")
print()
new_return = " return [\n"
for i, tool in enumerate(tools):
new_return += f" {tool}\n"
# Add newlines every 10 tools for readability
if (i + 1) % 10 == 0 and i < len(tools) - 1:
new_return += "\n"
new_return += " ]"
print(f"✅ Generated new return statement with {len(tools)} Tool definitions")
# Replace return statement
print("Replacing return statement...")
new_content = content[:return_pos] + new_return + content[closing_pos + 1:]
# Write back to server.py
with open(server_file, 'w') as f:
f.write(new_content)
print(f"✅ Updated {server_file}")
print(f"✅ Replaced return statement with {len(tools)} Tool definitions")
# Verify
print("Verifying...")
print()
with open(server_file, 'r') as f:
updated_content = f.read()
# Count Tool definitions
updated_tool_count = updated_content.count('Tool(')
print(f"✅ Updated Tool count: {updated_tool_count}")
# Find new return statement
new_return_pos = updated_content.find('return [', return_pos)
if new_return_pos == -1:
print("❌ Error: Could not verify new return statement")
else:
new_return_section = updated_content[new_return_pos:new_return_pos + 500]
new_tools_in_return = new_return_section.count('Tool(')
print(f"✅ Verified: return statement now has {new_tools_in_return} Tool definitions")
if new_tools_in_return >= 1490:
print(f"✅ SUCCESS: All {new_tools_in_return} tools in return statement!")
else:
print(f"⚠️ Warning: Expected 1496 tools, found {new_tools_in_return}")
print()
print("=" * 80)
print("✅ RETURN STATEMENT REPLACED WITH ALL 1495 TOOLS")
print("=" * 80)
print()
print(f"Total tools: {len(tools)}")
print(f"Tools in return: {new_tools_in_return}")
print()
print("Next steps:")
print(" 1. Verify syntax: python3 -m py_compile lore_mcp_server/mcp_server/server.py")
print(" 2. Test server startup: python3 lore_mcp_server/mcp_server/server.py")
print(" 3. Commit: git add -A && git commit -m 'feat: Update list_tools() return with all 1496 MCP tools (ALL ENTITIES)'")
print(" 4. Push: git push origin master")
print()
print("=" * 80)
print("✅ READY TO VERIFY AND COMMIT")
print("=" * 80)