@zktx.io/sui-mcp 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/LICENSES/@mysten-bcs-2.0.5-Apache-2.0.txt +205 -0
- package/LICENSES/@mysten-sui-2.17.0-Apache-2.0.txt +201 -0
- package/LICENSES/@mysten-utils-0.3.3-Apache-2.0.txt +205 -0
- package/LICENSES/fancy-canvas-2.1.0-MIT.txt +7 -0
- package/LICENSES/lightweight-charts-5.2.0-NOTICE.txt +2 -0
- package/README.md +288 -0
- package/dist/adapters/adapterLifecycleValidators.js +5 -0
- package/dist/adapters/adapterPromptSurfaces.js +60 -0
- package/dist/adapters/deepbook/deepbookHumanReviewProducer.js +178 -0
- package/dist/adapters/deepbook/deepbookQuotePolicy.js +112 -0
- package/dist/adapters/deepbook/deepbookReviewEvidence.js +507 -0
- package/dist/adapters/deepbook/deepbookReviewLifecycle.js +85 -0
- package/dist/adapters/deepbook/deepbookSwapIntent.js +79 -0
- package/dist/adapters/deepbook/deepbookTransactionMaterialProducer.js +254 -0
- package/dist/adapters/intentPlanFactories.js +51 -0
- package/dist/adapters/reviewAdapters.js +47 -0
- package/dist/core/action/adapterLifecycleValidation.js +12 -0
- package/dist/core/action/contractNameRegistry.js +151 -0
- package/dist/core/action/forbiddenFields.js +43 -0
- package/dist/core/action/humanReadableReviewEvidence.js +193 -0
- package/dist/core/action/humanReadableReviewProjectionVerifier.js +29 -0
- package/dist/core/action/ptbVisualizationProducer.js +71 -0
- package/dist/core/action/receiptPtbGraph.js +29 -0
- package/dist/core/action/reviewCheckResults.js +6 -0
- package/dist/core/action/reviewStateValidation.js +11 -0
- package/dist/core/action/reviewTimeSimulationEvidence.js +470 -0
- package/dist/core/action/schemas.js +491 -0
- package/dist/core/action/signableAdapterContract.js +998 -0
- package/dist/core/action/suiChainReceiptEvidence.js +106 -0
- package/dist/core/action/suiChainReceiptMapping.js +107 -0
- package/dist/core/action/suiChainReceiptReader.js +211 -0
- package/dist/core/action/suiChainReceiptVerifier.js +178 -0
- package/dist/core/action/swapHumanReadableReviewProjection.js +130 -0
- package/dist/core/action/swapQuotePolicyEvidence.js +271 -0
- package/dist/core/action/transactionFunding.js +244 -0
- package/dist/core/action/transactionObjectOwnershipEvidence.js +256 -0
- package/dist/core/action/transactionObjectOwnershipProducer.js +323 -0
- package/dist/core/action/types.js +33 -0
- package/dist/core/action/walletReviewContractAssembler.js +286 -0
- package/dist/core/activity/accountAssetTimeline.js +157 -0
- package/dist/core/activity/accountAssetTimelineUsdcReferences.js +120 -0
- package/dist/core/activity/activityStore.js +16 -0
- package/dist/core/activity/externalActivityCoverage.js +76 -0
- package/dist/core/activity/externalActivityTransactionStream.js +82 -0
- package/dist/core/activity/localDataService.js +296 -0
- package/dist/core/activity/localDataTypes.js +11 -0
- package/dist/core/activity/localDataValidation.js +439 -0
- package/dist/core/activity/schemaVersion.js +2 -0
- package/dist/core/activity/sqliteActivityStore.js +1068 -0
- package/dist/core/activity/sqliteActivityStoreRows.js +389 -0
- package/dist/core/activity/sqliteActivityStoreSchema.js +367 -0
- package/dist/core/activity/sqliteActivityStoreTypes.js +5 -0
- package/dist/core/activity/suiFunctionTarget.js +43 -0
- package/dist/core/activity/transactionActivityAccountEffects.js +186 -0
- package/dist/core/activity/transactionActivityAnalysis.js +295 -0
- package/dist/core/activity/transactionActivityClassifier.js +306 -0
- package/dist/core/activity/transactionActivityDetails.js +229 -0
- package/dist/core/activity/transactionActivityProtocolRules.js +218 -0
- package/dist/core/activity/transactionActivityScanPolicy.js +170 -0
- package/dist/core/activity/transactionActivityService.js +379 -0
- package/dist/core/activity/transactionActivityTypes.js +18 -0
- package/dist/core/eventlog/sink.js +35 -0
- package/dist/core/evidence/settlementFamilies.js +85 -0
- package/dist/core/evidence/userAnswerUse.js +1 -0
- package/dist/core/numeric/rawU64.js +63 -0
- package/dist/core/preferences/preferencesStore.js +26 -0
- package/dist/core/preferences/sqlitePreferencesRepository.js +136 -0
- package/dist/core/proposal/externalProposalReview.js +347 -0
- package/dist/core/proposal/schemas.js +208 -0
- package/dist/core/proposal/types.js +35 -0
- package/dist/core/read/amounts.js +14 -0
- package/dist/core/read/coinMetadata.js +60 -0
- package/dist/core/read/deepbookOfficialIndexerSource.js +373 -0
- package/dist/core/read/deepbookRawQuoteClient.js +86 -0
- package/dist/core/read/deepbookReadHelpers.js +321 -0
- package/dist/core/read/deepbookRegistry.js +157 -0
- package/dist/core/read/deepbookSourceOwners.js +159 -0
- package/dist/core/read/deepbookUsdcChartService.js +342 -0
- package/dist/core/read/intentEvidenceResponseFormatting.js +228 -0
- package/dist/core/read/readCardInputs.js +19 -0
- package/dist/core/read/readCardResult.js +40 -0
- package/dist/core/read/readResponseGuidance.js +402 -0
- package/dist/core/read/readService.js +1639 -0
- package/dist/core/read/readServiceTypes.js +88 -0
- package/dist/core/read/settlementParityFormatting.js +82 -0
- package/dist/core/read/walletReadHelpers.js +99 -0
- package/dist/core/review/reviewChecks.js +45 -0
- package/dist/core/review/reviewComputation.js +38 -0
- package/dist/core/review/reviewComputationResult.js +87 -0
- package/dist/core/session/cardSession.js +31 -0
- package/dist/core/session/cardSessionStore.js +204 -0
- package/dist/core/session/keyedRecordStore.js +18 -0
- package/dist/core/session/liveReviewSessionContract.js +3 -0
- package/dist/core/session/localSession.js +31 -0
- package/dist/core/session/privateReviewArtifacts.js +75 -0
- package/dist/core/session/reviewValidity.js +49 -0
- package/dist/core/session/sessionErrors.js +9 -0
- package/dist/core/session/sessionRecordStore.js +40 -0
- package/dist/core/session/sessionStore.js +655 -0
- package/dist/core/session/settingsSession.js +1 -0
- package/dist/core/session/settingsSessions.js +45 -0
- package/dist/core/session/sqliteCardStore.js +88 -0
- package/dist/core/session/sqliteSessionStore.js +213 -0
- package/dist/core/session/sqliteTransactionMaterialStore.js +64 -0
- package/dist/core/session/sqliteWalletWorkflowStore.js +821 -0
- package/dist/core/session/status.js +60 -0
- package/dist/core/session/transactionMaterialStore.js +221 -0
- package/dist/core/session/transactionRequest.js +72 -0
- package/dist/core/session/wait.js +79 -0
- package/dist/core/session/walletConnection.js +92 -0
- package/dist/core/session/walletRuntime.js +38 -0
- package/dist/core/session/walletWorkflow.js +608 -0
- package/dist/core/session/workflowState.js +80 -0
- package/dist/core/session/workflowView.js +150 -0
- package/dist/core/suiAddress.js +18 -0
- package/dist/core/suiEndpoint.js +72 -0
- package/dist/mcp/activeAccountResponse.js +24 -0
- package/dist/mcp/prompts.js +146 -0
- package/dist/mcp/registerTool.js +19 -0
- package/dist/mcp/resources.js +72 -0
- package/dist/mcp/responseGuidance.js +326 -0
- package/dist/mcp/result.js +17 -0
- package/dist/mcp/schemas.js +11 -0
- package/dist/mcp/server.js +32 -0
- package/dist/mcp/serverInfo.js +131 -0
- package/dist/mcp/toolErrors.js +118 -0
- package/dist/mcp/toolNames.js +58 -0
- package/dist/mcp/tools/account/index.js +44 -0
- package/dist/mcp/tools/action/prepareSuiActionReview.js +126 -0
- package/dist/mcp/tools/read/commonSchemas.js +43 -0
- package/dist/mcp/tools/read/deepbookReadTools.js +686 -0
- package/dist/mcp/tools/read/index.js +14 -0
- package/dist/mcp/tools/read/readToolHelpers.js +97 -0
- package/dist/mcp/tools/read/reviewActivityTools.js +179 -0
- package/dist/mcp/tools/read/serverStatusTools.js +100 -0
- package/dist/mcp/tools/read/transactionActivityOutput.js +371 -0
- package/dist/mcp/tools/read/transactionActivityTools.js +858 -0
- package/dist/mcp/tools/read/walletReadTools.js +734 -0
- package/dist/mcp/tools/session/executionResultTools.js +44 -0
- package/dist/mcp/tools/session/index.js +8 -0
- package/dist/mcp/tools/session/shared.js +36 -0
- package/dist/mcp/tools/session/statusTools.js +69 -0
- package/dist/mcp/tools/session/walletConnectionTools.js +69 -0
- package/dist/mcp/tools/settings/index.js +66 -0
- package/dist/mcp-app/account.html +3133 -0
- package/dist/mcp-app/account.notices.txt +973 -0
- package/dist/mcp-app/chart.html +3354 -0
- package/dist/mcp-app/chart.notices.txt +1194 -0
- package/dist/mcp-app/connect.html +3179 -0
- package/dist/mcp-app/connect.notices.txt +1012 -0
- package/dist/mcp-app/receipt.html +8430 -0
- package/dist/mcp-app/receipt.notices.txt +3549 -0
- package/dist/mcp-app/review.html +8430 -0
- package/dist/mcp-app/review.notices.txt +3549 -0
- package/dist/mcp-ui/contracts.js +31 -0
- package/dist/mcp-ui/readCards.js +28 -0
- package/dist/mcp-ui/tools.js +134 -0
- package/dist/review-app/brand-dark.svg +1 -0
- package/dist/review-app/brand-light.svg +1 -0
- package/dist/review-app/favicon.svg +1 -0
- package/dist/review-app/settings.css +1 -0
- package/dist/review-app/settings.js +1 -0
- package/dist/review-app/ui.css +809 -0
- package/dist/review-server/assets.js +48 -0
- package/dist/review-server/html.js +45 -0
- package/dist/review-server/http.js +47 -0
- package/dist/review-server/middleware/hostOrigin.js +48 -0
- package/dist/review-server/middleware/reviewToken.js +7 -0
- package/dist/review-server/reviewServerPolicy.js +1 -0
- package/dist/review-server/server.js +72 -0
- package/dist/review-server/settingsApi.js +158 -0
- package/dist/runtime/application.js +203 -0
- package/dist/runtime/config.js +97 -0
- package/dist/runtime/localSettingsService.js +198 -0
- package/dist/runtime/logger.js +66 -0
- package/dist/runtime/reviewDependencies.js +58 -0
- package/dist/runtime/reviewServerAcquire.js +93 -0
- package/dist/runtime/runtimeTermination.js +60 -0
- package/dist/runtime/shared/authenticatedFetch.js +127 -0
- package/dist/runtime/shared/control.js +93 -0
- package/dist/runtime/shared/dataAccess.js +66 -0
- package/dist/runtime/shared/mcpHttp.js +84 -0
- package/dist/runtime/shared/ownerLease.js +50 -0
- package/dist/runtime/shared/server.js +98 -0
- package/dist/runtime/shared/stdio.js +113 -0
- package/dist/runtime/smokeMainnetRead.js +391 -0
- package/dist/runtime/smokeMainnetReadAssertions.js +306 -0
- package/dist/runtime/smokeReview.js +40 -0
- package/dist/runtime/start.js +90 -0
- package/dist/runtime/suiEndpoint.js +97 -0
- package/dist/runtime/suiTransactionGraphqlMapping.js +200 -0
- package/dist/runtime/suiTransactionGraphqlQueries.js +231 -0
- package/dist/runtime/suiTransactionGraphqlSource.js +148 -0
- package/dist/runtime/walletConnectConfig.js +3 -0
- package/dist/runtime/walletConnectStorage.js +99 -0
- package/dist/runtime/walletConnectTransport.js +128 -0
- package/dist/runtime/walletSdkChild.js +3 -0
- package/dist/runtime/walletSdkChildRuntime.js +160 -0
- package/dist/runtime/walletSdkIpc.js +26 -0
- package/dist/runtime/walletSdkProcess.js +358 -0
- package/docs/AGENT_BEHAVIOR.md +524 -0
- package/docs/AGENT_DEVELOPMENT_POLICY.md +815 -0
- package/docs/FRONTEND_POLICY.md +534 -0
- package/docs/LOCAL_DB_ARCHITECTURE.md +381 -0
- package/docs/MCP_SETUP.md +742 -0
- package/docs/MCP_TOOLS.md +1318 -0
- package/docs/SDK_API.md +206 -0
- package/docs/SIGNABLE_ADAPTER_CONTRACT.md +396 -0
- package/docs/TRANSACTION_ACTIVITY_LOG.md +194 -0
- package/docs/UTILITY_INDEX.md +275 -0
- package/docs/WALLET_CONNECTION.md +238 -0
- package/docs/golden-scenarios/BEHAVIOR_MATRIX.md +166 -0
- package/docs/golden-scenarios/INTENT_EVIDENCE_GOLDEN_ANSWERS.md +161 -0
- package/docs/golden-scenarios/INTENT_EVIDENCE_MATRIX.md +259 -0
- package/package.json +79 -0
- package/protocols/deepbook-margin.md +15 -0
- package/protocols/deepbook-v3.md +24 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { registerDeepbookReadTools } from "./deepbookReadTools.js";
|
|
2
|
+
import { registerReviewActivityListTool, registerReviewActivitySummaryTools } from "./reviewActivityTools.js";
|
|
3
|
+
import { registerServerStatusTools, SUPPORTED_PROTOCOLS } from "./serverStatusTools.js";
|
|
4
|
+
import { registerTransactionActivityTools } from "./transactionActivityTools.js";
|
|
5
|
+
import { registerWalletReadTools } from "./walletReadTools.js";
|
|
6
|
+
export { SUPPORTED_PROTOCOLS };
|
|
7
|
+
export function registerReadTools(server, deps) {
|
|
8
|
+
registerServerStatusTools(server);
|
|
9
|
+
registerDeepbookReadTools(server, deps);
|
|
10
|
+
registerWalletReadTools(server, deps);
|
|
11
|
+
registerReviewActivityListTool(server, deps);
|
|
12
|
+
registerTransactionActivityTools(server, deps);
|
|
13
|
+
registerReviewActivitySummaryTools(server, deps);
|
|
14
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { CONNECTION_CONFLICT_MESSAGE } from "../../../core/session/walletConnection.js";
|
|
2
|
+
import { ReadServiceCacheError, ReadServiceInputError } from "../../../core/read/readService.js";
|
|
3
|
+
import { parseSuiAddress } from "../../../core/suiAddress.js";
|
|
4
|
+
import { errorToolResult } from "../../result.js";
|
|
5
|
+
import { activityStoreToolError } from "../../toolErrors.js";
|
|
6
|
+
import { walletUnavailable } from "../../../core/session/walletConnection.js";
|
|
7
|
+
import { TOOL_NAMES } from "../../toolNames.js";
|
|
8
|
+
export async function resolveExplicitOrActiveAccount(input, deps) {
|
|
9
|
+
if (input.mode === "explicit_or_connected" && input.account !== undefined) {
|
|
10
|
+
const explicitAccount = parseSuiAddress(input.account);
|
|
11
|
+
if (explicitAccount === undefined) {
|
|
12
|
+
return {
|
|
13
|
+
status: "error",
|
|
14
|
+
result: errorToolResult({
|
|
15
|
+
kind: "input_invalid",
|
|
16
|
+
details: {
|
|
17
|
+
field: "account"
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return { status: "ok", account: explicitAccount };
|
|
23
|
+
}
|
|
24
|
+
let active;
|
|
25
|
+
try {
|
|
26
|
+
active = await deps.activityStore.getActiveAccount();
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return { status: "error", result: activityStoreToolError(error, deps.logger) };
|
|
30
|
+
}
|
|
31
|
+
if (!active && input.mode === "explicit_or_connected") {
|
|
32
|
+
const message = "Please provide a Sui address in chat.";
|
|
33
|
+
return {
|
|
34
|
+
status: "address_required", message,
|
|
35
|
+
result: errorToolResult({
|
|
36
|
+
kind: "active_account_not_set",
|
|
37
|
+
details: {
|
|
38
|
+
action: "provide_account", message
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const context = deps.workflow?.readConnectionContext();
|
|
45
|
+
if (context?.assetReadAccount.status === "available")
|
|
46
|
+
return { status: "ok", account: context.assetReadAccount.account };
|
|
47
|
+
const availability = context?.walletAvailability ?? walletUnavailable("initialization_failed");
|
|
48
|
+
if (input.mode === "connected_only") {
|
|
49
|
+
if (availability.status !== "available")
|
|
50
|
+
return { status: "error", result: errorToolResult({ kind: "wallet_unavailable",
|
|
51
|
+
details: { ...(availability.status === "unavailable" ? { reason: availability.reason } : {}), message: availability.message, walletAvailability: availability } }) };
|
|
52
|
+
return { status: "error", result: errorToolResult({ kind: active ? "input_invalid" : "active_account_not_set",
|
|
53
|
+
details: { reason: "connected_account_required",
|
|
54
|
+
message: context?.connectionConflict ? CONNECTION_CONFLICT_MESSAGE : "This tool requires a selected account with a usable wallet connection. An address alone cannot be used.",
|
|
55
|
+
...(context?.connectionConflict ? { connectionConflict: context.connectionConflict } : {}),
|
|
56
|
+
followUp: { tool: TOOL_NAMES.sessionGetInteractionStatus,
|
|
57
|
+
answerFields: ["walletAvailability", "connections", "pendingWalletConnections", "assetReadAccount"],
|
|
58
|
+
reason: `Check current connections and pending operations. Use pendingWalletConnections.items[].cardId with ${TOOL_NAMES.sessionGetWalletConnection} or ${TOOL_NAMES.sessionWaitWalletConnection}. If no operation is pending and the user requests connection or account selection, open ${TOOL_NAMES.sessionCreateWalletConnection}. Only the user may act in that card.` } } }) };
|
|
59
|
+
}
|
|
60
|
+
const message = context?.connectionConflict ? CONNECTION_CONFLICT_MESSAGE + " Provide a Sui address in chat for this public read." : availability.status !== "available"
|
|
61
|
+
? "The wallet connection cannot be checked. Please provide a Sui address in chat to view its assets."
|
|
62
|
+
: "No connected wallet is available for the selected account. Please provide a Sui address in chat.";
|
|
63
|
+
return { status: "address_required", message, result: errorToolResult({ kind: "input_invalid",
|
|
64
|
+
details: { field: "account", reason: "address_required", message, walletAvailability: availability } }) };
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
return { status: "error", result: activityStoreToolError(error, deps.logger) };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export function readServiceError(error, deps) {
|
|
71
|
+
if (error instanceof ReadServiceCacheError) {
|
|
72
|
+
deps.logger.error("read service metadata cache failed", {
|
|
73
|
+
operation: error.details.operation,
|
|
74
|
+
error: error.cause instanceof Error ? error.cause.message : String(error.cause)
|
|
75
|
+
});
|
|
76
|
+
return errorToolResult({
|
|
77
|
+
kind: error.kind,
|
|
78
|
+
details: error.details
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (error instanceof ReadServiceInputError) {
|
|
82
|
+
return errorToolResult({
|
|
83
|
+
kind: error.kind,
|
|
84
|
+
details: error.details
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
deps.logger.error("read service call failed", {
|
|
88
|
+
error: error instanceof Error ? error.message : String(error)
|
|
89
|
+
});
|
|
90
|
+
return errorToolResult({
|
|
91
|
+
kind: "internal_error",
|
|
92
|
+
details: { message: "Read service call failed" }
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
export function activityStoreReadError(error, deps) {
|
|
96
|
+
return activityStoreToolError(error, deps.logger);
|
|
97
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { TRANSACTION_REQUEST_STATUSES, transactionRequestSchema, transactionRequestStatusSchema } from "../../../core/session/transactionRequest.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { actionPlanSchema, internalSessionStatusSchema, reviewStateOutputSchema } from "../../../core/action/schemas.js";
|
|
4
|
+
import { REVIEW_ACTIVITY_LIST_DEFAULT_LIMIT, REVIEW_ACTIVITY_LIST_MAX_LIMIT, REVIEW_ACTIVITY_LOW_SAMPLE_THRESHOLD } from "../../../core/activity/activityStore.js";
|
|
5
|
+
import { successOutputSchema } from "../../schemas.js";
|
|
6
|
+
import { okToolResult } from "../../result.js";
|
|
7
|
+
import { TOOL_NAMES } from "../../toolNames.js";
|
|
8
|
+
import { reviewActivityListUserAnswerUse, reviewFunnelUserAnswerUse, reviewSessionDetailUserAnswerUse } from "../../responseGuidance.js";
|
|
9
|
+
import { fetchedAtSchema, reviewActivityAccountSourceSchema, reviewActivityDataScopeSchema, reviewActivityInputSchema, userAnswerUseSchema } from "./commonSchemas.js";
|
|
10
|
+
import { activityStoreReadError } from "./readToolHelpers.js";
|
|
11
|
+
const reviewActivityCommonOutput = {
|
|
12
|
+
dataScope: reviewActivityDataScopeSchema,
|
|
13
|
+
accountSource: reviewActivityAccountSourceSchema,
|
|
14
|
+
userAnswerUse: userAnswerUseSchema,
|
|
15
|
+
lowSampleWarning: z.boolean(),
|
|
16
|
+
lowSampleThreshold: z.literal(REVIEW_ACTIVITY_LOW_SAMPLE_THRESHOLD),
|
|
17
|
+
truncated: z.object({
|
|
18
|
+
activities: z.boolean(),
|
|
19
|
+
snapshots: z.boolean(),
|
|
20
|
+
transitions: z.boolean(),
|
|
21
|
+
requests: z.boolean().optional()
|
|
22
|
+
})
|
|
23
|
+
};
|
|
24
|
+
const reviewActivityRowSchema = z.object({
|
|
25
|
+
reviewSessionId: z.string(),
|
|
26
|
+
planId: z.string(),
|
|
27
|
+
actionKind: z.string(),
|
|
28
|
+
adapterId: z.string(),
|
|
29
|
+
protocol: z.string(),
|
|
30
|
+
reviewStatus: internalSessionStatusSchema,
|
|
31
|
+
currentAttemptId: z.string().optional(),
|
|
32
|
+
requestStatus: transactionRequestStatusSchema.optional(),
|
|
33
|
+
reviewRevision: z.number().int().nonnegative().optional(),
|
|
34
|
+
account: z.string(),
|
|
35
|
+
createdAt: fetchedAtSchema,
|
|
36
|
+
updatedAt: fetchedAtSchema,
|
|
37
|
+
executionStatus: z.enum(["success", "failure"]).optional(),
|
|
38
|
+
transactionDigest: z.string().optional(),
|
|
39
|
+
snapshotCount: z.number().int().nonnegative(),
|
|
40
|
+
transitionCount: z.number().int().nonnegative()
|
|
41
|
+
});
|
|
42
|
+
export function registerReviewActivityListTool(server, deps) {
|
|
43
|
+
server.registerTool(TOOL_NAMES.readListReviewActivity, {
|
|
44
|
+
title: "List review activity",
|
|
45
|
+
description: "List local Sui MCP review-session records for one account. Not wallet transaction history.",
|
|
46
|
+
inputSchema: z.object({
|
|
47
|
+
...reviewActivityInputSchema,
|
|
48
|
+
reviewStatus: internalSessionStatusSchema.optional(),
|
|
49
|
+
requestStatus: transactionRequestStatusSchema.optional(),
|
|
50
|
+
executionStatus: z.enum(["success", "failure"]).optional(),
|
|
51
|
+
limit: z.number().int().min(1).max(REVIEW_ACTIVITY_LIST_MAX_LIMIT).optional()
|
|
52
|
+
}).strict(),
|
|
53
|
+
outputSchema: successOutputSchema({
|
|
54
|
+
...reviewActivityCommonOutput,
|
|
55
|
+
activities: z.array(reviewActivityRowSchema)
|
|
56
|
+
}),
|
|
57
|
+
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
58
|
+
}, async ({ account, from, to, reviewStatus, requestStatus, executionStatus, limit }) => {
|
|
59
|
+
try {
|
|
60
|
+
const result = await deps.activityStore.listReviewActivity({
|
|
61
|
+
account,
|
|
62
|
+
from,
|
|
63
|
+
to,
|
|
64
|
+
reviewStatus, requestStatus, executionStatus,
|
|
65
|
+
limit: limit ?? REVIEW_ACTIVITY_LIST_DEFAULT_LIMIT
|
|
66
|
+
});
|
|
67
|
+
return okToolResult({
|
|
68
|
+
...result,
|
|
69
|
+
userAnswerUse: reviewActivityListUserAnswerUse()
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
return activityStoreReadError(error, deps);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export function registerReviewActivitySummaryTools(server, deps) {
|
|
78
|
+
server.registerTool(TOOL_NAMES.readSummarizeReviewFunnel, {
|
|
79
|
+
title: "Summarize review funnel",
|
|
80
|
+
description: "Lifecycle counts for local Sui MCP review sessions in one account scope.",
|
|
81
|
+
inputSchema: reviewActivityInputSchema,
|
|
82
|
+
outputSchema: successOutputSchema({
|
|
83
|
+
...reviewActivityCommonOutput,
|
|
84
|
+
summary: z.object({
|
|
85
|
+
total: z.number().int().nonnegative(),
|
|
86
|
+
opened: z.number().int().nonnegative(),
|
|
87
|
+
walletConnected: z.number().int().nonnegative(),
|
|
88
|
+
stateComputed: z.number().int().nonnegative(),
|
|
89
|
+
reviewStatusCounts: z.record(internalSessionStatusSchema, z.number().int().nonnegative()),
|
|
90
|
+
requestStatusCounts: z.array(z.object({ requestStatus: z.enum(TRANSACTION_REQUEST_STATUSES), count: z.number().int().nonnegative() }).strict()),
|
|
91
|
+
executionStatusCounts: z.object({ success: z.number().int().nonnegative(), failure: z.number().int().nonnegative() }),
|
|
92
|
+
withoutRequest: z.number().int().nonnegative(),
|
|
93
|
+
withoutExecutionResult: z.number().int().nonnegative(),
|
|
94
|
+
everReachedReviewStateCounts: z.object({
|
|
95
|
+
ready_for_wallet_review: z.number().int().nonnegative(),
|
|
96
|
+
blocked: z.number().int().nonnegative(),
|
|
97
|
+
refresh_required: z.number().int().nonnegative()
|
|
98
|
+
}),
|
|
99
|
+
everAwaitedChainResult: z.number().int().nonnegative(),
|
|
100
|
+
expiredWithoutExecutionResult: z.number().int().nonnegative(),
|
|
101
|
+
avgCreatedToSignatureVerifiedSeconds: z.number().nullable(),
|
|
102
|
+
avgOpenedToSignatureVerifiedSeconds: z.number().nullable()
|
|
103
|
+
})
|
|
104
|
+
}),
|
|
105
|
+
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
106
|
+
}, async ({ account, from, to }) => {
|
|
107
|
+
try {
|
|
108
|
+
const result = await deps.activityStore.summarizeReviewFunnel({ account, from, to });
|
|
109
|
+
return okToolResult({
|
|
110
|
+
...result,
|
|
111
|
+
userAnswerUse: reviewFunnelUserAnswerUse()
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
return activityStoreReadError(error, deps);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
server.registerTool(TOOL_NAMES.readGetReviewSessionDetail, {
|
|
119
|
+
title: "Get review session detail",
|
|
120
|
+
description: "Return one stored Sui MCP review session with plan, snapshots, transitions, and result.",
|
|
121
|
+
inputSchema: {
|
|
122
|
+
reviewSessionId: z.string().min(1),
|
|
123
|
+
account: z.string().min(1).optional()
|
|
124
|
+
},
|
|
125
|
+
outputSchema: successOutputSchema({
|
|
126
|
+
...reviewActivityCommonOutput,
|
|
127
|
+
session: reviewActivityRowSchema.omit({
|
|
128
|
+
executionStatus: true,
|
|
129
|
+
transactionDigest: true,
|
|
130
|
+
requestStatus: true,
|
|
131
|
+
reviewRevision: true,
|
|
132
|
+
snapshotCount: true,
|
|
133
|
+
transitionCount: true
|
|
134
|
+
}),
|
|
135
|
+
planJson: actionPlanSchema,
|
|
136
|
+
intentJson: z.unknown().optional(),
|
|
137
|
+
stateSnapshots: z.array(z.object({
|
|
138
|
+
id: z.number().int().positive(),
|
|
139
|
+
reviewRevision: z.number().int().nonnegative(),
|
|
140
|
+
planId: z.string(),
|
|
141
|
+
account: z.string(),
|
|
142
|
+
status: z.string(),
|
|
143
|
+
blockedReason: z.string().optional(),
|
|
144
|
+
refreshReason: z.string().optional(),
|
|
145
|
+
stateJson: reviewStateOutputSchema,
|
|
146
|
+
updatedAt: fetchedAtSchema,
|
|
147
|
+
recordedAt: fetchedAtSchema
|
|
148
|
+
})),
|
|
149
|
+
transitions: z.array(z.object({
|
|
150
|
+
id: z.number().int().positive(),
|
|
151
|
+
event: z.string(),
|
|
152
|
+
domain: z.enum(["review", "request"]),
|
|
153
|
+
attemptId: z.string().optional(),
|
|
154
|
+
fromStatus: z.string().optional(),
|
|
155
|
+
toStatus: z.string(),
|
|
156
|
+
isNoOp: z.boolean(),
|
|
157
|
+
account: z.string().optional(),
|
|
158
|
+
reason: z.string().optional(),
|
|
159
|
+
transitionedAt: fetchedAtSchema
|
|
160
|
+
})),
|
|
161
|
+
request: transactionRequestSchema.optional(),
|
|
162
|
+
requestCount: z.number().int().nonnegative(),
|
|
163
|
+
requests: z.array(transactionRequestSchema)
|
|
164
|
+
}),
|
|
165
|
+
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
166
|
+
}, async ({ reviewSessionId, account }) => {
|
|
167
|
+
try {
|
|
168
|
+
const result = await deps.activityStore.getReviewSessionDetail({ reviewSessionId, account });
|
|
169
|
+
return okToolResult({
|
|
170
|
+
...result,
|
|
171
|
+
userAnswerUse: reviewSessionDetailUserAnswerUse({ hasCurrentRequest: !!result.request, hasCurrentExecution: !!result.request?.execution,
|
|
172
|
+
hasHistoricalExecution: result.requests.some((request) => !!request.execution) })
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
return activityStoreReadError(error, deps);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { noParamsInputSchema, successOutputSchema } from "../../schemas.js";
|
|
3
|
+
import { okToolResult } from "../../result.js";
|
|
4
|
+
import { MCP_PROMPTS } from "../../prompts.js";
|
|
5
|
+
import { MCP_RESOURCES } from "../../resources.js";
|
|
6
|
+
import { EVIDENCE_POLICY, FAIL_CLOSED_TOOLS, IMPLEMENTED_TOOLS, PACKAGE_NAME, SERVER_LIMITATIONS, SERVER_NAME, SERVER_NETWORK, SERVER_RUNTIME, SERVER_TRANSPORT, SERVER_VERSION } from "../../serverInfo.js";
|
|
7
|
+
import { TOOL_NAMES } from "../../toolNames.js";
|
|
8
|
+
// Executable swap adapters precede protocol-notes-only entries.
|
|
9
|
+
export const SUPPORTED_PROTOCOLS = [
|
|
10
|
+
{ id: "deepbook-v3", status: "mainnet", support: "read_and_local_review" },
|
|
11
|
+
{ id: "deepbook-margin", status: "mainnet", support: "protocol_notes_only" }
|
|
12
|
+
];
|
|
13
|
+
export function registerServerStatusTools(server) {
|
|
14
|
+
server.registerTool(TOOL_NAMES.readGetServerStatus, {
|
|
15
|
+
title: "Get server status",
|
|
16
|
+
description: "Return package, runtime, tool, resource, and prompt status.",
|
|
17
|
+
inputSchema: noParamsInputSchema,
|
|
18
|
+
outputSchema: successOutputSchema({
|
|
19
|
+
packageName: z.string(),
|
|
20
|
+
serverName: z.string(),
|
|
21
|
+
version: z.string(),
|
|
22
|
+
evidencePolicy: z.object({
|
|
23
|
+
version: z.string(),
|
|
24
|
+
releaseGate: z.literal("intent_evidence_v1"),
|
|
25
|
+
requiredFirstCheck: z.literal(true),
|
|
26
|
+
requiredStatusFields: z.array(z.string()),
|
|
27
|
+
gates: z.array(z.string())
|
|
28
|
+
}),
|
|
29
|
+
network: z.literal("mainnet"),
|
|
30
|
+
runtime: z.literal("local_stdio"),
|
|
31
|
+
transport: z.literal("grpc_graphql"),
|
|
32
|
+
implementedTools: z.array(z.string()),
|
|
33
|
+
implementedToolsCount: z.number().int().nonnegative(),
|
|
34
|
+
failClosedTools: z.array(z.string()),
|
|
35
|
+
resources: z.object({
|
|
36
|
+
count: z.number().int().nonnegative(),
|
|
37
|
+
uris: z.array(z.string()),
|
|
38
|
+
items: z.array(z.object({
|
|
39
|
+
name: z.string(),
|
|
40
|
+
uri: z.string(),
|
|
41
|
+
title: z.string(),
|
|
42
|
+
description: z.string()
|
|
43
|
+
}))
|
|
44
|
+
}),
|
|
45
|
+
prompts: z.object({
|
|
46
|
+
count: z.number().int().nonnegative(),
|
|
47
|
+
names: z.array(z.string())
|
|
48
|
+
}),
|
|
49
|
+
protocolsTool: z.literal("read.list_supported_protocols"),
|
|
50
|
+
limitations: z.array(z.string())
|
|
51
|
+
}),
|
|
52
|
+
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
53
|
+
}, async () => okToolResult({
|
|
54
|
+
packageName: PACKAGE_NAME,
|
|
55
|
+
serverName: SERVER_NAME,
|
|
56
|
+
version: SERVER_VERSION,
|
|
57
|
+
evidencePolicy: {
|
|
58
|
+
...EVIDENCE_POLICY,
|
|
59
|
+
requiredStatusFields: [...EVIDENCE_POLICY.requiredStatusFields],
|
|
60
|
+
gates: [...EVIDENCE_POLICY.gates]
|
|
61
|
+
},
|
|
62
|
+
network: SERVER_NETWORK,
|
|
63
|
+
runtime: SERVER_RUNTIME,
|
|
64
|
+
transport: SERVER_TRANSPORT,
|
|
65
|
+
implementedTools: [...IMPLEMENTED_TOOLS],
|
|
66
|
+
implementedToolsCount: IMPLEMENTED_TOOLS.length,
|
|
67
|
+
failClosedTools: [...FAIL_CLOSED_TOOLS],
|
|
68
|
+
resources: {
|
|
69
|
+
count: MCP_RESOURCES.length,
|
|
70
|
+
uris: MCP_RESOURCES.map((resource) => resource.uri),
|
|
71
|
+
items: MCP_RESOURCES.map((resource) => ({
|
|
72
|
+
name: resource.name,
|
|
73
|
+
uri: resource.uri,
|
|
74
|
+
title: resource.title,
|
|
75
|
+
description: resource.description
|
|
76
|
+
}))
|
|
77
|
+
},
|
|
78
|
+
prompts: {
|
|
79
|
+
count: MCP_PROMPTS.length,
|
|
80
|
+
names: MCP_PROMPTS.map((prompt) => prompt.name)
|
|
81
|
+
},
|
|
82
|
+
protocolsTool: TOOL_NAMES.readListSupportedProtocols,
|
|
83
|
+
limitations: [...SERVER_LIMITATIONS]
|
|
84
|
+
}));
|
|
85
|
+
server.registerTool(TOOL_NAMES.readListSupportedProtocols, {
|
|
86
|
+
title: "List supported protocols",
|
|
87
|
+
description: "List current mainnet protocol surfaces and support levels.",
|
|
88
|
+
inputSchema: noParamsInputSchema,
|
|
89
|
+
outputSchema: successOutputSchema({
|
|
90
|
+
protocols: z.array(z.object({
|
|
91
|
+
id: z.string(),
|
|
92
|
+
status: z.literal("mainnet"),
|
|
93
|
+
support: z.string()
|
|
94
|
+
}))
|
|
95
|
+
}),
|
|
96
|
+
annotations: { readOnlyHint: true, openWorldHint: false }
|
|
97
|
+
}, async () => okToolResult({
|
|
98
|
+
protocols: [...SUPPORTED_PROTOCOLS]
|
|
99
|
+
}));
|
|
100
|
+
}
|