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] || '未知类型',
      };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states the calculation action but doesn't describe what '详细结果' (detailed results) includes, whether this is a read-only computation or creates persistent data, error conditions, or performance characteristics. The description provides minimal behavioral context beyond the basic purpose.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with just two sentences that directly address purpose and parameter requirements. Every word earns its place with no redundancy or unnecessary elaboration. It's front-loaded with the core purpose followed by the key requirement.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a calculation tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what '详细结果' (detailed results) includes, the format of the MBTI type output, potential error conditions, or whether this operation has side effects. Given the complexity of MBTI calculation and lack of structured output documentation, more context is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents the single 'session' parameter and its required nested properties. The description adds that the session must contain '所有题目的答案' (all question answers), which provides useful semantic context about completeness requirements, but doesn't significantly expand beyond what the schema provides. Baseline 3 is appropriate given high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '根据所有答案计算最终的MBTI类型和详细结果' (calculate final MBTI type and detailed results based on all answers). It specifies the verb '计算' (calculate) and resource 'MBTI类型和详细结果' (MBTI type and detailed results), but doesn't explicitly differentiate from sibling tools like 'get_progress' or 'answer_question' beyond implying this is the final calculation step.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides implied usage context: '需要传入完整的测试会话状态' (requires passing complete test session state), suggesting this should be used when all answers are available. However, it doesn't explicitly state when to use this vs. alternatives like 'get_progress' for intermediate results or 'start_mbti_test' to begin, nor does it mention prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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