MCPcopy
hub / github.com/msgbyte/tianji / testConnection

Method testConnection

packages/cli/src/utils/api.ts:46–69  ·  view source on GitHub ↗

* Test connection by calling worker get endpoint with an invalid ID * Uses the OpenAPI SDK

()

Source from the content-addressed store, hash-verified

44 * Uses the OpenAPI SDK
45 */
46 async testConnection(): Promise<boolean> {
47 try {
48 // Try to get a worker with an invalid ID just to test auth
49 // This will fail but if auth is correct, it won't be a 401/403
50 await openApiClient.WorkerService.workerGet({
51 workspaceId: this.config.workspaceId,
52 workerId: 'test-invalid-id',
53 }).catch((error: any) => {
54 // If it's not an auth error, the connection is valid
55 if (error.status !== 401 && error.status !== 403) {
56 return true;
57 }
58 throw error;
59 });
60 return true;
61 } catch (error: any) {
62 // If we get 401 or 403, auth is invalid
63 if (error.status === 401 || error.status === 403) {
64 return false;
65 }
66 // Any other error means connection is OK (just worker doesn't exist or other issue)
67 return true;
68 }
69 }
70
71 /**
72 * Upsert worker (create or update)

Callers 1

handlerFunction · 0.80

Calls 2

catchMethod · 0.80
workerGetMethod · 0.80

Tested by

no test coverage detected