Creating an SSE server as a web app
The big difference compared to using the STDIO transport is that we need to expose an SSE server as a web application. Depending on whether we use Python or TypeScript, that means we need to implement the necessary HTTP endpoints.
Specifically for Python, we need to leverage a framework supporting Asynchronous Server Gateway Interface (ASGI). ASGI is a specification that allows Python web frameworks to handle asynchronous and synchronous code, making it ideal for modern web applications. Let us look at Starlette.
Starlette
Starlette is a lightweight ASGI framework that we will use to build our SSE server. Previously, we mentioned endpoints that needed to be implemented, and Starlette will help us with that. It provides a simple way to create an ASGI application and handle routing, middleware, and other features.
Let’s look at how Starlette works and then explain in more detail how to build an SSE server using it.
A typical...