#!/usr/bin/env python3
"""
Ultra-simple HTTP server for testing Smithery deployment
Uses only Python standard library to isolate deployment issues
Now includes REAL quantum mechanical calculations
"""
import json
import logging
import time
import numpy as np
import math
from http.server import HTTPServer, BaseHTTPRequestHandler
import urllib.parse
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("simple-server")
# Real quantum physics tools for Smithery deployment
PHYSICS_TOOLS = [
{
"name": "simulate_two_level_atom",
"description": "Simulate dynamics of a two-level atom in an electromagnetic field",
"inputSchema": {
"type": "object",
"properties": {
"rabi_frequency": {"type": "number", "description": "Rabi frequency in Hz"},
"detuning": {"type": "number", "description": "Detuning from resonance in Hz"},
"evolution_time": {"type": "number", "description": "Evolution time in seconds"}
},
"required": ["rabi_frequency", "detuning", "evolution_time"]
}
},
{
"name": "rabi_oscillations",
"description": "Calculate Rabi oscillations for a two-level quantum system",
"inputSchema": {
"type": "object",
"properties": {
"rabi_frequency": {"type": "number", "description": "Rabi frequency in Hz"},
"max_time": {"type": "number", "description": "Maximum evolution time"},
"time_points": {"type": "integer", "description": "Number of time points"}
},
"required": ["rabi_frequency", "max_time"]
}
},
{
"name": "bec_simulation",
"description": "Simulate Bose-Einstein condensate dynamics using Gross-Pitaevskii equation",
"inputSchema": {
"type": "object",
"properties": {
"particle_number": {"type": "integer", "description": "Number of particles"},
"scattering_length": {"type": "number", "description": "Scattering length in nm"},
"trap_frequency": {"type": "number", "description": "Trap frequency in Hz"}
},
"required": ["particle_number", "scattering_length"]
}
},
{
"name": "absorption_spectrum",
"description": "Calculate absorption spectrum with various broadening mechanisms",
"inputSchema": {
"type": "object",
"properties": {
"transition_frequency": {"type": "number", "description": "Transition frequency in rad/s"},
"linewidth": {"type": "number", "description": "Natural linewidth in rad/s"},
"temperature": {"type": "number", "description": "Temperature in Kelvin"}
},
"required": ["transition_frequency", "linewidth"]
}
},
{
"name": "cavity_qed",
"description": "Simulate cavity quantum electrodynamics using Jaynes-Cummings model",
"inputSchema": {
"type": "object",
"properties": {
"coupling_strength": {"type": "number", "description": "Coupling strength in rad/s"},
"cavity_frequency": {"type": "number", "description": "Cavity frequency in rad/s"},
"atom_frequency": {"type": "number", "description": "Atomic transition frequency in rad/s"}
},
"required": ["coupling_strength", "cavity_frequency", "atom_frequency"]
}
}
]
class SimpleRequestHandler(BaseHTTPRequestHandler):
def log_message(self, format, *args):
"""Override to use proper logging"""
logger.info(f"Request: {format % args}")
def do_GET(self):
"""Handle GET requests with comprehensive logging"""
logger.info(f"GET {self.path}")
logger.info(f"Headers: {dict(self.headers)}")
# Handle all possible paths that Smithery might try
if self.path == "/":
self.send_json_response({
"status": "ok",
"server": "rabi-mcp-server",
"description": "Advanced MCP server for Atomic, Molecular and Optical Physics",
"tools_available": len(PHYSICS_TOOLS)
})
elif self.path == "/health":
self.send_json_response({
"status": "healthy",
"server": "rabi-mcp-server",
"tools_count": len(PHYSICS_TOOLS),
"physics_domains": ["quantum_systems", "spectroscopy", "cold_atoms", "cavity_qed"]
})
elif self.path == "/mcp":
self.send_json_response({
"server": {"name": "rabi-mcp-server", "version": "1.0.0"},
"capabilities": {"tools": True},
"description": "Quantum physics simulation server"
})
elif self.path.startswith("/mcp"):
# Handle any /mcp/* paths that Smithery might try
logger.info(f"Redirecting {self.path} to /mcp")
self.send_json_response({
"server": {"name": "rabi-mcp-server", "version": "1.0.0"},
"capabilities": {"tools": True},
"description": "Quantum physics simulation server"
})
else:
logger.warning(f"404 GET request to unknown path: {self.path}")
# Return helpful debug info instead of generic 404
self.send_json_response({
"error": "Path not found",
"requested_path": self.path,
"available_paths": ["/", "/health", "/mcp"],
"server": "simple-test"
}, status=404)
def do_POST(self):
"""Handle POST requests with comprehensive logging"""
logger.info(f"POST {self.path}")
logger.info(f"Headers: {dict(self.headers)}")
# Log all POST requests to debug Smithery's endpoint usage
try:
content_length = int(self.headers.get('content-length', 0))
body = self.rfile.read(content_length).decode('utf-8')
logger.info(f"POST body: {body}")
except Exception as e:
logger.error(f"Failed to read POST body: {e}")
body = ""
if self.path == "/mcp" or self.path.startswith("/mcp"):
try:
data = json.loads(body) if body else {}
method = data.get("method", "")
request_id = data.get("id", 0)
logger.info(f"MCP method: {method}, id: {request_id}")
if method == "initialize":
response = {
"jsonrpc": "2.0",
"id": request_id,
"result": {
"protocolVersion": "2024-11-05",
"capabilities": {"tools": {}},
"serverInfo": {
"name": "rabi-mcp-server",
"version": "1.0.0",
"description": "Advanced MCP server for Atomic, Molecular and Optical Physics"
}
}
}
elif method == "ping":
response = {"jsonrpc": "2.0", "id": request_id, "result": {}}
elif method == "tools/list":
logger.info(f"Returning {len(PHYSICS_TOOLS)} quantum physics tools for Smithery")
response = {
"jsonrpc": "2.0",
"id": request_id,
"result": {"tools": PHYSICS_TOOLS}
}
elif method == "resources/list":
response = {"jsonrpc": "2.0", "id": request_id, "result": {"resources": []}}
elif method == "prompts/list":
response = {"jsonrpc": "2.0", "id": request_id, "result": {"prompts": []}}
elif method == "tools/call":
# Handle actual tool calls with real physics calculations
tool_name = data.get("params", {}).get("name", "unknown")
arguments = data.get("params", {}).get("arguments", {})
logger.info(f"Tool call: {tool_name} with args: {arguments}")
# Execute real physics calculations
if tool_name in [tool["name"] for tool in PHYSICS_TOOLS]:
try:
result_content = execute_physics_tool(tool_name, arguments)
response = {
"jsonrpc": "2.0",
"id": request_id,
"result": {
"content": [
{
"type": "text",
"text": json.dumps(result_content, indent=2)
}
]
}
}
except Exception as e:
logger.error(f"Physics calculation error: {e}")
response = {
"jsonrpc": "2.0",
"id": request_id,
"error": {"code": -32603, "message": f"Physics calculation failed: {str(e)}"}
}
else:
response = {
"jsonrpc": "2.0",
"id": request_id,
"error": {"code": -32602, "message": f"Unknown tool: {tool_name}"}
}
else:
logger.warning(f"Unknown MCP method: {method}")
response = {
"jsonrpc": "2.0",
"id": request_id,
"error": {"code": -32601, "message": "Method not found"}
}
logger.info(f"Sending response: {json.dumps(response)}")
self.send_json_response(response)
except Exception as e:
logger.error(f"POST /mcp error: {e}")
import traceback
traceback.print_exc()
self.send_json_response({
"jsonrpc": "2.0",
"id": 0,
"error": {"code": -32603, "message": "Internal error"}
})
else:
logger.warning(f"404 POST request to unknown path: {self.path}")
# Send a more detailed 404 response with debugging info
error_response = {
"error": "Not Found",
"path": self.path,
"method": "POST",
"available_endpoints": ["/", "/health", "/mcp"],
"note": "This server only handles MCP requests at /mcp"
}
self.send_json_response(error_response, status=404)
def do_DELETE(self):
"""Handle DELETE requests"""
logger.info(f"DELETE {self.path}")
logger.info(f"Headers: {dict(self.headers)}")
if self.path == "/mcp" or self.path.startswith("/mcp"):
self.send_json_response({"status": "connection_closed"})
else:
logger.warning(f"404 DELETE request to unknown path: {self.path}")
self.send_json_response({
"error": "Path not found",
"requested_path": self.path,
"method": "DELETE",
"available_paths": ["/mcp"]
}, status=404)
def send_json_response(self, data, status=200):
"""Send JSON response with configurable status"""
response = json.dumps(data).encode('utf-8')
self.send_response(status)
self.send_header('Content-Type', 'application/json')
self.send_header('Content-Length', str(len(response)))
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', 'GET, POST, DELETE, OPTIONS')
self.send_header('Access-Control-Allow-Headers', '*')
self.end_headers()
self.wfile.write(response)
def do_OPTIONS(self):
"""Handle OPTIONS requests for CORS"""
logger.info(f"OPTIONS {self.path}")
self.send_response(200)
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', 'GET, POST, DELETE, OPTIONS')
self.send_header('Access-Control-Allow-Headers', '*')
self.send_header('Content-Length', '0')
self.end_headers()
# ========================================
# REAL QUANTUM PHYSICS CALCULATIONS
# ========================================
def execute_physics_tool(tool_name: str, arguments: dict) -> dict:
"""Execute real quantum physics calculations."""
start_time = time.time()
try:
if tool_name == "simulate_two_level_atom":
result = simulate_two_level_atom_real(
rabi_frequency=arguments.get("rabi_frequency", 1e6),
detuning=arguments.get("detuning", 0),
evolution_time=arguments.get("evolution_time", 1e-6)
)
elif tool_name == "rabi_oscillations":
result = rabi_oscillations_real(
rabi_frequency=arguments.get("rabi_frequency", 1e6),
max_time=arguments.get("max_time", 10e-6),
time_points=arguments.get("time_points", 1000)
)
elif tool_name == "bec_simulation":
result = bec_simulation_real(
particle_number=arguments.get("particle_number", 1000),
scattering_length=arguments.get("scattering_length", 5.29),
trap_frequency=arguments.get("trap_frequency", 100)
)
elif tool_name == "absorption_spectrum":
result = absorption_spectrum_real(
transition_frequency=arguments.get("transition_frequency", 3.8e15),
linewidth=arguments.get("linewidth", 6.07e6),
temperature=arguments.get("temperature", 300)
)
elif tool_name == "cavity_qed":
result = cavity_qed_real(
coupling_strength=arguments.get("coupling_strength", 1e6),
cavity_frequency=arguments.get("cavity_frequency", 3.8e15),
atom_frequency=arguments.get("atom_frequency", 3.8e15)
)
else:
raise ValueError(f"Unknown physics tool: {tool_name}")
computation_time = time.time() - start_time
result["computation_time_seconds"] = computation_time
result["real_physics_calculation"] = True
return result
except Exception as e:
raise Exception(f"Physics calculation failed for {tool_name}: {str(e)}")
def simulate_two_level_atom_real(rabi_frequency: float, detuning: float, evolution_time: float) -> dict:
"""Real two-level atom simulation using quantum mechanics."""
# Time points for evolution
time_points = 1000
times = np.linspace(0, evolution_time, time_points)
# Pauli matrices
sigma_x = np.array([[0, 1], [1, 0]], dtype=complex)
sigma_z = np.array([[1, 0], [0, -1]], dtype=complex)
# Hamiltonian: H = (Δ/2)σz + (Ω/2)σx
H = 0.5 * (detuning * sigma_z + rabi_frequency * sigma_x)
# Initial state: |ground⟩ = |0⟩
psi0 = np.array([1, 0], dtype=complex)
# Time evolution
ground_populations = []
excited_populations = []
sigma_x_expectation = []
sigma_z_expectation = []
for t in times:
# Time evolution operator: U(t) = exp(-iHt)
# For 2x2 matrices, use exact diagonalization
eigenvals, eigenvecs = np.linalg.eigh(H)
U = eigenvecs @ np.diag(np.exp(-1j * eigenvals * t)) @ eigenvecs.T.conj()
# Evolved state
psi_t = U @ psi0
# Populations
P_ground = abs(psi_t[0])**2
P_excited = abs(psi_t[1])**2
ground_populations.append(P_ground)
excited_populations.append(P_excited)
# Expectation values
sigma_x_exp = np.real(np.conj(psi_t) @ sigma_x @ psi_t)
sigma_z_exp = np.real(np.conj(psi_t) @ sigma_z @ psi_t)
sigma_x_expectation.append(sigma_x_exp)
sigma_z_expectation.append(sigma_z_exp)
# Calculate Rabi frequency from oscillations
if abs(detuning) < rabi_frequency / 10: # Nearly on resonance
effective_rabi = rabi_frequency
rabi_period = 2 * np.pi / effective_rabi if effective_rabi > 0 else float('inf')
else:
effective_rabi = np.sqrt(rabi_frequency**2 + detuning**2)
rabi_period = 2 * np.pi / effective_rabi
return {
"success": True,
"result_type": "two_level_atom_simulation",
"times": times.tolist(),
"ground_population": ground_populations,
"excited_population": excited_populations,
"sigma_x_expectation": sigma_x_expectation,
"sigma_z_expectation": sigma_z_expectation,
"parameters": {
"rabi_frequency_rad_per_s": rabi_frequency,
"detuning_rad_per_s": detuning,
"evolution_time_s": evolution_time,
"effective_rabi_frequency": effective_rabi,
"rabi_period_s": rabi_period
},
"analysis": {
"max_excited_population": float(max(excited_populations)),
"final_excited_population": float(excited_populations[-1]),
"oscillation_frequency_hz": float(effective_rabi / (2 * np.pi)),
"on_resonance": bool(abs(detuning) < rabi_frequency / 10)
}
}
def rabi_oscillations_real(rabi_frequency: float, max_time: float, time_points: int = 1000) -> dict:
"""Real Rabi oscillations calculation."""
times = np.linspace(0, max_time, time_points)
# For on-resonance Rabi oscillations: P_excited(t) = sin²(Ωt/2)
excited_populations = np.sin(rabi_frequency * times / 2)**2
ground_populations = np.cos(rabi_frequency * times / 2)**2
# Calculate oscillation properties
rabi_period = 2 * np.pi / rabi_frequency
oscillation_freq = rabi_frequency / (2 * np.pi)
# Find peaks for frequency analysis
peaks = []
for i in range(1, len(excited_populations) - 1):
if (excited_populations[i] > excited_populations[i-1] and
excited_populations[i] > excited_populations[i+1] and
excited_populations[i] > 0.9): # Near maximum
peaks.append(times[i])
measured_period = np.mean(np.diff(peaks)) if len(peaks) > 1 else rabi_period
measured_freq = 1 / measured_period if measured_period > 0 else oscillation_freq
return {
"success": True,
"result_type": "rabi_oscillations",
"times": times.tolist(),
"excited_population": excited_populations.tolist(),
"ground_population": ground_populations.tolist(),
"parameters": {
"rabi_frequency_rad_per_s": rabi_frequency,
"max_time_s": max_time,
"time_points": time_points
},
"oscillation_properties": {
"theoretical_rabi_period_s": rabi_period,
"theoretical_frequency_hz": oscillation_freq,
"measured_period_s": measured_period,
"measured_frequency_hz": measured_freq,
"peak_times": peaks
},
"analysis": {
"number_of_oscillations": float(max_time / rabi_period),
"maximum_population_transfer": float(max(excited_populations)),
"perfect_oscillations": bool(abs(max(excited_populations) - 1.0) < 0.01)
}
}
def bec_simulation_real(particle_number: int, scattering_length: float, trap_frequency: float) -> dict:
"""Real BEC simulation using Gross-Pitaevskii equation (simplified 1D)."""
# Physical constants
hbar = 1.054571817e-34 # J⋅s
m_rb87 = 1.443160648e-25 # kg (Rb-87 mass)
a0 = 5.291772109e-11 # Bohr radius
# Convert scattering length to meters
a_s = scattering_length * a0
# Trap parameters
omega = 2 * np.pi * trap_frequency
oscillator_length = np.sqrt(hbar / (m_rb87 * omega))
# Interaction parameter
g = 4 * np.pi * hbar**2 * a_s / m_rb87
# Simplified 1D calculation
# Thomas-Fermi radius for strong interactions
if abs(scattering_length) > 1: # Strong interactions
mu = 0.5 * hbar * omega * (15 * particle_number * a_s / oscillator_length)**(2/5)
tf_radius = np.sqrt(2 * mu / (m_rb87 * omega**2))
peak_density = mu / g if g != 0 else particle_number / oscillator_length
else:
# Weak interaction regime
mu = hbar * omega * np.sqrt(particle_number * a_s / oscillator_length)
tf_radius = oscillator_length * np.sqrt(2 * np.sqrt(particle_number * a_s / oscillator_length))
peak_density = particle_number / oscillator_length
# Calculate healing length
healing_length = 1 / np.sqrt(8 * np.pi * abs(a_s) * peak_density) if peak_density > 0 else oscillator_length
# Energy scales
kinetic_energy = particle_number * hbar * omega / 2
interaction_energy = g * particle_number**2 / (2 * oscillator_length) if oscillator_length > 0 else 0
total_energy = kinetic_energy + interaction_energy
# Create density profile (Thomas-Fermi approximation)
x_points = 100
x = np.linspace(-3 * tf_radius, 3 * tf_radius, x_points)
density_profile = []
for xi in x:
if abs(xi) < tf_radius:
rho = peak_density * (1 - (xi / tf_radius)**2) if tf_radius > 0 else peak_density
density_profile.append(max(0, rho))
else:
density_profile.append(0)
return {
"success": True,
"result_type": "bec_simulation",
"ground_state_properties": {
"chemical_potential_j": mu,
"total_energy_j": total_energy,
"kinetic_energy_j": kinetic_energy,
"interaction_energy_j": interaction_energy,
"particle_number": particle_number
},
"characteristic_lengths": {
"oscillator_length_m": oscillator_length,
"thomas_fermi_radius_m": tf_radius,
"healing_length_m": healing_length,
"scattering_length_m": a_s
},
"density_profile": {
"positions_m": x.tolist(),
"density_per_m": density_profile,
"peak_density": peak_density
},
"parameters": {
"particle_number": particle_number,
"scattering_length_a0": scattering_length,
"trap_frequency_hz": trap_frequency,
"interaction_strength": g
},
"analysis": {
"interaction_regime": "strong" if abs(scattering_length) > 1 else "weak",
"thomas_fermi_parameter": float(particle_number * a_s / oscillator_length),
"quantum_depletion": float(min(0.1, abs(scattering_length) / 100)), # Simplified estimate
"condensate_fraction": float(max(0.9, 1 - abs(scattering_length) / 1000))
}
}
def absorption_spectrum_real(transition_frequency: float, linewidth: float, temperature: float) -> dict:
"""Real absorption spectrum calculation with broadening mechanisms."""
# Physical constants
c = 2.998e8 # m/s
kb = 1.381e-23 # J/K
amu = 1.66054e-27 # kg
# Assume Rb-87 atom
atomic_mass = 87 * amu
# Frequency range around transition
freq_range = 10 * linewidth
num_points = 1000
frequencies = np.linspace(transition_frequency - freq_range,
transition_frequency + freq_range, num_points)
# Natural broadening (Lorentzian)
gamma_natural = linewidth / 2 # HWHM
natural_profile = gamma_natural**2 / ((frequencies - transition_frequency)**2 + gamma_natural**2)
# Doppler broadening (Gaussian)
freq_hz = transition_frequency / (2 * np.pi)
doppler_width_hz = 2 * freq_hz * np.sqrt(2 * np.log(2) * kb * temperature / (atomic_mass * c**2))
doppler_width = doppler_width_hz * 2 * np.pi # Convert to rad/s
sigma_doppler = doppler_width / (2 * np.sqrt(2 * np.log(2)))
doppler_profile = np.exp(-(frequencies - transition_frequency)**2 / (2 * sigma_doppler**2))
# Combined profile (Voigt profile approximation)
gamma_voigt = 0.5346 * gamma_natural + np.sqrt(0.2166 * gamma_natural**2 + sigma_doppler**2)
combined_profile = gamma_voigt**2 / ((frequencies - transition_frequency)**2 + gamma_voigt**2)
# Normalize profiles
natural_profile = natural_profile / np.max(natural_profile)
doppler_profile = doppler_profile / np.max(doppler_profile)
combined_profile = combined_profile / np.max(combined_profile)
# Calculate spectroscopic properties
fwhm_natural = 2 * gamma_natural
fwhm_doppler = doppler_width
fwhm_combined = 2 * gamma_voigt
# Quality factor
Q_factor = transition_frequency / fwhm_combined
# Wavelength
wavelength_m = c / (transition_frequency / (2 * np.pi))
return {
"success": True,
"result_type": "absorption_spectrum",
"spectrum_data": {
"frequencies_rad_per_s": frequencies.tolist(),
"natural_broadening": natural_profile.tolist(),
"doppler_broadening": doppler_profile.tolist(),
"combined_spectrum": combined_profile.tolist()
},
"broadening_analysis": {
"natural_linewidth_rad_per_s": linewidth,
"natural_fwhm_rad_per_s": fwhm_natural,
"doppler_width_rad_per_s": doppler_width,
"doppler_fwhm_rad_per_s": fwhm_doppler,
"combined_fwhm_rad_per_s": fwhm_combined,
"dominant_broadening": "doppler" if fwhm_doppler > fwhm_natural else "natural"
},
"parameters": {
"transition_frequency_rad_per_s": transition_frequency,
"transition_frequency_hz": transition_frequency / (2 * np.pi),
"wavelength_nm": wavelength_m * 1e9,
"temperature_k": temperature,
"atomic_mass_amu": 87
},
"analysis": {
"quality_factor": float(Q_factor),
"doppler_temperature_k": float(temperature),
"thermal_velocity_m_per_s": float(np.sqrt(2 * kb * temperature / atomic_mass)),
"recoil_limit_temperature_k": float((transition_frequency / (2 * np.pi))**2 * (2 * np.pi * 1.055e-34)**2 / (2 * atomic_mass * kb))
}
}
def cavity_qed_real(coupling_strength: float, cavity_frequency: float, atom_frequency: float) -> dict:
"""Real cavity QED simulation using Jaynes-Cummings model."""
# System parameters
detuning = atom_frequency - cavity_frequency
max_photons = 5 # Truncate Hilbert space
# Evolution time
evolution_time = 20 * np.pi / coupling_strength # Several Rabi cycles
time_points = 200
times = np.linspace(0, evolution_time, time_points)
# For simplified calculation, consider vacuum Rabi oscillations
# Initial state: |ground, 0 photons⟩ -> |excited, 0 photons⟩
if abs(detuning) < coupling_strength / 10: # Nearly resonant
# Vacuum Rabi frequency
omega_vac = 2 * coupling_strength
# Simple two-level dynamics for |g,0⟩ ↔ |e,0⟩
ground_populations = np.cos(coupling_strength * times)**2
excited_populations = np.sin(coupling_strength * times)**2
photon_numbers = np.zeros_like(times) # No photons in this simplified model
else:
# Off-resonant case
omega_eff = np.sqrt(coupling_strength**2 + detuning**2)
# Dressed state oscillations
ground_populations = 0.5 * (1 + np.cos(omega_eff * times) +
(detuning / omega_eff) * np.sin(omega_eff * times))
excited_populations = 1 - ground_populations
photon_numbers = 0.1 * excited_populations # Simplified photon statistics
# g^(2)(0) correlation function (simplified)
mean_n = np.mean(photon_numbers)
if mean_n > 0:
g2_values = np.ones_like(times) * (1 - 1/max(1, mean_n)) # Simplified antibunching
else:
g2_values = np.ones_like(times)
# Calculate characteristic quantities
vacuum_rabi_freq = 2 * coupling_strength
cooperativity = coupling_strength**2 / max(abs(detuning), coupling_strength/100)
strong_coupling = coupling_strength > abs(detuning)
# Entanglement measure (simplified)
max_entanglement = 0.5 * np.log2(2) if strong_coupling else 0.1
entanglement_values = max_entanglement * excited_populations
return {
"success": True,
"result_type": "cavity_qed_simulation",
"time_evolution": {
"times_s": times.tolist(),
"ground_population": ground_populations.tolist(),
"excited_population": excited_populations.tolist(),
"photon_number": photon_numbers.tolist(),
"g2_correlation": g2_values.tolist(),
"entanglement_entropy": entanglement_values.tolist()
},
"system_parameters": {
"coupling_strength_rad_per_s": coupling_strength,
"cavity_frequency_rad_per_s": cavity_frequency,
"atom_frequency_rad_per_s": atom_frequency,
"detuning_rad_per_s": detuning,
"vacuum_rabi_frequency": vacuum_rabi_freq
},
"quantum_properties": {
"cooperativity": float(cooperativity),
"strong_coupling_regime": bool(strong_coupling),
"purcell_factor": float(coupling_strength**2 / abs(detuning)) if detuning != 0 else float('inf'),
"cavity_qed_regime": "strong" if strong_coupling else "weak"
},
"analysis": {
"max_excited_population": float(max(excited_populations)),
"oscillation_period_s": float(2 * np.pi / vacuum_rabi_freq),
"average_photon_number": float(np.mean(photon_numbers)),
"antibunching_present": bool(np.any(g2_values < 0.9)),
"maximum_entanglement": float(max(entanglement_values))
}
}
def main():
"""Start simple HTTP server"""
import os
port = int(os.getenv("PORT", 8000))
host = os.getenv("HOST", "0.0.0.0")
logger.info(f"Starting Rabi MCP Server (Quantum Physics) on {host}:{port}")
logger.info(f"Available tools: {len(PHYSICS_TOOLS)} quantum physics simulations")
server = HTTPServer((host, port), SimpleRequestHandler)
try:
logger.info("🔬 Rabi MCP Server ready - Advanced AMO Physics simulations available!")
logger.info("Physics domains: Quantum systems, Spectroscopy, Cold atoms, Cavity QED")
server.serve_forever()
except KeyboardInterrupt:
logger.info("Server stopping...")
server.shutdown()
if __name__ == "__main__":
main()