1717
1818from mcp_youtube_transcript import Transcript
1919
20- params = StdioServerParameters (command = "uv" , args = ["run" , "mcp-youtube-transcript" ])
21-
2220
2321def fetch_title (url : str , lang : str ) -> str :
2422 res = requests .get (f"https://www.youtube.com/watch?v={ url } " , headers = {"Accept-Language" : lang })
@@ -28,6 +26,7 @@ def fetch_title(url: str, lang: str) -> str:
2826
2927@pytest .fixture (scope = "module" )
3028async def mcp_client_session () -> AsyncGenerator [ClientSession , None ]:
29+ params = StdioServerParameters (command = "uv" , args = ["run" , "mcp-youtube-transcript" , "--response-limit" , "-1" ])
3130 async with stdio_client (params ) as streams :
3231 async with ClientSession (streams [0 ], streams [1 ]) as session :
3332 await session .initialize ()
@@ -49,7 +48,8 @@ async def test_get_transcript(mcp_client_session: ClientSession) -> None:
4948
5049 title = fetch_title (video_id , "en" )
5150 expect = Transcript (
52- title = title , transcript = "\n " .join ((item .text for item in YouTubeTranscriptApi ().fetch (video_id )))
51+ title = title ,
52+ transcript = "\n " .join ((item .text for item in YouTubeTranscriptApi ().fetch (video_id ))),
5353 )
5454
5555 res = await mcp_client_session .call_tool (
@@ -72,7 +72,8 @@ async def test_get_transcript_with_language(mcp_client_session: ClientSession) -
7272
7373 title = fetch_title (video_id , "ja" )
7474 expect = Transcript (
75- title = title , transcript = "\n " .join ((item .text for item in YouTubeTranscriptApi ().fetch (video_id , ["ja" ])))
75+ title = title ,
76+ transcript = "\n " .join ((item .text for item in YouTubeTranscriptApi ().fetch (video_id , ["ja" ]))),
7677 )
7778
7879 res = await mcp_client_session .call_tool (
@@ -97,7 +98,8 @@ async def test_get_transcript_fallback_language(
9798
9899 title = fetch_title (video_id , "en" )
99100 expect = Transcript (
100- title = title , transcript = "\n " .join ((item .text for item in YouTubeTranscriptApi ().fetch (video_id )))
101+ title = title ,
102+ transcript = "\n " .join ((item .text for item in YouTubeTranscriptApi ().fetch (video_id ))),
101103 )
102104
103105 res = await mcp_client_session .call_tool (
@@ -140,7 +142,8 @@ async def test_get_transcript_with_short_url(mcp_client_session: ClientSession)
140142
141143 title = fetch_title (video_id , "en" )
142144 expect = Transcript (
143- title = title , transcript = "\n " .join ((item .text for item in YouTubeTranscriptApi ().fetch (video_id )))
145+ title = title ,
146+ transcript = "\n " .join ((item .text for item in YouTubeTranscriptApi ().fetch (video_id ))),
144147 )
145148
146149 res = await mcp_client_session .call_tool (
@@ -152,3 +155,44 @@ async def test_get_transcript_with_short_url(mcp_client_session: ClientSession)
152155 transcript = Transcript .model_validate_json (res .content [0 ].text )
153156 assert transcript == expect
154157 assert not res .isError
158+
159+
160+ @pytest .fixture (scope = "module" )
161+ async def mcp_client_session_with_response_limit () -> AsyncGenerator [ClientSession , None ]:
162+ params = StdioServerParameters (command = "uv" , args = ["run" , "mcp-youtube-transcript" , "--response-limit" , "3000" ])
163+ async with stdio_client (params ) as streams :
164+ async with ClientSession (streams [0 ], streams [1 ]) as session :
165+ await session .initialize ()
166+ yield session
167+
168+
169+ @pytest .mark .skipif (os .getenv ("CI" ) == "true" , reason = "Skipping this test on CI" )
170+ @pytest .mark .default_cassette ("LPZh9BOjkQs.yaml" )
171+ @pytest .mark .vcr
172+ @pytest .mark .anyio
173+ async def test_get_transcript_with_response_limit (mcp_client_session_with_response_limit : ClientSession ) -> None :
174+ video_id = "LPZh9BOjkQs"
175+
176+ expect = Transcript (
177+ title = fetch_title (video_id , "en" ),
178+ transcript = "\n " .join ((item .text for item in YouTubeTranscriptApi ().fetch (video_id ))),
179+ )
180+
181+ transcript = ""
182+ cursor = None
183+ while True :
184+ res = await mcp_client_session_with_response_limit .call_tool (
185+ "get_transcript" ,
186+ arguments = {"url" : f"https://www.youtube.com/watch?v={ video_id } " , "next_cursor" : cursor },
187+ )
188+ assert not res .isError
189+ assert isinstance (res .content [0 ], TextContent )
190+
191+ t = Transcript .model_validate_json (res .content [0 ].text )
192+ transcript += t .transcript + "\n "
193+ if t .next_cursor is None :
194+ break
195+ cursor = t .next_cursor
196+
197+ assert t .title == expect .title
198+ assert transcript [:- 1 ] == expect .transcript
0 commit comments