Skip to main content
Glama
test_server.py6.72 kB
#!/usr/bin/env python3 """ Persona MCP Server 테스트 스크립트 """ import asyncio import sys import os from dotenv import load_dotenv # .env 파일 로드 load_dotenv() # 프로젝트 루트를 경로에 추가 sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from src.main import ( health_impl, get_statistics_impl, list_personas_impl, ListPersonasRequest, create_survey_impl, CreateSurveyRequest, get_persona_impl, GetPersonaRequest, check_freshness_impl, CheckFreshnessRequest, ) async def test_health(): """헬스 체크 테스트""" print("\n" + "="*50) print("1. 헬스 체크 테스트") print("="*50) try: result = await health_impl() print(f"✅ 헬스 체크 성공: {result}") return True except Exception as e: print(f"❌ 헬스 체크 실패: {e}") return False async def test_statistics(): """통계 조회 테스트""" print("\n" + "="*50) print("2. 통계 조회 테스트") print("="*50) try: result = await get_statistics_impl() print(f"✅ 통계 조회 성공") print(f" - 페르소나 수: {result.get('persona_count', 0)}") print(f" - 설문 수: {result.get('survey_count', 0)}") print(f" - 응답 수: {result.get('response_count', 0)}") return True except Exception as e: print(f"❌ 통계 조회 실패: {e}") import traceback traceback.print_exc() return False async def test_list_personas(): """페르소나 목록 조회 테스트""" print("\n" + "="*50) print("3. 페르소나 목록 조회 테스트") print("="*50) try: req = ListPersonasRequest(limit=5) result = await list_personas_impl(req) personas = result.get('personas', []) print(f"✅ 페르소나 목록 조회 성공: {len(personas)}개") if personas: print(f" 첫 번째 페르소나: {personas[0].get('persona_id', 'N/A')}") return personas[0].get('persona_id') if personas else None except Exception as e: print(f"❌ 페르소나 목록 조회 실패: {e}") import traceback traceback.print_exc() return None async def test_get_persona(persona_id): """페르소나 상세 조회 테스트""" if not persona_id: print("\n" + "="*50) print("4. 페르소나 상세 조회 테스트 (스킵: 페르소나 없음)") print("="*50) return False print("\n" + "="*50) print("4. 페르소나 상세 조회 테스트") print("="*50) try: req = GetPersonaRequest(persona_id=persona_id) result = await get_persona_impl(req) print(f"✅ 페르소나 상세 조회 성공") print(f" - 페르소나 ID: {result.get('persona_id', 'N/A')}") print(f" - 나이대: {result.get('basic_profile', {}).get('age_range', 'N/A')}") print(f" - 성별: {result.get('basic_profile', {}).get('gender', 'N/A')}") return True except Exception as e: print(f"❌ 페르소나 상세 조회 실패: {e}") import traceback traceback.print_exc() return False async def test_check_freshness(persona_id): """신선도 확인 테스트""" if not persona_id: print("\n" + "="*50) print("5. 신선도 확인 테스트 (스킵: 페르소나 없음)") print("="*50) return False print("\n" + "="*50) print("5. 신선도 확인 테스트") print("="*50) try: req = CheckFreshnessRequest(persona_id=persona_id) result = await check_freshness_impl(req) print(f"✅ 신선도 확인 성공") print(f" - 신선도 점수: {result.get('freshness_score', 0)}") print(f" - 상태: {result.get('status', 'N/A')}") return True except Exception as e: print(f"❌ 신선도 확인 실패: {e}") import traceback traceback.print_exc() return False async def test_create_survey(): """설문 생성 테스트""" print("\n" + "="*50) print("6. 설문 생성 테스트") print("="*50) try: req = CreateSurveyRequest(category="general") result = await create_survey_impl(req) survey_id = result.get('survey_id') print(f"✅ 설문 생성 성공") print(f" - 설문 ID: {survey_id}") print(f" - 첫 번째 질문: {result.get('first_question', {}).get('question', 'N/A')[:50]}...") return survey_id except Exception as e: print(f"❌ 설문 생성 실패: {e}") import traceback traceback.print_exc() return None async def main(): """메인 테스트 함수""" print("\n" + "="*70) print("Persona MCP Server 테스트 시작") print("="*70) # 환경 변수 확인 groq_key = os.environ.get("GROQ_API_KEY", "") if not groq_key: print("\n⚠️ 경고: GROQ_API_KEY가 설정되지 않았습니다.") print(" 일부 기능(LLM 기반)은 작동하지 않을 수 있습니다.") else: print(f"\n✅ GROQ_API_KEY 설정됨: {groq_key[:10]}...") results = [] # 테스트 실행 results.append(("헬스 체크", await test_health())) results.append(("통계 조회", await test_statistics())) persona_id = await test_list_personas() results.append(("페르소나 목록", persona_id is not None)) results.append(("페르소나 상세", await test_get_persona(persona_id))) results.append(("신선도 확인", await test_check_freshness(persona_id))) survey_id = await test_create_survey() results.append(("설문 생성", survey_id is not None)) # 결과 요약 print("\n" + "="*70) print("테스트 결과 요약") print("="*70) passed = sum(1 for _, result in results if result) total = len(results) for name, result in results: status = "✅ 통과" if result else "❌ 실패" print(f" {status}: {name}") print(f"\n총 {passed}/{total} 테스트 통과") print("="*70) if passed == total: print("\n🎉 모든 테스트 통과!") return 0 else: print(f"\n⚠️ {total - passed}개 테스트 실패") return 1 if __name__ == "__main__": try: exit_code = asyncio.run(main()) sys.exit(exit_code) except KeyboardInterrupt: print("\n\n테스트가 중단되었습니다.") sys.exit(1) except Exception as e: print(f"\n\n테스트 실행 중 오류 발생: {e}") import traceback traceback.print_exc() sys.exit(1)

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/SeoNaRu/persona-mcp'

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