@kya-os/mcp-i
Version:
COMING SOON:Production-ready MCP Identity with automatic registration, key rotation, and optimized performance
83 lines ⢠3.79 kB
JavaScript
/**
* Next.js specific helpers for MCP-I
*
* Provides optimized initialization for Next.js apps with:
* - Automatic Vercel detection
* - Enhanced error messages
* - Developer-friendly console output
*/
import { enableMCPIdentity } from "./index.js";
/**
* Initialize MCP-I for Next.js with optimized defaults
*/
export async function enableMCPIdentityForNextJS(options = {}) {
const isProduction = process.env.NODE_ENV === "production";
const isVercel = process.env.VERCEL || process.env.VERCEL_ENV;
try {
console.log(`\nš Initializing MCP-I for Next.js...`);
const identity = await enableMCPIdentity({
...options,
// Force Next.js compatible settings
transport: "fetch",
storage: "memory",
// Use appropriate log level
logLevel: options.logLevel || (isProduction ? "error" : "info"),
// Set mode based on environment
mode: isProduction ? "production" : "development",
});
// Show success with clear next steps
if (!isProduction && options.showSetupInstructions !== false) {
console.log("\nā
MCP-I Ready for Next.js!");
console.log(`\nš Quick Info:`);
console.log(` Environment: ${isVercel ? "Vercel" : "Local"}`);
console.log(` DID: ${identity.did}`);
// For Vercel, remind about env vars
if (isVercel && !process.env.MCP_IDENTITY_AGENT_DID) {
console.log("\nā ļø Remember to set environment variables in Vercel Dashboard!");
console.log(" See console output above for the exact variables to add.");
}
}
return identity;
}
catch (error) {
// Enhanced error messages for common Next.js issues
console.error("\nā MCP-I Initialization Failed\n");
if (error?.message?.includes("429")) {
console.error("š Rate Limit Hit");
console.error(" You've made too many registration attempts.");
console.error(" Wait a few minutes and try again.");
console.error("\nš” Tip: In development, you can use environment variables to persist identity:");
console.error(" 1. Copy the MCP_IDENTITY_* variables from a successful run");
console.error(" 2. Add them to your .env.local file");
}
else if (error?.message?.includes("500") ||
error?.message?.includes("fetch failed")) {
console.error("š Server Connection Error");
console.error(" Cannot connect to knowthat.ai registry.");
console.error("\nš” Possible causes:");
console.error(" - Registry is temporarily down");
console.error(" - Network connectivity issues");
console.error(" - Firewall blocking outbound connections");
console.error("\nš” Workaround for development:");
console.error(' Add to your route: mode: "development" to allow offline mode');
}
else if (error?.message?.includes("MODULE_NOT_FOUND")) {
console.error("š Missing Dependencies");
console.error(" Make sure all dependencies are installed:");
console.error(" npm install @kya-os/mcp-i");
}
else {
console.error("š Unexpected Error:", error?.message || error);
}
// In development, show full error
if (!isProduction) {
console.error("\nš Full Error Details:");
console.error(error);
}
throw error;
}
}
// Re-export main functions
export { enableMCPIdentity, MCPIdentity } from "./index.js";
export * from "./types.js";
//# sourceMappingURL=nextjs.js.map