Summary
Batch operations for efficiency: register multiple hashes in a single transaction and record data access events. These reduce gas costs when working with multiple data items.
Part of #43. Depends on chain infrastructure setup.
What to Implement
1. batch_anchor Tool
Register up to 50 Swarm hashes in a single blockchain transaction.
Tool(
name="batch_anchor",
description="Register multiple Swarm reference hashes on-chain in a single transaction. More gas-efficient than individual anchor_hash calls when registering many hashes. Maximum 50 hashes per batch. Costs gas.",
inputSchema={
"type": "object",
"properties": {
"swarm_hashes": {
"type": "array",
"items": {
"type": "string",
"pattern": "^[a-fA-F0-9]{64}$"
},
"description": "Array of 64-character hex Swarm reference hashes to anchor",
"minItems": 1,
"maxItems": 50
},
"data_type": {
"type": "string",
"description": "Category/type label applied to all hashes in the batch (default: 'swarm-provenance')",
"default": "swarm-provenance",
"maxLength": 64
}
},
"required": ["swarm_hashes"]
}
)
Handler calls ChainClient.batch_anchor(hashes, data_types). Report: how many anchored, tx hash, gas used, any that were already registered.
2. record_access Tool
Record that data was accessed (for audit trail / usage tracking).
Tool(
name="record_access",
description="Record a data access event on-chain. Creates an audit trail of when data was accessed. Supports single hash or batch of up to 100 hashes. Costs gas.",
inputSchema={
"type": "object",
"properties": {
"swarm_hashes": {
"type": "array",
"items": {
"type": "string",
"pattern": "^[a-fA-F0-9]{64}$"
},
"description": "Array of Swarm reference hashes that were accessed (1-100)",
"minItems": 1,
"maxItems": 100
}
},
"required": ["swarm_hashes"]
}
)
Handler calls ChainClient.access() for single hash or ChainClient.batch_access() for multiple.
Design Notes
batch_anchor: Validates all hashes before submitting. If any are already registered, skip them and report.
record_access: Each access event is timestamped on-chain. Useful for compliance and audit trails.
- Both are gas-consuming write operations.
- Contract limits: MAX_BATCH_REGISTER = 50, MAX_BATCH_ACCESS = 100
Files to Modify
swarm_provenance_mcp/server.py — add 2 tool definitions, handlers, routing
tests/test_integration.py — add tests
Reference
- CLI:
chain_anchor (single), ChainClient batch_anchor() and batch_access()
- Contract constants:
MAX_BATCH_REGISTER = 50, MAX_BATCH_ACCESS = 100
Acceptance Criteria
Summary
Batch operations for efficiency: register multiple hashes in a single transaction and record data access events. These reduce gas costs when working with multiple data items.
Part of #43. Depends on chain infrastructure setup.
What to Implement
1.
batch_anchorToolRegister up to 50 Swarm hashes in a single blockchain transaction.
Handler calls
ChainClient.batch_anchor(hashes, data_types). Report: how many anchored, tx hash, gas used, any that were already registered.2.
record_accessToolRecord that data was accessed (for audit trail / usage tracking).
Handler calls
ChainClient.access()for single hash orChainClient.batch_access()for multiple.Design Notes
batch_anchor: Validates all hashes before submitting. If any are already registered, skip them and report.record_access: Each access event is timestamped on-chain. Useful for compliance and audit trails.Files to Modify
swarm_provenance_mcp/server.py— add 2 tool definitions, handlers, routingtests/test_integration.py— add testsReference
chain_anchor(single), ChainClientbatch_anchor()andbatch_access()MAX_BATCH_REGISTER = 50,MAX_BATCH_ACCESS = 100Acceptance Criteria
batch_anchoraccepts array of hashes (1-50)batch_anchorvalidates all hashes before submittingbatch_anchorreports count anchored, skipped (already registered), gas usedrecord_accessaccepts array of hashes (1-100)record_accessuses batch method for multiple hashes