@prsna_ai/mcp-server
Version:
Model Context Protocol server for PRSNA personality profiles and communication insights
72 lines • 2.29 kB
JavaScript
import { z } from 'zod';
import { logger } from '../utils/logger.js';
import { PRSNAApiClient } from '../api/client.js';
import { safeJSONStringify } from '../utils/json.js';
// Input schema for the login tool
const LoginSchema = z.object({
token: z.string().min(1, 'Token is required')
});
export async function prsnaLogin(args) {
try {
// Validate input
const { token } = LoginSchema.parse(args);
logger.info('PRSNA login attempt initiated');
// Create API client and test authentication
const client = new PRSNAApiClient(token);
const userProfile = await client.authenticate();
// Destroy client after authentication (we'll create new ones for other tools)
client.destroy();
const result = {
success: true,
message: 'Authentication successful',
user: {
id: userProfile._id,
name: userProfile.name,
email: userProfile.email,
subscriptionStatus: userProfile.subscriptionStatus,
subscriptionPlan: userProfile.subscriptionPlan
}
};
logger.info('PRSNA login successful', {
userId: userProfile._id,
name: userProfile.name
});
return {
content: [{
type: "text",
text: safeJSONStringify(result, 2)
}]
};
}
catch (error) {
const errorMessage = error.message;
logger.error('PRSNA login failed', { error: errorMessage });
const result = {
success: false,
message: 'Authentication failed',
error: errorMessage
};
return {
content: [{
type: "text",
text: safeJSONStringify(result, 2)
}]
};
}
}
// Tool definition for MCP
export const authTool = {
name: "prsna_login",
description: "Authenticate with PRSNA using bearer token",
inputSchema: {
type: "object",
properties: {
token: {
type: "string",
description: "PRSNA API bearer token"
}
},
required: ["token"]
}
};
//# sourceMappingURL=auth.js.map