"""Test if MCP server can communicate via stdio (required by Claude Desktop)"""
import sys
import json
# Simulate what Claude Desktop does - send initialization message
def test_stdio_communication():
print("Testing stdio communication...", file=sys.stderr)
# Read from stdin
try:
line = sys.stdin.readline()
if line:
print(f"Received: {line}", file=sys.stderr)
try:
msg = json.loads(line.strip())
print(f"Parsed JSON: {msg}", file=sys.stderr)
return True
except json.JSONDecodeError as e:
print(f"JSON decode error: {e}", file=sys.stderr)
return False
else:
print("No input received", file=sys.stderr)
return False
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
return False
if __name__ == "__main__":
# Import the actual server
import sys
import os
sys.path.insert(0, os.path.dirname(__file__))
# Try to import and check if server is ready
try:
from inventory_mcp_server import mcp
print("Server imported successfully", file=sys.stderr)
print("MCP server is ready for stdio communication", file=sys.stderr)
except ImportError as e:
# Handle the hyphen in filename
print(f"Import error (expected): {e}", file=sys.stderr)
print("This is normal - filename has hyphen", file=sys.stderr)
# Try direct import
import importlib.util
spec = importlib.util.spec_from_file_location("server", "inventory-mcp-server.py")
server_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(server_module)
print("Server loaded directly", file=sys.stderr)