Skip to content

Commit 2dabc4a

Browse files
committed
refactor: update get_transcript method to improve context type handling
1 parent e20582d commit 2dabc4a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/mcp_youtube_transcript/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import requests
1717
from bs4 import BeautifulSoup
18+
from mcp import ServerSession
1819
from mcp.server import FastMCP
1920
from mcp.server.fastmcp import Context
2021
from 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

Comments
 (0)