get_all_topic_posts
Fetch all posts from a USCardForum topic with automatic pagination, supporting range selection and safety limits for large discussions.
Instructions
Fetch all posts from a topic with automatic pagination.
Args:
topic_id: The numeric topic ID
include_raw: Include markdown source (default: False)
start_post_number: First post to fetch (default: 1)
end_post_number: Last post to fetch (optional, fetches to end if not set)
max_posts: Maximum number of posts to return (optional safety limit)
This automatically handles pagination to fetch multiple batches.
IMPORTANT: For topics with many posts (>100), use max_posts to limit
the response size. You can always fetch more with start_post_number.
Use cases:
- Fetch entire small topic: get_all_topic_posts(topic_id=123)
- Fetch first 50 posts: get_all_topic_posts(topic_id=123, max_posts=50)
- Fetch posts 51-100: get_all_topic_posts(topic_id=123, start_post_number=51, max_posts=50)
- Fetch specific range: get_all_topic_posts(topic_id=123, start=10, end=30)
Returns the same Post structure as get_topic_posts but for all matching posts.
Pro tip: Use get_topic_info first to check post_count before deciding
whether to fetch all or paginate manually.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| topic_id | Yes | The numeric topic ID | |
| include_raw | No | Include markdown source (default: False) | |
| start_post_number | No | First post to fetch (default: 1) | |
| end_post_number | No | Last post to fetch (optional, fetches to end if not set) | |
| max_posts | No | Maximum number of posts to return (optional safety limit) |
Implementation Reference
- The primary MCP tool handler for 'get_all_topic_posts'. Decorated with @mcp.tool(), defines input schema using Pydantic Annotated Fields, includes comprehensive docstring with usage examples, and delegates execution to DiscourseClient.get_all_topic_posts() via get_client().@mcp.tool() def get_all_topic_posts( topic_id: Annotated[ int, Field(description="The numeric topic ID"), ], include_raw: Annotated[ bool, Field(default=False, description="Include markdown source (default: False)"), ] = False, start_post_number: Annotated[ int, Field(default=1, description="First post to fetch (default: 1)"), ] = 1, end_post_number: Annotated[ int | None, Field(default=None, description="Last post to fetch (optional, fetches to end if not set)"), ] = None, max_posts: Annotated[ int | None, Field(default=None, description="Maximum number of posts to return (optional safety limit)"), ] = None, ) -> list[Post]: """ Fetch all posts from a topic with automatic pagination. Args: topic_id: The numeric topic ID include_raw: Include markdown source (default: False) start_post_number: First post to fetch (default: 1) end_post_number: Last post to fetch (optional, fetches to end if not set) max_posts: Maximum number of posts to return (optional safety limit) This automatically handles pagination to fetch multiple batches. IMPORTANT: For topics with many posts (>100), use max_posts to limit the response size. You can always fetch more with start_post_number. Use cases: - Fetch entire small topic: get_all_topic_posts(topic_id=123) - Fetch first 50 posts: get_all_topic_posts(topic_id=123, max_posts=50) - Fetch posts 51-100: get_all_topic_posts(topic_id=123, start_post_number=51, max_posts=50) - Fetch specific range: get_all_topic_posts(topic_id=123, start=10, end=30) Returns the same Post structure as get_topic_posts but for all matching posts. Pro tip: Use get_topic_info first to check post_count before deciding whether to fetch all or paginate manually. """ return get_client().get_all_topic_posts( topic_id, include_raw=include_raw, start_post_number=start_post_number, end_post_number=end_post_number, max_posts=max_posts, )
- src/uscardforum/client.py:232-260 (helper)Client wrapper method in DiscourseClient that delegates get_all_topic_posts to the TopicsAPI implementation, handling the high-level interface for the forum client.def get_all_topic_posts( self, topic_id: int, *, include_raw: bool = False, start_post_number: int = 1, end_post_number: int | None = None, max_posts: int | None = None, ) -> list[Post]: """Fetch all posts in a topic with automatic pagination. Args: topic_id: Topic ID include_raw: Include raw markdown (default: False) start_post_number: Starting post number (default: 1) end_post_number: Optional ending post number max_posts: Optional maximum posts to fetch Returns: List of all matching posts """ return self._topics.get_all_topic_posts( topic_id, include_raw=include_raw, start_post_number=start_post_number, end_post_number=end_post_number, max_posts=max_posts, )
- Core implementation of get_all_topic_posts in TopicsAPI. Performs automatic pagination by repeatedly calling get_topic_posts(), handles limits, ranges, deduplication, and sorting of Post objects.def get_all_topic_posts( self, topic_id: int, *, include_raw: bool = False, start_post_number: int = 1, end_post_number: int | None = None, max_posts: int | None = None, ) -> list[Post]: """Fetch all posts in a topic with automatic pagination. Args: topic_id: Topic ID include_raw: Include raw markdown (default: False) start_post_number: Starting post number (default: 1) end_post_number: Optional ending post number max_posts: Optional maximum posts to fetch Returns: List of all matching posts """ current = max(1, int(start_post_number)) collected: list[Post] = [] seen_numbers: set[int] = set() while True: if max_posts is not None and len(collected) >= int(max_posts): break batch = self.get_topic_posts( topic_id, post_number=current, include_raw=include_raw ) if not batch: break last_in_batch: int | None = None for post in batch: pn = post.post_number if pn not in seen_numbers: if end_post_number is not None and pn > int(end_post_number): last_in_batch = last_in_batch or pn continue seen_numbers.add(pn) collected.append(post) last_in_batch = pn if max_posts is not None and len(collected) >= int(max_posts): break if last_in_batch is None: break current = last_in_batch + 1 if end_post_number is not None and current > int(end_post_number): break collected.sort(key=lambda p: p.post_number) return collected
- src/uscardforum/server_tools/__init__.py:32-103 (registration)Imports the get_all_topic_posts tool from .topics and includes it in __all__ for re-export, making it available when importing from server_tools.from .topics import get_topic_info, get_topic_posts, get_all_topic_posts # ============================================================================= # 👤 Users — Profile & activity research # ============================================================================= from .users import ( get_user_summary, get_user_topics, get_user_replies, get_user_actions, get_user_badges, get_user_following, get_user_followers, get_user_reactions, list_users_with_badge, ) # ============================================================================= # 🔐 Auth — Authenticated actions (requires login) # ============================================================================= from .auth import ( login, get_current_session, get_notifications, bookmark_post, subscribe_topic, ) # ============================================================================= # Prompts & Resources # ============================================================================= from .prompts import analyze_user, compare_cards, find_data_points, research_topic from .resources import resource_categories, resource_hot_topics, resource_new_topics __all__ = [ # 📰 Discovery "get_hot_topics", "get_new_topics", "get_top_topics", "search_forum", "get_categories", # 📖 Reading "get_topic_info", "get_topic_posts", "get_all_topic_posts", # 👤 Users "get_user_summary", "get_user_topics", "get_user_replies", "get_user_actions", "get_user_badges", "get_user_following", "get_user_followers", "get_user_reactions", "list_users_with_badge", # 🔐 Auth "login", "get_current_session", "get_notifications", "bookmark_post", "subscribe_topic", # Prompts "analyze_user", "compare_cards", "find_data_points", "research_topic", # Resources "resource_categories", "resource_hot_topics", "resource_new_topics", ]
- src/uscardforum/server.py:15-85 (registration)Imports and re-exports get_all_topic_posts in the main server entrypoint module, ensuring the tool is available in the MCP server context.from uscardforum.server_tools import ( analyze_user, bookmark_post, compare_cards, find_data_points, get_all_topic_posts, get_categories, get_current_session, get_hot_topics, get_new_topics, get_notifications, get_top_topics, get_topic_info, get_topic_posts, get_user_actions, get_user_badges, get_user_followers, get_user_following, get_user_reactions, get_user_replies, get_user_summary, get_user_topics, list_users_with_badge, login, research_topic, resource_categories, resource_hot_topics, resource_new_topics, search_forum, subscribe_topic, ) __all__ = [ "MCP_HOST", "MCP_PORT", "MCP_TRANSPORT", "NITAN_TOKEN", "SERVER_INSTRUCTIONS", "get_client", "main", "mcp", "analyze_user", "bookmark_post", "compare_cards", "find_data_points", "get_all_topic_posts", "get_categories", "get_current_session", "get_hot_topics", "get_new_topics", "get_notifications", "get_top_topics", "get_topic_info", "get_topic_posts", "get_user_actions", "get_user_badges", "get_user_followers", "get_user_following", "get_user_reactions", "get_user_replies", "get_user_summary", "get_user_topics", "list_users_with_badge", "login", "resource_categories", "resource_hot_topics", "resource_new_topics", "search_forum", "subscribe_topic", "research_topic", ]