Skip to content

Commit 715e76e

Browse files
committed
moved ListToolInforHandler to separate service, fixed doc strings, cleaned up comments
1 parent 56b1bfd commit 715e76e

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

jupyter_server/extension/manager.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,11 @@ def module(self):
130130
return self._module
131131

132132
@property
133-
def tools(self):
134-
"""Structured tools exposed by this extension point, if any."""
133+
def tools(self):
134+
"""Structured tools exposed by this extension point, if any.
135+
136+
Searches for a `jupyter_server_extension_tools` function on the extension module or app.
137+
"""
135138
loc = self.app or self.module
136139
if not loc:
137140
return {}
@@ -499,15 +502,15 @@ def load_all_extensions(self):
499502
self.load_extension(name)
500503

501504
def get_tools(self) -> Dict[str, Any]:
502-
"""Aggregate tools from all extensions that expose them."""
505+
"""Aggregate and return structured tools (with metadata) from all enabled extensions."""
503506
all_tools = {}
504507

505508
for ext_name, ext_pkg in self.extensions.items():
506509
if not ext_pkg.enabled:
507510
continue
508511

509512
for point in ext_pkg.extension_points.values():
510-
for name, tool in point.tools.items(): # <— new property!
513+
for name, tool in point.tools.items():
511514
if name in all_tools:
512515
raise ValueError(f"Duplicate tool name detected: '{name}'")
513516
all_tools[name] = tool

jupyter_server/serverapp.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,8 +2540,9 @@ def load_server_extensions(self) -> None:
25402540
"""
25412541
self.extension_manager.load_all_extensions()
25422542

2543-
# is this how I would expose it? and Is this a good name?
2544-
def get_tools(self):
2543+
2544+
def get_tools(self):
2545+
"""Aggregate and return tools + tool metadata from all the extensions that expose them."""
25452546
return self.extension_manager.get_tools()
25462547

25472548
def init_mime_overrides(self) -> None:

jupyter_server/services/contents/handlers.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -424,13 +424,6 @@ async def post(self, path=""):
424424
self.finish()
425425

426426

427-
# Somehow this doesn't feel like the right service for this to go in?
428-
class ListToolInfoHandler(APIHandler):
429-
@web.authenticated
430-
async def get(self):
431-
tools = self.serverapp.extension_manager.discover_tools()
432-
self.finish({"discovered_tools": tools})
433-
434427

435428
# -----------------------------------------------------------------------------
436429
# URL to handler mappings
@@ -449,5 +442,4 @@ async def get(self):
449442
(r"/api/contents%s/trust" % path_regex, TrustNotebooksHandler),
450443
(r"/api/contents%s" % path_regex, ContentsHandler),
451444
(r"/api/notebooks/?(.*)", NotebooksRedirectHandler),
452-
(r"/api/tools", ListToolInfoHandler),
453445
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from tornado import web
2+
from jupyter_server.base.handlers import APIHandler
3+
4+
class ListToolInfoHandler(APIHandler):
5+
@web.authenticated
6+
async def get(self):
7+
tools = self.serverapp.extension_manager.discover_tools()
8+
self.finish({"discovered_tools": tools})
9+
10+
11+
12+
default_handlers = [
13+
(r"/api/tools", ListToolInfoHandler),
14+
]

0 commit comments

Comments
 (0)