test_features.pyโข3.29 kB
#!/usr/bin/env python3
"""
Test script to verify the updated MCP PowerShell server features.
"""
import asyncio
import sys
import os
# Add the server directory to the path
sys.path.insert(0, os.path.dirname(__file__))
from server import mcp
async def test_server_features():
"""Test the new server features."""
print("๐งช Testing MCP PowerShell Server Features")
print("=" * 50)
# Test 1: List available tools
print("\n1๏ธโฃ Available Tools:")
tools = await mcp.list_tools()
for tool in tools:
print(f" โ
{tool.name}: {tool.description}")
# Test 2: List available resources
print("\n2๏ธโฃ Available Resources:")
resources = await mcp.list_resources()
for resource in resources:
print(f" ๐ {resource.uri}: {resource.name}")
# Test 3: List available prompts
print("\n3๏ธโฃ Available Prompts:")
prompts = await mcp.list_prompts()
for prompt in prompts:
print(f" ๐ฌ {prompt.name}: {prompt.description}")
# Test 4: Test a resource
print("\n4๏ธโฃ Testing System Info Resource:")
try:
system_info_result = await mcp.read_resource("system://info")
# system_info_result is an iterable of ReadResourceContents
system_info_list = list(system_info_result)
if system_info_list:
system_info = system_info_list[0].text if hasattr(system_info_list[0], 'text') else str(system_info_list[0])
print(f" โ
System info retrieved ({len(system_info)} characters)")
print(" ๐ Sample data:", system_info[:200] + "..." if len(system_info) > 200 else system_info)
else:
print(" โ No system info data returned")
except Exception as e:
print(f" โ Error: {e}")
# Test 5: Test templates list resource
print("\n5๏ธโฃ Testing Templates List Resource:")
try:
templates_result = await mcp.read_resource("templates://list")
templates_list = list(templates_result)
if templates_list:
templates = templates_list[0].text if hasattr(templates_list[0], 'text') else str(templates_list[0])
print(f" โ
Templates list retrieved ({len(templates)} characters)")
print(" ๐ Sample data:", templates[:200] + "..." if len(templates) > 200 else templates)
else:
print(" โ No templates data returned")
except Exception as e:
print(f" โ Error: {e}")
# Test 6: Test a simple PowerShell command
print("\n6๏ธโฃ Testing Simple PowerShell Command:")
try:
result = await mcp.call_tool("run_powershell", {"code": "Get-Date | ConvertTo-Json", "timeout": 30})
# result is a sequence of Content objects
result_list = list(result)
if result_list:
result_text = result_list[0].text if hasattr(result_list[0], 'text') else str(result_list[0])
print(f" โ
PowerShell command executed successfully")
print(f" ๐ Result: {result_text[:200]}...")
else:
print(" โ No result returned")
except Exception as e:
print(f" โ Error: {e}")
print("\n๐ Test completed!")
if __name__ == "__main__":
asyncio.run(test_server_features())