MCPcopy
hub / github.com/ValueCell-ai/ClawX / rpc

Method rpc

electron/gateway/manager.ts:867–942  ·  view source on GitHub ↗

* Make an RPC call to the Gateway * Uses OpenClaw protocol format: { type: "req", id: "...", method: "...", params: {...} }

(method: string, params?: unknown, timeoutMs = 30000)

Source from the content-addressed store, hash-verified

865 * Uses OpenClaw protocol format: { type: "req", id: "...", method: "...", params: {...} }
866 */
867 async rpc<T>(method: string, params?: unknown, timeoutMs = 30000): Promise<T> {
868 const startedAt = Date.now();
869 return await new Promise<T>((resolve, reject) => {
870 if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
871 reject(new Error('Gateway not connected'));
872 return;
873 }
874
875 const id = crypto.randomUUID();
876
877 // Set timeout for request
878 const timeout = setTimeout(() => {
879 rejectPendingGatewayRequest(this.pendingRequests, id, new Error(`RPC timeout: ${method}`));
880 }, timeoutMs);
881
882 // Store pending request
883 this.pendingRequests.set(id, {
884 resolve: resolve as (value: unknown) => void,
885 reject,
886 timeout,
887 });
888
889 // Send request using OpenClaw protocol format
890 const request = {
891 type: 'req',
892 id,
893 method,
894 params,
895 };
896
897 try {
898 if (isGatewayWsTraceEnabled()) {
899 logger.debug('[gateway-ws-trace] send', {
900 summary: summarizeGatewayFrameForTrace(request),
901 frame: redactGatewayFrameForTrace(request),
902 });
903 }
904 this.ws.send(JSON.stringify(request));
905 } catch (error) {
906 rejectPendingGatewayRequest(this.pendingRequests, id, new Error(`Failed to send RPC request: ${error}`));
907 }
908 }).then((result) => {
909 this.recordRpcSuccess();
910 if (isCoreRpcMethod(method)) {
911 this.capabilityMonitor.recordCoreProbe({
912 ok: true,
913 checkedAt: Date.now(),
914 durationMs: Date.now() - startedAt,
915 });
916 }
917 const capability = classifyCapabilityMethod(method);
918 if (capability) {
919 this.capabilityMonitor.recordCapabilitySuccess(
920 capability,
921 result as GatewayRuntimePayload,
922 Date.now() - startedAt,
923 );
924 }

Callers 15

stopMethod · 0.95
checkHealthMethod · 0.95
approvePairingRequestFunction · 0.80
registerCronHandlersFunction · 0.80
registerGatewayHandlersFunction · 0.80
createSkillsApiFunction · 0.80
createChatApiFunction · 0.80
createGatewayApiFunction · 0.80
listCronJobsFunction · 0.80
createCronApiFunction · 0.80

Calls 13

recordRpcSuccessMethod · 0.95
recordRpcFailureMethod · 0.95
isGatewayWsTraceEnabledFunction · 0.90
isCoreRpcMethodFunction · 0.85
classifyCapabilityMethodFunction · 0.85
isTransportRpcFailureFunction · 0.85
recordCoreProbeMethod · 0.80
setMethod · 0.65

Tested by

no test coverage detected