get_linkedin_user_connections
Retrieve LinkedIn user connections data from your account, with options to filter by connection date and limit results for efficient network analysis.
Instructions
Get list of LinkedIn user connections. Account ID is taken from environment.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| connected_after | No | Filter users that added after the specified date (timestamp) | |
| count | No | Max connections to return | |
| timeout | No | Timeout in seconds |
Implementation Reference
- src/index.ts:999-1026 (handler)Handler and registration for 'get_linkedin_user_connections' tool. Makes API request to retrieve the authenticated user's LinkedIn connections with optional filters for time and count.server.tool( "get_linkedin_user_connections", "Get user's LinkedIn connections (requires ACCOUNT_ID)", { connected_after: z.number().optional().describe("Filter connections after timestamp"), count: z.number().default(20).describe("Max connections"), timeout: z.number().default(300).describe("Timeout in seconds") }, async ({ connected_after, count, timeout }) => { const requestData: any = { timeout, account_id: ACCOUNT_ID, count }; if (connected_after != null) { requestData.connected_after = connected_after; } log("Starting LinkedIn user connections lookup"); try { const response = await makeRequest(API_CONFIG.ENDPOINTS.USER_CONNECTIONS, requestData); return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] }; } catch (error) { log("LinkedIn user connections lookup error:", error); return { content: [{ type: "text", text: `LinkedIn user connections API error: ${formatError(error)}` }], isError: true }; } } );
- src/types.ts:75-79 (schema)TypeScript interface defining the input arguments for the get_linkedin_user_connections tool.export interface GetLinkedinUserConnectionsArgs { connected_after?: number; count?: number; timeout?: number; }
- src/types.ts:552-561 (helper)Type guard function to validate input arguments for the get_linkedin_user_connections tool.export function isValidGetLinkedinUserConnectionsArgs( args: unknown ): args is GetLinkedinUserConnectionsArgs { if (typeof args !== "object" || args === null) return false; const obj = args as Record<string, unknown>; if (obj.connected_after !== undefined && typeof obj.connected_after !== "number") return false; if (obj.count !== undefined && typeof obj.count !== "number") return false; if (obj.timeout !== undefined && typeof obj.timeout !== "number") return false; return true; }
- src/index.ts:36-36 (helper)API endpoint constant used by the tool handler to fetch user connections.USER_CONNECTIONS: "/api/linkedin/management/user/connections",
- src/index.ts:100-145 (helper)Generic HTTP request helper function used by all tools including get_linkedin_user_connections to make API calls.const makeRequest = (endpoint: string, data: any, method: string = "POST"): Promise<any> => { return new Promise((resolve, reject) => { const url = new URL(endpoint, API_CONFIG.BASE_URL); const postData = JSON.stringify(data); const options = { hostname: url.hostname, port: url.port || 443, path: url.pathname, method: method, headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(postData), "access-token": API_KEY, ...(ACCOUNT_ID && { "x-account-id": ACCOUNT_ID }) } }; const req = https.request(options, (res) => { let responseData = ""; res.on("data", (chunk) => { responseData += chunk; }); res.on("end", () => { try { const parsed = JSON.parse(responseData); if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) { resolve(parsed); } else { reject(new Error(`API error ${res.statusCode}: ${JSON.stringify(parsed)}`)); } } catch (e) { reject(new Error(`Failed to parse response: ${responseData}`)); } }); }); req.on("error", (error) => { reject(error); }); req.write(postData); req.end(); }); };