libentry 1.22.4__py3-none-any.whl → 1.23__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/api.py +1 -1
- libentry/mcp/__init__.py +1 -0
- libentry/mcp/api.py +101 -0
- libentry/mcp/client.py +644 -0
- libentry/mcp/service.py +883 -0
- libentry/mcp/types.py +441 -0
- libentry/schema.py +105 -50
- libentry/service/flask.py +1 -1
- {libentry-1.22.4.dist-info → libentry-1.23.dist-info}/METADATA +2 -1
- libentry-1.23.dist-info/RECORD +30 -0
- libentry/service/flask_mcp.py +0 -337
- libentry-1.22.4.dist-info/RECORD +0 -26
- {libentry-1.22.4.dist-info → libentry-1.23.dist-info}/LICENSE +0 -0
- {libentry-1.22.4.dist-info → libentry-1.23.dist-info}/WHEEL +0 -0
- {libentry-1.22.4.dist-info → libentry-1.23.dist-info}/entry_points.txt +0 -0
- {libentry-1.22.4.dist-info → libentry-1.23.dist-info}/top_level.txt +0 -0
- {libentry-1.22.4.dist-info → libentry-1.23.dist-info}/zip-safe +0 -0
libentry/api.py
CHANGED
@@ -225,7 +225,7 @@ class BaseClient:
|
|
225
225
|
verify: bool,
|
226
226
|
) -> Union[bytes, Iterable[bytes]]:
|
227
227
|
headers = self.headers if headers is None else {**self.headers, **headers}
|
228
|
-
response = self.URLLIB3_POOL[int(verify)].
|
228
|
+
response = self.URLLIB3_POOL[int(verify)].http_request(
|
229
229
|
method=method,
|
230
230
|
url=url,
|
231
231
|
body=body,
|
libentry/mcp/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
#!/usr/bin/env python3
|
libentry/mcp/api.py
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
|
3
|
+
__author__ = "xi"
|
4
|
+
__all__ = [
|
5
|
+
"APIInfo",
|
6
|
+
"api",
|
7
|
+
"route",
|
8
|
+
"get",
|
9
|
+
"post",
|
10
|
+
"tool",
|
11
|
+
"resource",
|
12
|
+
"list_api_info",
|
13
|
+
]
|
14
|
+
|
15
|
+
from functools import partial
|
16
|
+
from typing import Callable, List, Literal, Optional, Tuple
|
17
|
+
|
18
|
+
from pydantic import BaseModel, ConfigDict
|
19
|
+
|
20
|
+
API_INFO_FIELD = "__api_info__"
|
21
|
+
|
22
|
+
|
23
|
+
class APIInfo(BaseModel):
|
24
|
+
path: str
|
25
|
+
methods: List[Literal["GET", "POST"]]
|
26
|
+
name: str
|
27
|
+
description: Optional[str]
|
28
|
+
tag: Optional[str] = None
|
29
|
+
|
30
|
+
model_config = ConfigDict(extra="allow")
|
31
|
+
|
32
|
+
|
33
|
+
def api(
|
34
|
+
path: Optional[str] = None,
|
35
|
+
methods: List[Literal["GET", "POST"]] = ("GET", "POST"),
|
36
|
+
name: Optional[str] = None,
|
37
|
+
description: Optional[str] = None,
|
38
|
+
tag: Optional[str] = None,
|
39
|
+
**kwargs
|
40
|
+
) -> Callable:
|
41
|
+
def decorator(fn: Callable):
|
42
|
+
if not hasattr(fn, "__name__"):
|
43
|
+
raise RuntimeError("At least one of \"path\" or \"fn.__name__\" should be given.")
|
44
|
+
fn_name = getattr(fn, "__name__")
|
45
|
+
fn_doc = getattr(fn, "__doc__")
|
46
|
+
|
47
|
+
api_info = APIInfo(
|
48
|
+
path=path or f"/{fn_name}",
|
49
|
+
methods=methods,
|
50
|
+
name=name or fn_name,
|
51
|
+
description=description or fn_doc,
|
52
|
+
tag=tag
|
53
|
+
)
|
54
|
+
api_info.model_extra.update(kwargs)
|
55
|
+
setattr(fn, API_INFO_FIELD, api_info)
|
56
|
+
return fn
|
57
|
+
|
58
|
+
return decorator
|
59
|
+
|
60
|
+
|
61
|
+
route = api
|
62
|
+
get = partial(api, methods=["GET"])
|
63
|
+
post = partial(api, methods=["POST"])
|
64
|
+
|
65
|
+
|
66
|
+
def tool(path=None, name=None, description=None, **kwargs):
|
67
|
+
return api(
|
68
|
+
path=path,
|
69
|
+
methods=["POST"],
|
70
|
+
name=name,
|
71
|
+
description=description,
|
72
|
+
tag="tool",
|
73
|
+
**kwargs
|
74
|
+
)
|
75
|
+
|
76
|
+
|
77
|
+
def resource(uri, name=None, description=None, mime_type=None, size=None, **kwargs):
|
78
|
+
return api(
|
79
|
+
path=None,
|
80
|
+
methods=["POST"],
|
81
|
+
name=name,
|
82
|
+
description=description,
|
83
|
+
tag="resource",
|
84
|
+
mimeType=mime_type,
|
85
|
+
size=size,
|
86
|
+
uri=uri,
|
87
|
+
**kwargs
|
88
|
+
)
|
89
|
+
|
90
|
+
|
91
|
+
def list_api_info(obj) -> List[Tuple[Callable, APIInfo]]:
|
92
|
+
api_list = []
|
93
|
+
for name in dir(obj):
|
94
|
+
fn = getattr(obj, name)
|
95
|
+
if not callable(fn):
|
96
|
+
continue
|
97
|
+
if not hasattr(fn, API_INFO_FIELD):
|
98
|
+
continue
|
99
|
+
api_info = getattr(fn, API_INFO_FIELD)
|
100
|
+
api_list.append((fn, api_info))
|
101
|
+
return api_list
|