@@ -42,38 +42,66 @@ def _format_page(p: dict[str, Any]) -> dict[str, Any]:
4242def _register_read_tools (mcp : FastMCP ) -> None :
4343 @mcp .tool (annotations = READONLY )
4444 @require_permission (PermissionLevel .READ )
45- async def list_collectives () -> str :
46- """List all collectives the current user has access to.
45+ async def list_collectives (limit : int = 50 , offset : int = 0 ) -> str :
46+ """List collectives the current user has access to.
4747
4848 Collectives are shared knowledge bases with wiki-style pages.
49- Each collective has a landing page and may contain nested subpages.
49+
50+ Args:
51+ limit: Maximum number of collectives to return (1-200, default 50).
52+ offset: Number of collectives to skip for pagination (default 0).
5053
5154 Returns:
52- JSON list of collectives with id, name, emoji, permissions.
55+ JSON with "data" (list of collectives with id, name, emoji, permissions)
56+ and "pagination" (count, offset, limit, has_more).
5357 """
58+ limit = max (1 , min (200 , limit ))
59+ offset = max (0 , offset )
5460 client = get_client ()
5561 data = await client .ocs_get (f"{ API } /collectives" )
56- collectives = [_format_collective (c ) for c in data ["collectives" ]]
57- return json .dumps (collectives , default = str )
62+ all_collectives = [_format_collective (c ) for c in data ["collectives" ]]
63+ page = all_collectives [offset : offset + limit ]
64+ has_more = offset + limit < len (all_collectives )
65+
66+ return json .dumps (
67+ {
68+ "data" : page ,
69+ "pagination" : {"count" : len (page ), "offset" : offset , "limit" : limit , "has_more" : has_more },
70+ },
71+ default = str ,
72+ )
5873
5974 @mcp .tool (annotations = READONLY )
6075 @require_permission (PermissionLevel .READ )
61- async def get_collective_pages (collective_id : int ) -> str :
62- """List all pages in a collective.
76+ async def get_collective_pages (collective_id : int , limit : int = 50 , offset : int = 0 ) -> str :
77+ """List pages in a collective.
6378
64- Returns the full page tree including the landing page and all subpages.
65- Each page has a title, emoji, timestamp, size, and file path.
79+ Returns the page tree including the landing page and all subpages.
6680
6781 Args:
6882 collective_id: The numeric collective ID. Use list_collectives to find IDs.
83+ limit: Maximum number of pages to return (1-200, default 50).
84+ offset: Number of pages to skip for pagination (default 0).
6985
7086 Returns:
71- JSON list of pages with id, title, emoji, timestamp, size, file_name, file_path.
87+ JSON with "data" (list of pages with id, title, emoji, timestamp, size)
88+ and "pagination" (count, offset, limit, has_more).
7289 """
90+ limit = max (1 , min (200 , limit ))
91+ offset = max (0 , offset )
7392 client = get_client ()
7493 data = await client .ocs_get (f"{ API } /collectives/{ collective_id } /pages" )
75- pages = [_format_page (p ) for p in data ["pages" ]]
76- return json .dumps (pages , default = str )
94+ all_pages = [_format_page (p ) for p in data ["pages" ]]
95+ page = all_pages [offset : offset + limit ]
96+ has_more = offset + limit < len (all_pages )
97+
98+ return json .dumps (
99+ {
100+ "data" : page ,
101+ "pagination" : {"count" : len (page ), "offset" : offset , "limit" : limit , "has_more" : has_more },
102+ },
103+ default = str ,
104+ )
77105
78106 @mcp .tool (annotations = READONLY )
79107 @require_permission (PermissionLevel .READ )
0 commit comments