1515
1616import requests
1717from bs4 import BeautifulSoup
18+ from mcp import ServerSession
1819from mcp .server import FastMCP
1920from mcp .server .fastmcp import Context
2021from pydantic import Field , BaseModel
@@ -80,7 +81,7 @@ def server(
8081
8182 @mcp .tool ()
8283 async def get_transcript (
83- ctx : Context ,
84+ ctx : Context [ ServerSession , AppContext ] ,
8485 url : str = Field (description = "The URL of the YouTube video" ),
8586 lang : str = Field (description = "The preferred language for the transcript" , default = "en" ),
8687 next_cursor : str | None = Field (description = "Cursor to retrieve the next page of the transcript" , default = None ),
@@ -95,8 +96,7 @@ async def get_transcript(
9596 raise ValueError (f"couldn't find a video ID from the provided URL: { url } ." )
9697 video_id = q [0 ]
9798
98- app_ctx : AppContext = ctx .request_context .lifespan_context # type: ignore
99- title , transcripts = _get_transcript (app_ctx , video_id , lang )
99+ title , transcripts = _get_transcript (ctx .request_context .lifespan_context , video_id , lang )
100100
101101 if response_limit is None or response_limit <= 0 :
102102 return Transcript (title = title , transcript = "\n " .join (transcripts ))
0 commit comments