@kya-os/mcp-i 0.1.0-alpha.1.0 → 0.1.0-alpha.2.1
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 +66 -90
- package/dist/__tests__/challenge-response.test.d.ts +5 -0
- package/dist/__tests__/challenge-response.test.d.ts.map +1 -0
- package/dist/__tests__/challenge-response.test.js +218 -0
- package/dist/__tests__/challenge-response.test.js.map +1 -0
- package/dist/__tests__/crypto.test.d.ts +5 -0
- package/dist/__tests__/crypto.test.d.ts.map +1 -0
- package/dist/__tests__/crypto.test.js +153 -0
- package/dist/__tests__/crypto.test.js.map +1 -0
- package/dist/auto-enhance.d.ts +41 -0
- package/dist/auto-enhance.d.ts.map +1 -0
- package/dist/auto-enhance.js +193 -0
- package/dist/auto-enhance.js.map +1 -0
- package/dist/auto-init.d.ts +12 -0
- package/dist/auto-init.d.ts.map +1 -0
- package/dist/auto-init.js +166 -0
- package/dist/auto-init.js.map +1 -0
- package/dist/auto.d.ts +13 -0
- package/dist/auto.d.ts.map +1 -0
- package/dist/auto.js +24 -0
- package/dist/auto.js.map +1 -0
- package/dist/crypto.d.ts +32 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +117 -0
- package/dist/crypto.js.map +1 -0
- package/dist/index.d.ts +43 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +208 -28
- package/dist/index.js.map +1 -1
- package/dist/patch.d.ts +22 -0
- package/dist/patch.d.ts.map +1 -0
- package/dist/patch.js +164 -0
- package/dist/patch.js.map +1 -0
- package/dist/transparent.d.ts +40 -0
- package/dist/transparent.d.ts.map +1 -0
- package/dist/transparent.js +167 -0
- package/dist/transparent.js.map +1 -0
- package/dist/types.d.ts +79 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/package.json +19 -4
package/dist/index.d.ts
CHANGED
|
@@ -4,51 +4,66 @@
|
|
|
4
4
|
* Enable any MCP server to get a verifiable identity with just 2 lines of code:
|
|
5
5
|
*
|
|
6
6
|
* ```typescript
|
|
7
|
-
* import
|
|
8
|
-
* const identity = await MCPIdentity.init();
|
|
7
|
+
* import "@kya-os/mcp-i/auto"; // That's it! Your server now has identity
|
|
9
8
|
* ```
|
|
10
9
|
*
|
|
11
|
-
*
|
|
10
|
+
* Or with configuration:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { enableMCPIdentity } from "@kya-os/mcp-i";
|
|
13
|
+
* await enableMCPIdentity({ name: "My Amazing Agent" });
|
|
14
|
+
* ```
|
|
12
15
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
description?: string;
|
|
16
|
-
repository?: string;
|
|
17
|
-
apiEndpoint?: string;
|
|
18
|
-
persistencePath?: string;
|
|
19
|
-
}
|
|
16
|
+
import { MCPIdentityOptions, Challenge, ChallengeResponse, MCPICapabilities, SignedResponse } from './types';
|
|
17
|
+
export * from './types';
|
|
20
18
|
export declare class MCPIdentity {
|
|
21
19
|
readonly did: string;
|
|
22
20
|
readonly publicKey: string;
|
|
23
21
|
private privateKey;
|
|
22
|
+
private timestampTolerance;
|
|
23
|
+
private enableNonceTracking;
|
|
24
|
+
private usedNonces;
|
|
25
|
+
private nonceCleanupInterval?;
|
|
24
26
|
private constructor();
|
|
25
27
|
/**
|
|
26
28
|
* Initialize MCP Identity - the main entry point
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```typescript
|
|
30
|
-
* import { MCPIdentity } from "@kya-os/mcp-i";
|
|
31
|
-
* const identity = await MCPIdentity.init();
|
|
32
|
-
* ```
|
|
33
29
|
*/
|
|
34
30
|
static init(options?: MCPIdentityOptions): Promise<MCPIdentity>;
|
|
35
31
|
/**
|
|
36
|
-
* Sign a message with the agent's private key
|
|
32
|
+
* Sign a message with the agent's private key using Ed25519
|
|
33
|
+
*/
|
|
34
|
+
sign(message: string | Buffer): Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Verify a signature against a public key
|
|
37
|
+
*/
|
|
38
|
+
verify(message: string | Buffer, signature: string, publicKey?: string): Promise<boolean>;
|
|
39
|
+
/**
|
|
40
|
+
* Respond to an MCP-I challenge
|
|
37
41
|
*/
|
|
38
|
-
|
|
42
|
+
respondToChallenge(challenge: Challenge): Promise<ChallengeResponse>;
|
|
39
43
|
/**
|
|
40
|
-
* Get MCP-I capabilities
|
|
44
|
+
* Get MCP-I capabilities for advertisement
|
|
41
45
|
*/
|
|
42
|
-
getCapabilities():
|
|
43
|
-
version: string;
|
|
44
|
-
did: string;
|
|
45
|
-
publicKey: string;
|
|
46
|
-
conformanceLevel: number;
|
|
47
|
-
};
|
|
46
|
+
getCapabilities(): MCPICapabilities;
|
|
48
47
|
/**
|
|
49
|
-
* Sign an MCP response
|
|
48
|
+
* Sign an MCP response with identity metadata
|
|
50
49
|
*/
|
|
51
|
-
signResponse(response:
|
|
50
|
+
signResponse<T = any>(response: T): Promise<SignedResponse<T>>;
|
|
51
|
+
/**
|
|
52
|
+
* Generate a new nonce for challenges
|
|
53
|
+
*/
|
|
54
|
+
static generateNonce(): string;
|
|
55
|
+
/**
|
|
56
|
+
* Clean up old nonces periodically to prevent memory leaks
|
|
57
|
+
*/
|
|
58
|
+
private startNonceCleanup;
|
|
59
|
+
/**
|
|
60
|
+
* Clean up resources
|
|
61
|
+
*/
|
|
62
|
+
destroy(): void;
|
|
52
63
|
}
|
|
53
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Enable MCP Identity for any MCP server
|
|
66
|
+
* This is the main integration point that patches the MCP Server
|
|
67
|
+
*/
|
|
68
|
+
export declare function enableMCPIdentity(options?: MCPIdentityOptions): Promise<MCPIdentity>;
|
|
54
69
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.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BAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CAW1F"}
|
package/dist/index.js
CHANGED
|
@@ -5,11 +5,14 @@
|
|
|
5
5
|
* Enable any MCP server to get a verifiable identity with just 2 lines of code:
|
|
6
6
|
*
|
|
7
7
|
* ```typescript
|
|
8
|
-
* import
|
|
9
|
-
* const identity = await MCPIdentity.init();
|
|
8
|
+
* import "@kya-os/mcp-i/auto"; // That's it! Your server now has identity
|
|
10
9
|
* ```
|
|
11
10
|
*
|
|
12
|
-
*
|
|
11
|
+
* Or with configuration:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { enableMCPIdentity } from "@kya-os/mcp-i";
|
|
14
|
+
* await enableMCPIdentity({ name: "My Amazing Agent" });
|
|
15
|
+
* ```
|
|
13
16
|
*/
|
|
14
17
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
18
|
if (k2 === undefined) k2 = k;
|
|
@@ -44,30 +47,44 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
44
47
|
return result;
|
|
45
48
|
};
|
|
46
49
|
})();
|
|
50
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
51
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
52
|
+
};
|
|
47
53
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
54
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
55
|
};
|
|
50
56
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
57
|
exports.MCPIdentity = void 0;
|
|
58
|
+
exports.enableMCPIdentity = enableMCPIdentity;
|
|
52
59
|
const axios_1 = __importDefault(require("axios"));
|
|
53
60
|
const fs = __importStar(require("fs"));
|
|
54
61
|
const path = __importStar(require("path"));
|
|
62
|
+
const crypto = __importStar(require("./crypto"));
|
|
63
|
+
// Re-export types for convenience
|
|
64
|
+
__exportStar(require("./types"), exports);
|
|
65
|
+
// Global identity instance
|
|
66
|
+
let globalIdentity = null;
|
|
55
67
|
class MCPIdentity {
|
|
56
|
-
constructor(identity) {
|
|
68
|
+
constructor(identity, options = {}) {
|
|
69
|
+
this.usedNonces = new Set();
|
|
57
70
|
this.did = identity.did;
|
|
58
71
|
this.publicKey = identity.publicKey;
|
|
59
72
|
this.privateKey = identity.privateKey;
|
|
73
|
+
this.timestampTolerance = options.timestampTolerance || 60000; // 60 seconds
|
|
74
|
+
this.enableNonceTracking = options.enableNonceTracking !== false;
|
|
75
|
+
// Start nonce cleanup if tracking is enabled
|
|
76
|
+
if (this.enableNonceTracking) {
|
|
77
|
+
this.startNonceCleanup();
|
|
78
|
+
}
|
|
60
79
|
}
|
|
61
80
|
/**
|
|
62
81
|
* Initialize MCP Identity - the main entry point
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* import { MCPIdentity } from "@kya-os/mcp-i";
|
|
67
|
-
* const identity = await MCPIdentity.init();
|
|
68
|
-
* ```
|
|
69
82
|
*/
|
|
70
83
|
static async init(options) {
|
|
84
|
+
// Return existing global identity if already initialized (unless forced)
|
|
85
|
+
if (globalIdentity && !options?.forceNew) {
|
|
86
|
+
return globalIdentity;
|
|
87
|
+
}
|
|
71
88
|
// Try to load existing identity
|
|
72
89
|
let identity = await loadIdentity(options?.persistencePath);
|
|
73
90
|
// Auto-register if needed
|
|
@@ -88,50 +105,208 @@ class MCPIdentity {
|
|
|
88
105
|
agentSlug: response.agent.slug,
|
|
89
106
|
registeredAt: new Date().toISOString(),
|
|
90
107
|
};
|
|
108
|
+
// If no private key was provided, generate one
|
|
109
|
+
if (!identity.privateKey) {
|
|
110
|
+
console.log('[MCP-I] Generating cryptographic keys...');
|
|
111
|
+
const keyPair = await crypto.generateKeyPair();
|
|
112
|
+
identity.publicKey = keyPair.publicKey;
|
|
113
|
+
identity.privateKey = keyPair.privateKey;
|
|
114
|
+
}
|
|
91
115
|
// Save for future use
|
|
92
116
|
await saveIdentity(identity, options?.persistencePath);
|
|
93
117
|
console.log('[MCP-I] ✅ Success! Your agent has been registered.');
|
|
94
118
|
console.log(`[MCP-I] DID: ${response.did}`);
|
|
95
119
|
console.log(`[MCP-I] Profile: ${response.agent.url}`);
|
|
96
120
|
}
|
|
97
|
-
|
|
121
|
+
globalIdentity = new MCPIdentity(identity, options);
|
|
122
|
+
return globalIdentity;
|
|
98
123
|
}
|
|
99
124
|
/**
|
|
100
|
-
* Sign a message with the agent's private key
|
|
125
|
+
* Sign a message with the agent's private key using Ed25519
|
|
101
126
|
*/
|
|
102
127
|
async sign(message) {
|
|
103
|
-
|
|
104
|
-
|
|
128
|
+
return crypto.sign(message, this.privateKey);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Verify a signature against a public key
|
|
132
|
+
*/
|
|
133
|
+
async verify(message, signature, publicKey) {
|
|
134
|
+
return crypto.verify(message, signature, publicKey || this.publicKey);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Respond to an MCP-I challenge
|
|
138
|
+
*/
|
|
139
|
+
async respondToChallenge(challenge) {
|
|
140
|
+
// Validate timestamp to prevent replay attacks
|
|
141
|
+
const now = Date.now();
|
|
142
|
+
const challengeAge = now - challenge.timestamp;
|
|
143
|
+
if (challengeAge > this.timestampTolerance) {
|
|
144
|
+
throw new Error('Challenge expired');
|
|
145
|
+
}
|
|
146
|
+
if (challengeAge < 0) {
|
|
147
|
+
throw new Error('Challenge timestamp is in the future');
|
|
148
|
+
}
|
|
149
|
+
// Check for nonce reuse if tracking is enabled
|
|
150
|
+
if (this.enableNonceTracking) {
|
|
151
|
+
if (this.usedNonces.has(challenge.nonce)) {
|
|
152
|
+
throw new Error('Nonce already used');
|
|
153
|
+
}
|
|
154
|
+
this.usedNonces.add(challenge.nonce);
|
|
155
|
+
}
|
|
156
|
+
// Create the message to sign
|
|
157
|
+
const messageComponents = [
|
|
158
|
+
challenge.nonce,
|
|
159
|
+
challenge.timestamp.toString(),
|
|
160
|
+
this.did,
|
|
161
|
+
challenge.verifier_did || '',
|
|
162
|
+
(challenge.scope || []).join(',')
|
|
163
|
+
];
|
|
164
|
+
const message = messageComponents.join(':');
|
|
165
|
+
// Sign the challenge
|
|
166
|
+
const signature = await this.sign(message);
|
|
167
|
+
// Return the response
|
|
168
|
+
return {
|
|
169
|
+
did: this.did,
|
|
170
|
+
signature,
|
|
171
|
+
timestamp: now,
|
|
172
|
+
nonce: challenge.nonce,
|
|
173
|
+
publicKey: this.publicKey
|
|
174
|
+
};
|
|
105
175
|
}
|
|
106
176
|
/**
|
|
107
|
-
* Get MCP-I capabilities
|
|
177
|
+
* Get MCP-I capabilities for advertisement
|
|
108
178
|
*/
|
|
109
179
|
getCapabilities() {
|
|
110
180
|
return {
|
|
111
181
|
version: '1.0',
|
|
112
182
|
did: this.did,
|
|
113
183
|
publicKey: this.publicKey,
|
|
114
|
-
conformanceLevel:
|
|
184
|
+
conformanceLevel: 2, // Level 2: Full crypto with challenge-response
|
|
185
|
+
handshakeSupported: true,
|
|
186
|
+
handshakeEndpoint: '/_mcp-i/handshake',
|
|
187
|
+
verificationEndpoint: `https://knowthat.ai/api/agents/${this.did}/verify`
|
|
115
188
|
};
|
|
116
189
|
}
|
|
117
190
|
/**
|
|
118
|
-
* Sign an MCP response
|
|
191
|
+
* Sign an MCP response with identity metadata
|
|
119
192
|
*/
|
|
120
|
-
signResponse(response) {
|
|
121
|
-
|
|
193
|
+
async signResponse(response) {
|
|
194
|
+
const timestamp = new Date().toISOString();
|
|
195
|
+
const responseWithIdentity = {
|
|
122
196
|
...response,
|
|
123
197
|
_mcp_identity: {
|
|
124
198
|
did: this.did,
|
|
125
|
-
signature:
|
|
126
|
-
timestamp
|
|
199
|
+
signature: '', // Will be filled below
|
|
200
|
+
timestamp,
|
|
201
|
+
conformanceLevel: 2
|
|
127
202
|
}
|
|
128
203
|
};
|
|
204
|
+
// Sign the response content (excluding the signature field)
|
|
205
|
+
const contentToSign = JSON.stringify({
|
|
206
|
+
...response,
|
|
207
|
+
_mcp_identity: {
|
|
208
|
+
did: this.did,
|
|
209
|
+
timestamp,
|
|
210
|
+
conformanceLevel: 2
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
responseWithIdentity._mcp_identity.signature = await this.sign(contentToSign);
|
|
214
|
+
return responseWithIdentity;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Generate a new nonce for challenges
|
|
218
|
+
*/
|
|
219
|
+
static generateNonce() {
|
|
220
|
+
return crypto.generateNonce();
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Clean up old nonces periodically to prevent memory leaks
|
|
224
|
+
*/
|
|
225
|
+
startNonceCleanup() {
|
|
226
|
+
// Clean up nonces older than 2x the timestamp tolerance
|
|
227
|
+
this.nonceCleanupInterval = setInterval(() => {
|
|
228
|
+
// In a production system, you'd track nonce timestamps
|
|
229
|
+
// For now, we'll clear all nonces periodically
|
|
230
|
+
if (this.usedNonces.size > 10000) {
|
|
231
|
+
this.usedNonces.clear();
|
|
232
|
+
}
|
|
233
|
+
}, this.timestampTolerance * 2);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Clean up resources
|
|
237
|
+
*/
|
|
238
|
+
destroy() {
|
|
239
|
+
if (this.nonceCleanupInterval) {
|
|
240
|
+
clearInterval(this.nonceCleanupInterval);
|
|
241
|
+
}
|
|
242
|
+
this.usedNonces.clear();
|
|
129
243
|
}
|
|
130
244
|
}
|
|
131
245
|
exports.MCPIdentity = MCPIdentity;
|
|
246
|
+
/**
|
|
247
|
+
* Enable MCP Identity for any MCP server
|
|
248
|
+
* This is the main integration point that patches the MCP Server
|
|
249
|
+
*/
|
|
250
|
+
async function enableMCPIdentity(options) {
|
|
251
|
+
const identity = await MCPIdentity.init(options);
|
|
252
|
+
// Try to patch MCP Server if available
|
|
253
|
+
try {
|
|
254
|
+
patchMCPServer(identity);
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
console.log('[MCP-I] MCP Server not found, identity initialized for manual use');
|
|
258
|
+
}
|
|
259
|
+
return identity;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Patch the MCP Server to automatically add identity
|
|
263
|
+
*/
|
|
264
|
+
function patchMCPServer(identity) {
|
|
265
|
+
try {
|
|
266
|
+
// Try to import the MCP SDK
|
|
267
|
+
const MCPModule = require('@modelcontextprotocol/sdk/server/index.js');
|
|
268
|
+
const OriginalServer = MCPModule.Server;
|
|
269
|
+
if (!OriginalServer) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
// Store original methods
|
|
273
|
+
const originalSetRequestHandler = OriginalServer.prototype.setRequestHandler;
|
|
274
|
+
const originalConnect = OriginalServer.prototype.connect;
|
|
275
|
+
// Patch setRequestHandler to wrap all responses
|
|
276
|
+
OriginalServer.prototype.setRequestHandler = function (method, handler) {
|
|
277
|
+
const wrappedHandler = async (...args) => {
|
|
278
|
+
const result = await handler(...args);
|
|
279
|
+
// If result has content, sign it
|
|
280
|
+
if (result && typeof result === 'object' && 'content' in result) {
|
|
281
|
+
const signed = await identity.signResponse(result);
|
|
282
|
+
return signed;
|
|
283
|
+
}
|
|
284
|
+
return result;
|
|
285
|
+
};
|
|
286
|
+
return originalSetRequestHandler.call(this, method, wrappedHandler);
|
|
287
|
+
};
|
|
288
|
+
// Patch connect to advertise MCP-I capabilities
|
|
289
|
+
OriginalServer.prototype.connect = async function (transport) {
|
|
290
|
+
// Add MCP-I capabilities to server info
|
|
291
|
+
if (this.serverInfo && this.serverInfo.capabilities) {
|
|
292
|
+
this.serverInfo.capabilities['mcp-i'] = identity.getCapabilities();
|
|
293
|
+
}
|
|
294
|
+
// Set up MCP-I handshake handler
|
|
295
|
+
this.setRequestHandler('mcp-i/challenge', async (request) => {
|
|
296
|
+
return identity.respondToChallenge(request.params);
|
|
297
|
+
});
|
|
298
|
+
// Call original connect
|
|
299
|
+
return originalConnect.call(this, transport);
|
|
300
|
+
};
|
|
301
|
+
console.log('[MCP-I] ✨ MCP Server patched - all responses will be automatically signed');
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
// MCP SDK not available, that's okay
|
|
305
|
+
}
|
|
306
|
+
}
|
|
132
307
|
// Helper functions (inline to keep package standalone)
|
|
133
308
|
async function loadIdentity(customPath) {
|
|
134
|
-
// Check environment variables first
|
|
309
|
+
// Check environment variables first (already loaded by process)
|
|
135
310
|
if (process.env.AGENT_DID && process.env.AGENT_PUBLIC_KEY && process.env.AGENT_PRIVATE_KEY) {
|
|
136
311
|
return {
|
|
137
312
|
did: process.env.AGENT_DID,
|
|
@@ -142,7 +317,7 @@ async function loadIdentity(customPath) {
|
|
|
142
317
|
registeredAt: new Date().toISOString()
|
|
143
318
|
};
|
|
144
319
|
}
|
|
145
|
-
// Check file
|
|
320
|
+
// Check JSON file (most reliable for programmatic access)
|
|
146
321
|
const filePath = customPath || path.join(process.cwd(), '.mcp-identity.json');
|
|
147
322
|
try {
|
|
148
323
|
if (fs.existsSync(filePath)) {
|
|
@@ -156,7 +331,7 @@ async function loadIdentity(customPath) {
|
|
|
156
331
|
return null;
|
|
157
332
|
}
|
|
158
333
|
async function saveIdentity(identity, customPath) {
|
|
159
|
-
// Save to .env.local
|
|
334
|
+
// Save to .env (standard) and .env.local (for frameworks)
|
|
160
335
|
const envContent = `
|
|
161
336
|
# MCP-I Identity (auto-generated)
|
|
162
337
|
AGENT_DID="${identity.did}"
|
|
@@ -165,11 +340,16 @@ AGENT_PRIVATE_KEY="${identity.privateKey}"
|
|
|
165
340
|
AGENT_ID="${identity.agentId}"
|
|
166
341
|
AGENT_SLUG="${identity.agentSlug}"
|
|
167
342
|
`;
|
|
168
|
-
|
|
343
|
+
// Save to .env for standard Node.js compatibility
|
|
344
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
169
345
|
fs.writeFileSync(envPath, envContent.trim());
|
|
170
|
-
// Also save
|
|
346
|
+
// Also save to .env.local for framework compatibility (Next.js, Vite, etc.)
|
|
347
|
+
const envLocalPath = path.join(process.cwd(), '.env.local');
|
|
348
|
+
fs.writeFileSync(envLocalPath, envContent.trim());
|
|
349
|
+
// Also save as JSON for programmatic access
|
|
171
350
|
const filePath = customPath || path.join(process.cwd(), '.mcp-identity.json');
|
|
172
351
|
fs.writeFileSync(filePath, JSON.stringify(identity, null, 2));
|
|
352
|
+
console.log('[MCP-I] Identity saved to .env, .env.local, and .mcp-identity.json');
|
|
173
353
|
}
|
|
174
354
|
async function autoRegister(options) {
|
|
175
355
|
try {
|
|
@@ -181,7 +361,7 @@ async function autoRegister(options) {
|
|
|
181
361
|
version: '1.0.0'
|
|
182
362
|
},
|
|
183
363
|
clientInfo: {
|
|
184
|
-
sdkVersion: '0.1.0',
|
|
364
|
+
sdkVersion: '0.1.0-alpha.2.0',
|
|
185
365
|
language: 'typescript',
|
|
186
366
|
platform: 'node' // Always node for MCP servers
|
|
187
367
|
}
|
|
@@ -189,7 +369,7 @@ async function autoRegister(options) {
|
|
|
189
369
|
timeout: 30000,
|
|
190
370
|
headers: {
|
|
191
371
|
'Content-Type': 'application/json',
|
|
192
|
-
'User-Agent': '@kya-os/mcp-i/0.1.0'
|
|
372
|
+
'User-Agent': '@kya-os/mcp-i/0.1.0-alpha.2.0'
|
|
193
373
|
}
|
|
194
374
|
});
|
|
195
375
|
return response.data;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0PH,8CAWC;AAnQD,kDAA0B;AAC1B,uCAAyB;AACzB,2CAA6B;AAC7B,iDAAmC;AAWnC,kCAAkC;AAClC,0CAAwB;AAExB,2BAA2B;AAC3B,IAAI,cAAc,G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,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,YAAY,EAAE,+BAA+B;aAC9C;SACF,CACF,CAAC;QAEF,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,IAAI,KAAK,CAAC,QAAQ,EAAE,MAAM,KAAK,GAAG,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;QACD,MAAM,IAAI,KAAK,CACb,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO;YAC7B,KAAK,CAAC,OAAO;YACb,+BAA+B,CAChC,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/patch.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Monkey-patch approach for zero-code integration
|
|
3
|
+
*
|
|
4
|
+
* This can be loaded before any MCP server code to automatically
|
|
5
|
+
* add identity to all servers without any code changes.
|
|
6
|
+
*
|
|
7
|
+
* Usage: node -r @kya-os/mcp-i/patch your-server.js
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Wrap a response to add identity without changing its type
|
|
11
|
+
*/
|
|
12
|
+
declare function addIdentityToResponse(response: any): Promise<any>;
|
|
13
|
+
/**
|
|
14
|
+
* Wrap a handler function to add identity to its responses
|
|
15
|
+
*/
|
|
16
|
+
declare function wrapHandler(handler: Function): Function;
|
|
17
|
+
/**
|
|
18
|
+
* Patch a server instance to wrap all its handler methods
|
|
19
|
+
*/
|
|
20
|
+
declare function patchServerInstance(instance: any): any;
|
|
21
|
+
export { addIdentityToResponse, wrapHandler, patchServerInstance };
|
|
22
|
+
//# sourceMappingURL=patch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch.d.ts","sourceRoot":"","sources":["../src/patch.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAWH;;GAEG;AACH,iBAAe,qBAAqB,CAAC,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CA8DhE;AAED;;GAEG;AACH,iBAAS,WAAW,CAAC,OAAO,EAAE,QAAQ,GAAG,QAAQ,CAKhD;AAED;;GAEG;AACH,iBAAS,mBAAmB,CAAC,QAAQ,EAAE,GAAG,OAmBzC;AAgED,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC"}
|
package/dist/patch.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Monkey-patch approach for zero-code integration
|
|
4
|
+
*
|
|
5
|
+
* This can be loaded before any MCP server code to automatically
|
|
6
|
+
* add identity to all servers without any code changes.
|
|
7
|
+
*
|
|
8
|
+
* Usage: node -r @kya-os/mcp-i/patch your-server.js
|
|
9
|
+
*/
|
|
10
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.addIdentityToResponse = addIdentityToResponse;
|
|
15
|
+
exports.wrapHandler = wrapHandler;
|
|
16
|
+
exports.patchServerInstance = patchServerInstance;
|
|
17
|
+
const index_1 = require("./index");
|
|
18
|
+
const module_1 = __importDefault(require("module"));
|
|
19
|
+
// Store identity globally
|
|
20
|
+
let identity = null;
|
|
21
|
+
// Store original constructors
|
|
22
|
+
const originalConstructors = new Map();
|
|
23
|
+
/**
|
|
24
|
+
* Wrap a response to add identity without changing its type
|
|
25
|
+
*/
|
|
26
|
+
async function addIdentityToResponse(response) {
|
|
27
|
+
if (!response || typeof response !== 'object' || Array.isArray(response)) {
|
|
28
|
+
return response;
|
|
29
|
+
}
|
|
30
|
+
// Initialize identity if needed
|
|
31
|
+
if (!identity) {
|
|
32
|
+
identity = await index_1.MCPIdentity.init();
|
|
33
|
+
}
|
|
34
|
+
// Create identity metadata
|
|
35
|
+
const timestamp = new Date().toISOString();
|
|
36
|
+
const contentToSign = JSON.stringify({
|
|
37
|
+
...response,
|
|
38
|
+
_mcp_identity: {
|
|
39
|
+
did: identity.did,
|
|
40
|
+
timestamp,
|
|
41
|
+
conformanceLevel: 2
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const signature = await identity.sign(contentToSign);
|
|
45
|
+
// Create a new object that includes _mcp_identity
|
|
46
|
+
// but maintains the original prototype chain
|
|
47
|
+
const enhancedResponse = Object.create(Object.getPrototypeOf(response));
|
|
48
|
+
Object.assign(enhancedResponse, response);
|
|
49
|
+
// Add _mcp_identity as a non-enumerable property
|
|
50
|
+
Object.defineProperty(enhancedResponse, '_mcp_identity', {
|
|
51
|
+
value: {
|
|
52
|
+
did: identity.did,
|
|
53
|
+
signature,
|
|
54
|
+
timestamp,
|
|
55
|
+
conformanceLevel: 2
|
|
56
|
+
},
|
|
57
|
+
writable: false,
|
|
58
|
+
enumerable: false,
|
|
59
|
+
configurable: true
|
|
60
|
+
});
|
|
61
|
+
// Override toJSON to include _mcp_identity
|
|
62
|
+
const hasToJSON = 'toJSON' in enhancedResponse && typeof enhancedResponse.toJSON === 'function';
|
|
63
|
+
if (!hasToJSON) {
|
|
64
|
+
Object.defineProperty(enhancedResponse, 'toJSON', {
|
|
65
|
+
value: function () {
|
|
66
|
+
const obj = {};
|
|
67
|
+
for (const key in this) {
|
|
68
|
+
if (this.hasOwnProperty(key)) {
|
|
69
|
+
obj[key] = this[key];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
obj._mcp_identity = this._mcp_identity;
|
|
73
|
+
return obj;
|
|
74
|
+
},
|
|
75
|
+
writable: true,
|
|
76
|
+
enumerable: false,
|
|
77
|
+
configurable: true
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return enhancedResponse;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Wrap a handler function to add identity to its responses
|
|
84
|
+
*/
|
|
85
|
+
function wrapHandler(handler) {
|
|
86
|
+
return async function (...args) {
|
|
87
|
+
const result = await handler.apply(this, args);
|
|
88
|
+
return addIdentityToResponse(result);
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Patch a server instance to wrap all its handler methods
|
|
93
|
+
*/
|
|
94
|
+
function patchServerInstance(instance) {
|
|
95
|
+
// Methods to wrap
|
|
96
|
+
const methodsToWrap = ['setRequestHandler', 'tool', 'resource', 'prompt'];
|
|
97
|
+
methodsToWrap.forEach(methodName => {
|
|
98
|
+
if (typeof instance[methodName] === 'function') {
|
|
99
|
+
const original = instance[methodName];
|
|
100
|
+
instance[methodName] = function (...args) {
|
|
101
|
+
// Find the handler function in the arguments
|
|
102
|
+
const handlerIndex = args.findIndex(arg => typeof arg === 'function');
|
|
103
|
+
if (handlerIndex !== -1) {
|
|
104
|
+
args[handlerIndex] = wrapHandler(args[handlerIndex]);
|
|
105
|
+
}
|
|
106
|
+
return original.apply(this, args);
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
return instance;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Override require to patch MCP SDK modules
|
|
114
|
+
*/
|
|
115
|
+
const originalRequire = module_1.default.prototype.require;
|
|
116
|
+
module_1.default.prototype.require = function (id) {
|
|
117
|
+
const exports = originalRequire.apply(this, [id]);
|
|
118
|
+
// Check if this is an MCP SDK module
|
|
119
|
+
if (id.includes('@modelcontextprotocol/sdk')) {
|
|
120
|
+
// Patch Server constructor
|
|
121
|
+
if (exports.Server && !originalConstructors.has('Server')) {
|
|
122
|
+
originalConstructors.set('Server', exports.Server);
|
|
123
|
+
exports.Server = class extends originalConstructors.get('Server') {
|
|
124
|
+
constructor(...args) {
|
|
125
|
+
super(...args);
|
|
126
|
+
patchServerInstance(this);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
// Copy static properties
|
|
130
|
+
Object.setPrototypeOf(exports.Server, originalConstructors.get('Server'));
|
|
131
|
+
Object.getOwnPropertyNames(originalConstructors.get('Server')).forEach(prop => {
|
|
132
|
+
if (prop !== 'prototype' && prop !== 'constructor' && prop !== 'length' && prop !== 'name') {
|
|
133
|
+
exports.Server[prop] = originalConstructors.get('Server')[prop];
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
// Patch McpServer constructor
|
|
138
|
+
if (exports.McpServer && !originalConstructors.has('McpServer')) {
|
|
139
|
+
originalConstructors.set('McpServer', exports.McpServer);
|
|
140
|
+
exports.McpServer = class extends originalConstructors.get('McpServer') {
|
|
141
|
+
constructor(...args) {
|
|
142
|
+
super(...args);
|
|
143
|
+
patchServerInstance(this);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
// Copy static properties
|
|
147
|
+
Object.setPrototypeOf(exports.McpServer, originalConstructors.get('McpServer'));
|
|
148
|
+
Object.getOwnPropertyNames(originalConstructors.get('McpServer')).forEach(prop => {
|
|
149
|
+
if (prop !== 'prototype' && prop !== 'constructor' && prop !== 'length' && prop !== 'name') {
|
|
150
|
+
exports.McpServer[prop] = originalConstructors.get('McpServer')[prop];
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return exports;
|
|
156
|
+
};
|
|
157
|
+
// Initialize identity on load
|
|
158
|
+
index_1.MCPIdentity.init().then(i => {
|
|
159
|
+
identity = i;
|
|
160
|
+
console.log('[MCP-I] Auto-patch loaded. Identity initialized:', i.did);
|
|
161
|
+
}).catch(err => {
|
|
162
|
+
console.error('[MCP-I] Failed to initialize identity:', err.message);
|
|
163
|
+
});
|
|
164
|
+
//# sourceMappingURL=patch.js.map
|