UNPKG

@kya-os/mcp-bri

Version:

Give your MCP server cryptographic identity in 2 lines of code

113 lines 3.84 kB
"use strict"; /** * KnowThat.ai Registry Adapter * Primary registry that can host DIDs */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.KnowThatRegistry = void 0; const axios_1 = __importDefault(require("axios")); class KnowThatRegistry { constructor(endpoint = 'https://knowthat.ai') { this.name = 'knowthat'; this.type = 'primary'; this.endpoint = endpoint; } /** * Primary registration - creates DID and hosts DID document */ async publish(data) { try { // For KnowThat, we use the auto-register endpoint for primary registration const response = await axios_1.default.post(`${this.endpoint}/api/agents/auto-register`, { metadata: { name: data.name, description: data.description, repository: data.repository, version: '1.0.0' }, clientInfo: { sdkVersion: '0.2.0', language: 'typescript', platform: 'node' }, // If we already have a public key, send it publicKey: data.publicKey || undefined }, { timeout: 30000, headers: { 'Content-Type': 'application/json', 'User-Agent': '@kya-os/mcp-i/0.2.0' } }); return { success: true, registryAgentId: response.data.agent.id, profileUrl: response.data.agent.url }; } catch (error) { if (error.response?.status === 429) { return { success: false, error: 'Rate limit exceeded. Please try again later.' }; } return { success: false, error: error.response?.data?.message || error.message || 'Failed to register with KnowThat.ai' }; } } /** * Verify agent exists and is valid */ async verify(did) { try { const agentSlug = this.extractAgentSlug(did); const response = await axios_1.default.get(`${this.endpoint}/api/agents/${agentSlug}/verify`, { timeout: 5000 }); return response.data.valid === true; } catch { return false; } } /** * Get agent status in KnowThat registry */ async getStatus(did) { try { const agentSlug = this.extractAgentSlug(did); const response = await axios_1.default.get(`${this.endpoint}/api/agents/${agentSlug}/status`, { timeout: 5000 }); return { name: this.name, status: response.data.verified ? 'active' : 'pending', registeredAt: response.data.registeredAt, lastSyncAt: new Date().toISOString(), type: 'primary', registryAgentId: response.data.agentId }; } catch (error) { return { name: this.name, status: 'failed', type: 'primary', error: 'Failed to get status', lastSyncAt: new Date().toISOString() }; } } /** * Extract agent slug from DID */ extractAgentSlug(did) { // did:web:knowthat.ai:agents:my-agent -> my-agent const parts = did.split(':'); return parts[parts.length - 1]; } } exports.KnowThatRegistry = KnowThatRegistry; //# sourceMappingURL=knowthat.js.map