From d88b3ddc4a3d2cafda4cd241df57ae0ca037b522 Mon Sep 17 00:00:00 2001 From: yevhen-m Date: Fri, 18 Jul 2025 16:15:36 +0300 Subject: [PATCH] Add get_comment_by_id tool response wrapper schema to avoid $ref in response schema --- src/reddit_mcp/tools/get_comments.py | 10 ++++++++-- tests/test_reddit_tools.py | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/reddit_mcp/tools/get_comments.py b/src/reddit_mcp/tools/get_comments.py index 6c9f8fd..1270f76 100644 --- a/src/reddit_mcp/tools/get_comments.py +++ b/src/reddit_mcp/tools/get_comments.py @@ -70,8 +70,13 @@ def get_comments_by_submission( ] +class GetCommentResponse(BaseModel): + """Response wrapper for get_comment_by_id""" + comment: CommentResult + + @validate_call(validate_return=True) -def get_comment_by_id(comment_id: str) -> CommentResult: +def get_comment_by_id(comment_id: str) -> GetCommentResponse: """ Retrieve a specific comment by ID. @@ -82,4 +87,5 @@ def get_comment_by_id(comment_id: str) -> CommentResult: Comment details with any replies """ client = RedditClient.get_instance() - return comment_to_model(client.reddit.comment(comment_id)) + comment = comment_to_model(client.reddit.comment(comment_id)) + return GetCommentResponse(comment=comment) diff --git a/tests/test_reddit_tools.py b/tests/test_reddit_tools.py index 4913f33..c67e864 100644 --- a/tests/test_reddit_tools.py +++ b/tests/test_reddit_tools.py @@ -67,7 +67,9 @@ def test_get_comments(): assert isinstance(comments[0].body, str) # Test getting single comment - comment = get_comment_by_id("mgmk7d2") + response = get_comment_by_id("mgmk7d2") + assert hasattr(response, 'comment') + comment = response.comment assert isinstance(comment, CommentResult) assert isinstance(comment.id, str) assert isinstance(comment.body, str)