@rohan-protocol/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/README.md +189 -0
- package/dist/firewall.d.ts +10 -0
- package/dist/firewall.d.ts.map +1 -0
- package/dist/firewall.js +23 -0
- package/dist/firewall.js.map +1 -0
- package/dist/gateway.d.ts +48 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +41 -0
- package/dist/gateway.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +132 -0
- package/dist/server.js.map +1 -0
- package/package.json +21 -0
- package/src/firewall.js +8 -0
- package/src/firewall.ts +33 -0
- package/src/gateway.ts +50 -0
- package/src/index.ts +2 -0
- package/src/server.ts +161 -0
- package/tsconfig.json +17 -0
package/README.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# Rohan MCP Gateway 🤖 (`@rohan-protocol/mcp`)
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@rohan-protocol/mcp)
|
|
4
|
+
[](https://modelcontextprotocol.io)
|
|
5
|
+
[](#streamable-http-handshake-lifecycle)
|
|
6
|
+
[](#security-architecture)
|
|
7
|
+
[](https://midnight.network)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
|
|
10
|
+
> **Official Model Context Protocol (MCP) Server for Confidential Agent-to-Agent ZK-Handshakes.**
|
|
11
|
+
> Equips AI Agents in Claude Desktop, Cursor, and autonomous runtimes with native Zero-Knowledge transaction capability and real-time **Streamable HTTP (NDJSON)** progress telemetry on Midnight.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## ⚡ The Threat: Indirect Prompt Injection (Security Vector V-01)
|
|
16
|
+
|
|
17
|
+
When autonomous AI agents execute machine-to-machine tools, malicious third parties can inject prompt instructions into tool payloads (*Indirect Prompt Injection*). Without deterministic verification, a compromised agent could be tricked into signing unauthorized agreements, leaking confidential session parameters, or executing blind on-chain actions.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 🛡️ The Defense: Pre-Prover Semantic Firewall + Streamable HTTP
|
|
22
|
+
|
|
23
|
+
`@rohan-protocol/mcp` acts as a zero-trust gateway. Before any Zero-Knowledge proof is computed or relayed:
|
|
24
|
+
|
|
25
|
+
1. **Semantic Inspection (V-01)**: Validates intent structures, schema boundaries, and agent DIDs against prompt injection patterns and role-reversal exploits.
|
|
26
|
+
2. **RAM-Only Proving (V-02)**: Calls `@rohan-protocol/sdk` to generate a 580-byte ZK-SNARK with instant memory zeroization (`zeroize`).
|
|
27
|
+
3. **⚡ Streamable HTTP (NDJSON)**: Uses chunked HTTP streaming (`POST /api/v1/handshake/stream`) to provide granular real-time progress events back to the calling agent context.
|
|
28
|
+
4. **Gasless Settlement**: Hands off the proof to the Rohan Relayer for on-chain anchoring on Midnight Preprod without requiring the agent to manage private keys or gas tokens (`tDUST`).
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 📦 Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install @rohan-protocol/mcp
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Or run directly without installation via `npx`:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npx @rohan-protocol/mcp
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 💻 Setup: Connect Your AI Agents
|
|
47
|
+
|
|
48
|
+
### 1. Claude Desktop Integration
|
|
49
|
+
|
|
50
|
+
Add the Rohan MCP server to your `claude_desktop_config.json`:
|
|
51
|
+
- **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
52
|
+
- **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
53
|
+
- **Linux**: `~/.config/Claude/claude_desktop_config.json`
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"mcpServers": {
|
|
58
|
+
"rohan-zk-gateway": {
|
|
59
|
+
"command": "npx",
|
|
60
|
+
"args": ["-y", "@rohan-protocol/mcp"],
|
|
61
|
+
"env": {
|
|
62
|
+
"ROHAN_CONTRACT_ADDRESS": "6d2d603235f996424d76c85186a79cc403245ea8ee1ba9087e40967fe71bdc4d",
|
|
63
|
+
"ROHAN_RELAYER_URL": "https://api.rohanprotocol.network/api/v1/handshake/stream",
|
|
64
|
+
"ROHAN_API_KEY": "rohan_live_..."
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
> **Sandbox vs. Production**: The MCP server works out of the box with **10 free handshakes per day** without an API key. For continuous agent workflows, provide `ROHAN_API_KEY` in the environment configuration.
|
|
72
|
+
|
|
73
|
+
### 2. Cursor IDE Integration
|
|
74
|
+
|
|
75
|
+
In Cursor, navigate to **Settings > Features > MCP Servers > Add New MCP Server**:
|
|
76
|
+
- **Name**: `rohan-zk`
|
|
77
|
+
- **Type**: `command`
|
|
78
|
+
- **Command**: `npx -y @rohan-protocol/mcp`
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## 🛠️ Exposed MCP Tools
|
|
83
|
+
|
|
84
|
+
The server automatically registers the following tool in your LLM's context:
|
|
85
|
+
|
|
86
|
+
### `rohan_zk_handshake`
|
|
87
|
+
|
|
88
|
+
Executes a confidential, tamper-proof Zero-Knowledge handshake on Midnight with real-time streamable verification.
|
|
89
|
+
|
|
90
|
+
#### Input Schema:
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"agentId": {
|
|
95
|
+
"type": "string",
|
|
96
|
+
"description": "Decentralized Identifier (DID) of the initiator agent (e.g. did:midnight:agent-01)"
|
|
97
|
+
},
|
|
98
|
+
"intent": {
|
|
99
|
+
"type": "string",
|
|
100
|
+
"description": "Semantic action plan, financial intent, or agreement to seal in ZK"
|
|
101
|
+
},
|
|
102
|
+
"counterpartyId": {
|
|
103
|
+
"type": "string",
|
|
104
|
+
"description": "Optional DID of the target recipient agent"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
#### Example Agent Invocation Prompt:
|
|
110
|
+
|
|
111
|
+
> *"Claude, seal our data-sharing agreement with `did:midnight:agent-partner` using Rohan ZK Handshake."*
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
<a id="streamable-http-handshake-lifecycle"></a>
|
|
116
|
+
## ⚡ Streamable HTTP Handshake Lifecycle
|
|
117
|
+
|
|
118
|
+
During tool execution, the MCP server connects to the Relayer via Chunked Transfer-Encoding (NDJSON), processing the following sequential stages:
|
|
119
|
+
|
|
120
|
+
```text
|
|
121
|
+
📡 [LIVE CHUNK] stage: 'received' | Data: {"stage":"received","timestamp":1788903808207}
|
|
122
|
+
📡 [LIVE CHUNK] stage: 'firewall_approved' | Data: {"stage":"firewall_approved","v01":"passed"}
|
|
123
|
+
📡 [LIVE CHUNK] stage: 'subsidizing_gas' | Data: {"stage":"subsidizing_gas","gasPayer":"rohan-relayer-node-01"}
|
|
124
|
+
📡 [LIVE CHUNK] stage: 'confirmed' | Data: {"stage":"confirmed","status":"success","txHash":"0x7c92...","intentHash":"0916..."}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### Returned Structured Receipt to LLM:
|
|
128
|
+
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"status": "success",
|
|
132
|
+
"receipt": {
|
|
133
|
+
"stage": "confirmed",
|
|
134
|
+
"status": "success",
|
|
135
|
+
"contractAddress": "6d2d603235f996424d76c85186a79cc403245ea8ee1ba9087e40967fe71bdc4d",
|
|
136
|
+
"intentHash": "0916542f526dd3117104f23f113873a5331fdc2d885340081aef79dab0ee7393",
|
|
137
|
+
"txHash": "0x7c92f75ca7d3bc8c767953b69c29d87d3848084c68d401bbd7987ff1afdb8271",
|
|
138
|
+
"gasPaidBy": "rohan-relayer-node-01",
|
|
139
|
+
"timestamp": 1788903808208
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
<a id="security-architecture"></a>
|
|
147
|
+
## 🔒 Security Architecture (V-01 & V-02)
|
|
148
|
+
|
|
149
|
+
```text
|
|
150
|
+
┌────────────────────────────────────────────────────────┐
|
|
151
|
+
│ AI Agent (Claude / Cursor / Headless Bot) │
|
|
152
|
+
│ "Perform confidential handshake with Agent B" │
|
|
153
|
+
└──────────────────────────┬─────────────────────────────┘
|
|
154
|
+
│ 💬 MCP Tool Request: rohan_zk_handshake
|
|
155
|
+
▼
|
|
156
|
+
┌────────────────────────────────────────────────────────┐
|
|
157
|
+
│ 🛡️ PRE-PROVER SEMANTIC FIREWALL (V-01) │
|
|
158
|
+
│ - Inspects against indirect injection patterns │
|
|
159
|
+
│ - Validates schema and DID integrity │
|
|
160
|
+
└──────────────────────────┬─────────────────────────────┘
|
|
161
|
+
│ ✅ Filter Passed
|
|
162
|
+
▼
|
|
163
|
+
┌────────────────────────────────────────────────────────┐
|
|
164
|
+
│ 📦 @rohan-protocol/sdk (Local WASM Engine) │
|
|
165
|
+
│ - Computes ZK-Proof in isolated RAM │
|
|
166
|
+
│ - Multi-pass memory wipe destroys witness w (V-02) │
|
|
167
|
+
└──────────────────────────┬─────────────────────────────┘
|
|
168
|
+
│ 📡 Streamable HTTP (POST /api/v1/handshake/stream)
|
|
169
|
+
▼
|
|
170
|
+
┌────────────────────────────────────────────────────────┐
|
|
171
|
+
│ ⚡ Rohan Relayer & Gas Station (NDJSON Stream) │
|
|
172
|
+
│ - Chunk 1: stage: 'received' │
|
|
173
|
+
│ - Chunk 2: stage: 'firewall_approved' │
|
|
174
|
+
│ - Chunk 3: stage: 'subsidizing_gas' │
|
|
175
|
+
│ - Chunk 4: stage: 'confirmed' (on-chain finalization)│
|
|
176
|
+
└──────────────────────────┬─────────────────────────────┘
|
|
177
|
+
│
|
|
178
|
+
┌──────────────────────────▼─────────────────────────────┐
|
|
179
|
+
│ 🌌 Midnight Network Settlement Layer │
|
|
180
|
+
│ - Compact Smart Contract: rohan_handshake │
|
|
181
|
+
│ - Preprod Address: 6d2d603235f996424d76c85186a... │
|
|
182
|
+
└────────────────────────────────────────────────────────┘
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## 📄 License
|
|
188
|
+
|
|
189
|
+
MIT © Rohan Protocol. Part of the Private Agentic Economy.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface HandshakeIntent {
|
|
2
|
+
agentId: string;
|
|
3
|
+
action: string;
|
|
4
|
+
payload: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
export declare class SemanticFirewall {
|
|
7
|
+
private static readonly INJECTION_REGEX;
|
|
8
|
+
static validate(intent: HandshakeIntent): boolean;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=firewall.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firewall.d.ts","sourceRoot":"","sources":["../src/firewall.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CACmI;IAE1K,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAqBhD;CACF"}
|
package/dist/firewall.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class SemanticFirewall {
|
|
2
|
+
static INJECTION_REGEX = /(?: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;
|
|
3
|
+
static validate(intent) {
|
|
4
|
+
if (!intent.agentId || typeof intent.agentId !== 'string' || intent.agentId.length > 128) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
if (!intent.action || (intent.action !== 'rohan_zk_handshake' && intent.action !== 'verify_batched_handshakes')) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
if (!intent.payload || typeof intent.payload !== 'object') {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const serialized = JSON.stringify(intent.payload);
|
|
14
|
+
if (serialized.length > 8192) {
|
|
15
|
+
return false; // Denial-of-Service Schutz
|
|
16
|
+
}
|
|
17
|
+
if (this.INJECTION_REGEX.test(serialized)) {
|
|
18
|
+
return false; // Prompt Injection blockiert
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=firewall.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firewall.js","sourceRoot":"","sources":["../src/firewall.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,gBAAgB;IACnB,MAAM,CAAU,eAAe,GACrC,uKAAuK,CAAC;IAE1K,MAAM,CAAC,QAAQ,CAAC,MAAuB;QACrC,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YACzF,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,oBAAoB,IAAI,MAAM,CAAC,MAAM,KAAK,2BAA2B,CAAC,EAAE,CAAC;YAChH,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YAC1D,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAClD,IAAI,UAAU,CAAC,MAAM,GAAG,IAAI,EAAE,CAAC;YAC7B,OAAO,KAAK,CAAC,CAAC,2BAA2B;QAC3C,CAAC;QAED,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAC1C,OAAO,KAAK,CAAC,CAAC,6BAA6B;QAC7C,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { RohanRelayerClient } from '../../sdk/dist/index.js';
|
|
2
|
+
export interface RohanMcpGatewayOptions {
|
|
3
|
+
transport?: 'stdio' | 'streamable-http';
|
|
4
|
+
relayerUrl?: string;
|
|
5
|
+
contractAddress?: string;
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* ⚡ RohanMcpGateway
|
|
10
|
+
* Connects AI Agent pipelines (Google ADK 2.0, Gemini, Claude, Cursor)
|
|
11
|
+
* to the Rohan Protocol Gas Station via Streamable HTTP (NDJSON) or Stdio.
|
|
12
|
+
*/
|
|
13
|
+
export declare class RohanMcpGateway {
|
|
14
|
+
readonly transport: string;
|
|
15
|
+
readonly relayerClient: RohanRelayerClient;
|
|
16
|
+
constructor(options?: RohanMcpGatewayOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Generates a tool specification compliant with Google ADK 2.0 and Gemini tool calling.
|
|
19
|
+
*/
|
|
20
|
+
asAdkTool(): {
|
|
21
|
+
name: string;
|
|
22
|
+
description: string;
|
|
23
|
+
parameters: {
|
|
24
|
+
type: string;
|
|
25
|
+
properties: {
|
|
26
|
+
agentId: {
|
|
27
|
+
type: string;
|
|
28
|
+
description: string;
|
|
29
|
+
};
|
|
30
|
+
intent: {
|
|
31
|
+
type: string;
|
|
32
|
+
description: string;
|
|
33
|
+
};
|
|
34
|
+
proof: {
|
|
35
|
+
type: string;
|
|
36
|
+
description: string;
|
|
37
|
+
};
|
|
38
|
+
publicInputs: {
|
|
39
|
+
type: string;
|
|
40
|
+
description: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
required: string[];
|
|
44
|
+
};
|
|
45
|
+
execute: (params: any) => Promise<any>;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=gateway.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE,OAAO,GAAG,iBAAiB,CAAC;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,qBAAa,eAAe;IAC1B,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAgB,aAAa,EAAE,kBAAkB,CAAC;IAElD,YAAY,OAAO,GAAE,sBAA2B,EAO/C;IAED;;OAEG;IACH,SAAS;QAEL,IAAI;QACJ,WAAW;QACX,UAAU;YACR,IAAI;YACJ,UAAU;gBACR,OAAO;oBAAI,IAAI;oBAAY,WAAW;;gBACtC,MAAM;oBAAI,IAAI;oBAAY,WAAW;;gBACrC,KAAK;oBAAI,IAAI;oBAAY,WAAW;;gBACpC,YAAY;oBAAI,IAAI;oBAAY,WAAW;;;YAE7C,QAAQ;;QAEV,OAAO,WAAiB,GAAG;MAI9B;CACF"}
|
package/dist/gateway.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { RohanRelayerClient } from '../../sdk/dist/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* ⚡ RohanMcpGateway
|
|
4
|
+
* Connects AI Agent pipelines (Google ADK 2.0, Gemini, Claude, Cursor)
|
|
5
|
+
* to the Rohan Protocol Gas Station via Streamable HTTP (NDJSON) or Stdio.
|
|
6
|
+
*/
|
|
7
|
+
export class RohanMcpGateway {
|
|
8
|
+
transport;
|
|
9
|
+
relayerClient;
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
this.transport = options.transport || 'streamable-http';
|
|
12
|
+
this.relayerClient = new RohanRelayerClient({
|
|
13
|
+
relayerUrl: options.relayerUrl || 'http://127.0.0.1:4005/api/v1/handshake',
|
|
14
|
+
contractAddress: options.contractAddress || '6d2d603235f996424d76c85186a79cc403245ea8ee1ba9087e40967fe71bdc4d',
|
|
15
|
+
apiKey: options.apiKey,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Generates a tool specification compliant with Google ADK 2.0 and Gemini tool calling.
|
|
20
|
+
*/
|
|
21
|
+
asAdkTool() {
|
|
22
|
+
return {
|
|
23
|
+
name: 'rohan_zk_handshake',
|
|
24
|
+
description: 'Executes a zero-knowledge verifiable handshake proof on Midnight Network with zero plaintext leaks.',
|
|
25
|
+
parameters: {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
agentId: { type: 'string', description: 'Identifier of calling agent' },
|
|
29
|
+
intent: { type: 'string', description: 'Semantic action intent' },
|
|
30
|
+
proof: { type: 'string', description: 'ZK-SNARK proof payload' },
|
|
31
|
+
publicInputs: { type: 'object', description: 'Public inputs for on-chain verification' },
|
|
32
|
+
},
|
|
33
|
+
required: ['agentId', 'intent'],
|
|
34
|
+
},
|
|
35
|
+
execute: async (params) => {
|
|
36
|
+
return await this.relayerClient.submitProof(params);
|
|
37
|
+
},
|
|
38
|
+
};
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,MAAM,CAAC,CAAC;YACtD,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":""}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import { SemanticFirewall } from './firewall.js';
|
|
6
|
+
import { RohanClient } from '../../sdk/dist/index.js';
|
|
7
|
+
// Midnight Preprod Contract Adresse
|
|
8
|
+
const CONTRACT_ADDRESS = process.env.ROHAN_CONTRACT_ADDRESS || '6d2d603235f996424d76c85186a79cc403245ea8ee1ba9087e40967fe71bdc4d';
|
|
9
|
+
const RELAYER_URL = process.env.ROHAN_RELAYER_URL || 'http://127.0.0.1:4005/api/v1/handshake';
|
|
10
|
+
const rohanClient = new RohanClient(CONTRACT_ADDRESS);
|
|
11
|
+
/**
|
|
12
|
+
* 🛡️ ROHAN PROTOCOL MCP SERVER
|
|
13
|
+
* Ermöglicht KI-Agenten native Zero-Knowledge Handshakes über das Model Context Protocol.
|
|
14
|
+
*/
|
|
15
|
+
const server = new Server({
|
|
16
|
+
name: 'rohan-protocol-mcp',
|
|
17
|
+
version: '0.5.0',
|
|
18
|
+
}, {
|
|
19
|
+
capabilities: {
|
|
20
|
+
tools: {},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
// 1. Tool-Liste für LLMs deklarieren
|
|
24
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
25
|
+
return {
|
|
26
|
+
tools: [
|
|
27
|
+
{
|
|
28
|
+
name: 'rohan_zk_handshake',
|
|
29
|
+
description: 'Führt einen kryptographischen Zero-Knowledge Handshake auf der Midnight Blockchain aus. Beweist einen Intent oder eine Vereinbarung zwischen Agenten ohne Preisgabe vertraulicher Inhalte.',
|
|
30
|
+
inputSchema: {
|
|
31
|
+
type: 'object',
|
|
32
|
+
properties: {
|
|
33
|
+
agentId: {
|
|
34
|
+
type: 'string',
|
|
35
|
+
description: 'Die dezentrale Identität (DID) oder ID des initiierenden Agenten',
|
|
36
|
+
},
|
|
37
|
+
intent: {
|
|
38
|
+
type: 'string',
|
|
39
|
+
description: 'Der semantische Aktionsplan oder Vereinbarungsinhalt, der im ZK-Proof versiegelt wird',
|
|
40
|
+
},
|
|
41
|
+
counterpartyId: {
|
|
42
|
+
type: 'string',
|
|
43
|
+
description: 'Optionale ID des Empfänger-Agenten',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
required: ['agentId', 'intent'],
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
// 2. Tool-Aufruf ausführen
|
|
53
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
54
|
+
if (request.params.name !== 'rohan_zk_handshake') {
|
|
55
|
+
throw new Error(`Unbekanntes Tool: ${request.params.name}`);
|
|
56
|
+
}
|
|
57
|
+
const args = request.params.arguments;
|
|
58
|
+
// A. Semantic Firewall Prüfung (Sicherheits-Vektor V-01)
|
|
59
|
+
const isValid = SemanticFirewall.validate({
|
|
60
|
+
agentId: args.agentId,
|
|
61
|
+
action: 'rohan_zk_handshake',
|
|
62
|
+
payload: args,
|
|
63
|
+
});
|
|
64
|
+
if (!isValid) {
|
|
65
|
+
return {
|
|
66
|
+
content: [
|
|
67
|
+
{
|
|
68
|
+
type: 'text',
|
|
69
|
+
text: JSON.stringify({
|
|
70
|
+
success: false,
|
|
71
|
+
error: 'Security Violation: Intent rejected by Semantic Firewall (V-01)',
|
|
72
|
+
}),
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
isError: true,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
// B. ZK-Proof im Client-RAM generieren (inkl. V-02 Memory Sanitation!)
|
|
80
|
+
const proofData = await rohanClient.generateHandshakeProof({
|
|
81
|
+
agentId: args.agentId,
|
|
82
|
+
intent: args.intent,
|
|
83
|
+
});
|
|
84
|
+
// C. Proof an Relayer (Gas Station) übermitteln
|
|
85
|
+
const headers = { 'Content-Type': 'application/json' };
|
|
86
|
+
if (process.env.ROHAN_API_KEY) {
|
|
87
|
+
headers['x-rohan-api-key'] = process.env.ROHAN_API_KEY;
|
|
88
|
+
}
|
|
89
|
+
const response = await fetch(RELAYER_URL, {
|
|
90
|
+
method: 'POST',
|
|
91
|
+
headers,
|
|
92
|
+
body: JSON.stringify(proofData),
|
|
93
|
+
});
|
|
94
|
+
const receipt = await response.json();
|
|
95
|
+
return {
|
|
96
|
+
content: [
|
|
97
|
+
{
|
|
98
|
+
type: 'text',
|
|
99
|
+
text: JSON.stringify({
|
|
100
|
+
status: 'success',
|
|
101
|
+
message: 'Zero-Knowledge Handshake erfolgreich auf Midnight Blockchain verankert!',
|
|
102
|
+
receipt,
|
|
103
|
+
}, null, 2),
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
return {
|
|
110
|
+
content: [
|
|
111
|
+
{
|
|
112
|
+
type: 'text',
|
|
113
|
+
text: JSON.stringify({
|
|
114
|
+
success: false,
|
|
115
|
+
error: err.message || 'Handshake execution failed',
|
|
116
|
+
}),
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
isError: true,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
async function run() {
|
|
124
|
+
const transport = new StdioServerTransport();
|
|
125
|
+
await server.connect(transport);
|
|
126
|
+
console.error('🛡️ Rohan Protocol MCP Server läuft via Stdio...');
|
|
127
|
+
}
|
|
128
|
+
run().catch((error) => {
|
|
129
|
+
console.error('Fataler Serverfehler:', error);
|
|
130
|
+
process.exit(1);
|
|
131
|
+
});
|
|
132
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,oCAAoC;AACpC,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,kEAAkE,CAAC;AAClI,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,wCAAwC,CAAC;AAE9F,MAAM,WAAW,GAAG,IAAI,WAAW,CAAC,gBAAgB,CAAC,CAAC;AAEtD;;;GAGG;AACH,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB;IACE,IAAI,EAAE,oBAAoB;IAC1B,OAAO,EAAE,OAAO;CACjB,EACD;IACE,YAAY,EAAE;QACZ,KAAK,EAAE,EAAE;KACV;C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,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,KAAK,UAAU,GAAG;IAChB,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAC;AACpE,CAAC;AAED,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACpB,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;IAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rohan-protocol/mcp",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Model Context Protocol (MCP) Gateway for Rohan Protocol ZK-Handshakes",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"start": "node dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
14
|
+
"@rohan-protocol/sdk": "^0.5.0"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/node": "*",
|
|
18
|
+
"typescript": "^7.0.2"
|
|
19
|
+
},
|
|
20
|
+
"bin": "./dist/server.js"
|
|
21
|
+
}
|
package/src/firewall.js
ADDED
package/src/firewall.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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 || (intent.action !== 'rohan_zk_handshake' && intent.action !== 'verify_batched_handshakes')) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (!intent.payload || typeof intent.payload !== 'object') {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const serialized = JSON.stringify(intent.payload);
|
|
23
|
+
if (serialized.length > 8192) {
|
|
24
|
+
return false; // Denial-of-Service Schutz
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (this.INJECTION_REGEX.test(serialized)) {
|
|
28
|
+
return false; // Prompt Injection blockiert
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/gateway.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { RohanRelayerClient } from '../../sdk/dist/index.js';
|
|
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 || '6d2d603235f996424d76c85186a79cc403245ea8ee1ba9087e40967fe71bdc4d',
|
|
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_zk_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: 'Identifier of calling agent' },
|
|
39
|
+
intent: { type: 'string', description: 'Semantic action intent' },
|
|
40
|
+
proof: { type: 'string', description: 'ZK-SNARK proof payload' },
|
|
41
|
+
publicInputs: { type: 'object', description: 'Public inputs for on-chain verification' },
|
|
42
|
+
},
|
|
43
|
+
required: ['agentId', 'intent'],
|
|
44
|
+
},
|
|
45
|
+
execute: async (params: any) => {
|
|
46
|
+
return await this.relayerClient.submitProof(params);
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/index.ts
ADDED
package/src/server.ts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
import {
|
|
5
|
+
CallToolRequestSchema,
|
|
6
|
+
ListToolsRequestSchema,
|
|
7
|
+
} from '@modelcontextprotocol/sdk/types.js';
|
|
8
|
+
|
|
9
|
+
import { SemanticFirewall } from './firewall.js';
|
|
10
|
+
import { RohanClient } from '../../sdk/dist/index.js';
|
|
11
|
+
|
|
12
|
+
// Midnight Preprod Contract Adresse
|
|
13
|
+
const CONTRACT_ADDRESS = process.env.ROHAN_CONTRACT_ADDRESS || '6d2d603235f996424d76c85186a79cc403245ea8ee1ba9087e40967fe71bdc4d';
|
|
14
|
+
const RELAYER_URL = process.env.ROHAN_RELAYER_URL || 'http://127.0.0.1:4005/api/v1/handshake';
|
|
15
|
+
|
|
16
|
+
const rohanClient = new RohanClient(CONTRACT_ADDRESS);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 🛡️ ROHAN PROTOCOL MCP SERVER
|
|
20
|
+
* Ermöglicht KI-Agenten native Zero-Knowledge Handshakes über das Model Context Protocol.
|
|
21
|
+
*/
|
|
22
|
+
const server = new Server(
|
|
23
|
+
{
|
|
24
|
+
name: 'rohan-protocol-mcp',
|
|
25
|
+
version: '0.5.0',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
capabilities: {
|
|
29
|
+
tools: {},
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
// 1. Tool-Liste für LLMs deklarieren
|
|
35
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
36
|
+
return {
|
|
37
|
+
tools: [
|
|
38
|
+
{
|
|
39
|
+
name: 'rohan_zk_handshake',
|
|
40
|
+
description:
|
|
41
|
+
'Führt einen kryptographischen Zero-Knowledge Handshake auf der Midnight Blockchain aus. Beweist einen Intent oder eine Vereinbarung zwischen Agenten ohne Preisgabe vertraulicher Inhalte.',
|
|
42
|
+
inputSchema: {
|
|
43
|
+
type: 'object',
|
|
44
|
+
properties: {
|
|
45
|
+
agentId: {
|
|
46
|
+
type: 'string',
|
|
47
|
+
description: 'Die dezentrale Identität (DID) oder ID des initiierenden Agenten',
|
|
48
|
+
},
|
|
49
|
+
intent: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
description: 'Der semantische Aktionsplan oder Vereinbarungsinhalt, der im ZK-Proof versiegelt wird',
|
|
52
|
+
},
|
|
53
|
+
counterpartyId: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
description: 'Optionale ID des Empfänger-Agenten',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
required: ['agentId', 'intent'],
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// 2. Tool-Aufruf ausführen
|
|
66
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
67
|
+
if (request.params.name !== 'rohan_zk_handshake') {
|
|
68
|
+
throw new Error(`Unbekanntes Tool: ${request.params.name}`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const args = request.params.arguments as {
|
|
72
|
+
agentId: string;
|
|
73
|
+
intent: string;
|
|
74
|
+
counterpartyId?: string;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// A. Semantic Firewall Prüfung (Sicherheits-Vektor V-01)
|
|
78
|
+
const isValid = SemanticFirewall.validate({
|
|
79
|
+
agentId: args.agentId,
|
|
80
|
+
action: 'rohan_zk_handshake',
|
|
81
|
+
payload: args,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
if (!isValid) {
|
|
85
|
+
return {
|
|
86
|
+
content: [
|
|
87
|
+
{
|
|
88
|
+
type: 'text',
|
|
89
|
+
text: JSON.stringify({
|
|
90
|
+
success: false,
|
|
91
|
+
error: 'Security Violation: Intent rejected by Semantic Firewall (V-01)',
|
|
92
|
+
}),
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
isError: true,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
// B. ZK-Proof im Client-RAM generieren (inkl. V-02 Memory Sanitation!)
|
|
101
|
+
const proofData = await rohanClient.generateHandshakeProof({
|
|
102
|
+
agentId: args.agentId,
|
|
103
|
+
intent: args.intent,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// C. Proof an Relayer (Gas Station) übermitteln
|
|
107
|
+
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
|
|
108
|
+
if (process.env.ROHAN_API_KEY) {
|
|
109
|
+
headers['x-rohan-api-key'] = process.env.ROHAN_API_KEY;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const response = await fetch(RELAYER_URL, {
|
|
113
|
+
method: 'POST',
|
|
114
|
+
headers,
|
|
115
|
+
body: JSON.stringify(proofData),
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const receipt = await response.json();
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
content: [
|
|
122
|
+
{
|
|
123
|
+
type: 'text',
|
|
124
|
+
text: JSON.stringify(
|
|
125
|
+
{
|
|
126
|
+
status: 'success',
|
|
127
|
+
message: 'Zero-Knowledge Handshake erfolgreich auf Midnight Blockchain verankert!',
|
|
128
|
+
receipt,
|
|
129
|
+
},
|
|
130
|
+
null,
|
|
131
|
+
2
|
|
132
|
+
),
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
};
|
|
136
|
+
} catch (err: any) {
|
|
137
|
+
return {
|
|
138
|
+
content: [
|
|
139
|
+
{
|
|
140
|
+
type: 'text',
|
|
141
|
+
text: JSON.stringify({
|
|
142
|
+
success: false,
|
|
143
|
+
error: err.message || 'Handshake execution failed',
|
|
144
|
+
}),
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
isError: true,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
async function run() {
|
|
153
|
+
const transport = new StdioServerTransport();
|
|
154
|
+
await server.connect(transport);
|
|
155
|
+
console.error('🛡️ Rohan Protocol MCP Server läuft via Stdio...');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
run().catch((error) => {
|
|
159
|
+
console.error('Fataler Serverfehler:', error);
|
|
160
|
+
process.exit(1);
|
|
161
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"declarationMap": true,
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"outDir": "./dist",
|
|
10
|
+
"rootDir": "./src",
|
|
11
|
+
"strict": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["src/**/*"]
|
|
17
|
+
}
|