libentry 1.23.3__py3-none-any.whl → 1.23.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- libentry/mcp/api.py +8 -2
- libentry/mcp/service.py +22 -17
- {libentry-1.23.3.dist-info → libentry-1.23.4.dist-info}/METADATA +1 -1
- {libentry-1.23.3.dist-info → libentry-1.23.4.dist-info}/RECORD +9 -9
- {libentry-1.23.3.dist-info → libentry-1.23.4.dist-info}/LICENSE +0 -0
- {libentry-1.23.3.dist-info → libentry-1.23.4.dist-info}/WHEEL +0 -0
- {libentry-1.23.3.dist-info → libentry-1.23.4.dist-info}/entry_points.txt +0 -0
- {libentry-1.23.3.dist-info → libentry-1.23.4.dist-info}/top_level.txt +0 -0
- {libentry-1.23.3.dist-info → libentry-1.23.4.dist-info}/zip-safe +0 -0
libentry/mcp/api.py
CHANGED
@@ -19,6 +19,12 @@ from pydantic import BaseModel, ConfigDict
|
|
19
19
|
|
20
20
|
API_INFO_FIELD = "__api_info__"
|
21
21
|
|
22
|
+
TAG_SUBROUTINE = "subroutine"
|
23
|
+
TAG_JSONRPC = "jsonrpc"
|
24
|
+
TAG_ENDPOINT = "endpoint"
|
25
|
+
TAG_TOOL = "tool"
|
26
|
+
TAG_RESOURCE = "resource"
|
27
|
+
|
22
28
|
|
23
29
|
class APIInfo(BaseModel):
|
24
30
|
path: str
|
@@ -69,7 +75,7 @@ def tool(path=None, name=None, description=None, **kwargs):
|
|
69
75
|
methods=["POST"],
|
70
76
|
name=name,
|
71
77
|
description=description,
|
72
|
-
tag=
|
78
|
+
tag=TAG_TOOL,
|
73
79
|
**kwargs
|
74
80
|
)
|
75
81
|
|
@@ -80,7 +86,7 @@ def resource(uri, name=None, description=None, mime_type=None, size=None, **kwar
|
|
80
86
|
methods=["POST"],
|
81
87
|
name=name,
|
82
88
|
description=description,
|
83
|
-
tag=
|
89
|
+
tag=TAG_RESOURCE,
|
84
90
|
mimeType=mime_type,
|
85
91
|
size=size,
|
86
92
|
uri=uri,
|
libentry/mcp/service.py
CHANGED
@@ -233,18 +233,18 @@ class FlaskHandler:
|
|
233
233
|
|
234
234
|
self.subroutine_adapter = SubroutineAdapter(fn, self.api_signature)
|
235
235
|
self.jsonrpc_adapter = JSONRPCAdapter(fn, self.api_signature)
|
236
|
-
self.default_adapter = self.subroutine_adapter
|
237
236
|
|
237
|
+
adapter_mapping = {
|
238
|
+
api.TAG_ENDPOINT: self.fn,
|
239
|
+
"free": self.fn,
|
240
|
+
"schema_free": self.fn,
|
241
|
+
"schema-free": self.fn,
|
242
|
+
api.TAG_JSONRPC: self.jsonrpc_adapter,
|
243
|
+
"rpc": self.jsonrpc_adapter,
|
244
|
+
"mcp": self.jsonrpc_adapter,
|
245
|
+
}
|
238
246
|
tag = self.api_info.tag if self.api_info else None
|
239
|
-
|
240
|
-
tag = tag.lower()
|
241
|
-
if tag in {"free", "schema_free", "schema-free"}:
|
242
|
-
self.default_adapter = self.fn
|
243
|
-
elif tag in {"jsonrpc", "rpc"}:
|
244
|
-
self.default_adapter = self.jsonrpc_adapter
|
245
|
-
|
246
|
-
# todo: debug info
|
247
|
-
print(f"{api_info.path}: {type(self.default_adapter)}\t{self.api_signature.input_model}")
|
247
|
+
self.default_adapter = adapter_mapping.get(tag, self.subroutine_adapter)
|
248
248
|
|
249
249
|
def __call__(self):
|
250
250
|
args = flask_request.args
|
@@ -369,7 +369,7 @@ class SSEService:
|
|
369
369
|
self.sse_dict = {}
|
370
370
|
|
371
371
|
# noinspection PyUnusedLocal
|
372
|
-
@api.get("/sse", tag=
|
372
|
+
@api.get("/sse", tag=api.TAG_ENDPOINT)
|
373
373
|
def sse(self, raw_request: Dict[str, Any]) -> Iterable[SSE]:
|
374
374
|
session_id = str(uuid.uuid4())
|
375
375
|
queue = Queue(8)
|
@@ -395,7 +395,7 @@ class SSEService:
|
|
395
395
|
|
396
396
|
return _stream()
|
397
397
|
|
398
|
-
@api.route("/sse/message", tag=
|
398
|
+
@api.route("/sse/message", tag=api.TAG_ENDPOINT)
|
399
399
|
def sse_message(self, raw_request: Dict[str, Any]) -> None:
|
400
400
|
################################################################################
|
401
401
|
# session validation
|
@@ -471,7 +471,7 @@ class JSONRPCService:
|
|
471
471
|
|
472
472
|
self.type_adapter = TypeAdapter(Union[JSONRPCRequest, JSONRPCNotification])
|
473
473
|
|
474
|
-
@api.route(tag=
|
474
|
+
@api.route(tag=api.TAG_ENDPOINT)
|
475
475
|
def message(self, raw_request: Dict[str, Any]) -> Union[JSONRPCResponse, Iterable[JSONRPCResponse], None]:
|
476
476
|
request = self.type_adapter.validate_python(raw_request)
|
477
477
|
path = f"/{request.method}"
|
@@ -521,7 +521,7 @@ class ToolsService:
|
|
521
521
|
self._tool_routes = {}
|
522
522
|
for route in self.service_routes.values():
|
523
523
|
api_info = route.api_info
|
524
|
-
if api_info.tag !=
|
524
|
+
if api_info.tag != api.TAG_TOOL:
|
525
525
|
continue
|
526
526
|
self._tool_routes[api_info.name] = route
|
527
527
|
return self._tool_routes
|
@@ -636,7 +636,7 @@ class ResourcesService:
|
|
636
636
|
self._resource_routes = {}
|
637
637
|
for route in self.service_routes.values():
|
638
638
|
api_info = route.api_info
|
639
|
-
if api_info.tag !=
|
639
|
+
if api_info.tag != api.TAG_RESOURCE:
|
640
640
|
continue
|
641
641
|
uri = api_info.model_extra.get("uri", api_info.path)
|
642
642
|
self._resource_routes[uri] = route
|
@@ -771,10 +771,15 @@ class FlaskServer(Flask):
|
|
771
771
|
logger.error(f"Async function \"{fn.__name__}\" is not supported.")
|
772
772
|
continue
|
773
773
|
|
774
|
-
logger.info(f"Serving {path} as {', '.join(methods)}.")
|
775
|
-
|
776
774
|
handler = FlaskHandler(fn, api_info, self)
|
777
775
|
routes[path] = Route(api_info=api_info, fn=fn, handler=handler)
|
776
|
+
|
777
|
+
mode = api.TAG_ENDPOINT
|
778
|
+
if isinstance(handler.default_adapter, SubroutineAdapter):
|
779
|
+
mode = api.TAG_SUBROUTINE
|
780
|
+
elif isinstance(handler.default_adapter, JSONRPCAdapter):
|
781
|
+
mode = api.TAG_JSONRPC
|
782
|
+
logger.info(f"{mode.capitalize()}:\tmethod={'|'.join(methods)}\tpath={path}")
|
778
783
|
return routes
|
779
784
|
|
780
785
|
def ok(self, body: Union[str, Iterable[str], None], mimetype: str):
|
@@ -10,9 +10,9 @@ libentry/schema.py,sha256=40SOhCF_eytWOF47MWKCRHKHl_lCaQVetx1Af62PkiI,10439
|
|
10
10
|
libentry/test_api.py,sha256=Xw7B7sH6g1iCTV5sFzyBF3JAJzeOr9xg0AyezTNsnIk,4452
|
11
11
|
libentry/utils.py,sha256=O7P6GadtUIjq0N2IZH7PhHZDUM3NebzcqyDqytet7CM,683
|
12
12
|
libentry/mcp/__init__.py,sha256=1oLL20yLB1GL9IbFiZD8OReDqiCpFr-yetIR6x1cNkI,23
|
13
|
-
libentry/mcp/api.py,sha256=
|
13
|
+
libentry/mcp/api.py,sha256=KSvz6_TNGKQQoFJPNH1XIc8CMji0I2_CqC9VCSOPRfc,2491
|
14
14
|
libentry/mcp/client.py,sha256=tEJbMpXiMKQ0qDgLGyavE2A4jpoXliqbrVj_TMfOGXI,22488
|
15
|
-
libentry/mcp/service.py,sha256=
|
15
|
+
libentry/mcp/service.py,sha256=xInlf_u8AVlGtnWH6gky_l3IolmYahm-FYMqsbm6t3w,32563
|
16
16
|
libentry/mcp/types.py,sha256=xTQCnKAgeJNss4klJ33MrWHGCzG_LeR3urizO_Z9q9U,12239
|
17
17
|
libentry/service/__init__.py,sha256=1oLL20yLB1GL9IbFiZD8OReDqiCpFr-yetIR6x1cNkI,23
|
18
18
|
libentry/service/common.py,sha256=OVaW2afgKA6YqstJmtnprBCqQEUZEWotZ6tHavmJJeU,42
|
@@ -21,10 +21,10 @@ libentry/service/list.py,sha256=ElHWhTgShGOhaxMUEwVbMXos0NQKjHsODboiQ-3AMwE,1397
|
|
21
21
|
libentry/service/running.py,sha256=FrPJoJX6wYxcHIysoatAxhW3LajCCm0Gx6l7__6sULQ,5105
|
22
22
|
libentry/service/start.py,sha256=mZT7b9rVULvzy9GTZwxWnciCHgv9dbGN2JbxM60OMn4,1270
|
23
23
|
libentry/service/stop.py,sha256=wOpwZgrEJ7QirntfvibGq-XsTC6b3ELhzRW2zezh-0s,1187
|
24
|
-
libentry-1.23.
|
25
|
-
libentry-1.23.
|
26
|
-
libentry-1.23.
|
27
|
-
libentry-1.23.
|
28
|
-
libentry-1.23.
|
29
|
-
libentry-1.23.
|
30
|
-
libentry-1.23.
|
24
|
+
libentry-1.23.4.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
25
|
+
libentry-1.23.4.dist-info/METADATA,sha256=-gzj-ialfjOVVPyc_tv-Jj1qH7LlrauZnossj2nOFX4,1135
|
26
|
+
libentry-1.23.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
27
|
+
libentry-1.23.4.dist-info/entry_points.txt,sha256=1v_nLVDsjvVJp9SWhl4ef2zZrsLTBtFWgrYFgqvQBgc,61
|
28
|
+
libentry-1.23.4.dist-info/top_level.txt,sha256=u2uF6-X5fn2Erf9PYXOg_6tntPqTpyT-yzUZrltEd6I,9
|
29
|
+
libentry-1.23.4.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
30
|
+
libentry-1.23.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|