-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_tools.py
More file actions
272 lines (209 loc) · 8.09 KB
/
Copy pathtest_tools.py
File metadata and controls
272 lines (209 loc) · 8.09 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/usr/bin/env python3
"""
Test script for Unipile LinkedIn MCP tools.
Tests each tool individually to verify API connectivity and response formats.
"""
import asyncio
import json
import sys
from dotenv import load_dotenv
load_dotenv()
# Import all tools from the MCP server
from unipile_linkedin import (
list_accounts,
get_my_profile,
search_people,
search_people_sales_nav,
search_companies,
search_posts,
get_search_params,
get_profile,
get_company_profile,
send_invitation,
list_invitations_sent,
list_invitations_received,
list_relations,
list_chats,
get_chat_messages,
start_chat,
send_message,
send_inmail,
get_inmail_credits,
cancel_invitation,
accept_invitation,
decline_invitation,
)
def print_result(name: str, result: dict, truncate: bool = True):
"""Pretty print a test result"""
print(f"\n{'='*60}")
print(f"TEST: {name}")
print(f"{'='*60}")
if "error" in result:
print(f"❌ ERROR: {result.get('error', 'Unknown error')}")
return False
else:
output = json.dumps(result, indent=2, default=str)
if truncate and len(output) > 2000:
output = output[:2000] + "\n... (truncated)"
print(f"✅ SUCCESS")
print(output)
return True
async def test_accounts():
"""Test account-related tools"""
print("\n" + "="*60)
print("TESTING: ACCOUNT TOOLS")
print("="*60)
# Test list_accounts
result = await list_accounts()
success = print_result("list_accounts", result)
# Test get_my_profile
result = await get_my_profile()
success = print_result("get_my_profile", result) and success
return success
async def test_search():
"""Test search-related tools"""
print("\n" + "="*60)
print("TESTING: SEARCH TOOLS")
print("="*60)
success = True
# Test get_search_params for locations (note: param_type must be uppercase)
result = await get_search_params(param_type="LOCATION", query="San Francisco")
success = print_result("get_search_params (LOCATION)", result) and success
# Test get_search_params for industries
result = await get_search_params(param_type="INDUSTRY", query="Software")
success = print_result("get_search_params (INDUSTRY)", result) and success
# Test search_people (Classic)
result = await search_people(keywords="software engineer", limit=5)
success = print_result("search_people (Classic)", result) and success
# Save a provider_id for later tests if we got results
# The provider_id from search has a prefix like "search_people_profile:"
# We need to extract the actual ID for profile lookup
provider_id = None
public_identifier = None
if "items" in result and len(result["items"]) > 0:
item = result["items"][0]
provider_id = item.get("provider_id")
public_identifier = item.get("public_identifier")
# Extract clean provider_id if it has a prefix
if provider_id and ":" in provider_id:
provider_id = provider_id.split(":")[-1]
print(f"\n📝 Got provider_id: {provider_id}")
print(f"📝 Got public_identifier: {public_identifier}")
# Test search_people_sales_nav
result = await search_people_sales_nav(keywords="CTO", limit=5)
success = print_result("search_people_sales_nav", result) and success
# Test search_companies
result = await search_companies(keywords="AI startup", limit=5)
success = print_result("search_companies", result) and success
# Test search_posts
result = await search_posts(keywords="artificial intelligence", limit=5)
success = print_result("search_posts", result) and success
return success, provider_id, public_identifier
async def test_profiles(provider_id: str = None, public_identifier: str = None):
"""Test profile-related tools"""
print("\n" + "="*60)
print("TESTING: PROFILE TOOLS")
print("="*60)
success = True
# Test get_profile if we have a provider_id or public_identifier
if provider_id:
result = await get_profile(provider_id=provider_id)
success = print_result("get_profile (provider_id)", result) and success
elif public_identifier:
result = await get_profile(provider_id=public_identifier)
success = print_result("get_profile (public_identifier)", result) and success
else:
print("⚠️ Skipping get_profile - no provider_id or public_identifier available")
# Test get_company_profile - try with numeric ID first since name might not work
# LinkedIn's company ID is 1337
result = await get_company_profile(company_id="1337")
success = print_result("get_company_profile (LinkedIn ID: 1337)", result) and success
return success
async def test_connections():
"""Test connection-related tools (read-only)"""
print("\n" + "="*60)
print("TESTING: CONNECTION TOOLS (READ-ONLY)")
print("="*60)
success = True
# Test list_invitations_sent
result = await list_invitations_sent(limit=5)
success = print_result("list_invitations_sent", result) and success
# Test list_invitations_received
result = await list_invitations_received(limit=5)
success = print_result("list_invitations_received", result) and success
# Test list_relations
result = await list_relations(limit=5)
success = print_result("list_relations", result) and success
# Note: Not testing send_invitation, accept/decline/cancel as they modify state
print("\n⚠️ Skipping send_invitation, accept/decline/cancel (state-modifying)")
return success
async def test_messaging():
"""Test messaging-related tools (read-only)"""
print("\n" + "="*60)
print("TESTING: MESSAGING TOOLS (READ-ONLY)")
print("="*60)
success = True
# Test list_chats
result = await list_chats(limit=5)
success = print_result("list_chats", result) and success
# Get a chat_id for message testing
chat_id = None
if "items" in result and len(result["items"]) > 0:
chat_id = result["items"][0].get("id")
# Test get_chat_messages if we have a chat
if chat_id:
result = await get_chat_messages(chat_id=chat_id, limit=5)
success = print_result("get_chat_messages", result) and success
else:
print("⚠️ Skipping get_chat_messages - no chat_id available")
# Note: Not testing send_message, start_chat as they modify state
print("\n⚠️ Skipping send_message, start_chat (state-modifying)")
return success
async def test_inmail():
"""Test InMail-related tools (read-only)"""
print("\n" + "="*60)
print("TESTING: INMAIL TOOLS")
print("="*60)
success = True
# Test get_inmail_credits
result = await get_inmail_credits()
success = print_result("get_inmail_credits", result) and success
# Note: Not testing send_inmail as it uses credits and modifies state
print("\n⚠️ Skipping send_inmail (uses credits, state-modifying)")
return success
async def main():
"""Run all tests"""
print("\n" + "#"*60)
print("# UNIPILE LINKEDIN MCP - TOOL TESTS")
print("#"*60)
all_success = True
# Test accounts
success = await test_accounts()
all_success = all_success and success
# Test search (and get a provider_id for profile tests)
success, provider_id, public_identifier = await test_search()
all_success = all_success and success
# Test profiles
success = await test_profiles(provider_id, public_identifier)
all_success = all_success and success
# Test connections (read-only)
success = await test_connections()
all_success = all_success and success
# Test messaging (read-only)
success = await test_messaging()
all_success = all_success and success
# Test InMail
success = await test_inmail()
all_success = all_success and success
# Summary
print("\n" + "#"*60)
print("# TEST SUMMARY")
print("#"*60)
if all_success:
print("\n✅ ALL TESTS PASSED!")
return 0
else:
print("\n❌ SOME TESTS FAILED - check output above")
return 1
if __name__ == "__main__":
sys.exit(asyncio.run(main()))