@@ -100,7 +100,6 @@ class MCPConfig(BaseModel):
100100
101101 model_config = ConfigDict (arbitrary_types_allowed = True )
102102
103- workflow : "Workflow" = Field (..., description = "The MCP workflow to use" )
104103 name : str = Field (description = "Name of the MCP application" )
105104 tools : List [Tool ] = Field (default_factory = list , description = "List of tools to register with MCP" )
106105 resources : List [Resource ] = Field (default_factory = list , description = "List of resources for MCP" )
@@ -191,6 +190,8 @@ def mount(self, app: FastAPI, router: APIRouter) -> None:
191190 for tool in self .mcp .tools :
192191 mcp .add_tool (tool )
193192
193+ app .mount ("/mcp" , mcp .http_app ("/" , stateless_http = True , transport = "sse" ))
194+
194195 if not self .chat or not self .chat .assistant :
195196 raise ValueError ("Chat configuration or assistant is not properly set" )
196197
@@ -232,13 +233,13 @@ async def chat_interface(request: Request) -> HTMLResponse:
232233
233234 if self .workflows :
234235 session_type = "workflow"
235- executor_id = self .workflows [0 ].id if hasattr (self .workflows [0 ], 'id' ) else ""
236+ executor_id = self .workflows [0 ].id if hasattr (self .workflows [0 ], "id" ) else ""
236237 elif self .agents :
237238 session_type = "agent"
238- executor_id = self .agents [0 ].id if hasattr (self .agents [0 ], 'id' ) else ""
239+ executor_id = self .agents [0 ].id if hasattr (self .agents [0 ], "id" ) else ""
239240 elif self .teams :
240241 session_type = "team"
241- executor_id = self .teams [0 ].id if hasattr (self .teams [0 ], 'id' ) else ""
242+ executor_id = self .teams [0 ].id if hasattr (self .teams [0 ], "id" ) else ""
242243
243244 # Create the response using render_template which returns a TemplateResponse
244245 response = self .render_template (
@@ -744,7 +745,7 @@ async def executor_runs(request: Request) -> Dict[str, Any]:
744745 return {
745746 "error" : "Missing required field: 'message'" ,
746747 "status" : "error" ,
747- "code" : 400
748+ "code" : 400 ,
748749 }
749750
750751 # Get the runner from the assistant config
@@ -807,64 +808,93 @@ async def executor_runs(request: Request) -> Dict[str, Any]:
807808 }
808809
809810 @router_os .get ("/sessions/{session_id}/runs" , include_in_schema = False )
810- async def get_session_runs (session_id : str ) -> List [Dict [str , Any ]]:
811+ async def get_session_runs (session_id : str , request : Request ) -> List [Dict [str , Any ]]:
811812 """Get all runs for a session."""
812813 try :
813814 # Get the runner from the assistant config
814815 runner = self .chat .assistant .runner
815-
816+
816817 # Check if the runner has a database
817- if not hasattr (runner , 'db' ) or runner .db is None :
818+ if not hasattr (runner , "db" ) or runner .db is None :
818819 logger .debug (f"No database configured for runner, returning empty list for session { session_id } " )
819820 return []
820-
821+
822+ # Get session type from query params if provided
823+ session_type = request .query_params .get ("type" )
824+
821825 # Get the session from the database - try different session types
822826 session = None
823- for session_type in ["workflow" , "agent" , "team" ]:
827+ if session_type :
828+ # If type is specified, only try that type
824829 try :
825830 session = runner .db .get_session (session_id , session_type )
826- if session :
827- break
828831 except Exception :
829- continue
832+ pass
833+ else :
834+ # Otherwise try all types
835+ for st in ["agent" , "workflow" , "team" ]:
836+ try :
837+ session = runner .db .get_session (session_id , st )
838+ if session :
839+ break
840+ except Exception :
841+ continue
830842
831843 if not session :
832844 logger .debug (f"No session found for { session_id } " )
833845 return []
834-
846+
835847 # Extract runs from the session
836848 runs = []
837- if hasattr (session , ' agent_runs' ) :
849+ if hasattr (session , " agent_runs" ) and session . agent_runs :
838850 # For agent sessions
839851 for run in session .agent_runs :
840- runs .append ({
841- "run_id" : run .run_id ,
842- "session_id" : session_id ,
843- "input" : run .user_message ,
844- "output" : run .response ,
845- "created_at" : run .created_at .isoformat () if hasattr (run .created_at , 'isoformat' ) else str (run .created_at ),
846- })
847- elif hasattr (session , 'workflow_runs' ):
852+ runs .append (
853+ {
854+ "run_id" : run .run_id ,
855+ "session_id" : session_id ,
856+ "input" : getattr (run , "user_message" , getattr (run , "input" , "" )),
857+ "output" : getattr (run , "response" , getattr (run , "output" , "" )),
858+ "created_at" : (
859+ run .created_at .isoformat ()
860+ if hasattr (run .created_at , "isoformat" )
861+ else str (run .created_at )
862+ ),
863+ }
864+ )
865+ elif hasattr (session , "workflow_runs" ) and session .workflow_runs :
848866 # For workflow sessions
849867 for run in session .workflow_runs :
850- runs .append ({
851- "run_id" : run .run_id ,
852- "session_id" : session_id ,
853- "input" : run .input ,
854- "output" : run .output ,
855- "created_at" : run .created_at .isoformat () if hasattr (run .created_at , 'isoformat' ) else str (run .created_at ),
856- })
857- elif hasattr (session , 'team_runs' ):
868+ runs .append (
869+ {
870+ "run_id" : run .run_id ,
871+ "session_id" : session_id ,
872+ "input" : getattr (run , "input" , getattr (run , "user_message" , "" )),
873+ "output" : getattr (run , "output" , getattr (run , "response" , "" )),
874+ "created_at" : (
875+ run .created_at .isoformat ()
876+ if hasattr (run .created_at , "isoformat" )
877+ else str (run .created_at )
878+ ),
879+ }
880+ )
881+ elif hasattr (session , "team_runs" ) and session .team_runs :
858882 # For team sessions
859883 for run in session .team_runs :
860- runs .append ({
861- "run_id" : run .run_id ,
862- "session_id" : session_id ,
863- "input" : run .input ,
864- "output" : run .output ,
865- "created_at" : run .created_at .isoformat () if hasattr (run .created_at , 'isoformat' ) else str (run .created_at ),
866- })
867-
884+ runs .append (
885+ {
886+ "run_id" : run .run_id ,
887+ "session_id" : session_id ,
888+ "input" : getattr (run , "input" , getattr (run , "user_message" , "" )),
889+ "output" : getattr (run , "output" , getattr (run , "response" , "" )),
890+ "created_at" : (
891+ run .created_at .isoformat ()
892+ if hasattr (run .created_at , "isoformat" )
893+ else str (run .created_at )
894+ ),
895+ }
896+ )
897+
868898 logger .debug (f"Retrieved { len (runs )} runs for session { session_id } " )
869899 return runs
870900
0 commit comments