@kya-os/mcp-i
Version:
The TypeScript MCP framework with identity features built-in
136 lines (135 loc) • 3.82 kB
JavaScript
;
/**
* XMCP-I Demo Features - Optional identity badge and development helpers
*
* Provides opt-in demo features for showcasing identity capabilities.
* All features are disabled by default and must be explicitly enabled.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.DemoConsole = exports.DemoManager = void 0;
exports.createDemoManager = createDemoManager;
exports.formatVerifyLink = formatVerifyLink;
/**
* Demo manager for optional features
*/
class DemoManager {
config;
identity;
constructor(identity, config = {}) {
this.identity = identity;
this.config = {
identityBadge: false, // Default disabled
environment: "development",
...config,
};
// Force disable in production
if (this.config.environment === "production") {
this.config.identityBadge = false;
}
}
/**
* Generate identity badge if enabled
*/
generateIdentityBadge() {
if (!this.config.identityBadge ||
this.config.environment === "production") {
return null;
}
// Extract short identifier from DID
const shortDid = this.extractShortDid(this.identity.did);
return `🔐 ${shortDid}`;
}
/**
* Add identity badge to response if enabled
*/
addIdentityBadgeToResponse(response) {
const badge = this.generateIdentityBadge();
if (!badge) {
return response;
}
// Add badge to response metadata
if (typeof response === "object" && response !== null) {
return {
...response,
_identity: badge,
};
}
return response;
}
/**
* Check if identity badge is enabled
*/
isIdentityBadgeEnabled() {
return (this.config.identityBadge === true &&
this.config.environment !== "production");
}
/**
* Extract short DID identifier for display
*/
extractShortDid(did) {
// For did:web:example.com:agents:my-agent, return "my-agent"
const parts = did.split(":");
if (parts.length >= 2) {
const lastPart = parts[parts.length - 1];
// Truncate if too long
return lastPart.length > 12 ? `${lastPart.slice(0, 12)}...` : lastPart;
}
return "agent";
}
/**
* Get demo configuration
*/
getConfig() {
return { ...this.config };
}
/**
* Update demo configuration
*/
updateConfig(updates) {
this.config = { ...this.config, ...updates };
// Force disable in production
if (this.config.environment === "production") {
this.config.identityBadge = false;
}
}
}
exports.DemoManager = DemoManager;
/**
* Create demo manager
*/
function createDemoManager(identity, config = {}) {
return new DemoManager(identity, config);
}
/**
* Utility to format verify link for console output
*/
function formatVerifyLink(baseUrl = "http://localhost:3000") {
return `${baseUrl}/verify`;
}
/**
* Console output helpers for development
*/
exports.DemoConsole = {
/**
* Print verify link if enabled
*/
printVerifyLink(enabled, environment, baseUrl = "http://localhost:3000") {
if (enabled && environment === "development") {
console.error(`🔍 Debug: ${formatVerifyLink(baseUrl)}`);
}
},
/**
* Print identity badge if enabled
*/
printIdentityBadge(badge) {
if (badge) {
console.error(`${badge} Identity verified`);
}
},
/**
* Print demo warning
*/
printDemoWarning() {
console.error("⚠️ Demo features enabled - disable in production");
},
};