Advertisement
justinooo

SSE MCP Log Test

May 7th, 2025
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. from fastapi import FastAPI
  2. from mcp.server.fastmcp import FastMCP, Context
  3. import argparse
  4. import asyncio
  5. import uvicorn
  6.  
  7. app = FastAPI()
  8. mcp = FastMCP("sse_log_test")
  9.  
  10.  
  11. @mcp.tool()
  12. async def log_test(ctx: Context):
  13.     """Log testing tool."""
  14.     await ctx.session.send_log_message("info", "Initial log message")
  15.     await asyncio.sleep(2)
  16.     await ctx.session.send_log_message("info", "Delayed log message")
  17.     return {"status": "Logging completed"}
  18.  
  19. app.mount("/", mcp.sse_app())
  20.  
  21.  
  22. def main():
  23.     parser = argparse.ArgumentParser(
  24.         description="Run Simple SSE Logger server")
  25.     parser.add_argument("--port", type=int, default=8888,
  26.                         help="Port to run the server on")
  27.     parser.add_argument("--host", type=str, default="0.0.0.0",
  28.                         help="Host to bind the server to")
  29.     args = parser.parse_args()
  30.     uvicorn.run(app, host=args.host, port=args.port)
  31.  
  32.  
  33. if __name__ == "__main__":
  34.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement