@kya-os/mcp-i 0.1.0-alpha.2.4 → 0.1.0-alpha.2.6

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.
@@ -11,16 +11,8 @@ async function initWithDevExperience(options = {}) {
11
11
  logger.info('🔧 Development mode detected - agents will be created as drafts');
12
12
  }
13
13
  if (!options.name && !process.env.MCP_SERVER_NAME) {
14
- try {
15
- const pkg = require(process.cwd() + '/package.json');
16
- options.name = pkg.name || 'Unnamed MCP Server';
17
- options.description = pkg.description;
18
- options.repository = pkg.repository?.url || pkg.repository;
19
- logger.info(`📦 Auto-detected agent name: ${options.name}`);
20
- }
21
- catch {
22
- options.name = 'Development MCP Server';
23
- }
14
+ options.name = 'Development MCP Server';
15
+ logger.info('💡 Tip: Provide a name in options for better agent identification');
24
16
  }
25
17
  if (!options.storage) {
26
18
  logger.info('💡 Tip: Use storage: "file" for persistent identity across restarts');
package/dist/index.js CHANGED
@@ -128,20 +128,58 @@ class MCPIdentity {
128
128
  });
129
129
  const apiEndpoint = options?.apiEndpoint || 'https://knowthat.ai';
130
130
  logger.info('Registering with knowthat.ai...');
131
+ logger.info('Generating cryptographic keys...');
132
+ const keyPair = await crypto.generateKeyPair();
131
133
  const registrationData = {
132
134
  name: options?.name || process.env.MCP_SERVER_NAME || 'Unnamed MCP Server',
133
135
  description: options?.description,
134
136
  repository: options?.repository,
137
+ publicKey: keyPair.publicKey,
135
138
  directories: options?.directories,
136
139
  isDraft: options?.mode === 'development'
137
140
  };
138
- logger.info('Generating cryptographic keys...');
139
- const keyPair = await crypto.generateKeyPair();
140
- const response = await autoRegister(transport, {
141
- ...registrationData,
142
- apiEndpoint,
143
- directories: options?.directories
141
+ logger.debug('Registration data:', {
142
+ name: registrationData.name,
143
+ hasDescription: !!registrationData.description,
144
+ hasRepository: !!registrationData.repository,
145
+ hasPublicKey: !!registrationData.publicKey,
146
+ directories: registrationData.directories,
147
+ isDraft: registrationData.isDraft
144
148
  });
149
+ let response;
150
+ try {
151
+ response = await autoRegister(transport, {
152
+ ...registrationData,
153
+ apiEndpoint,
154
+ directories: options?.directories
155
+ });
156
+ }
157
+ catch (registrationError) {
158
+ logger.error('Failed to register with knowthat.ai:', registrationError.message);
159
+ if (options?.mode === 'development' || process.env.NODE_ENV === 'development') {
160
+ logger.warn('Running in offline development mode with temporary identity');
161
+ const tempSlug = `temp-${Date.now()}-${Math.random().toString(36).substring(7)}`;
162
+ response = {
163
+ did: `did:web:localhost:agents:${tempSlug}`,
164
+ agent: {
165
+ id: tempSlug,
166
+ slug: tempSlug,
167
+ name: registrationData.name,
168
+ url: `http://localhost:3000/agents/${tempSlug}`,
169
+ claimUrl: `http://localhost:3000/agents/claim?did=${tempSlug}`
170
+ },
171
+ keys: {
172
+ publicKey: keyPair.publicKey,
173
+ privateKey: keyPair.privateKey
174
+ }
175
+ };
176
+ logger.warn('⚠️ Using temporary development identity. This will not persist across restarts.');
177
+ logger.warn('⚠️ To use a permanent identity, ensure you can connect to knowthat.ai');
178
+ }
179
+ else {
180
+ throw registrationError;
181
+ }
182
+ }
145
183
  identity = {
146
184
  did: response.did,
147
185
  publicKey: keyPair.publicKey,
@@ -429,34 +467,58 @@ function patchMCPServer(identity) {
429
467
  }
430
468
  }
431
469
  async function autoRegister(transport, options) {
470
+ const logger = (0, logger_1.getLogger)();
432
471
  try {
433
- const response = await transport.post(`${options.apiEndpoint}/api/agents/auto-register`, {
472
+ const requestBody = {
434
473
  metadata: {
435
474
  name: options.name,
436
475
  description: options.description,
437
476
  repository: options.repository,
477
+ publicKey: options.publicKey,
438
478
  version: '1.0.0',
439
479
  isDraft: options.isDraft,
440
480
  directories: options.directories || 'verified'
441
481
  },
442
482
  clientInfo: {
443
- sdkVersion: '0.3.0',
483
+ sdkVersion: '0.1.0-alpha.2.5',
444
484
  language: 'typescript',
445
- platform: 'node'
485
+ platform: typeof process !== 'undefined' ? 'node' : 'browser'
446
486
  }
447
- }, {
487
+ };
488
+ logger.debug('Sending registration request to:', `${options.apiEndpoint}/api/agents/auto-register`);
489
+ const response = await transport.post(`${options.apiEndpoint}/api/agents/auto-register`, requestBody, {
448
490
  timeout: 30000,
449
491
  headers: {
450
492
  'Content-Type': 'application/json',
451
- 'User-Agent': '@kya-os/mcp-i/0.3.0'
493
+ 'User-Agent': '@kya-os/mcp-i/0.1.0-alpha.2.5'
452
494
  }
453
495
  });
496
+ logger.debug('Registration response received:', {
497
+ status: response.status,
498
+ hasData: !!response.data,
499
+ hasDid: !!response.data?.did,
500
+ hasAgent: !!response.data?.agent
501
+ });
454
502
  return response.data;
455
503
  }
456
504
  catch (error) {
505
+ logger.error('Registration failed:', {
506
+ message: error.message,
507
+ status: error.status,
508
+ response: error.response
509
+ });
457
510
  if (error.message?.includes('429')) {
458
511
  throw new Error('Rate limit exceeded. Please try again later.');
459
512
  }
513
+ if (error.message?.includes('500')) {
514
+ throw new Error('Server error during registration. This might be a temporary issue.\n' +
515
+ 'Please try again in a few moments, or register manually at https://knowthat.ai/submit-agent');
516
+ }
517
+ if (error.message?.includes('400')) {
518
+ throw new Error('Invalid registration data. Please ensure all required fields are provided:\n' +
519
+ '- name: A unique name for your agent\n' +
520
+ '- publicKey: Generated automatically (check if generation succeeded)');
521
+ }
460
522
  throw new Error(error.message || 'Failed to auto-register agent');
461
523
  }
462
524
  }
@@ -24,6 +24,7 @@ export declare class AxiosTransport implements Transport {
24
24
  export declare class RuntimeDetector {
25
25
  static isEdgeRuntime(): boolean;
26
26
  static isNodeRuntime(): boolean;
27
+ static isNextJs(): boolean;
27
28
  static hasFetch(): boolean;
28
29
  static isLambda(): boolean;
29
30
  }
package/dist/transport.js CHANGED
@@ -1,37 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.TransportFactory = exports.RuntimeDetector = exports.AxiosTransport = exports.FetchTransport = void 0;
37
4
  class FetchTransport {
@@ -145,8 +112,14 @@ class AxiosTransport {
145
112
  }
146
113
  async getAxios() {
147
114
  if (!this.axiosInstance) {
148
- const axiosModule = await Promise.resolve().then(() => __importStar(require('axios')));
149
- this.axiosInstance = axiosModule.default;
115
+ try {
116
+ const axios = require('axios');
117
+ this.axiosInstance = axios.default || axios;
118
+ }
119
+ catch (error) {
120
+ throw new Error('axios is not installed. Please install it with: npm install axios\n' +
121
+ 'Or use the fetch transport instead by setting transport: "fetch" in options');
122
+ }
150
123
  }
151
124
  return this.axiosInstance;
152
125
  }
@@ -162,7 +135,13 @@ class RuntimeDetector {
162
135
  }
163
136
  static isNodeRuntime() {
164
137
  return !!(process.versions?.node &&
165
- !this.isEdgeRuntime());
138
+ !this.isEdgeRuntime() &&
139
+ !this.isNextJs());
140
+ }
141
+ static isNextJs() {
142
+ return !!(process.env.NEXT_RUNTIME ||
143
+ globalThis.__NEXT_DATA__ ||
144
+ process.env.NEXT_PUBLIC_VERCEL_ENV);
166
145
  }
167
146
  static hasFetch() {
168
147
  return typeof globalThis.fetch === 'function';
@@ -190,6 +169,9 @@ class TransportFactory {
190
169
  if (RuntimeDetector.isEdgeRuntime() && RuntimeDetector.hasFetch()) {
191
170
  return new FetchTransport();
192
171
  }
172
+ if (RuntimeDetector.isNextJs() && RuntimeDetector.hasFetch()) {
173
+ return new FetchTransport();
174
+ }
193
175
  if (RuntimeDetector.isLambda() && RuntimeDetector.hasFetch()) {
194
176
  return new FetchTransport();
195
177
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kya-os/mcp-i",
3
- "version": "0.1.0-alpha.2.4",
3
+ "version": "0.1.0-alpha.2.6",
4
4
  "description": "Production-ready MCP Identity with automatic registration, key rotation, and optimized performance",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",