55import importlib
66from itertools import starmap
77
8+ import jsonschema
89from tornado .gen import multi
910from traitlets import Any , Bool , Dict , HasTraits , Instance , List , Unicode , default , observe
1011from traitlets import validate as validate_trait
1112from traitlets .config import LoggingConfigurable
12- import jsonschema
13-
1413
1514from .config import ExtensionConfigManager
1615from .utils import ExtensionMetadataError , ExtensionModuleNotFound , get_loader , get_metadata
1716
18-
1917# probably this should go in it's own file? Not sure where though
2018MCP_TOOL_SCHEMA = {
2119 "type" : "object" ,
2725 "properties" : {
2826 "type" : {"type" : "string" , "enum" : ["object" ]},
2927 "properties" : {"type" : "object" },
30- "required" : {"type" : "array" , "items" : {"type" : "string" }}
28+ "required" : {"type" : "array" , "items" : {"type" : "string" }},
3129 },
32- "required" : ["type" , "properties" ]
30+ "required" : ["type" , "properties" ],
3331 },
3432 "annotations" : {
3533 "type" : "object" ,
3836 "readOnlyHint" : {"type" : "boolean" },
3937 "destructiveHint" : {"type" : "boolean" },
4038 "idempotentHint" : {"type" : "boolean" },
41- "openWorldHint" : {"type" : "boolean" }
39+ "openWorldHint" : {"type" : "boolean" },
4240 },
43- "additionalProperties" : True
44- }
41+ "additionalProperties" : True ,
42+ },
4543 },
4644 "required" : ["name" , "inputSchema" ],
47- "additionalProperties" : False
45+ "additionalProperties" : False ,
4846}
4947
48+
5049class ExtensionPoint (HasTraits ):
5150 """A simple API for connecting to a Jupyter Server extension
5251 point defined by metadata and importable from a Python package.
@@ -129,9 +128,9 @@ def name(self):
129128 def module (self ):
130129 """The imported module (using importlib.import_module)"""
131130 return self ._module
132-
131+
133132 @property
134- def tools (self ):
133+ def tools (self ):
135134 """Structured tools exposed by this extension point, if any."""
136135 loc = self .app or self .module
137136 if not loc :
@@ -149,7 +148,7 @@ def tools(self):
149148 jsonschema .validate (instance = tool ["metadata" ], schema = MCP_TOOL_SCHEMA )
150149 tools [name ] = tool
151150 except Exception as e :
152- # not sure if this should fail quietly, raise an error, or log it?
151+ # not sure if this should fail quietly, raise an error, or log it?
153152 print (f"[tool-discovery] Failed to load tools from { self .module_name } : { e } " )
154153 return tools
155154
@@ -167,7 +166,6 @@ def _get_linker(self):
167166 )
168167 return linker
169168
170-
171169 def _get_loader (self ):
172170 """Get a loader."""
173171 loc = self .app
@@ -500,7 +498,6 @@ def load_all_extensions(self):
500498 for name in self .sorted_extensions :
501499 self .load_extension (name )
502500
503-
504501 def get_tools (self ) -> Dict [str , Any ]:
505502 """Aggregate tools from all extensions that expose them."""
506503 all_tools = {}
0 commit comments