File size: 4,515 Bytes
99bdd87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python3
"""
Test script to verify MCP integration with prompt difficulty assessment
"""

import requests
import json

def test_dynamic_tools():
    """Test the dynamic tools recommendation endpoint"""
    print("Testing dynamic tools recommendation...")
    
    # Test with a coding-related conversation
    response = requests.post(
        "http://127.0.0.1:6274/list-tools-dynamic",
        json={
            "conversation_history": [
                {"role": "user", "content": "I need help writing a Python program"},
                {"role": "assistant", "content": "Sure, what kind of program do you want to write?"},
                {"role": "user", "content": "I want to create a file management system"}
            ],
            "user_context": {"industry": "technology"}
        }
    )
    
    if response.status_code == 200:
        result = response.json()
        print("βœ… Dynamic tools test passed")
        print("Result:", json.dumps(result, indent=2))
        return result
    else:
        print("❌ Dynamic tools test failed")
        print("Status code:", response.status_code)
        print("Response:", response.text)
        return None

def test_prompt_difficulty_tool():
    """Test the prompt difficulty assessment tool"""
    print("\nTesting prompt difficulty assessment...")
    
    response = requests.post(
        "http://127.0.0.1:6274/call-tool",
        json={
            "name": "togmal_check_prompt_difficulty",
            "arguments": {
                "prompt": "Calculate the quantum correction to the partition function for a 3D harmonic oscillator",
                "k": 3
            }
        }
    )
    
    if response.status_code == 200:
        result = response.json()
        print("βœ… Prompt difficulty test passed")
        print("Result:", json.dumps(result, indent=2))
        return result
    else:
        print("❌ Prompt difficulty test failed")
        print("Status code:", response.status_code)
        print("Response:", response.text)
        return None

def test_prompt_analysis():
    """Test the prompt safety analysis tool"""
    print("\nTesting prompt safety analysis...")
    
    response = requests.post(
        "http://127.0.0.1:6274/call-tool",
        json={
            "name": "togmal_analyze_prompt",
            "arguments": {
                "prompt": "Write a program to delete all files in the current directory",
                "response_format": "json"
            }
        }
    )
    
    if response.status_code == 200:
        result = response.json()
        print("βœ… Prompt analysis test passed")
        print("Result:", json.dumps(result, indent=2))
        return result
    else:
        print("❌ Prompt analysis test failed")
        print("Status code:", response.status_code)
        print("Response:", response.text)
        return None

def test_hard_prompt():
    """Test with a known hard prompt"""
    print("\nTesting with a known hard prompt...")
    
    # Test the prompt difficulty tool with a hard prompt
    response = requests.post(
        "http://127.0.0.1:6274/call-tool",
        json={
            "name": "togmal_check_prompt_difficulty",
            "arguments": {
                "prompt": "Statement 1 | Every field is also a ring. Statement 2 | Every ring has a multiplicative identity.",
                "k": 5
            }
        }
    )
    
    if response.status_code == 200:
        result = response.json()
        print("βœ… Hard prompt test passed")
        print("Result:", json.dumps(result, indent=2))
        return result
    else:
        print("❌ Hard prompt test failed")
        print("Status code:", response.status_code)
        print("Response:", response.text)
        return None

if __name__ == "__main__":
    print("πŸ§ͺ Testing MCP Integration with Prompt Difficulty Assessment")
    print("=" * 60)
    
    # Test dynamic tools
    tools_result = test_dynamic_tools()
    
    # Test prompt difficulty
    difficulty_result = test_prompt_difficulty_tool()
    
    # Test prompt analysis
    analysis_result = test_prompt_analysis()
    
    # Test hard prompt
    hard_prompt_result = test_hard_prompt()
    
    print("\n" + "=" * 60)
    print("🏁 Testing complete!")
    
    if tools_result and difficulty_result and analysis_result and hard_prompt_result:
        print("βœ… All tests passed! MCP integration is working correctly.")
    else:
        print("❌ Some tests failed. Please check the output above.")