File size: 1,456 Bytes
82bf89e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import asyncio
import os
import nest_asyncio
import atexit
from services.chat_service import init_session
from services.logging_service import get_logger
from services.task_monitor import get_task_monitor
from utils.async_helpers import on_shutdown
from apps import mcp_playground

# Apply nest_asyncio to allow nested asyncio event loops (needed for Streamlit's execution model)
nest_asyncio.apply()

page_icon_path = os.path.join('.', 'icons', 'playground.png')

st.set_page_config(
                   page_title="MCP Playground",
                   page_icon=(page_icon_path),
                   layout='wide',
                   initial_sidebar_state="expanded"
                    )

# Customize css
with open(os.path.join('.', '.streamlit', 'style.css')) as f:
   st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)


def main():
    # Initialize session state for event loop
    if "loop" not in st.session_state:
        st.session_state.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(st.session_state.loop)
    
    # Initialize logging system
    logger = get_logger()
    logger.log_system_status("Application started")
    
    # Initialize task monitor
    task_monitor = get_task_monitor()
    
    # Register shutdown handler
    atexit.register(on_shutdown)
    
    # Initialize the primary application
    init_session()
    mcp_playground.main()

if __name__ == "__main__":
    main()