libentry 1.30.1__py3-none-any.whl → 1.30.3__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/service.py +57 -1
- libentry/mcp/types.py +8 -3
- {libentry-1.30.1.dist-info → libentry-1.30.3.dist-info}/METADATA +1 -1
- {libentry-1.30.1.dist-info → libentry-1.30.3.dist-info}/RECORD +9 -9
- {libentry-1.30.1.dist-info → libentry-1.30.3.dist-info}/LICENSE +0 -0
- {libentry-1.30.1.dist-info → libentry-1.30.3.dist-info}/WHEEL +0 -0
- {libentry-1.30.1.dist-info → libentry-1.30.3.dist-info}/entry_points.txt +0 -0
- {libentry-1.30.1.dist-info → libentry-1.30.3.dist-info}/top_level.txt +0 -0
- {libentry-1.30.1.dist-info → libentry-1.30.3.dist-info}/zip-safe +0 -0
libentry/mcp/service.py
CHANGED
@@ -4,6 +4,7 @@ __author__ = "xi"
|
|
4
4
|
|
5
5
|
import asyncio
|
6
6
|
import base64
|
7
|
+
import copy
|
7
8
|
import uuid
|
8
9
|
from dataclasses import dataclass
|
9
10
|
from queue import Empty, Queue
|
@@ -592,6 +593,59 @@ class NotificationsService:
|
|
592
593
|
pass
|
593
594
|
|
594
595
|
|
596
|
+
def resolve_ref(schema, root=None, seen=None):
|
597
|
+
if root is None:
|
598
|
+
root = schema
|
599
|
+
if seen is None:
|
600
|
+
seen = set()
|
601
|
+
|
602
|
+
if isinstance(schema, dict):
|
603
|
+
if "$ref" in schema:
|
604
|
+
ref_path = schema["$ref"]
|
605
|
+
if not ref_path.startswith("#/"):
|
606
|
+
raise ValueError(f"只支持本地引用: {ref_path}")
|
607
|
+
|
608
|
+
if ref_path in seen:
|
609
|
+
# 循环引用,返回原样
|
610
|
+
return {"$ref": ref_path}
|
611
|
+
|
612
|
+
seen.add(ref_path)
|
613
|
+
|
614
|
+
# 路径解析
|
615
|
+
parts = ref_path[2:].split("/")
|
616
|
+
target = root
|
617
|
+
for part in parts:
|
618
|
+
target = target[part]
|
619
|
+
|
620
|
+
resolved = copy.deepcopy(target)
|
621
|
+
resolved = resolve_ref(resolved, root, seen)
|
622
|
+
|
623
|
+
seen.remove(ref_path)
|
624
|
+
|
625
|
+
# 合并额外字段(除 $ref 之外的部分)
|
626
|
+
extras = {k: v for k, v in schema.items() if k != "$ref"}
|
627
|
+
if extras:
|
628
|
+
if isinstance(resolved, dict):
|
629
|
+
merged = copy.deepcopy(resolved)
|
630
|
+
for k, v in extras.items():
|
631
|
+
merged[k] = resolve_ref(v, root, seen)
|
632
|
+
return merged
|
633
|
+
else:
|
634
|
+
# 被引用的不是 dict,无法合并,直接返回展开的结果
|
635
|
+
return resolved
|
636
|
+
|
637
|
+
return resolved
|
638
|
+
|
639
|
+
else:
|
640
|
+
return {k: resolve_ref(v, root, seen) for k, v in schema.items()}
|
641
|
+
|
642
|
+
elif isinstance(schema, list):
|
643
|
+
return [resolve_ref(v, root, seen) for v in schema]
|
644
|
+
|
645
|
+
else:
|
646
|
+
return schema
|
647
|
+
|
648
|
+
|
595
649
|
class ToolsService:
|
596
650
|
|
597
651
|
def __init__(self, service_routes: Dict[str, "Route"]):
|
@@ -615,10 +669,12 @@ class ToolsService:
|
|
615
669
|
api_info = route.api_info
|
616
670
|
api_models = route.fn if isinstance(route.fn, APISignature) else get_api_signature(route.fn)
|
617
671
|
args_model = api_models.input_model or api_models.bundled_model
|
672
|
+
json_schema = args_model.model_json_schema()
|
673
|
+
resolved_schema = resolve_ref(json_schema)
|
618
674
|
tool = Tool(
|
619
675
|
name=api_info.name,
|
620
676
|
description=api_info.description,
|
621
|
-
inputSchema=ToolSchema.model_validate(
|
677
|
+
inputSchema=ToolSchema.model_validate(resolved_schema)
|
622
678
|
)
|
623
679
|
tools.append(tool)
|
624
680
|
# schema = query_api(route.fn)
|
libentry/mcp/types.py
CHANGED
@@ -314,14 +314,19 @@ class ToolProperty(BaseModel):
|
|
314
314
|
type: Optional[str] = None
|
315
315
|
anyOf: Optional[List["ToolProperty"]] = None
|
316
316
|
items: Optional["ToolProperty"] = None
|
317
|
-
|
317
|
+
properties: Optional[Dict[str, "ToolProperty"]] = None
|
318
|
+
additionalProperties: Optional[Union[bool, "ToolProperty"]] = None
|
319
|
+
# title: Optional[str] = None
|
318
320
|
description: Optional[str] = None
|
321
|
+
required: Optional[List[str]] = None
|
319
322
|
|
320
323
|
|
321
324
|
class ToolSchema(BaseModel):
|
322
325
|
type: str = "object"
|
323
|
-
properties: Dict[str, ToolProperty] =
|
324
|
-
|
326
|
+
properties: Optional[Dict[str, "ToolProperty"]] = None
|
327
|
+
# title: Optional[str] = None
|
328
|
+
description: Optional[str] = None
|
329
|
+
required: Optional[List[str]] = None
|
325
330
|
|
326
331
|
|
327
332
|
class Tool(BaseModel):
|
@@ -13,8 +13,8 @@ libentry/utils.py,sha256=vCm6UyAlibnPOlPJHZO57u3TXhw5PZmGM5_vBAPUnB4,1981
|
|
13
13
|
libentry/mcp/__init__.py,sha256=1oLL20yLB1GL9IbFiZD8OReDqiCpFr-yetIR6x1cNkI,23
|
14
14
|
libentry/mcp/api.py,sha256=hhveOjDYhWiEEq3C7wSAOdpbPn9JP1T1CW3QYWrLHa4,3679
|
15
15
|
libentry/mcp/client.py,sha256=_O-O6OETwHidhiFmg7P01NIrVhHgEetwFeFfJNqRt6M,24899
|
16
|
-
libentry/mcp/service.py,sha256=
|
17
|
-
libentry/mcp/types.py,sha256=
|
16
|
+
libentry/mcp/service.py,sha256=Awi1JDcfxKI7q9YHfRB-7nCbO4X-MCvL1_LRZiBrREw,42589
|
17
|
+
libentry/mcp/types.py,sha256=0Wsd-Aq1ChzsiSkZt14UcRCSJvuM-vq2HRy-NeuqFZE,15394
|
18
18
|
libentry/service/__init__.py,sha256=1oLL20yLB1GL9IbFiZD8OReDqiCpFr-yetIR6x1cNkI,23
|
19
19
|
libentry/service/common.py,sha256=OVaW2afgKA6YqstJmtnprBCqQEUZEWotZ6tHavmJJeU,42
|
20
20
|
libentry/service/flask.py,sha256=2egCFFhRAfLpmSyibgaJ-3oexI-j27P1bmaPEn-hSlc,13817
|
@@ -22,10 +22,10 @@ libentry/service/list.py,sha256=ElHWhTgShGOhaxMUEwVbMXos0NQKjHsODboiQ-3AMwE,1397
|
|
22
22
|
libentry/service/running.py,sha256=FrPJoJX6wYxcHIysoatAxhW3LajCCm0Gx6l7__6sULQ,5105
|
23
23
|
libentry/service/start.py,sha256=mZT7b9rVULvzy9GTZwxWnciCHgv9dbGN2JbxM60OMn4,1270
|
24
24
|
libentry/service/stop.py,sha256=wOpwZgrEJ7QirntfvibGq-XsTC6b3ELhzRW2zezh-0s,1187
|
25
|
-
libentry-1.30.
|
26
|
-
libentry-1.30.
|
27
|
-
libentry-1.30.
|
28
|
-
libentry-1.30.
|
29
|
-
libentry-1.30.
|
30
|
-
libentry-1.30.
|
31
|
-
libentry-1.30.
|
25
|
+
libentry-1.30.3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
26
|
+
libentry-1.30.3.dist-info/METADATA,sha256=K1d4uO687Db-PzZh90WAd9DsjI8yqs5bStDnOVIoXWA,1161
|
27
|
+
libentry-1.30.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
28
|
+
libentry-1.30.3.dist-info/entry_points.txt,sha256=1v_nLVDsjvVJp9SWhl4ef2zZrsLTBtFWgrYFgqvQBgc,61
|
29
|
+
libentry-1.30.3.dist-info/top_level.txt,sha256=u2uF6-X5fn2Erf9PYXOg_6tntPqTpyT-yzUZrltEd6I,9
|
30
|
+
libentry-1.30.3.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
31
|
+
libentry-1.30.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|