@opendatalabs/personal-server-ts-core 0.2.0 → 1.1.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/dist/api/index.d.ts +160 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +774 -0
- package/dist/api/index.js.map +1 -0
- package/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +2 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/request.d.ts +28 -0
- package/dist/auth/request.d.ts.map +1 -0
- package/dist/auth/request.js +106 -0
- package/dist/auth/request.js.map +1 -0
- package/dist/client.d.ts +233 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +243 -0
- package/dist/client.js.map +1 -0
- package/dist/config/defaults.d.ts +5 -5
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +3 -5
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/index.d.ts +0 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +0 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/paths.d.ts.map +1 -1
- package/dist/config/paths.js +1 -9
- package/dist/config/paths.js.map +1 -1
- package/dist/contracts/access-logs.d.ts +8 -0
- package/dist/contracts/access-logs.d.ts.map +1 -0
- package/dist/contracts/access-logs.js +7 -0
- package/dist/contracts/access-logs.js.map +1 -0
- package/dist/contracts/auth-device.d.ts +70 -0
- package/dist/contracts/auth-device.d.ts.map +1 -0
- package/dist/contracts/auth-device.js +163 -0
- package/dist/contracts/auth-device.js.map +1 -0
- package/dist/contracts/binary.d.ts +54 -0
- package/dist/contracts/binary.d.ts.map +1 -0
- package/dist/contracts/binary.js +92 -0
- package/dist/contracts/binary.js.map +1 -0
- package/dist/contracts/config.d.ts +5 -0
- package/dist/contracts/config.d.ts.map +1 -0
- package/dist/contracts/config.js +30 -0
- package/dist/contracts/config.js.map +1 -0
- package/dist/contracts/data.d.ts +115 -0
- package/dist/contracts/data.d.ts.map +1 -0
- package/dist/contracts/data.js +237 -0
- package/dist/contracts/data.js.map +1 -0
- package/dist/contracts/grants.d.ts +45 -0
- package/dist/contracts/grants.d.ts.map +1 -0
- package/dist/contracts/grants.js +177 -0
- package/dist/contracts/grants.js.map +1 -0
- package/dist/contracts/http.d.ts +21 -0
- package/dist/contracts/http.d.ts.map +1 -0
- package/dist/contracts/http.js +49 -0
- package/dist/contracts/http.js.map +1 -0
- package/dist/contracts/index.d.ts +16 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +10 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/contracts/oauth.d.ts +38 -0
- package/dist/contracts/oauth.d.ts.map +1 -0
- package/dist/contracts/oauth.js +130 -0
- package/dist/contracts/oauth.js.map +1 -0
- package/dist/contracts/sync.d.ts +10 -0
- package/dist/contracts/sync.d.ts.map +1 -0
- package/dist/contracts/sync.js +34 -0
- package/dist/contracts/sync.js.map +1 -0
- package/dist/errors/catalog.d.ts +9 -0
- package/dist/errors/catalog.d.ts.map +1 -1
- package/dist/errors/catalog.js +15 -0
- package/dist/errors/catalog.js.map +1 -1
- package/dist/grants/index.d.ts +2 -4
- package/dist/grants/index.d.ts.map +1 -1
- package/dist/grants/index.js +1 -2
- package/dist/grants/index.js.map +1 -1
- package/dist/keys/index.d.ts +1 -2
- package/dist/keys/index.d.ts.map +1 -1
- package/dist/keys/index.js +1 -2
- package/dist/keys/index.js.map +1 -1
- package/dist/keys/server-account.d.ts +5 -9
- package/dist/keys/server-account.d.ts.map +1 -1
- package/dist/keys/server-account.js +1 -47
- package/dist/keys/server-account.js.map +1 -1
- package/dist/logger/index.d.ts +6 -2
- package/dist/logger/index.d.ts.map +1 -1
- package/dist/logger/index.js +2 -6
- package/dist/logger/index.js.map +1 -1
- package/dist/logging/access-log.d.ts +0 -1
- package/dist/logging/access-log.d.ts.map +1 -1
- package/dist/logging/access-log.js +1 -24
- package/dist/logging/access-log.js.map +1 -1
- package/dist/logging/access-reader.d.ts +0 -5
- package/dist/logging/access-reader.d.ts.map +1 -1
- package/dist/logging/access-reader.js +1 -49
- package/dist/logging/access-reader.js.map +1 -1
- package/dist/mcp/activity.d.ts +68 -0
- package/dist/mcp/activity.d.ts.map +1 -0
- package/dist/mcp/activity.js +111 -0
- package/dist/mcp/activity.js.map +1 -0
- package/dist/mcp/builder-registration.d.ts +24 -0
- package/dist/mcp/builder-registration.d.ts.map +1 -0
- package/dist/mcp/builder-registration.js +89 -0
- package/dist/mcp/builder-registration.js.map +1 -0
- package/dist/mcp/connection-api.d.ts +170 -0
- package/dist/mcp/connection-api.d.ts.map +1 -0
- package/dist/mcp/connection-api.js +379 -0
- package/dist/mcp/connection-api.js.map +1 -0
- package/dist/mcp/grantee.d.ts +52 -0
- package/dist/mcp/grantee.d.ts.map +1 -0
- package/dist/mcp/grantee.js +91 -0
- package/dist/mcp/grantee.js.map +1 -0
- package/dist/mcp/index.d.ts +10 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +10 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/read-client.d.ts +136 -0
- package/dist/mcp/read-client.d.ts.map +1 -0
- package/dist/mcp/read-client.js +306 -0
- package/dist/mcp/read-client.js.map +1 -0
- package/dist/mcp/resources.d.ts +37 -0
- package/dist/mcp/resources.d.ts.map +1 -0
- package/dist/mcp/resources.js +114 -0
- package/dist/mcp/resources.js.map +1 -0
- package/dist/mcp/search/index.d.ts +34 -0
- package/dist/mcp/search/index.d.ts.map +1 -0
- package/dist/mcp/search/index.js +69 -0
- package/dist/mcp/search/index.js.map +1 -0
- package/dist/mcp/server.d.ts +53 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +308 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/store.d.ts +13 -0
- package/dist/mcp/store.d.ts.map +1 -0
- package/dist/mcp/store.js +98 -0
- package/dist/mcp/store.js.map +1 -0
- package/dist/mcp/tools.d.ts +60 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +1058 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/mcp/types.d.ts +97 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +24 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/payment/index.d.ts +2 -0
- package/dist/payment/index.d.ts.map +1 -0
- package/dist/payment/index.js +2 -0
- package/dist/payment/index.js.map +1 -0
- package/dist/payment/x402.d.ts +155 -0
- package/dist/payment/x402.d.ts.map +1 -0
- package/dist/payment/x402.js +402 -0
- package/dist/payment/x402.js.map +1 -0
- package/dist/policy/data-read.d.ts +15 -0
- package/dist/policy/data-read.d.ts.map +1 -0
- package/dist/policy/data-read.js +84 -0
- package/dist/policy/data-read.js.map +1 -0
- package/dist/policy/index.d.ts +2 -0
- package/dist/policy/index.d.ts.map +1 -0
- package/dist/policy/index.js +2 -0
- package/dist/policy/index.js.map +1 -0
- package/dist/ports/index.d.ts +95 -0
- package/dist/ports/index.d.ts.map +1 -0
- package/dist/ports/index.js +7 -0
- package/dist/ports/index.js.map +1 -0
- package/dist/schemas/server-config.d.ts +12 -0
- package/dist/schemas/server-config.d.ts.map +1 -1
- package/dist/schemas/server-config.js +34 -4
- package/dist/schemas/server-config.js.map +1 -1
- package/dist/signing/index.d.ts +0 -1
- package/dist/signing/index.d.ts.map +1 -1
- package/dist/signing/index.js +0 -1
- package/dist/signing/index.js.map +1 -1
- package/dist/signing/request-signer.d.ts +8 -2
- package/dist/signing/request-signer.d.ts.map +1 -1
- package/dist/signing/request-signer.js +5 -31
- package/dist/signing/request-signer.js.map +1 -1
- package/dist/signing/signer.d.ts +20 -2
- package/dist/signing/signer.d.ts.map +1 -1
- package/dist/signing/signer.js +23 -13
- package/dist/signing/signer.js.map +1 -1
- package/dist/storage/adapters/index.d.ts +2 -1
- package/dist/storage/adapters/index.d.ts.map +1 -1
- package/dist/storage/adapters/index.js +2 -1
- package/dist/storage/adapters/index.js.map +1 -1
- package/dist/storage/adapters/interface.d.ts +10 -0
- package/dist/storage/adapters/interface.d.ts.map +1 -1
- package/dist/storage/adapters/sdk.d.ts +23 -0
- package/dist/storage/adapters/sdk.d.ts.map +1 -0
- package/dist/storage/adapters/sdk.js +73 -0
- package/dist/storage/adapters/sdk.js.map +1 -0
- package/dist/storage/adapters/vana.d.ts +7 -30
- package/dist/storage/adapters/vana.d.ts.map +1 -1
- package/dist/storage/adapters/vana.js +37 -92
- package/dist/storage/adapters/vana.js.map +1 -1
- package/dist/storage/blocks/build.d.ts +20 -0
- package/dist/storage/blocks/build.d.ts.map +1 -0
- package/dist/storage/blocks/build.js +378 -0
- package/dist/storage/blocks/build.js.map +1 -0
- package/dist/storage/blocks/cursor.d.ts +33 -0
- package/dist/storage/blocks/cursor.d.ts.map +1 -0
- package/dist/storage/blocks/cursor.js +142 -0
- package/dist/storage/blocks/cursor.js.map +1 -0
- package/dist/storage/blocks/errors.d.ts +6 -0
- package/dist/storage/blocks/errors.d.ts.map +1 -0
- package/dist/storage/blocks/errors.js +9 -0
- package/dist/storage/blocks/errors.js.map +1 -0
- package/dist/storage/blocks/index.d.ts +5 -0
- package/dist/storage/blocks/index.d.ts.map +1 -0
- package/dist/storage/blocks/index.js +4 -0
- package/dist/storage/blocks/index.js.map +1 -0
- package/dist/storage/blocks/types.d.ts +49 -0
- package/dist/storage/blocks/types.d.ts.map +1 -0
- package/dist/storage/blocks/types.js +2 -0
- package/dist/{grants → storage/blocks}/types.js.map +1 -1
- package/dist/storage/hierarchy/index.d.ts +0 -1
- package/dist/storage/hierarchy/index.d.ts.map +1 -1
- package/dist/storage/hierarchy/index.js +0 -1
- package/dist/storage/hierarchy/index.js.map +1 -1
- package/dist/storage/hierarchy/manager.d.ts +0 -14
- package/dist/storage/hierarchy/manager.d.ts.map +1 -1
- package/dist/storage/hierarchy/manager.js +1 -59
- package/dist/storage/hierarchy/manager.js.map +1 -1
- package/dist/storage/hierarchy/paths.d.ts.map +1 -1
- package/dist/storage/hierarchy/paths.js +11 -4
- package/dist/storage/hierarchy/paths.js.map +1 -1
- package/dist/storage/index/index.d.ts +2 -3
- package/dist/storage/index/index.d.ts.map +1 -1
- package/dist/storage/index/index.js +1 -2
- package/dist/storage/index/index.js.map +1 -1
- package/dist/storage/index/manager.d.ts +26 -6
- package/dist/storage/index/manager.d.ts.map +1 -1
- package/dist/storage/index/manager.js +1 -131
- package/dist/storage/index/manager.js.map +1 -1
- package/dist/storage/index/schema.d.ts +1 -3
- package/dist/storage/index/schema.d.ts.map +1 -1
- package/dist/storage/index/schema.js +1 -26
- package/dist/storage/index/schema.js.map +1 -1
- package/dist/storage/index/types.d.ts +16 -0
- package/dist/storage/index/types.d.ts.map +1 -1
- package/dist/storage/preview.d.ts +12 -0
- package/dist/storage/preview.d.ts.map +1 -0
- package/dist/storage/preview.js +239 -0
- package/dist/storage/preview.js.map +1 -0
- package/dist/sync/cursor.d.ts +5 -7
- package/dist/sync/cursor.d.ts.map +1 -1
- package/dist/sync/cursor.js +1 -18
- package/dist/sync/cursor.js.map +1 -1
- package/dist/sync/engine/sync-manager.d.ts +17 -0
- package/dist/sync/engine/sync-manager.d.ts.map +1 -1
- package/dist/sync/engine/sync-manager.js +104 -43
- package/dist/sync/engine/sync-manager.js.map +1 -1
- package/dist/sync/index.d.ts +4 -2
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +1 -1
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/issues.d.ts +55 -0
- package/dist/sync/issues.d.ts.map +1 -0
- package/dist/sync/issues.js +168 -0
- package/dist/sync/issues.js.map +1 -0
- package/dist/sync/retry-memory.d.ts +33 -0
- package/dist/sync/retry-memory.d.ts.map +1 -0
- package/dist/sync/retry-memory.js +68 -0
- package/dist/sync/retry-memory.js.map +1 -0
- package/dist/sync/types.d.ts +9 -24
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/sync/workers/delete.d.ts +42 -0
- package/dist/sync/workers/delete.d.ts.map +1 -0
- package/dist/sync/workers/delete.js +40 -0
- package/dist/sync/workers/delete.js.map +1 -0
- package/dist/sync/workers/download.d.ts +64 -18
- package/dist/sync/workers/download.d.ts.map +1 -1
- package/dist/sync/workers/download.js +396 -54
- package/dist/sync/workers/download.js.map +1 -1
- package/dist/sync/workers/upload.d.ts +29 -18
- package/dist/sync/workers/upload.d.ts.map +1 -1
- package/dist/sync/workers/upload.js +163 -46
- package/dist/sync/workers/upload.js.map +1 -1
- package/dist/test-utils/wallet.d.ts +1 -0
- package/dist/test-utils/wallet.d.ts.map +1 -1
- package/dist/test-utils/wallet.js +9 -31
- package/dist/test-utils/wallet.js.map +1 -1
- package/package.json +51 -27
- package/dist/auth/web3-signed.d.ts +0 -48
- package/dist/auth/web3-signed.d.ts.map +0 -1
- package/dist/auth/web3-signed.js +0 -110
- package/dist/auth/web3-signed.js.map +0 -1
- package/dist/config/loader.d.ts +0 -8
- package/dist/config/loader.d.ts.map +0 -1
- package/dist/config/loader.js +0 -38
- package/dist/config/loader.js.map +0 -1
- package/dist/gateway/client.d.ts +0 -98
- package/dist/gateway/client.d.ts.map +0 -1
- package/dist/gateway/client.js +0 -171
- package/dist/gateway/client.js.map +0 -1
- package/dist/grants/eip712.d.ts +0 -28
- package/dist/grants/eip712.d.ts.map +0 -1
- package/dist/grants/eip712.js +0 -30
- package/dist/grants/eip712.js.map +0 -1
- package/dist/grants/types.d.ts +0 -29
- package/dist/grants/types.d.ts.map +0 -1
- package/dist/grants/types.js +0 -6
- package/dist/grants/verify.d.ts +0 -24
- package/dist/grants/verify.d.ts.map +0 -1
- package/dist/grants/verify.js +0 -71
- package/dist/grants/verify.js.map +0 -1
- package/dist/keys/derive.d.ts +0 -18
- package/dist/keys/derive.d.ts.map +0 -1
- package/dist/keys/derive.js +0 -43
- package/dist/keys/derive.js.map +0 -1
- package/dist/schemas/data-file.d.ts +0 -20
- package/dist/schemas/data-file.d.ts.map +0 -1
- package/dist/schemas/data-file.js +0 -23
- package/dist/schemas/data-file.js.map +0 -1
- package/dist/scopes/index.d.ts +0 -3
- package/dist/scopes/index.d.ts.map +0 -1
- package/dist/scopes/index.js +0 -3
- package/dist/scopes/index.js.map +0 -1
- package/dist/scopes/match.d.ts +0 -13
- package/dist/scopes/match.d.ts.map +0 -1
- package/dist/scopes/match.js +0 -23
- package/dist/scopes/match.js.map +0 -1
- package/dist/scopes/parse.d.ts +0 -12
- package/dist/scopes/parse.d.ts.map +0 -1
- package/dist/scopes/parse.js +0 -29
- package/dist/scopes/parse.js.map +0 -1
- package/dist/signing/eip712.d.ts +0 -69
- package/dist/signing/eip712.d.ts.map +0 -1
- package/dist/signing/eip712.js +0 -68
- package/dist/signing/eip712.js.map +0 -1
- package/dist/storage/encryption/decrypt.d.ts +0 -10
- package/dist/storage/encryption/decrypt.d.ts.map +0 -1
- package/dist/storage/encryption/decrypt.js +0 -19
- package/dist/storage/encryption/decrypt.js.map +0 -1
- package/dist/storage/encryption/encrypt.d.ts +0 -10
- package/dist/storage/encryption/encrypt.d.ts.map +0 -1
- package/dist/storage/encryption/encrypt.js +0 -19
- package/dist/storage/encryption/encrypt.js.map +0 -1
- package/dist/storage/encryption/index.d.ts +0 -3
- package/dist/storage/encryption/index.d.ts.map +0 -1
- package/dist/storage/encryption/index.js +0 -3
- package/dist/storage/encryption/index.js.map +0 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-connection MCP grantee key generation + Web3Signed request signing.
|
|
3
|
+
*
|
|
4
|
+
* Each MCP connection gets a fresh secp256k1 keypair. The PS route uses this
|
|
5
|
+
* keypair to sign every read it performs on behalf of the connection so:
|
|
6
|
+
*
|
|
7
|
+
* 1. The data read flows through `authorizeBuilderRead` exactly like any
|
|
8
|
+
* external builder request.
|
|
9
|
+
* 2. The access log records the per-connection grantee address, not the
|
|
10
|
+
* owner.
|
|
11
|
+
* 3. Disconnecting one MCP client cannot affect another or the owner.
|
|
12
|
+
*
|
|
13
|
+
* This module does NOT do encryption-at-rest. The caller chooses the storage
|
|
14
|
+
* representation (`McpEncryptedPrivateKey`) — for Node the `plaintext` variant
|
|
15
|
+
* is fine (same trust boundary as the on-disk server key); for Web PS Lite the
|
|
16
|
+
* caller should wrap with the owner-derived master key.
|
|
17
|
+
*/
|
|
18
|
+
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
|
|
19
|
+
import { buildWeb3SignedHeader } from "@opendatalabs/vana-sdk/browser";
|
|
20
|
+
/**
|
|
21
|
+
* Generate a new MCP grantee keypair and return both the persisted
|
|
22
|
+
* (plaintext-wrapped) form and a ready-to-sign `ServerAccount`.
|
|
23
|
+
*/
|
|
24
|
+
export function generateMcpGrantee() {
|
|
25
|
+
const privateKey = generatePrivateKey();
|
|
26
|
+
const account = privateKeyToAccount(privateKey);
|
|
27
|
+
const serverAccount = {
|
|
28
|
+
address: account.address,
|
|
29
|
+
publicKey: account.publicKey,
|
|
30
|
+
async signTypedData(params) {
|
|
31
|
+
return account.signTypedData({
|
|
32
|
+
domain: params.domain,
|
|
33
|
+
types: params.types,
|
|
34
|
+
primaryType: params.primaryType,
|
|
35
|
+
message: params.message,
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
async signMessage(message) {
|
|
39
|
+
return account.signMessage({ message });
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
key: {
|
|
44
|
+
address: account.address,
|
|
45
|
+
publicKey: account.publicKey,
|
|
46
|
+
encryptedPrivateKey: { kind: "plaintext", privateKey },
|
|
47
|
+
},
|
|
48
|
+
account: serverAccount,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Reconstruct a `ServerAccount` from a persisted MCP grantee record.
|
|
53
|
+
* Only `plaintext` is supported here; Web PS Lite must decrypt to plaintext
|
|
54
|
+
* before calling.
|
|
55
|
+
*/
|
|
56
|
+
export function loadMcpGranteeAccount(key) {
|
|
57
|
+
if (key.encryptedPrivateKey.kind !== "plaintext") {
|
|
58
|
+
throw new Error("loadMcpGranteeAccount: only plaintext keys are supported here; decrypt first");
|
|
59
|
+
}
|
|
60
|
+
const account = privateKeyToAccount(key.encryptedPrivateKey.privateKey);
|
|
61
|
+
return {
|
|
62
|
+
address: account.address,
|
|
63
|
+
publicKey: account.publicKey,
|
|
64
|
+
async signTypedData(params) {
|
|
65
|
+
return account.signTypedData({
|
|
66
|
+
domain: params.domain,
|
|
67
|
+
types: params.types,
|
|
68
|
+
primaryType: params.primaryType,
|
|
69
|
+
message: params.message,
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
async signMessage(message) {
|
|
73
|
+
return account.signMessage({ message });
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Build a Web3Signed Authorization header that authenticates the bearer as the
|
|
79
|
+
* MCP connection's grantee for a given grant id and request URL.
|
|
80
|
+
*/
|
|
81
|
+
export async function signMcpGranteeRequest(params) {
|
|
82
|
+
return buildWeb3SignedHeader({
|
|
83
|
+
signMessage: (message) => params.account.signMessage(message),
|
|
84
|
+
aud: params.aud,
|
|
85
|
+
method: params.method,
|
|
86
|
+
uri: params.uri,
|
|
87
|
+
body: params.body,
|
|
88
|
+
grantId: params.grantId,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=grantee.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grantee.js","sourceRoot":"","sources":["../../src/mcp/grantee.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAevE;;;GAGG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,UAAU,GAAG,kBAAkB,EAAE,CAAC;IACxC,MAAM,OAAO,GAAG,mBAAmB,CA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,WAAW;gBAC/B,OAAO,EAAE,MAAM,CAAC,OAAO;aACxB,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,WAAW,CAAC,OAAO;YACvB,OAAO,OAAO,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;QAC1C,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,MAO3C;IACC,OAAO,qBAAqB,CAAC;QAC3B,WAAW,EAAE,CAAC,OAAe,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC;QACrE,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./store.js";
|
|
3
|
+
export * from "./grantee.js";
|
|
4
|
+
export * from "./builder-registration.js";
|
|
5
|
+
export * from "./read-client.js";
|
|
6
|
+
export * from "./tools.js";
|
|
7
|
+
export * from "./server.js";
|
|
8
|
+
export * from "./connection-api.js";
|
|
9
|
+
export * from "./activity.js";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./store.js";
|
|
3
|
+
export * from "./grantee.js";
|
|
4
|
+
export * from "./builder-registration.js";
|
|
5
|
+
export * from "./read-client.js";
|
|
6
|
+
export * from "./tools.js";
|
|
7
|
+
export * from "./server.js";
|
|
8
|
+
export * from "./connection-api.js";
|
|
9
|
+
export * from "./activity.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-process MCP read client.
|
|
3
|
+
*
|
|
4
|
+
* The MCP route accepts a tool call from an MCP client, then needs to read scoped data
|
|
5
|
+
* from the user's Personal Server *as the per-connection grantee*. We do NOT
|
|
6
|
+
* round-trip through the public HTTP origin for this — the relay/tunnel is only
|
|
7
|
+
* for inbound MCP traffic. Instead we:
|
|
8
|
+
*
|
|
9
|
+
* 1. Build a Web Request signed by the connection's grantee, with the
|
|
10
|
+
* existing grantId in the Web3Signed payload.
|
|
11
|
+
* 2. Use the same auth and access-log ports as `/v1/data`, then read bounded
|
|
12
|
+
* block sidecars from storage. MCP tools must not fall back to full envelope
|
|
13
|
+
* reads when sidecars are unavailable.
|
|
14
|
+
*
|
|
15
|
+
* This guarantees parity: the MCP read goes through the same policy check
|
|
16
|
+
* (`verifyDataReadPolicy`) and access-log path as an external builder read.
|
|
17
|
+
* No special owner-mode code path; no shared global grantee; logs record the
|
|
18
|
+
* per-connection grantee address.
|
|
19
|
+
*/
|
|
20
|
+
import type { ServerAccount } from "../keys/server-account.js";
|
|
21
|
+
import type { ScopeSummary } from "../storage/index/types.js";
|
|
22
|
+
import type { ReadScopeBlocksResponse } from "../storage/blocks/types.js";
|
|
23
|
+
import type { SearchHit } from "./search/index.js";
|
|
24
|
+
import { type PersonalServerDataApiDeps } from "../api/index.js";
|
|
25
|
+
export interface McpScopeMetadata {
|
|
26
|
+
scope: string;
|
|
27
|
+
collectedAt: string;
|
|
28
|
+
sizeBytes: number;
|
|
29
|
+
/** True when the bounded block read path is available for this scope. */
|
|
30
|
+
hasBlocks: boolean;
|
|
31
|
+
}
|
|
32
|
+
export interface McpDataReadClient {
|
|
33
|
+
/**
|
|
34
|
+
* Perform `GET /v1/data?scopePrefix=…` as the connection grantee. This is
|
|
35
|
+
* used only for discovery/expanding wildcard grants before a grant-gated
|
|
36
|
+
* read; it does not return scope contents.
|
|
37
|
+
*/
|
|
38
|
+
listScopes(params?: {
|
|
39
|
+
scopePrefix?: string;
|
|
40
|
+
limit?: number;
|
|
41
|
+
offset?: number;
|
|
42
|
+
}): Promise<McpDataListResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Return lightweight planning metadata for a scope using the storage index
|
|
45
|
+
* only — no network call, no block read, no auth. Used by list_granted_scopes
|
|
46
|
+
* to populate sizeBytes/sizeClass/recommendedAccess without reading data.
|
|
47
|
+
* Returns null when the scope has no local index entry.
|
|
48
|
+
*/
|
|
49
|
+
getScopeMetadata(scope: string): Promise<McpScopeMetadata | null>;
|
|
50
|
+
/**
|
|
51
|
+
* Perform a grant-gated bounded block read for MCP. This is the path used by
|
|
52
|
+
* MCP tools that need pagination and must not fall back to full envelope
|
|
53
|
+
* reads when the bounded storage path is unavailable.
|
|
54
|
+
*/
|
|
55
|
+
readScopeBlocks(params: {
|
|
56
|
+
scope: string;
|
|
57
|
+
grantId: string;
|
|
58
|
+
cursor?: string;
|
|
59
|
+
maxBytes?: number;
|
|
60
|
+
}): Promise<McpDataReadBlocksResult>;
|
|
61
|
+
/**
|
|
62
|
+
* Perform a grant-gated raw binary read for an approved binary scope. This
|
|
63
|
+
* reuses `/v1/data/{scope}?content=raw` so policy checks and access logs stay
|
|
64
|
+
* identical to normal builder reads.
|
|
65
|
+
*/
|
|
66
|
+
readRawScopeFile(params: {
|
|
67
|
+
scope: string;
|
|
68
|
+
grantId: string;
|
|
69
|
+
at?: string;
|
|
70
|
+
fileId?: string;
|
|
71
|
+
}): Promise<McpDataReadRawFileResult>;
|
|
72
|
+
/**
|
|
73
|
+
* Optional indexed search path. Implementations may return `missing` while
|
|
74
|
+
* an index is absent/stale; callers must keep the bounded block read path as
|
|
75
|
+
* fallback so full data remains accessible.
|
|
76
|
+
*/
|
|
77
|
+
searchScopeIndex?(params: {
|
|
78
|
+
scope: string;
|
|
79
|
+
grantId: string;
|
|
80
|
+
query: string;
|
|
81
|
+
maxResults: number;
|
|
82
|
+
}): Promise<{
|
|
83
|
+
status: "hit";
|
|
84
|
+
hits: SearchHit[];
|
|
85
|
+
} | {
|
|
86
|
+
status: "missing";
|
|
87
|
+
}>;
|
|
88
|
+
}
|
|
89
|
+
export interface McpDataListResult {
|
|
90
|
+
status: number;
|
|
91
|
+
scopes: ScopeSummary[];
|
|
92
|
+
total: number;
|
|
93
|
+
limit: number;
|
|
94
|
+
offset: number;
|
|
95
|
+
}
|
|
96
|
+
export interface McpDataReadBlocksResult extends ReadScopeBlocksResponse {
|
|
97
|
+
status: number;
|
|
98
|
+
}
|
|
99
|
+
export interface McpDataReadRawFileResult {
|
|
100
|
+
status: number;
|
|
101
|
+
scope: string;
|
|
102
|
+
collectedAt?: string;
|
|
103
|
+
fileId?: string;
|
|
104
|
+
mimeType: string;
|
|
105
|
+
filename?: string;
|
|
106
|
+
sizeBytes: number;
|
|
107
|
+
contentBase64: string;
|
|
108
|
+
metadata?: unknown;
|
|
109
|
+
}
|
|
110
|
+
export declare class McpDataReadError extends Error {
|
|
111
|
+
status: number;
|
|
112
|
+
body: unknown;
|
|
113
|
+
constructor(status: number, body: unknown);
|
|
114
|
+
}
|
|
115
|
+
export interface CreateMcpDataReadClientOptions {
|
|
116
|
+
/**
|
|
117
|
+
* Origin the Web3Signed payload's `aud` claim is bound to. This MUST match
|
|
118
|
+
* the `serverOrigin` configured on the data API auth port — otherwise the
|
|
119
|
+
* signature audience check will fail.
|
|
120
|
+
*/
|
|
121
|
+
serverOrigin: string;
|
|
122
|
+
granteeAccount: ServerAccount;
|
|
123
|
+
/**
|
|
124
|
+
* The data API deps used to mount `/v1/data` for external traffic. We reuse
|
|
125
|
+
* the exact same handler + ports so policy and access-logging are identical.
|
|
126
|
+
*/
|
|
127
|
+
dataApiDeps: PersonalServerDataApiDeps;
|
|
128
|
+
/**
|
|
129
|
+
* Base path the data API was mounted under externally — required so the
|
|
130
|
+
* Web3Signed signature URI matches what `handlePersonalServerDataRequest`
|
|
131
|
+
* expects after strip-base-path. Defaults to `/v1/data`.
|
|
132
|
+
*/
|
|
133
|
+
basePath?: string;
|
|
134
|
+
}
|
|
135
|
+
export declare function createMcpDataReadClient(options: CreateMcpDataReadClientOptions): McpDataReadClient;
|
|
136
|
+
//# sourceMappingURL=read-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-client.d.ts","sourceRoot":"","sources":["../../src/mcp/read-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAInD,OAAO,EAGL,KAAK,yBAAyB,EAC/B,MAAM,iBAAiB,CAAC;AAGzB,MAAM,WAAW,gBAAgB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AC;CACH;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,uBAAwB,SAAQ,uBAAuB;IACtE,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,qBAAa,gBAAiB,SAAQ,KAAK;IAEhC,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,OAAO;gBADb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO;CAWvB;AAED,MAAM,WAAW,8BAA8B;IAC7C;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,aAAa,CAAC;IAC9B;;;OAGG;IACH,WAAW,EAAE,yBAAyB,CAAC;IACvC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,8BAA8B,GACtC,iBAAiB,CAqQnB"}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-process MCP read client.
|
|
3
|
+
*
|
|
4
|
+
* The MCP route accepts a tool call from an MCP client, then needs to read scoped data
|
|
5
|
+
* from the user's Personal Server *as the per-connection grantee*. We do NOT
|
|
6
|
+
* round-trip through the public HTTP origin for this — the relay/tunnel is only
|
|
7
|
+
* for inbound MCP traffic. Instead we:
|
|
8
|
+
*
|
|
9
|
+
* 1. Build a Web Request signed by the connection's grantee, with the
|
|
10
|
+
* existing grantId in the Web3Signed payload.
|
|
11
|
+
* 2. Use the same auth and access-log ports as `/v1/data`, then read bounded
|
|
12
|
+
* block sidecars from storage. MCP tools must not fall back to full envelope
|
|
13
|
+
* reads when sidecars are unavailable.
|
|
14
|
+
*
|
|
15
|
+
* This guarantees parity: the MCP read goes through the same policy check
|
|
16
|
+
* (`verifyDataReadPolicy`) and access-log path as an external builder read.
|
|
17
|
+
* No special owner-mode code path; no shared global grantee; logs record the
|
|
18
|
+
* per-connection grantee address.
|
|
19
|
+
*/
|
|
20
|
+
import { decodeDataBlockCursor } from "../storage/blocks/index.js";
|
|
21
|
+
import { bytesToBase64, parseMetadataHeader } from "../contracts/binary.js";
|
|
22
|
+
import { signMcpGranteeRequest } from "./grantee.js";
|
|
23
|
+
import { handlePersonalServerDataRequest, reportPersonalServerReadFulfillment, } from "../api/index.js";
|
|
24
|
+
import { ProtocolError } from "../errors/catalog.js";
|
|
25
|
+
export class McpDataReadError extends Error {
|
|
26
|
+
status;
|
|
27
|
+
body;
|
|
28
|
+
constructor(status, body) {
|
|
29
|
+
super(typeof body === "object" && body !== null && "error" in body
|
|
30
|
+
? String(body.error?.message ??
|
|
31
|
+
`mcp data read failed (status ${status})`)
|
|
32
|
+
: `mcp data read failed (status ${status})`);
|
|
33
|
+
this.status = status;
|
|
34
|
+
this.body = body;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function createMcpDataReadClient(options) {
|
|
38
|
+
const basePath = options.basePath ?? "/v1/data";
|
|
39
|
+
return {
|
|
40
|
+
async listScopes({ scopePrefix, limit, offset } = {}) {
|
|
41
|
+
const params = new URLSearchParams();
|
|
42
|
+
if (scopePrefix)
|
|
43
|
+
params.set("scopePrefix", scopePrefix);
|
|
44
|
+
if (limit !== undefined)
|
|
45
|
+
params.set("limit", String(limit));
|
|
46
|
+
if (offset !== undefined)
|
|
47
|
+
params.set("offset", String(offset));
|
|
48
|
+
const query = params.toString();
|
|
49
|
+
const pathWithQuery = query ? `${basePath}?${query}` : basePath;
|
|
50
|
+
const authorization = await signMcpGranteeRequest({
|
|
51
|
+
account: options.granteeAccount,
|
|
52
|
+
aud: options.serverOrigin,
|
|
53
|
+
method: "GET",
|
|
54
|
+
uri: basePath,
|
|
55
|
+
grantId: "mcp-list",
|
|
56
|
+
});
|
|
57
|
+
const url = new URL(pathWithQuery, options.serverOrigin).toString();
|
|
58
|
+
const request = new Request(url, {
|
|
59
|
+
method: "GET",
|
|
60
|
+
headers: { Authorization: authorization },
|
|
61
|
+
});
|
|
62
|
+
const response = await handlePersonalServerDataRequest(request, options.dataApiDeps, { basePath });
|
|
63
|
+
const body = await parseJsonOrText(response);
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
throw new McpDataReadError(response.status, body);
|
|
66
|
+
}
|
|
67
|
+
return { status: response.status, ...normalizeListScopesPayload(body) };
|
|
68
|
+
},
|
|
69
|
+
async getScopeMetadata(scope) {
|
|
70
|
+
const storage = options.dataApiDeps.storage;
|
|
71
|
+
const entry = storage.findEntry({ scope });
|
|
72
|
+
if (!entry)
|
|
73
|
+
return null;
|
|
74
|
+
const hasBlocks = typeof storage.hasScopeBlocks === "function"
|
|
75
|
+
? await storage.hasScopeBlocks(scope, entry.collectedAt)
|
|
76
|
+
: false;
|
|
77
|
+
return {
|
|
78
|
+
scope,
|
|
79
|
+
collectedAt: entry.collectedAt,
|
|
80
|
+
sizeBytes: entry.sizeBytes,
|
|
81
|
+
hasBlocks,
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
async readScopeBlocks({ scope, grantId, cursor, maxBytes }) {
|
|
85
|
+
const storage = options.dataApiDeps.storage;
|
|
86
|
+
if (!storage.readScopeBlocks) {
|
|
87
|
+
throw new McpDataReadError(503, {
|
|
88
|
+
error: "BOUNDED_DATA_UNAVAILABLE",
|
|
89
|
+
message: "Bounded scope data is unavailable while the storage sidecar is missing or still indexing.",
|
|
90
|
+
scope,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
const pinnedCollectedAt = collectedAtFromCursor(scope, cursor);
|
|
94
|
+
const selectedEntry = storage.findEntry({
|
|
95
|
+
scope,
|
|
96
|
+
...(pinnedCollectedAt ? { at: pinnedCollectedAt } : {}),
|
|
97
|
+
});
|
|
98
|
+
if (!selectedEntry) {
|
|
99
|
+
throw new McpDataReadError(404, {
|
|
100
|
+
error: "NOT_FOUND",
|
|
101
|
+
message: `No data found for scope "${scope}"`,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
const safeScope = encodeURIComponent(scope);
|
|
105
|
+
const signingUri = `${basePath}/${safeScope}`;
|
|
106
|
+
const authorization = await signMcpGranteeRequest({
|
|
107
|
+
account: options.granteeAccount,
|
|
108
|
+
aud: options.serverOrigin,
|
|
109
|
+
method: "GET",
|
|
110
|
+
uri: signingUri,
|
|
111
|
+
grantId,
|
|
112
|
+
});
|
|
113
|
+
const url = new URL(signingUri, options.serverOrigin).toString();
|
|
114
|
+
const request = new Request(url, {
|
|
115
|
+
method: "GET",
|
|
116
|
+
headers: { Authorization: authorization },
|
|
117
|
+
});
|
|
118
|
+
let authResult;
|
|
119
|
+
try {
|
|
120
|
+
authResult = await options.dataApiDeps.auth.authorizeBuilderRead({
|
|
121
|
+
request,
|
|
122
|
+
scope,
|
|
123
|
+
grantId,
|
|
124
|
+
fileId: selectedEntry.fileId ?? undefined,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
if (err instanceof ProtocolError) {
|
|
129
|
+
throw new McpDataReadError(err.code, err.toJSON());
|
|
130
|
+
}
|
|
131
|
+
throw err;
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
const result = await storage.readScopeBlocks(scope, selectedEntry.collectedAt, {
|
|
135
|
+
cursor,
|
|
136
|
+
maxBytes: maxBytes ?? 16_384,
|
|
137
|
+
});
|
|
138
|
+
const logId = options.dataApiDeps.createLogId?.() ?? crypto.randomUUID();
|
|
139
|
+
const timestamp = (options.dataApiDeps.now ?? (() => new Date()))().toISOString();
|
|
140
|
+
const ipAddress = request.headers.get("x-forwarded-for") ??
|
|
141
|
+
request.headers.get("x-real-ip") ??
|
|
142
|
+
"unknown";
|
|
143
|
+
const userAgent = request.headers.get("user-agent") ?? "unknown";
|
|
144
|
+
await options.dataApiDeps.accessLogWriter.write({
|
|
145
|
+
logId,
|
|
146
|
+
grantId: authResult?.grantId ?? grantId,
|
|
147
|
+
builder: authResult?.builder ?? options.granteeAccount.address,
|
|
148
|
+
action: "read",
|
|
149
|
+
scope,
|
|
150
|
+
timestamp,
|
|
151
|
+
ipAddress,
|
|
152
|
+
userAgent,
|
|
153
|
+
});
|
|
154
|
+
if (authResult?.grantId &&
|
|
155
|
+
authResult.builder &&
|
|
156
|
+
!cursor &&
|
|
157
|
+
!result.nextCursor) {
|
|
158
|
+
reportPersonalServerReadFulfillment(options.dataApiDeps, {
|
|
159
|
+
builder: authResult.builder,
|
|
160
|
+
fileId: selectedEntry.fileId ?? undefined,
|
|
161
|
+
grantId: authResult.grantId,
|
|
162
|
+
ipAddress,
|
|
163
|
+
logId,
|
|
164
|
+
scope,
|
|
165
|
+
servedAt: timestamp,
|
|
166
|
+
userAgent,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return { status: 200, ...result };
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
if (err instanceof ProtocolError) {
|
|
173
|
+
throw new McpDataReadError(err.code, err.toJSON());
|
|
174
|
+
}
|
|
175
|
+
if (err instanceof Error) {
|
|
176
|
+
const code = dataBlockStorageErrorCode(err);
|
|
177
|
+
const status = code === "cursor_invalid" ? 400 : 503;
|
|
178
|
+
throw new McpDataReadError(status, {
|
|
179
|
+
error: code === "cursor_invalid"
|
|
180
|
+
? "INVALID_CURSOR"
|
|
181
|
+
: "BOUNDED_DATA_UNAVAILABLE",
|
|
182
|
+
message: code === "cursor_invalid"
|
|
183
|
+
? "The bounded read cursor is invalid for this scope."
|
|
184
|
+
: "Bounded scope data is unavailable while the storage sidecar is missing or still indexing.",
|
|
185
|
+
scope,
|
|
186
|
+
...(code ? { reason: code } : {}),
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
throw err;
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
async readRawScopeFile({ scope, grantId, at, fileId }) {
|
|
193
|
+
const storage = options.dataApiDeps.storage;
|
|
194
|
+
const selectedEntry = storage.findEntry({
|
|
195
|
+
scope,
|
|
196
|
+
...(fileId ? { fileId } : {}),
|
|
197
|
+
...(at ? { at } : {}),
|
|
198
|
+
});
|
|
199
|
+
if (!selectedEntry) {
|
|
200
|
+
throw new McpDataReadError(404, {
|
|
201
|
+
error: "NOT_FOUND",
|
|
202
|
+
message: `No data found for scope "${scope}"`,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
const safeScope = encodeURIComponent(scope);
|
|
206
|
+
const signingUri = `${basePath}/${safeScope}`;
|
|
207
|
+
const query = new URLSearchParams({ content: "raw" });
|
|
208
|
+
if (fileId)
|
|
209
|
+
query.set("fileId", fileId);
|
|
210
|
+
if (at)
|
|
211
|
+
query.set("at", at);
|
|
212
|
+
query.set("grantId", grantId);
|
|
213
|
+
const authorization = await signMcpGranteeRequest({
|
|
214
|
+
account: options.granteeAccount,
|
|
215
|
+
aud: options.serverOrigin,
|
|
216
|
+
method: "GET",
|
|
217
|
+
uri: signingUri,
|
|
218
|
+
grantId,
|
|
219
|
+
});
|
|
220
|
+
const url = new URL(`${signingUri}?${query.toString()}`, options.serverOrigin).toString();
|
|
221
|
+
const request = new Request(url, {
|
|
222
|
+
method: "GET",
|
|
223
|
+
headers: { Authorization: authorization },
|
|
224
|
+
});
|
|
225
|
+
const response = await handlePersonalServerDataRequest(request, options.dataApiDeps, { basePath });
|
|
226
|
+
if (!response.ok) {
|
|
227
|
+
throw new McpDataReadError(response.status, await parseJsonOrText(response));
|
|
228
|
+
}
|
|
229
|
+
const mimeType = response.headers.get("content-type") ?? "application/octet-stream";
|
|
230
|
+
if (mimeType.includes("application/json")) {
|
|
231
|
+
throw new McpDataReadError(400, {
|
|
232
|
+
error: "NOT_BINARY_SCOPE",
|
|
233
|
+
message: `Scope "${scope}" does not expose raw binary content.`,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
237
|
+
const contentDisposition = response.headers.get("content-disposition");
|
|
238
|
+
const metadataHeader = response.headers.get("x-vana-metadata");
|
|
239
|
+
return {
|
|
240
|
+
status: response.status,
|
|
241
|
+
scope,
|
|
242
|
+
collectedAt: selectedEntry.collectedAt,
|
|
243
|
+
fileId: selectedEntry.fileId ?? undefined,
|
|
244
|
+
mimeType,
|
|
245
|
+
filename: filenameFromContentDisposition(contentDisposition),
|
|
246
|
+
sizeBytes: bytes.byteLength,
|
|
247
|
+
contentBase64: bytesToBase64(bytes),
|
|
248
|
+
metadata: parseMetadataHeader(metadataHeader),
|
|
249
|
+
};
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
async function parseJsonOrText(response) {
|
|
254
|
+
const text = await response.text();
|
|
255
|
+
try {
|
|
256
|
+
return text ? JSON.parse(text) : null;
|
|
257
|
+
}
|
|
258
|
+
catch {
|
|
259
|
+
return text;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function filenameFromContentDisposition(value) {
|
|
263
|
+
if (!value)
|
|
264
|
+
return undefined;
|
|
265
|
+
const match = /filename="([^"]+)"/i.exec(value) ?? /filename=([^;]+)/i.exec(value);
|
|
266
|
+
return match?.[1]?.trim();
|
|
267
|
+
}
|
|
268
|
+
function collectedAtFromCursor(scope, cursor) {
|
|
269
|
+
if (!cursor)
|
|
270
|
+
return undefined;
|
|
271
|
+
const decoded = decodeDataBlockCursor(cursor);
|
|
272
|
+
if (!decoded.ok || decoded.cursor.scope !== scope)
|
|
273
|
+
return undefined;
|
|
274
|
+
return decoded.cursor.collectedAt;
|
|
275
|
+
}
|
|
276
|
+
function dataBlockStorageErrorCode(err) {
|
|
277
|
+
if (!("code" in err))
|
|
278
|
+
return undefined;
|
|
279
|
+
const code = err.code;
|
|
280
|
+
return typeof code === "string" ? code : undefined;
|
|
281
|
+
}
|
|
282
|
+
function normalizeListScopesPayload(body) {
|
|
283
|
+
if (typeof body !== "object" || body === null) {
|
|
284
|
+
return { scopes: [], total: 0, limit: 0, offset: 0 };
|
|
285
|
+
}
|
|
286
|
+
const payload = body;
|
|
287
|
+
const scopes = Array.isArray(payload.scopes)
|
|
288
|
+
? payload.scopes.filter(isScopeSummary)
|
|
289
|
+
: [];
|
|
290
|
+
return {
|
|
291
|
+
scopes,
|
|
292
|
+
total: typeof payload.total === "number" ? payload.total : scopes.length,
|
|
293
|
+
limit: typeof payload.limit === "number" ? payload.limit : scopes.length,
|
|
294
|
+
offset: typeof payload.offset === "number" ? payload.offset : 0,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function isScopeSummary(value) {
|
|
298
|
+
if (typeof value !== "object" || value === null) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
const summary = value;
|
|
302
|
+
return (typeof summary.scope === "string" &&
|
|
303
|
+
typeof summary.latestCollectedAt === "string" &&
|
|
304
|
+
typeof summary.versionCount === "number");
|
|
305
|
+
}
|
|
306
|
+
//# sourceMappingURL=read-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-client.js","sourceRoot":"","sources":["../../src/mcp/read-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAMH,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CA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AC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM;QACxE,KAAK,EAAE,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM;QACxE,MAAM,EAAE,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;KAChE,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,KAAc;IACpC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,OAAO,GAAG,KAIf,CAAC;IACF,OAAO,CACL,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ;QACjC,OAAO,OAAO,CAAC,iBAAiB,KAAK,QAAQ;QAC7C,OAAO,OAAO,CAAC,YAAY,KAAK,QAAQ,CACzC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ReadResourceResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { type McpDataReadClient } from "./read-client.js";
|
|
4
|
+
import type { McpConnectionRecord } from "./types.js";
|
|
5
|
+
export declare const RAW_SCOPE_RESOURCE_TEMPLATES: readonly ["vana://scope/{scope}/raw", "vana://scope/{scope}/raw/at/{at}", "vana://scope/{scope}/raw/file/{fileId}"];
|
|
6
|
+
export interface RawScopeResourceParams {
|
|
7
|
+
scope: string;
|
|
8
|
+
at?: string;
|
|
9
|
+
fileId?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface RawScopeResourceContext {
|
|
12
|
+
connection: McpConnectionRecord;
|
|
13
|
+
readClient: McpDataReadClient;
|
|
14
|
+
}
|
|
15
|
+
export declare function rawScopeResourceUri(params: RawScopeResourceParams): string;
|
|
16
|
+
export declare function parseRawScopeResourceUri(uri: URL): RawScopeResourceParams;
|
|
17
|
+
export declare function resolveGrantForRawScopeResource(connection: McpConnectionRecord, scope: string): {
|
|
18
|
+
grantId: string;
|
|
19
|
+
} | null;
|
|
20
|
+
export declare function readRawScopeResource(uri: URL, ctx: RawScopeResourceContext): Promise<ReadResourceResult>;
|
|
21
|
+
export declare function rawScopeMetadata(raw: {
|
|
22
|
+
scope: string;
|
|
23
|
+
collectedAt?: string;
|
|
24
|
+
fileId?: string;
|
|
25
|
+
filename?: string;
|
|
26
|
+
mimeType: string;
|
|
27
|
+
sizeBytes: number;
|
|
28
|
+
metadata?: unknown;
|
|
29
|
+
}): Record<string, unknown>;
|
|
30
|
+
export declare const rawScopeFileInputSchema: {
|
|
31
|
+
scope: z.ZodString;
|
|
32
|
+
at: z.ZodOptional<z.ZodString>;
|
|
33
|
+
fileId: z.ZodOptional<z.ZodString>;
|
|
34
|
+
includeContent: z.ZodOptional<z.ZodBoolean>;
|
|
35
|
+
maxBytes: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=resources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../src/mcp/resources.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAoB,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,eAAO,MAAM,4BAA4B,qHAI/B,CAAC;AAEX,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,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