1515from mcp .types import TextContent
1616from youtube_transcript_api import YouTubeTranscriptApi
1717
18+ from mcp_youtube_transcript import Transcript
19+
1820params = StdioServerParameters (command = "uv" , args = ["run" , "mcp-youtube-transcript" ])
1921
2022
@@ -44,14 +46,18 @@ async def test_get_transcript(mcp_client_session: ClientSession) -> None:
4446 video_id = "LPZh9BOjkQs"
4547
4648 title = fetch_title (video_id , "en" )
47- expect = f"# { title } \n " + "\n " .join ((item .text for item in YouTubeTranscriptApi ().fetch (video_id )))
49+ expect = Transcript (
50+ title = title , transcript = "\n " .join ((item .text for item in YouTubeTranscriptApi ().fetch (video_id )))
51+ )
4852
4953 res = await mcp_client_session .call_tool (
5054 "get_transcript" ,
5155 arguments = {"url" : f"https//www.youtube.com/watch?v={ video_id } " },
5256 )
5357 assert isinstance (res .content [0 ], TextContent )
54- assert res .content [0 ].text == expect
58+
59+ transcript = Transcript .model_validate_json (res .content [0 ].text )
60+ assert transcript == expect
5561 assert not res .isError
5662
5763
@@ -61,14 +67,18 @@ async def test_get_transcript_with_language(mcp_client_session: ClientSession) -
6167 video_id = "WjAXZkQSE2U"
6268
6369 title = fetch_title (video_id , "ja" )
64- expect = f"# { title } \n " + "\n " .join ((item .text for item in YouTubeTranscriptApi ().fetch (video_id , ["ja" ])))
70+ expect = Transcript (
71+ title = title , transcript = "\n " .join ((item .text for item in YouTubeTranscriptApi ().fetch (video_id , ["ja" ])))
72+ )
6573
6674 res = await mcp_client_session .call_tool (
6775 "get_transcript" ,
6876 arguments = {"url" : f"https//www.youtube.com/watch?v={ video_id } " , "lang" : "ja" },
6977 )
7078 assert isinstance (res .content [0 ], TextContent )
71- assert res .content [0 ].text == expect
79+
80+ transcript = Transcript .model_validate_json (res .content [0 ].text )
81+ assert transcript == expect
7282 assert not res .isError
7383
7484
@@ -80,7 +90,9 @@ async def test_get_transcript_fallback_language(
8090 video_id = "LPZh9BOjkQs"
8191
8292 title = fetch_title (video_id , "en" )
83- expect = f"# { title } \n " + "\n " .join ((item .text for item in YouTubeTranscriptApi ().fetch (video_id )))
93+ expect = Transcript (
94+ title = title , transcript = "\n " .join ((item .text for item in YouTubeTranscriptApi ().fetch (video_id )))
95+ )
8496
8597 res = await mcp_client_session .call_tool (
8698 "get_transcript" ,
@@ -90,7 +102,9 @@ async def test_get_transcript_fallback_language(
90102 },
91103 )
92104 assert isinstance (res .content [0 ], TextContent )
93- assert res .content [0 ].text == expect
105+
106+ transcript = Transcript .model_validate_json (res .content [0 ].text )
107+ assert transcript == expect
94108 assert not res .isError
95109
96110
@@ -115,12 +129,16 @@ async def test_get_transcript_with_short_url(mcp_client_session: ClientSession)
115129 video_id = "LPZh9BOjkQs"
116130
117131 title = fetch_title (video_id , "en" )
118- expect = f"# { title } \n " + "\n " .join ((item .text for item in YouTubeTranscriptApi ().fetch (video_id )))
132+ expect = Transcript (
133+ title = title , transcript = "\n " .join ((item .text for item in YouTubeTranscriptApi ().fetch (video_id )))
134+ )
119135
120136 res = await mcp_client_session .call_tool (
121137 "get_transcript" ,
122138 arguments = {"url" : f"https://youtu.be/{ video_id } " },
123139 )
124140 assert isinstance (res .content [0 ], TextContent )
125- assert res .content [0 ].text == expect
141+
142+ transcript = Transcript .model_validate_json (res .content [0 ].text )
143+ assert transcript == expect
126144 assert not res .isError
0 commit comments