@rohan-protocol/mcp 0.8.1 β 0.8.2
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/README.md +49 -74
- package/dist/cli.d.ts +6 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +304 -0
- package/dist/cli.js.map +1 -0
- package/dist/mcp-app.d.ts +136 -0
- package/dist/mcp-app.d.ts.map +1 -0
- package/dist/mcp-app.js +401 -0
- package/dist/mcp-app.js.map +1 -0
- package/dist/server.d.ts +35 -34
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +49 -255
- package/dist/server.js.map +1 -1
- package/package.json +6 -2
- package/server.json +0 -46
- package/smithery.yaml +0 -23
- package/src/firewall.ts +0 -37
- package/src/gateway.ts +0 -59
- package/src/identity/handshake.ts +0 -82
- package/src/identity/keystore.ts +0 -385
- package/src/index.ts +0 -2
- package/src/server.ts +0 -310
- package/tests/firewall.test.js +0 -75
- package/tests/gateway.test.js +0 -27
- package/tests/identity.test.js +0 -170
- package/tsconfig.json +0 -17
package/dist/server.js
CHANGED
|
@@ -1,266 +1,60 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import crypto from 'node:crypto';
|
|
3
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
4
2
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
5
|
-
import {
|
|
6
|
-
import { SemanticFirewall } from './firewall.js';
|
|
7
|
-
import { RohanClient, sealActionIntent, canonicalizeJson } from '@rohan-protocol/sdk';
|
|
3
|
+
import { RohanClient } from '@rohan-protocol/sdk';
|
|
8
4
|
import { resolveAgentIdentity } from './identity/keystore.js';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
console.error(`π‘οΈ [MCP V-08] Keystore path: ${loadedIdentity.filePath}`);
|
|
19
|
-
}
|
|
20
|
-
const rohanClient = new RohanClient({
|
|
21
|
-
contractAddress: CONTRACT_ADDRESS,
|
|
22
|
-
relayerUrl: RELAYER_URL,
|
|
23
|
-
apiKey: API_KEY,
|
|
24
|
-
signer: configuredSigner,
|
|
25
|
-
});
|
|
26
|
-
const server = new Server({
|
|
27
|
-
name: 'rohan-protocol-mcp',
|
|
28
|
-
version: '0.8.1',
|
|
29
|
-
}, {
|
|
30
|
-
capabilities: {
|
|
31
|
-
tools: {},
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
// ββ Tool 2 Schema: Audit / In-Memory Verification βββββββββββββββββββββββββββ
|
|
35
|
-
export const ROHAN_VERIFY_TOOL_SCHEMA = {
|
|
36
|
-
name: 'rohan_verify_commitment',
|
|
37
|
-
description: 'Verifies a plaintext confidential payload against its SHA-256 digest using RFC 8785 JSON Canonicalization. Supply the inner payload digest, not the outer on-chain intentHash. Zero gas cost; runs in local memory.',
|
|
38
|
-
inputSchema: {
|
|
39
|
-
type: 'object',
|
|
40
|
-
properties: {
|
|
41
|
-
payload: {
|
|
42
|
-
type: 'object',
|
|
43
|
-
description: 'The plaintext contract, agreement, or intent data to be verified.',
|
|
44
|
-
},
|
|
45
|
-
expectedDigest: {
|
|
46
|
-
type: 'string',
|
|
47
|
-
pattern: '^(?:sha256:|0x)?[0-9a-fA-F]{64}$',
|
|
48
|
-
description: 'The expected SHA-256 digest of the canonicalized confidential payload (the inner payload digest referenced as digest: sha256:<hash> in actionSummary), not the outer timestamp-salted on-chain intentHash. Accepts raw hex, 0x, or sha256: prefixes.',
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
required: ['payload', 'expectedDigest'],
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
// ββ Tool 3 Schema: Read / Ledger State Inspection βββββββββββββββββββββββββββ
|
|
55
|
-
export const ROHAN_LEDGER_STATE_TOOL_SCHEMA = {
|
|
56
|
-
name: 'rohan_get_ledger_state',
|
|
57
|
-
description: 'Reads the current anchored state of the Rohan Protocol smart contract on Midnight Preprod L1. Returns the state root, block height, and last mined transaction hash from memory cache.',
|
|
58
|
-
inputSchema: {
|
|
59
|
-
type: 'object',
|
|
60
|
-
properties: {},
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
export const ROHAN_HISTORY_TOOL_SCHEMA = {
|
|
64
|
-
name: 'rohan_get_transaction_history',
|
|
65
|
-
description: 'Lists historical settlement transactions and receipts anchored on Midnight Preprod L1.',
|
|
66
|
-
inputSchema: {
|
|
67
|
-
type: 'object',
|
|
68
|
-
properties: {
|
|
69
|
-
limit: {
|
|
70
|
-
type: 'integer',
|
|
71
|
-
description: 'Maximum number of historical transactions to return (default: 10, max: 50).',
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
77
|
-
return {
|
|
78
|
-
tools: [
|
|
79
|
-
ROHAN_HANDSHAKE_TOOL_SCHEMA,
|
|
80
|
-
ROHAN_LEDGER_STATE_TOOL_SCHEMA,
|
|
81
|
-
ROHAN_HISTORY_TOOL_SCHEMA,
|
|
82
|
-
ROHAN_VERIFY_TOOL_SCHEMA,
|
|
83
|
-
],
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
87
|
-
const toolName = request.params.name;
|
|
88
|
-
const rawArgs = request.params?.arguments;
|
|
89
|
-
if (!rawArgs || typeof rawArgs !== 'object' || Array.isArray(rawArgs)) {
|
|
90
|
-
return {
|
|
91
|
-
content: [{ type: 'text', text: JSON.stringify({ success: false, error: 'INVALID_ARGUMENTS: Expected a valid arguments object.' }) }],
|
|
92
|
-
isError: true,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
const args = rawArgs;
|
|
96
|
-
// ββ Tool 1: rohan_zk_handshake ββββββββββββββββββββββββββββββββββββββββββββ
|
|
97
|
-
if (toolName === 'rohan_execute_handshake' || toolName === 'rohan_zk_handshake') {
|
|
98
|
-
const argumentsError = validateHandshakeArguments(args);
|
|
99
|
-
if (argumentsError) {
|
|
100
|
-
return {
|
|
101
|
-
content: [{ type: 'text', text: JSON.stringify({ success: false, error: argumentsError }) }],
|
|
102
|
-
isError: true,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
const identity = resolveHandshakeAgentId(args.agentId, configuredSigner);
|
|
106
|
-
if ('error' in identity) {
|
|
107
|
-
return {
|
|
108
|
-
content: [{ type: 'text', text: JSON.stringify({ success: false, error: identity.error }) }],
|
|
109
|
-
isError: true,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
const effectiveAgentId = identity.agentId;
|
|
113
|
-
const actionLabel = args.actionSummary;
|
|
114
|
-
const isValid = SemanticFirewall.validate({
|
|
115
|
-
agentId: effectiveAgentId,
|
|
116
|
-
action: 'rohan_execute_handshake',
|
|
117
|
-
payload: args,
|
|
118
|
-
});
|
|
119
|
-
if (!isValid) {
|
|
120
|
-
return {
|
|
121
|
-
content: [{ type: 'text', text: JSON.stringify({ success: false, error: 'Security Violation: Intent rejected by Semantic Firewall (V-01)' }) }],
|
|
122
|
-
isError: true,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
try {
|
|
126
|
-
const finalIntent = sealActionIntent(actionLabel, args.confidentialPayload);
|
|
127
|
-
const receipt = await rohanClient.submitHandshake({
|
|
128
|
-
agentId: effectiveAgentId,
|
|
129
|
-
intent: finalIntent,
|
|
130
|
-
counterpartyId: args.counterpartyId,
|
|
131
|
-
});
|
|
132
|
-
return {
|
|
133
|
-
content: [{
|
|
134
|
-
type: 'text',
|
|
135
|
-
text: JSON.stringify({
|
|
136
|
-
status: 'success',
|
|
137
|
-
message: 'Zero-Knowledge Handshake successfully settled on Midnight Blockchain with Sovereign Identity (V-08).',
|
|
138
|
-
agentDid: effectiveAgentId,
|
|
139
|
-
receipt,
|
|
140
|
-
}, null, 2),
|
|
141
|
-
}],
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
catch (err) {
|
|
145
|
-
return {
|
|
146
|
-
content: [{ type: 'text', text: JSON.stringify({ success: false, error: err.message || 'Handshake execution failed' }) }],
|
|
147
|
-
isError: true,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
// ββ Tool 2: rohan_verify_commitment βββββββββββββββββββββββββββββββββββββββ
|
|
152
|
-
if (toolName === 'rohan_verify_commitment') {
|
|
153
|
-
// Payload-Size-Guard (Max 256 KB im RAM)
|
|
154
|
-
const payloadString = JSON.stringify(args.payload);
|
|
155
|
-
if (payloadString.length > 256 * 1024) {
|
|
156
|
-
return {
|
|
157
|
-
content: [{ type: 'text', text: JSON.stringify({ success: false, error: 'PAYLOAD_TOO_LARGE: Plaintext exceeds maximum allowed size of 256 KB.' }) }],
|
|
158
|
-
isError: true,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
if (!args.payload || typeof args.payload !== 'object' || Array.isArray(args.payload)) {
|
|
162
|
-
return {
|
|
163
|
-
content: [{ type: 'text', text: JSON.stringify({ success: false, error: 'Invalid argument: payload must be a non-null object.' }) }],
|
|
164
|
-
isError: true,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
if (!args.expectedDigest || typeof args.expectedDigest !== 'string') {
|
|
168
|
-
return {
|
|
169
|
-
content: [{ type: 'text', text: JSON.stringify({ success: false, error: 'Invalid argument: expectedDigest must be a string.' }) }],
|
|
170
|
-
isError: true,
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
try {
|
|
174
|
-
// LLM Prefix Tolerance: Strips 'sha256:' or '0x'
|
|
175
|
-
const normalizedExpected = args.expectedDigest.replace(/^(?:sha256:|0x)/i, '').toLowerCase();
|
|
176
|
-
if (!/^[0-9a-f]{64}$/.test(normalizedExpected)) {
|
|
177
|
-
return {
|
|
178
|
-
content: [{ type: 'text', text: JSON.stringify({ success: false, error: 'Invalid expectedDigest: must resolve to a 64-character hexadecimal SHA-256 hash.' }) }],
|
|
179
|
-
isError: true,
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
// Single Source of Truth: Canonicalization via @rohan-protocol/sdk
|
|
183
|
-
const canonicalPayload = canonicalizeJson(args.payload);
|
|
184
|
-
const computedDigest = crypto.createHash('sha256').update(canonicalPayload, 'utf8').digest('hex').toLowerCase();
|
|
185
|
-
const match = crypto.timingSafeEqual(Buffer.from(computedDigest, 'hex'), Buffer.from(normalizedExpected, 'hex'));
|
|
186
|
-
return {
|
|
187
|
-
content: [{
|
|
188
|
-
type: 'text',
|
|
189
|
-
text: JSON.stringify({
|
|
190
|
-
status: 'success',
|
|
191
|
-
valid: match,
|
|
192
|
-
match,
|
|
193
|
-
expectedDigest: normalizedExpected,
|
|
194
|
-
computedDigest,
|
|
195
|
-
algorithm: 'SHA-256 (RFC 8785 JCS)',
|
|
196
|
-
verifiedAt: Date.now(),
|
|
197
|
-
}, null, 2),
|
|
198
|
-
}],
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
catch (err) {
|
|
202
|
-
return {
|
|
203
|
-
content: [{ type: 'text', text: JSON.stringify({ success: false, error: err.message || 'Verification execution failed' }) }],
|
|
204
|
-
isError: true,
|
|
205
|
-
};
|
|
206
|
-
}
|
|
5
|
+
import { ROHAN_HANDSHAKE_TOOL_SCHEMA } from './identity/handshake.js';
|
|
6
|
+
import { runCli } from './cli.js';
|
|
7
|
+
import { createRohanMcpServer, ROHAN_MCP_VERSION, ROHAN_MCP_INSTRUCTIONS, ROHAN_EXECUTE_TOOL_WITH_ANNOTATIONS, ROHAN_VERIFY_TOOL_SCHEMA, ROHAN_LEDGER_STATE_TOOL_SCHEMA, ROHAN_HISTORY_TOOL_SCHEMA, ROHAN_AGENT_STATUS_TOOL_SCHEMA, } from './mcp-app.js';
|
|
8
|
+
export const ROHAN_EXECUTE_TOOL_SCHEMA = ROHAN_EXECUTE_TOOL_WITH_ANNOTATIONS;
|
|
9
|
+
export { ROHAN_HANDSHAKE_TOOL_SCHEMA, ROHAN_MCP_INSTRUCTIONS, ROHAN_EXECUTE_TOOL_WITH_ANNOTATIONS, ROHAN_VERIFY_TOOL_SCHEMA, ROHAN_LEDGER_STATE_TOOL_SCHEMA, ROHAN_HISTORY_TOOL_SCHEMA, ROHAN_AGENT_STATUS_TOOL_SCHEMA, createRohanMcpServer, };
|
|
10
|
+
function resolveConfiguredNetwork() {
|
|
11
|
+
const raw = (process.env.ROHAN_NETWORK || 'preprod').trim().toLowerCase();
|
|
12
|
+
if (raw !== 'preprod' && raw !== 'testnet' && raw !== 'mainnet') {
|
|
13
|
+
throw new Error(`INVALID_CONFIGURATION: Unsupported ROHAN_NETWORK "${raw}". Expected preprod, testnet, or mainnet.`);
|
|
207
14
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
lastTxHash: ledgerState.lastTxHash ?? null,
|
|
222
|
-
network: ledgerState.network || 'midnight-preprod',
|
|
223
|
-
isMinedOnChain: ledgerState.isMinedOnChain ?? true,
|
|
224
|
-
cacheAgeMs: ledgerState.cacheAgeMs ?? cacheAgeMs,
|
|
225
|
-
cacheTtlMs: ledgerState.cacheTtlMs ?? 15000,
|
|
226
|
-
fetchedAt: ledgerState.fetchedAt,
|
|
227
|
-
}, null, 2),
|
|
228
|
-
}],
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
catch (err) {
|
|
232
|
-
return {
|
|
233
|
-
content: [{ type: 'text', text: JSON.stringify({ success: false, error: err.message || 'Failed to fetch ledger state' }) }],
|
|
234
|
-
isError: true,
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
if (toolName === 'rohan_get_transaction_history') {
|
|
239
|
-
try {
|
|
240
|
-
const rawLimit = Number(args.limit) || 10;
|
|
241
|
-
const history = await rohanClient.getTransactionHistory(rawLimit);
|
|
242
|
-
return {
|
|
243
|
-
content: [{
|
|
244
|
-
type: 'text',
|
|
245
|
-
text: JSON.stringify({ status: 'success', ...history }, null, 2),
|
|
246
|
-
}],
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
catch (err) {
|
|
250
|
-
return {
|
|
251
|
-
content: [{ type: 'text', text: JSON.stringify({ success: false, error: err.message || 'Failed to fetch transaction history' }) }],
|
|
252
|
-
isError: true,
|
|
253
|
-
};
|
|
254
|
-
}
|
|
15
|
+
return raw;
|
|
16
|
+
}
|
|
17
|
+
async function runStdioServer() {
|
|
18
|
+
const CONTRACT_ADDRESS = process.env.ROHAN_CONTRACT_ADDRESS ||
|
|
19
|
+
'585ac0c4448257507d8ffa2a89e2aa00abd86ec9e94bdb6f553bc83e05f4dd0e';
|
|
20
|
+
const RELAYER_URL = process.env.ROHAN_RELAYER_URL || 'https://api.rohanprotocol.network/api/v1/handshake';
|
|
21
|
+
const API_KEY = process.env.ROHAN_API_KEY || '';
|
|
22
|
+
const NETWORK = resolveConfiguredNetwork();
|
|
23
|
+
const loadedIdentity = await resolveAgentIdentity();
|
|
24
|
+
const configuredSigner = loadedIdentity.signer;
|
|
25
|
+
console.error(`π‘οΈ [MCP V-08] Agent identity active (${loadedIdentity.source}): ${loadedIdentity.did}`);
|
|
26
|
+
if (loadedIdentity.filePath) {
|
|
27
|
+
console.error(`π‘οΈ [MCP V-08] Keystore path: ${loadedIdentity.filePath}`);
|
|
255
28
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
29
|
+
const rohanClient = new RohanClient({
|
|
30
|
+
network: NETWORK,
|
|
31
|
+
contractAddress: CONTRACT_ADDRESS,
|
|
32
|
+
relayerUrl: RELAYER_URL,
|
|
33
|
+
apiKey: API_KEY,
|
|
34
|
+
signer: configuredSigner,
|
|
35
|
+
});
|
|
36
|
+
const server = createRohanMcpServer({
|
|
37
|
+
contractAddress: CONTRACT_ADDRESS,
|
|
38
|
+
relayerUrl: RELAYER_URL,
|
|
39
|
+
network: NETWORK,
|
|
40
|
+
rohanClient,
|
|
41
|
+
configuredSigner,
|
|
42
|
+
loadedIdentity,
|
|
43
|
+
});
|
|
259
44
|
const transport = new StdioServerTransport();
|
|
260
45
|
await server.connect(transport);
|
|
261
|
-
console.error(
|
|
46
|
+
console.error(`π‘οΈ Rohan Protocol MCP Server running via stdio (v${ROHAN_MCP_VERSION}, network=${NETWORK})...`);
|
|
47
|
+
}
|
|
48
|
+
async function main() {
|
|
49
|
+
const cliArgs = process.argv.slice(2);
|
|
50
|
+
if (cliArgs.length > 0 && cliArgs[0] !== '--stdio') {
|
|
51
|
+
const exitCode = await runCli(cliArgs);
|
|
52
|
+
process.exit(exitCode);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
await runStdioServer();
|
|
262
56
|
}
|
|
263
|
-
|
|
57
|
+
main().catch((error) => {
|
|
264
58
|
console.error('Fatal MCP server error:', error);
|
|
265
59
|
process.exit(1);
|
|
266
60
|
});
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,WAAW,EAAoC,MAAM,qBAAqB,CAAC;AAEpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,sBAAsB,EACtB,mCAAmC,EACnC,wBAAwB,EACx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
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"mcpName": "io.github.rohan-protocol/mcp",
|
|
5
5
|
"description": "Model Context Protocol (MCP) Gateway for Rohan Protocol ZK-Handshakes",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -23,8 +23,12 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
26
|
-
"@rohan-protocol/sdk": "^0.8.
|
|
26
|
+
"@rohan-protocol/sdk": "^0.8.2"
|
|
27
27
|
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
28
32
|
"devDependencies": {
|
|
29
33
|
"@types/node": "^22.0.0",
|
|
30
34
|
"typescript": "^5.5.0"
|
package/server.json
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
-
"name": "io.github.rohan-protocol/mcp",
|
|
4
|
-
"title": "Rohan Protocol MCP",
|
|
5
|
-
"description": "Stateless zero-knowledge trust gateway and WebMCP shield for AI agents on Midnight.",
|
|
6
|
-
"version": "0.8.1",
|
|
7
|
-
"websiteUrl": "https://rohanprotocol.network",
|
|
8
|
-
"repository": {
|
|
9
|
-
"url": "https://github.com/rohan-protocol/sdk",
|
|
10
|
-
"source": "github",
|
|
11
|
-
"subfolder": "packages/mcp"
|
|
12
|
-
},
|
|
13
|
-
"packages": [
|
|
14
|
-
{
|
|
15
|
-
"registryType": "npm",
|
|
16
|
-
"identifier": "@rohan-protocol/mcp",
|
|
17
|
-
"version": "0.8.1",
|
|
18
|
-
"transport": {
|
|
19
|
-
"type": "stdio"
|
|
20
|
-
},
|
|
21
|
-
"environmentVariables": [
|
|
22
|
-
{
|
|
23
|
-
"name": "ROHAN_AGENT_PRIVATE_KEY",
|
|
24
|
-
"description": "Optional 32-byte Ed25519 seed as 64 hex characters to override the auto-provisioned local identity. Keep it in a secret store; never provide it as a tool argument.",
|
|
25
|
-
"default": "",
|
|
26
|
-
"isRequired": false,
|
|
27
|
-
"format": "string"
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
"name": "ROHAN_CONTRACT_ADDRESS",
|
|
31
|
-
"description": "Midnight Preprod Contract Address for Rohan Trust Gateway",
|
|
32
|
-
"default": "585ac0c4448257507d8ffa2a89e2aa00abd86ec9e94bdb6f553bc83e05f4dd0e",
|
|
33
|
-
"isRequired": false,
|
|
34
|
-
"format": "string"
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
"name": "ROHAN_RELAYER_URL",
|
|
38
|
-
"description": "Rohan Relayer API URL",
|
|
39
|
-
"default": "https://api.rohanprotocol.network/api/v1/handshake",
|
|
40
|
-
"isRequired": false,
|
|
41
|
-
"format": "string"
|
|
42
|
-
}
|
|
43
|
-
]
|
|
44
|
-
}
|
|
45
|
-
]
|
|
46
|
-
}
|
package/smithery.yaml
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# Smithery configuration file: https://smithery.ai/docs/config#smitheryyaml
|
|
2
|
-
startCommand:
|
|
3
|
-
type: stdio
|
|
4
|
-
configSchema:
|
|
5
|
-
type: object
|
|
6
|
-
properties:
|
|
7
|
-
rohanApiKey:
|
|
8
|
-
type: string
|
|
9
|
-
description: "Optional Rohan Relayer API key for production throughput (defaults to free 10 tx/day sandbox)"
|
|
10
|
-
commandFunction:
|
|
11
|
-
|-
|
|
12
|
-
(config) => ({
|
|
13
|
-
command: 'npx',
|
|
14
|
-
args: ['-y', '@rohan-protocol/mcp@latest'],
|
|
15
|
-
env: {
|
|
16
|
-
ROHAN_FIREWALL_LEVEL: 'V-01_STRICT',
|
|
17
|
-
ROHAN_CONTRACT_ADDRESS: '585ac0c4448257507d8ffa2a89e2aa00abd86ec9e94bdb6f553bc83e05f4dd0e',
|
|
18
|
-
ROHAN_RELAYER_URL: 'https://api.rohanprotocol.network/api/v1/handshake/stream',
|
|
19
|
-
...(config.rohanApiKey ? { ROHAN_API_KEY: config.rohanApiKey } : {})
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
exampleConfig:
|
|
23
|
-
rohanApiKey: "rohan_live_alpha_..."
|
package/src/firewall.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export interface HandshakeIntent {
|
|
2
|
-
agentId: string;
|
|
3
|
-
action: string;
|
|
4
|
-
payload: Record<string, unknown>;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export class SemanticFirewall {
|
|
8
|
-
private static readonly INJECTION_REGEX =
|
|
9
|
-
/(?:ignore\s+(all\s+)?previous\s+instructions|system\s*:\s*override|you\s+are\s+now\s+a|assistant\s*:|\[INST\]|<\|im_start\|>|jailbreak|reveal\s+(your|the)\s+secret)/i;
|
|
10
|
-
|
|
11
|
-
static validate(intent: HandshakeIntent): boolean {
|
|
12
|
-
if (!intent.agentId || typeof intent.agentId !== 'string' || intent.agentId.length > 128) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
if (!intent.action || (
|
|
16
|
-
intent.action !== 'rohan_zk_handshake' &&
|
|
17
|
-
intent.action !== 'rohan_execute_handshake' &&
|
|
18
|
-
intent.action !== 'verify_batched_handshakes'
|
|
19
|
-
)) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
if (!intent.payload || typeof intent.payload !== 'object') {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const serialized = JSON.stringify(intent.payload);
|
|
27
|
-
if (serialized.length > 8192) {
|
|
28
|
-
return false; // Denial-of-Service Protection (Payload size cap)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (this.INJECTION_REGEX.test(serialized)) {
|
|
32
|
-
return false; // Semantic Prompt Injection detected
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
}
|
package/src/gateway.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { RohanRelayerClient } from '@rohan-protocol/sdk';
|
|
2
|
-
|
|
3
|
-
export interface RohanMcpGatewayOptions {
|
|
4
|
-
transport?: 'stdio' | 'streamable-http';
|
|
5
|
-
relayerUrl?: string;
|
|
6
|
-
contractAddress?: string;
|
|
7
|
-
apiKey?: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* RohanMcpGateway
|
|
12
|
-
* Connects AI Agent pipelines (Google ADK 2.0, Gemini, Claude, Cursor)
|
|
13
|
-
* to the Rohan Protocol Gas Station via Streamable HTTP (NDJSON) or Stdio.
|
|
14
|
-
*/
|
|
15
|
-
export class RohanMcpGateway {
|
|
16
|
-
public readonly transport: string;
|
|
17
|
-
public readonly relayerClient: RohanRelayerClient;
|
|
18
|
-
|
|
19
|
-
constructor(options: RohanMcpGatewayOptions = {}) {
|
|
20
|
-
this.transport = options.transport || 'streamable-http';
|
|
21
|
-
this.relayerClient = new RohanRelayerClient({
|
|
22
|
-
relayerUrl: options.relayerUrl || 'http://127.0.0.1:4005/api/v1/handshake',
|
|
23
|
-
contractAddress: options.contractAddress || '585ac0c4448257507d8ffa2a89e2aa00abd86ec9e94bdb6f553bc83e05f4dd0e',
|
|
24
|
-
apiKey: options.apiKey,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Generates a tool specification compliant with Google ADK 2.0 and Gemini tool calling.
|
|
30
|
-
*/
|
|
31
|
-
asAdkTool() {
|
|
32
|
-
return {
|
|
33
|
-
name: 'rohan_execute_handshake',
|
|
34
|
-
description: 'Executes a zero-knowledge verifiable handshake proof on Midnight Network with zero plaintext leaks.',
|
|
35
|
-
parameters: {
|
|
36
|
-
type: 'object',
|
|
37
|
-
properties: {
|
|
38
|
-
agentId: { type: 'string', description: 'Decentralized Identifier (DID) of calling agent' },
|
|
39
|
-
intent: { type: 'string', description: 'Semantic action intent or agreement payload' },
|
|
40
|
-
counterpartyId: { type: 'string', description: 'Optional recipient agent identifier' },
|
|
41
|
-
},
|
|
42
|
-
required: ['agentId', 'intent'],
|
|
43
|
-
},
|
|
44
|
-
execute: async (params: any) => {
|
|
45
|
-
return await this.relayerClient.submitHandshake(params);
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Generates the legacy tool name for integrations that have not migrated yet.
|
|
52
|
-
*/
|
|
53
|
-
asLegacyAdkTool() {
|
|
54
|
-
return {
|
|
55
|
-
...this.asAdkTool(),
|
|
56
|
-
name: 'rohan_zk_handshake',
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { AgentSigner } from '@rohan-protocol/sdk';
|
|
2
|
-
|
|
3
|
-
export const ROHAN_HANDSHAKE_TOOL_SCHEMA = {
|
|
4
|
-
name: 'rohan_execute_handshake',
|
|
5
|
-
description:
|
|
6
|
-
'Executes a confidential zero-knowledge state transition on Midnight Blockchain. Confidential parameters are automatically canonicalized (RFC 8785) and hashed in client RAMβnever exposed on-chain or in model logs.',
|
|
7
|
-
inputSchema: {
|
|
8
|
-
type: 'object',
|
|
9
|
-
properties: {
|
|
10
|
-
actionSummary: {
|
|
11
|
-
type: 'string',
|
|
12
|
-
minLength: 1,
|
|
13
|
-
description: 'Required public high-level action label.',
|
|
14
|
-
},
|
|
15
|
-
agentId: {
|
|
16
|
-
type: 'string',
|
|
17
|
-
description: "Optional Sovereign Agent DID. Defaults to the local signer's DID and must match it when provided.",
|
|
18
|
-
},
|
|
19
|
-
confidentialPayload: {
|
|
20
|
-
type: 'object',
|
|
21
|
-
description: 'Optional confidential parameters, canonicalized and hashed locally.',
|
|
22
|
-
},
|
|
23
|
-
counterpartyId: {
|
|
24
|
-
type: 'string',
|
|
25
|
-
description: 'Optional counterparty agent identifier.',
|
|
26
|
-
},
|
|
27
|
-
intent: {
|
|
28
|
-
type: 'string',
|
|
29
|
-
deprecated: true,
|
|
30
|
-
description: 'Deprecated alias. actionSummary remains required.',
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
required: ['actionSummary'],
|
|
34
|
-
additionalProperties: false,
|
|
35
|
-
},
|
|
36
|
-
} as const;
|
|
37
|
-
|
|
38
|
-
export function validateActionSummary(value: unknown): string | undefined {
|
|
39
|
-
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
40
|
-
return 'INVALID_ARGUMENTS: actionSummary is required and cannot be empty.';
|
|
41
|
-
}
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function validateHandshakeArguments(args: Record<string, unknown>): string | undefined {
|
|
46
|
-
const allowedProperties = new Set([
|
|
47
|
-
'actionSummary',
|
|
48
|
-
'agentId',
|
|
49
|
-
'confidentialPayload',
|
|
50
|
-
'counterpartyId',
|
|
51
|
-
'intent',
|
|
52
|
-
]);
|
|
53
|
-
if (Object.keys(args).some((key) => !allowedProperties.has(key))) {
|
|
54
|
-
return 'INVALID_ARGUMENTS: Handshake arguments contain unsupported properties.';
|
|
55
|
-
}
|
|
56
|
-
if (args.intent !== undefined && typeof args.intent !== 'string') {
|
|
57
|
-
return 'INVALID_ARGUMENTS: Deprecated intent must be a string when provided.';
|
|
58
|
-
}
|
|
59
|
-
return validateActionSummary(args.actionSummary);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function resolveHandshakeAgentId(
|
|
63
|
-
requestedAgentId: unknown,
|
|
64
|
-
signer?: AgentSigner
|
|
65
|
-
): { agentId: string } | { error: string } {
|
|
66
|
-
if (signer) {
|
|
67
|
-
if (requestedAgentId === undefined) return { agentId: signer.did };
|
|
68
|
-
if (typeof requestedAgentId !== 'string' || requestedAgentId !== signer.did) {
|
|
69
|
-
return {
|
|
70
|
-
error: 'IDENTITY_MISMATCH: Declared agentId does not match the armed Sovereign Signer DID.',
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
return { agentId: signer.did };
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (typeof requestedAgentId !== 'string' || requestedAgentId.trim().length === 0) {
|
|
77
|
-
return {
|
|
78
|
-
error: 'MISSING_AGENT_ID: An explicit agentId is required when no Sovereign Signer is armed.',
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
return { agentId: requestedAgentId };
|
|
82
|
-
}
|