Skip to main content
Glama

answer_question

Submit your answer (1-5) to the current MBTI test question and receive the next question or test progress. Requires complete session state.

Instructions

提交当前问题的答案(1-5分),并获取下一题或测试进度。需要传入完整的测试会话状态。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionYes测试会话状态,包含testType、answers数组和currentQuestionIndex
scoreYes对当前问题的回答(1=强烈不同意, 2=不同意, 3=中立, 4=同意, 5=强烈同意)

Implementation Reference

  • The core handler logic for the 'answer_question' tool. It processes the submitted score, updates the test session state, determines if the test is complete, and returns either the completion message or the next question.
    if (name === 'answer_question') {
      const session = args.session as TestSession;
      const score = args.score as number;
    
      const questions = session.testType === 'simplified'
        ? questionBank.simplified
        : questionBank.cognitive;
    
      const currentQuestion = questions[session.currentQuestionIndex];
    
      // Save answer
      const newAnswer: Answer = {
        questionId: currentQuestion.id,
        score,
      };
    
      const updatedSession: TestSession = {
        ...session,
        answers: [...session.answers, newAnswer],
        currentQuestionIndex: session.currentQuestionIndex + 1,
      };
    
      // Check if test is complete
      if (updatedSession.currentQuestionIndex >= questions.length) {
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                message: '所有问题已回答完毕!',
                completed: true,
                progress: {
                  answered: updatedSession.answers.length,
                  total: questions.length,
                },
                session: updatedSession,
                nextStep: '请使用 calculate_mbti_result 工具计算你的MBTI类型',
              }, null, 2),
            },
          ],
        };
      }
    
      // Return next question
      const nextQuestion = questions[updatedSession.currentQuestionIndex];
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              message: '答案已记录',
              progress: {
                answered: updatedSession.answers.length,
                total: questions.length,
              },
              nextQuestion: {
                index: updatedSession.currentQuestionIndex + 1,
                total: questions.length,
                question: nextQuestion,
              },
              session: updatedSession,
            }, null, 2),
          },
        ],
      };
    }
  • src/index.ts:43-77 (registration)
    Registration of the 'answer_question' tool in the ListTools response, including name, description, and input schema definition.
    {
      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'],
      },
    },
  • JSON schema definition for the input parameters of the 'answer_question' tool, specifying the structure of session and score.
    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'],
    },
  • Type definitions supporting the tool, including TestSession, Answer, and QuestionBank used in the handler for type safety.
    export interface QuestionBank {
      simplified: Question[];
      cognitive: Question[];
    }
  • The questionBank data structure used by the handler to retrieve questions based on test type.
    export const questionBank: QuestionBank = {
      simplified: simplifiedQuestions,
      cognitive: cognitiveQuestions,
    };

Tool Definition Quality

Score is being calculated. Check back soon.

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