@kya-os/mcp-i 0.1.0-alpha.1 → 0.1.0-alpha.2.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 +179 -106
- 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 +217 -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/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 +68 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +324 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +78 -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 +18 -27
package/dist/index.js
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @kya-os/mcp-i - Ultra-light MCP Identity auto-registration with challenge-response authentication
|
|
4
|
+
*
|
|
5
|
+
* Enable any MCP server to get a verifiable identity with just 2 lines of code:
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { MCPIdentity } from "@kya-os/mcp-i";
|
|
9
|
+
* const identity = await MCPIdentity.init();
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Now with full MCP-I Handshake support including cryptographic challenge-response!
|
|
13
|
+
*/
|
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
26
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
27
|
+
}) : function(o, v) {
|
|
28
|
+
o["default"] = v;
|
|
29
|
+
});
|
|
30
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
31
|
+
var ownKeys = function(o) {
|
|
32
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
33
|
+
var ar = [];
|
|
34
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
35
|
+
return ar;
|
|
36
|
+
};
|
|
37
|
+
return ownKeys(o);
|
|
38
|
+
};
|
|
39
|
+
return function (mod) {
|
|
40
|
+
if (mod && mod.__esModule) return mod;
|
|
41
|
+
var result = {};
|
|
42
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
43
|
+
__setModuleDefault(result, mod);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
48
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
49
|
+
};
|
|
50
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
51
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.MCPIdentity = void 0;
|
|
55
|
+
const axios_1 = __importDefault(require("axios"));
|
|
56
|
+
const fs = __importStar(require("fs"));
|
|
57
|
+
const path = __importStar(require("path"));
|
|
58
|
+
const crypto = __importStar(require("./crypto"));
|
|
59
|
+
// Re-export types for convenience
|
|
60
|
+
__exportStar(require("./types"), exports);
|
|
61
|
+
class MCPIdentity {
|
|
62
|
+
constructor(identity, options = {}) {
|
|
63
|
+
this.usedNonces = new Set();
|
|
64
|
+
this.did = identity.did;
|
|
65
|
+
this.publicKey = identity.publicKey;
|
|
66
|
+
this.privateKey = identity.privateKey;
|
|
67
|
+
this.timestampTolerance = options.timestampTolerance || 60000; // 60 seconds
|
|
68
|
+
this.enableNonceTracking = options.enableNonceTracking !== false;
|
|
69
|
+
// Start nonce cleanup if tracking is enabled
|
|
70
|
+
if (this.enableNonceTracking) {
|
|
71
|
+
this.startNonceCleanup();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Initialize MCP Identity - the main entry point
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* import { MCPIdentity } from "@kya-os/mcp-i";
|
|
80
|
+
* const identity = await MCPIdentity.init();
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
static async init(options) {
|
|
84
|
+
// Try to load existing identity
|
|
85
|
+
let identity = await loadIdentity(options?.persistencePath);
|
|
86
|
+
// Auto-register if needed
|
|
87
|
+
if (!identity) {
|
|
88
|
+
console.log('[MCP-I] No existing identity found, auto-registering...');
|
|
89
|
+
const response = await autoRegister({
|
|
90
|
+
name: options?.name || process.env.MCP_SERVER_NAME || 'Unnamed MCP Server',
|
|
91
|
+
description: options?.description,
|
|
92
|
+
repository: options?.repository,
|
|
93
|
+
apiEndpoint: options?.apiEndpoint || 'https://knowthat.ai'
|
|
94
|
+
});
|
|
95
|
+
// Create persisted identity
|
|
96
|
+
identity = {
|
|
97
|
+
did: response.did,
|
|
98
|
+
publicKey: response.keys.publicKey,
|
|
99
|
+
privateKey: response.keys.privateKey || '',
|
|
100
|
+
agentId: response.agent.id,
|
|
101
|
+
agentSlug: response.agent.slug,
|
|
102
|
+
registeredAt: new Date().toISOString(),
|
|
103
|
+
};
|
|
104
|
+
// If no private key was provided, generate one
|
|
105
|
+
if (!identity.privateKey) {
|
|
106
|
+
console.log('[MCP-I] Generating cryptographic keys...');
|
|
107
|
+
const keyPair = await crypto.generateKeyPair();
|
|
108
|
+
identity.publicKey = keyPair.publicKey;
|
|
109
|
+
identity.privateKey = keyPair.privateKey;
|
|
110
|
+
}
|
|
111
|
+
// Save for future use
|
|
112
|
+
await saveIdentity(identity, options?.persistencePath);
|
|
113
|
+
console.log('[MCP-I] ✅ Success! Your agent has been registered.');
|
|
114
|
+
console.log(`[MCP-I] DID: ${response.did}`);
|
|
115
|
+
console.log(`[MCP-I] Profile: ${response.agent.url}`);
|
|
116
|
+
}
|
|
117
|
+
return new MCPIdentity(identity, options);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Sign a message with the agent's private key using Ed25519
|
|
121
|
+
*/
|
|
122
|
+
async sign(message) {
|
|
123
|
+
return crypto.sign(message, this.privateKey);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Verify a signature against a public key
|
|
127
|
+
*/
|
|
128
|
+
async verify(message, signature, publicKey) {
|
|
129
|
+
return crypto.verify(message, signature, publicKey || this.publicKey);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Respond to an MCP-I challenge
|
|
133
|
+
* This is the core of the challenge-response authentication system
|
|
134
|
+
*/
|
|
135
|
+
async respondToChallenge(challenge) {
|
|
136
|
+
// Validate timestamp to prevent replay attacks
|
|
137
|
+
const now = Date.now();
|
|
138
|
+
const challengeAge = now - challenge.timestamp;
|
|
139
|
+
if (challengeAge > this.timestampTolerance) {
|
|
140
|
+
throw new Error('Challenge expired');
|
|
141
|
+
}
|
|
142
|
+
if (challengeAge < 0) {
|
|
143
|
+
throw new Error('Challenge timestamp is in the future');
|
|
144
|
+
}
|
|
145
|
+
// Check for nonce reuse if tracking is enabled
|
|
146
|
+
if (this.enableNonceTracking) {
|
|
147
|
+
if (this.usedNonces.has(challenge.nonce)) {
|
|
148
|
+
throw new Error('Nonce already used');
|
|
149
|
+
}
|
|
150
|
+
this.usedNonces.add(challenge.nonce);
|
|
151
|
+
}
|
|
152
|
+
// Create the message to sign
|
|
153
|
+
const messageComponents = [
|
|
154
|
+
challenge.nonce,
|
|
155
|
+
challenge.timestamp.toString(),
|
|
156
|
+
this.did,
|
|
157
|
+
challenge.verifier_did || '',
|
|
158
|
+
(challenge.scope || []).join(',')
|
|
159
|
+
];
|
|
160
|
+
const message = messageComponents.join(':');
|
|
161
|
+
// Sign the challenge
|
|
162
|
+
const signature = await this.sign(message);
|
|
163
|
+
// Return the response
|
|
164
|
+
return {
|
|
165
|
+
did: this.did,
|
|
166
|
+
signature,
|
|
167
|
+
timestamp: now,
|
|
168
|
+
nonce: challenge.nonce,
|
|
169
|
+
publicKey: this.publicKey
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Get MCP-I capabilities for advertisement
|
|
174
|
+
*/
|
|
175
|
+
getCapabilities() {
|
|
176
|
+
return {
|
|
177
|
+
version: '1.0',
|
|
178
|
+
did: this.did,
|
|
179
|
+
publicKey: this.publicKey,
|
|
180
|
+
conformanceLevel: 2, // Level 2: Full crypto with challenge-response
|
|
181
|
+
handshakeSupported: true,
|
|
182
|
+
handshakeEndpoint: '/_mcp-i/handshake',
|
|
183
|
+
verificationEndpoint: `https://knowthat.ai/api/agents/${this.did}/verify`
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Sign an MCP response with identity metadata
|
|
188
|
+
*/
|
|
189
|
+
async signResponse(response) {
|
|
190
|
+
const timestamp = new Date().toISOString();
|
|
191
|
+
const responseWithIdentity = {
|
|
192
|
+
...response,
|
|
193
|
+
_mcp_identity: {
|
|
194
|
+
did: this.did,
|
|
195
|
+
signature: '', // Will be filled below
|
|
196
|
+
timestamp,
|
|
197
|
+
conformanceLevel: 2
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
// Sign the response content (excluding the signature field)
|
|
201
|
+
const contentToSign = JSON.stringify({
|
|
202
|
+
...response,
|
|
203
|
+
_mcp_identity: {
|
|
204
|
+
did: this.did,
|
|
205
|
+
timestamp,
|
|
206
|
+
conformanceLevel: 2
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
responseWithIdentity._mcp_identity.signature = await this.sign(contentToSign);
|
|
210
|
+
return responseWithIdentity;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Generate a new nonce for challenges
|
|
214
|
+
*/
|
|
215
|
+
static generateNonce() {
|
|
216
|
+
return crypto.generateNonce();
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Clean up old nonces periodically to prevent memory leaks
|
|
220
|
+
*/
|
|
221
|
+
startNonceCleanup() {
|
|
222
|
+
// Clean up nonces older than 2x the timestamp tolerance
|
|
223
|
+
this.nonceCleanupInterval = setInterval(() => {
|
|
224
|
+
// In a production system, you'd track nonce timestamps
|
|
225
|
+
// For now, we'll clear all nonces periodically
|
|
226
|
+
if (this.usedNonces.size > 10000) {
|
|
227
|
+
this.usedNonces.clear();
|
|
228
|
+
}
|
|
229
|
+
}, this.timestampTolerance * 2);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Clean up resources
|
|
233
|
+
*/
|
|
234
|
+
destroy() {
|
|
235
|
+
if (this.nonceCleanupInterval) {
|
|
236
|
+
clearInterval(this.nonceCleanupInterval);
|
|
237
|
+
}
|
|
238
|
+
this.usedNonces.clear();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
exports.MCPIdentity = MCPIdentity;
|
|
242
|
+
// Helper functions (inline to keep package standalone)
|
|
243
|
+
async function loadIdentity(customPath) {
|
|
244
|
+
// Check environment variables first (already loaded by process)
|
|
245
|
+
if (process.env.AGENT_DID && process.env.AGENT_PUBLIC_KEY && process.env.AGENT_PRIVATE_KEY) {
|
|
246
|
+
return {
|
|
247
|
+
did: process.env.AGENT_DID,
|
|
248
|
+
publicKey: process.env.AGENT_PUBLIC_KEY,
|
|
249
|
+
privateKey: process.env.AGENT_PRIVATE_KEY,
|
|
250
|
+
agentId: process.env.AGENT_ID || '',
|
|
251
|
+
agentSlug: process.env.AGENT_SLUG || '',
|
|
252
|
+
registeredAt: new Date().toISOString()
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
// Check JSON file (most reliable for programmatic access)
|
|
256
|
+
const filePath = customPath || path.join(process.cwd(), '.mcp-identity.json');
|
|
257
|
+
try {
|
|
258
|
+
if (fs.existsSync(filePath)) {
|
|
259
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
260
|
+
return JSON.parse(content);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
// Ignore errors
|
|
265
|
+
}
|
|
266
|
+
// Note: We don't manually load .env or .env.local files here
|
|
267
|
+
// because that should be handled by the application's environment
|
|
268
|
+
// loading strategy (dotenv, framework, etc.)
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
async function saveIdentity(identity, customPath) {
|
|
272
|
+
// Save to .env (standard) and .env.local (for frameworks)
|
|
273
|
+
const envContent = `
|
|
274
|
+
# MCP-I Identity (auto-generated)
|
|
275
|
+
AGENT_DID="${identity.did}"
|
|
276
|
+
AGENT_PUBLIC_KEY="${identity.publicKey}"
|
|
277
|
+
AGENT_PRIVATE_KEY="${identity.privateKey}"
|
|
278
|
+
AGENT_ID="${identity.agentId}"
|
|
279
|
+
AGENT_SLUG="${identity.agentSlug}"
|
|
280
|
+
`;
|
|
281
|
+
// Save to .env for standard Node.js compatibility
|
|
282
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
283
|
+
fs.writeFileSync(envPath, envContent.trim());
|
|
284
|
+
// Also save to .env.local for framework compatibility (Next.js, Vite, etc.)
|
|
285
|
+
const envLocalPath = path.join(process.cwd(), '.env.local');
|
|
286
|
+
fs.writeFileSync(envLocalPath, envContent.trim());
|
|
287
|
+
// Also save as JSON for programmatic access
|
|
288
|
+
const filePath = customPath || path.join(process.cwd(), '.mcp-identity.json');
|
|
289
|
+
fs.writeFileSync(filePath, JSON.stringify(identity, null, 2));
|
|
290
|
+
console.log('[MCP-I] Identity saved to .env, .env.local, and .mcp-identity.json');
|
|
291
|
+
}
|
|
292
|
+
async function autoRegister(options) {
|
|
293
|
+
try {
|
|
294
|
+
const response = await axios_1.default.post(`${options.apiEndpoint}/api/agents/auto-register`, {
|
|
295
|
+
metadata: {
|
|
296
|
+
name: options.name,
|
|
297
|
+
description: options.description,
|
|
298
|
+
repository: options.repository,
|
|
299
|
+
version: '1.0.0'
|
|
300
|
+
},
|
|
301
|
+
clientInfo: {
|
|
302
|
+
sdkVersion: '0.2.0', // Updated version
|
|
303
|
+
language: 'typescript',
|
|
304
|
+
platform: 'node' // Always node for MCP servers
|
|
305
|
+
}
|
|
306
|
+
}, {
|
|
307
|
+
timeout: 30000,
|
|
308
|
+
headers: {
|
|
309
|
+
'Content-Type': 'application/json',
|
|
310
|
+
'User-Agent': '@kya-os/mcp-i/0.2.0'
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
return response.data;
|
|
314
|
+
}
|
|
315
|
+
catch (error) {
|
|
316
|
+
if (error.response?.status === 429) {
|
|
317
|
+
throw new Error('Rate limit exceeded. Please try again later.');
|
|
318
|
+
}
|
|
319
|
+
throw new Error(error.response?.data?.message ||
|
|
320
|
+
error.message ||
|
|
321
|
+
'Failed to auto-register agent');
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;;;;;;;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,GAAG,CAAC,oEAAoE,CAAC,CAAC;AACpF,CAAC;AAED,KAAK,UAAU,YAAY,CAAC,OAK3B;IACC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAC/B,GAAG,OAAO,CAAC,WAAW,2BAA2B,EACjD;YACE,QAAQ,EAAE;gBACR,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,OAAO,EAAE,OAAO;aACjB;YACD,UAAU,EAAE;gBACV,UAAU,EAAE,OAAO,EAAE,kBAAkB;gBACvC,QAAQ,EAAE,YAAY;gBACtB,QAAQ,EAAE,MAAM,CAAC,8BAA8B;aAChD;SACF,EACD;YACE,OAAO,EAAE,KAAK;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,YAAY,EAAE,qBAAqB;aACpC;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/types.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for MCP-I challenge-response authentication
|
|
3
|
+
*/
|
|
4
|
+
export interface MCPIdentityOptions {
|
|
5
|
+
name?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
repository?: string;
|
|
8
|
+
apiEndpoint?: string;
|
|
9
|
+
persistencePath?: string;
|
|
10
|
+
timestampTolerance?: number;
|
|
11
|
+
enableNonceTracking?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface AutoRegisterResponse {
|
|
14
|
+
success: boolean;
|
|
15
|
+
did: string;
|
|
16
|
+
agent: {
|
|
17
|
+
id: string;
|
|
18
|
+
slug: string;
|
|
19
|
+
name: string;
|
|
20
|
+
url: string;
|
|
21
|
+
};
|
|
22
|
+
keys: {
|
|
23
|
+
publicKey: string;
|
|
24
|
+
privateKey?: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export interface PersistedIdentity {
|
|
28
|
+
did: string;
|
|
29
|
+
publicKey: string;
|
|
30
|
+
privateKey: string;
|
|
31
|
+
agentId: string;
|
|
32
|
+
agentSlug: string;
|
|
33
|
+
registeredAt: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* MCP-I Challenge structure
|
|
37
|
+
*/
|
|
38
|
+
export interface Challenge {
|
|
39
|
+
nonce: string;
|
|
40
|
+
timestamp: number;
|
|
41
|
+
verifier_did?: string;
|
|
42
|
+
scope?: string[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* MCP-I Challenge Response structure
|
|
46
|
+
*/
|
|
47
|
+
export interface ChallengeResponse {
|
|
48
|
+
did: string;
|
|
49
|
+
signature: string;
|
|
50
|
+
timestamp: number;
|
|
51
|
+
nonce: string;
|
|
52
|
+
publicKey?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* MCP-I Capabilities advertisement
|
|
56
|
+
*/
|
|
57
|
+
export interface MCPICapabilities {
|
|
58
|
+
version: string;
|
|
59
|
+
did: string;
|
|
60
|
+
publicKey: string;
|
|
61
|
+
conformanceLevel: number;
|
|
62
|
+
handshakeSupported: boolean;
|
|
63
|
+
handshakeEndpoint?: string;
|
|
64
|
+
verificationEndpoint?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Response with MCP-I identity attached
|
|
68
|
+
*/
|
|
69
|
+
export interface SignedResponse<T = any> {
|
|
70
|
+
[key: string]: any;
|
|
71
|
+
_mcp_identity: {
|
|
72
|
+
did: string;
|
|
73
|
+
signature: string;
|
|
74
|
+
timestamp: string;
|
|
75
|
+
conformanceLevel?: number;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE;QACL,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,IAAI,EAAE;QACJ,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;CACH;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,GAAG;IACrC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IACnB,aAAa,EAAE;QACb,GAAG,EAAE,MAAM,CAAC;QACZ,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAC;CACH"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;GAEG"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kya-os/mcp-i",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-alpha.2.0",
|
|
4
|
+
"description": "Ultra-light MCP Identity auto-registration - 2 lines to agent identity",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -11,41 +11,32 @@
|
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "tsc",
|
|
14
|
-
"test": "
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"prepublishOnly": "npm run
|
|
18
|
-
"publish:alpha": "npm publish --tag alpha"
|
|
19
|
-
},
|
|
20
|
-
"repository": {
|
|
21
|
-
"type": "git",
|
|
22
|
-
"url": "https://github.com/vouched/kya-os.git",
|
|
23
|
-
"directory": "packages/mcp-i"
|
|
14
|
+
"test": "vitest",
|
|
15
|
+
"test:watch": "vitest watch",
|
|
16
|
+
"test:coverage": "vitest run --coverage",
|
|
17
|
+
"prepublishOnly": "npm run build"
|
|
24
18
|
},
|
|
25
19
|
"keywords": [
|
|
26
|
-
"kya-os",
|
|
27
|
-
"mcp-i",
|
|
28
20
|
"mcp",
|
|
21
|
+
"mcp-i",
|
|
29
22
|
"identity",
|
|
23
|
+
"agent",
|
|
30
24
|
"auto-registration",
|
|
31
|
-
"
|
|
25
|
+
"did"
|
|
32
26
|
],
|
|
33
|
-
"author": "Dylan Hobbs <dylan
|
|
27
|
+
"author": "Dylan Hobbs <dylan@vouched.id>",
|
|
34
28
|
"license": "MIT",
|
|
35
29
|
"dependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
38
|
-
"axios": "^1.6.7",
|
|
39
|
-
"dotenv": "^16.5.0"
|
|
30
|
+
"@noble/ed25519": "^2.1.0",
|
|
31
|
+
"axios": "^1.6.7"
|
|
40
32
|
},
|
|
41
33
|
"devDependencies": {
|
|
42
|
-
"@types/
|
|
43
|
-
"@
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"typescript": "^5.4.2"
|
|
34
|
+
"@types/node": "^20.0.0",
|
|
35
|
+
"@vitest/coverage-v8": "^2.0.0",
|
|
36
|
+
"typescript": "^5.0.0",
|
|
37
|
+
"vitest": "^2.0.0"
|
|
47
38
|
},
|
|
48
|
-
"
|
|
49
|
-
"
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=14.0.0"
|
|
50
41
|
}
|
|
51
42
|
}
|