Skip to main content
Glama

calculate_mbti_result

Calculate MBTI personality type and detailed analysis from test session answers. Processes complete test responses to determine personality profile.

Instructions

根据所有答案计算最终的MBTI类型和详细结果。需要传入完整的测试会话状态。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionYes测试会话状态,必须包含所有题目的答案

Implementation Reference

  • MCP tool handler for 'calculate_mbti_result': validates that all questions are answered, calls calculateResult helper with answers and testType, and returns the computed MBTI result.
    if (name === 'calculate_mbti_result') { const session = args.session as TestSession; const questions = session.testType === 'simplified' ? questionBank.simplified : questionBank.cognitive; if (session.answers.length < questions.length) { return { content: [ { type: 'text', text: JSON.stringify({ error: '测试尚未完成', progress: { answered: session.answers.length, total: questions.length, }, }, null, 2), }, ], }; } const result = calculateResult(session.answers, session.testType); return { content: [ { type: 'text', text: JSON.stringify({ message: '测试完成!', result, }, null, 2), }, ], }; }
  • Input schema definition for the 'calculate_mbti_result' tool, specifying the required 'session' object with testType, answers, and currentQuestionIndex.
    { name: 'calculate_mbti_result', description: '根据所有答案计算最终的MBTI类型和详细结果。需要传入完整的测试会话状态。', inputSchema: { type: 'object', properties: { session: { type: 'object', description: '测试会话状态,必须包含所有题目的答案', properties: { testType: { type: 'string' }, answers: { type: 'array' }, currentQuestionIndex: { type: 'number' }, }, required: ['testType', 'answers', 'currentQuestionIndex'], }, }, required: ['session'], }, },
  • src/index.ts:25-120 (registration)
    Registration of the 'calculate_mbti_result' tool in the ListToolsRequestHandler, including it in the list of available tools.
    server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: 'start_mbti_test', description: '开始MBTI人格测试。用户可以选择测试类型:simplified(简化版28题)或cognitive(认知功能版48题)。返回第一道题目和测试会话状态。', inputSchema: { type: 'object', properties: { testType: { type: 'string', enum: ['simplified', 'cognitive'], description: '测试类型:simplified(简化版)或cognitive(认知功能版)', }, }, required: ['testType'], }, }, { name: 'answer_question', description: '提交当前问题的答案(1-5分),并获取下一题或测试进度。需要传入完整的测试会话状态。', inputSchema: { type: 'object', properties: { session: { type: 'object', description: '测试会话状态,包含testType、answers数组和currentQuestionIndex', properties: { testType: { type: 'string' }, answers: { type: 'array', items: { type: 'object', properties: { questionId: { type: 'number' }, score: { type: 'number' }, }, }, }, currentQuestionIndex: { type: 'number' }, }, required: ['testType', 'answers', 'currentQuestionIndex'], }, score: { type: 'number', description: '对当前问题的回答(1=强烈不同意, 2=不同意, 3=中立, 4=同意, 5=强烈同意)', minimum: 1, maximum: 5, }, }, required: ['session', 'score'], }, }, { name: 'get_progress', description: '查询当前测试进度。需要传入测试会话状态。', inputSchema: { type: 'object', properties: { session: { type: 'object', description: '测试会话状态', properties: { testType: { type: 'string' }, answers: { type: 'array' }, currentQuestionIndex: { type: 'number' }, }, required: ['testType', 'answers', 'currentQuestionIndex'], }, }, required: ['session'], }, }, { name: 'calculate_mbti_result', description: '根据所有答案计算最终的MBTI类型和详细结果。需要传入完整的测试会话状态。', inputSchema: { type: 'object', properties: { session: { type: 'object', description: '测试会话状态,必须包含所有题目的答案', properties: { testType: { type: 'string' }, answers: { type: 'array' }, currentQuestionIndex: { type: 'number' }, }, required: ['testType', 'answers', 'currentQuestionIndex'], }, }, required: ['session'], }, }, ], }; });
  • Core helper function calculateResult that dispatches to simplified or cognitive calculation based on testType and computes the MBTI result.
    export function calculateResult(answers: Answer[], testType: TestType): TestResult { if (testType === 'simplified') { return calculateSimplifiedResult(answers); } else { return calculateCognitiveResult(answers); } }
  • Implementation of simplified test result calculation, scoring dimensions E/I, S/N, T/F, J/P using opposed scoring method.
    function calculateSimplifiedResult(answers: Answer[]): TestResult { const dimensionScores = { E: 0, I: 0, S: 0, N: 0, T: 0, F: 0, J: 0, P: 0, }; // Dimension pairs mapping const oppositeDimension: Record<MBTIDimension, MBTIDimension> = { E: 'I', I: 'E', S: 'N', N: 'S', T: 'F', F: 'T', J: 'P', P: 'J', }; // Calculate scores using opposed scoring method // 1 -> opposite+4, self+0 // 2 -> opposite+3, self+1 // 3 -> opposite+2, self+2 // 4 -> opposite+1, self+3 // 5 -> opposite+0, self+4 answers.forEach(answer => { const question = questionBank.simplified.find(q => q.id === answer.questionId); if (!question || !question.dimension) return; const score = answer.score; // 1-5 const dimension = question.dimension; const opposite = oppositeDimension[dimension]; // Convert 1-5 score to opposed scoring const selfScore = score - 1; // 0-4 const oppositeScore = 4 - selfScore; // 4-0 dimensionScores[dimension] += selfScore; dimensionScores[opposite] += oppositeScore; }); // Determine type by comparing pairs const type = (dimensionScores.E >= dimensionScores.I ? 'E' : 'I') + (dimensionScores.S >= dimensionScores.N ? 'S' : 'N') + (dimensionScores.T >= dimensionScores.F ? 'T' : 'F') + (dimensionScores.J >= dimensionScores.P ? 'J' : 'P'); return { mbtiType: type, dimensionScores, description: typeDescriptions[type] || '未知类型', }; }
  • Implementation of cognitive test result calculation, scoring functions, sorting to find dominant/auxiliary, matching to MBTI type stack.
    function calculateCognitiveResult(answers: Answer[]): TestResult { const functionScores: Record<CognitiveFunction, number> = { Ne: 0, Ni: 0, Se: 0, Si: 0, Te: 0, Ti: 0, Fe: 0, Fi: 0, }; // Calculate scores for each cognitive function answers.forEach(answer => { const question = questionBank.cognitive.find(q => q.id === answer.questionId); if (!question || !question.cognitiveFunction) return; const score = answer.score; // 1-5 functionScores[question.cognitiveFunction] += score; }); // Determine dominant and auxiliary functions const sortedFunctions = (Object.entries(functionScores) as [CognitiveFunction, number][]) .sort((a, b) => b[1] - a[1]); const dominant = sortedFunctions[0][0]; const auxiliary = sortedFunctions[1][0]; // Find MBTI type based on function stack let mbtiType = 'XXXX'; for (const [type, stack] of Object.entries(functionStacks)) { if (stack[0] === dominant && stack[1] === auxiliary) { mbtiType = type; break; } } // If no exact match, try to infer from dominant function if (mbtiType === 'XXXX') { mbtiType = inferTypeFromDominant(dominant, auxiliary); } return { mbtiType, cognitiveFunctionScores: functionScores, functionStack: functionStacks[mbtiType], description: typeDescriptions[mbtiType] || '未知类型', }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wenyili/mbti-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server