libentry 1.28.2__py3-none-any.whl → 1.28.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/argparse.py CHANGED
@@ -21,6 +21,7 @@ from typing import Dict, List, Optional, Sequence, Type, Union, get_args, get_or
21
21
 
22
22
  import yaml
23
23
  from pydantic import BaseModel
24
+ from pydantic_core import PydanticUndefined
24
25
 
25
26
 
26
27
  def literal_eval(exp):
@@ -213,6 +214,10 @@ class ArgumentParser(argparse.ArgumentParser):
213
214
  else:
214
215
  if not isinstance(value, DefaultValue):
215
216
  merged_flat_dict[name] = value
217
+ merged_flat_dict = {
218
+ k: v for k, v in merged_flat_dict.items()
219
+ if v is not None and v is not PydanticUndefined
220
+ }
216
221
 
217
222
  merged_json = {}
218
223
  self._json_unflatten(merged_flat_dict, merged_json)
libentry/mcp/client.py CHANGED
@@ -8,7 +8,7 @@ from queue import Queue
8
8
  from threading import Semaphore, Thread
9
9
  from time import sleep
10
10
  from types import GeneratorType
11
- from typing import Any, Dict, Iterable, List, Optional, Tuple, Type, Union
11
+ from typing import Any, Dict, Generator, Iterable, List, Optional, Tuple, Type, Union
12
12
  from urllib.parse import urlencode
13
13
 
14
14
  import httpx
@@ -248,7 +248,6 @@ class JSONRPCMixIn(abc.ABC):
248
248
  raise ServiceError.from_jsonrpc_error(chunk.error)
249
249
 
250
250
 
251
-
252
251
  class MCPMixIn(JSONRPCMixIn, abc.ABC):
253
252
 
254
253
  def initialize(self) -> InitializeResult:
@@ -282,10 +281,18 @@ class MCPMixIn(JSONRPCMixIn, abc.ABC):
282
281
  if not isinstance(result, GeneratorType):
283
282
  return CallToolResult.model_validate(result)
284
283
  else:
285
- return (
286
- CallToolResult.model_validate(item)
287
- for item in result
288
- )
284
+ def gen() -> Generator[CallToolResult, None, Optional[CallToolResult]]:
285
+ it = iter(result)
286
+ try:
287
+ while True:
288
+ item = next(it)
289
+ yield CallToolResult.model_validate(item)
290
+ except StopIteration as e:
291
+ item = e.value
292
+ if item is not None:
293
+ return CallToolResult.model_validate(item)
294
+
295
+ return gen()
289
296
 
290
297
  def list_resources(self) -> ListResourcesResult:
291
298
  result = self.call("resources/list")
@@ -297,10 +304,18 @@ class MCPMixIn(JSONRPCMixIn, abc.ABC):
297
304
  if not isinstance(result, GeneratorType):
298
305
  return ReadResourceResult.model_validate(result)
299
306
  else:
300
- return (
301
- ReadResourceResult.model_validate(item)
302
- for item in result
303
- )
307
+ def gen() -> Generator[ReadResourceResult, None, Optional[ReadResourceResult]]:
308
+ it = iter(result)
309
+ try:
310
+ while True:
311
+ item = next(it)
312
+ yield ReadResourceResult.model_validate(item)
313
+ except StopIteration as e:
314
+ item = e.value
315
+ if item is not None:
316
+ return ReadResourceResult.model_validate(item)
317
+
318
+ return gen()
304
319
 
305
320
 
306
321
  class APIClient(SubroutineMixIn, MCPMixIn):
libentry/mcp/service.py CHANGED
@@ -4,7 +4,6 @@ __author__ = "xi"
4
4
 
5
5
  import asyncio
6
6
  import base64
7
- import io
8
7
  import uuid
9
8
  from dataclasses import dataclass
10
9
  from queue import Empty, Queue
@@ -98,7 +97,7 @@ class SubroutineAdapter:
98
97
  @staticmethod
99
98
  def _iter_response(
100
99
  results: Iterable[Any]
101
- ) -> Iterable[SubroutineResponse]:
100
+ ) -> Generator[SubroutineResponse, None, Optional[SubroutineResponse]]:
102
101
  it = iter(results)
103
102
  try:
104
103
  while True:
@@ -113,6 +112,7 @@ class SubroutineAdapter:
113
112
  return result
114
113
  except Exception as e:
115
114
  yield SubroutineResponse(error=SubroutineError.from_exception(e))
115
+ return None
116
116
 
117
117
 
118
118
  class JSONRPCAdapter:
@@ -669,18 +669,17 @@ class ToolsService:
669
669
  @staticmethod
670
670
  def _iter_tool_results(
671
671
  responses: Iterable[SubroutineResponse]
672
- ) -> Generator[CallToolResult, None, CallToolResult]:
673
- final_text = io.StringIO()
674
- error = None
672
+ ) -> Generator[CallToolResult, None, Optional[CallToolResult]]:
675
673
  try:
676
- for response in responses:
674
+ it = iter(responses)
675
+ while True:
676
+ response = next(it)
677
677
  if response.error is not None:
678
678
  text = json.dumps(response.error)
679
- error = CallToolResult(
679
+ yield CallToolResult(
680
680
  content=[TextContent(text=text)],
681
681
  isError=True
682
682
  )
683
- yield error
684
683
  break
685
684
  else:
686
685
  result = response.result
@@ -689,7 +688,22 @@ class ToolsService:
689
688
  content=[TextContent(text=text)],
690
689
  isError=False
691
690
  )
692
- final_text.write(text)
691
+ except StopIteration as e:
692
+ response = e.value
693
+ if response is not None:
694
+ if response.error is not None:
695
+ text = json.dumps(response.error)
696
+ return CallToolResult(
697
+ content=[TextContent(text=text)],
698
+ isError=True
699
+ )
700
+ else:
701
+ result = response.result
702
+ text = json.dumps(result) if isinstance(result, (Dict, BaseModel)) else str(result)
703
+ return CallToolResult(
704
+ content=[TextContent(text=text)],
705
+ isError=False
706
+ )
693
707
  except Exception as e:
694
708
  text = json.dumps(SubroutineError.from_exception(e))
695
709
  error = CallToolResult(
@@ -697,14 +711,7 @@ class ToolsService:
697
711
  isError=True
698
712
  )
699
713
  yield error
700
-
701
- if error is None:
702
- return CallToolResult(
703
- content=[TextContent(text=final_text.getvalue())],
704
- isError=False
705
- )
706
- else:
707
- return error
714
+ return None
708
715
 
709
716
 
710
717
  class ResourcesService:
@@ -778,6 +785,7 @@ class ResourcesService:
778
785
  uri: str,
779
786
  mime_type: Optional[str] = None
780
787
  ) -> Generator[ReadResourceResult, None, Optional[ReadResourceResult]]:
788
+ # todo: returned content need to be processed
781
789
  for content in contents:
782
790
  if isinstance(content, str):
783
791
  yield ReadResourceResult(contents=[TextResourceContents(
libentry/schema.py CHANGED
@@ -232,8 +232,8 @@ def _parse_base_model(context: ParseContext) -> Optional[str]:
232
232
  def _parse_iterable(context: ParseContext) -> Optional[str]:
233
233
  if context.origin.__name__ in {"Iterable", "Generator", "range"} and issubclass(context.origin, Iterable):
234
234
  iter_args = get_args(context.annotation)
235
- if len(iter_args) != 1:
236
- raise TypeError("Only ONE type can be used as the type of iterable elements.")
235
+ if len(iter_args) < 1:
236
+ raise TypeError("At least ONE type should be specified for iterable elements.")
237
237
  iter_type = parse_type(iter_args[0], context.schemas)
238
238
  if isinstance(iter_type, list):
239
239
  raise TypeError("\"Union\" cannot be used as the type of iterable elements.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: libentry
3
- Version: 1.28.2
3
+ Version: 1.28.4
4
4
  Summary: Entries for experimental utilities.
5
5
  Home-page: https://github.com/XoriieInpottn/libentry
6
6
  Author: xi
@@ -1,19 +1,19 @@
1
1
  libentry/__init__.py,sha256=ko2YBIIx5H3dD0tedBkialzJGEDczFaP_PZmT1cIlak,148
2
2
  libentry/api.py,sha256=UkXdBv9oqQhaSESRReLWEPj8venBUoCBppIg-FAXqKA,24146
3
- libentry/argparse.py,sha256=0_0_EJzLEgE8UFD8fEWCddGnDW1qxyMYMvcD3cuChvY,8882
3
+ libentry/argparse.py,sha256=ti-eJ-lM0m671rqji3gGGDlF1CSluMADIB-_J2v4c6c,9079
4
4
  libentry/dataclasses.py,sha256=AQV2PuxplJCwGZ5HKX72U-z-POUhTdy3XtpEK9KNIGQ,4541
5
5
  libentry/executor.py,sha256=cTV0WxJi0nU1TP-cOwmeodN8DD6L1691M2HIQsJtGrU,6582
6
6
  libentry/experiment.py,sha256=ejgAHDXWIe9x4haUzIFuz1WasLY0_aD1z_vyEVGjTu8,4922
7
7
  libentry/json.py,sha256=gTjogVG6eGUMkVrjilKkpFC8ZkElGAyZIutO7mbmSzg,1956
8
8
  libentry/logging.py,sha256=IiYoCUzm8XTK1fduA-NA0FI2Qz_m81NEPV3d3tEfgdI,1349
9
9
  libentry/resource.py,sha256=qAPXF7RzRYeCM4xWft6XR3SYk7lEiQ6ymOHbpNoi0mQ,1821
10
- libentry/schema.py,sha256=40SOhCF_eytWOF47MWKCRHKHl_lCaQVetx1Af62PkiI,10439
10
+ libentry/schema.py,sha256=T_hM_F25ntfvczFFpJUM7_fu9V3J3-qR9kZR8bcxqhQ,10439
11
11
  libentry/test_api.py,sha256=bs7P8gveLtuUvHxrpujSrfuYqLVJ3fOXVg_MZnZxoJ4,4504
12
12
  libentry/utils.py,sha256=vCm6UyAlibnPOlPJHZO57u3TXhw5PZmGM5_vBAPUnB4,1981
13
13
  libentry/mcp/__init__.py,sha256=1oLL20yLB1GL9IbFiZD8OReDqiCpFr-yetIR6x1cNkI,23
14
14
  libentry/mcp/api.py,sha256=GDErVCz_hh_ZeMxLS8bTPyBUhCTHw3Mm-nGFMV2W2yo,3669
15
- libentry/mcp/client.py,sha256=u9u-hVwcHQLc9o-_CJumz2vtIDf-ZgQcgDTD5xSmZPA,24143
16
- libentry/mcp/service.py,sha256=RQ658-Ci69Z_h5d4Y43NN1BeykC8mjRpYbOPOGFxzlc,39736
15
+ libentry/mcp/client.py,sha256=_O-O6OETwHidhiFmg7P01NIrVhHgEetwFeFfJNqRt6M,24899
16
+ libentry/mcp/service.py,sha256=Zl031pZS-4wJjp0YG6825iDgcKNev8RdOANkWwO7WkU,40272
17
17
  libentry/mcp/types.py,sha256=aAoVO4jjqEvDzNneuZapmRYonLLnGsbcLoypVyRNNYg,12389
18
18
  libentry/service/__init__.py,sha256=1oLL20yLB1GL9IbFiZD8OReDqiCpFr-yetIR6x1cNkI,23
19
19
  libentry/service/common.py,sha256=OVaW2afgKA6YqstJmtnprBCqQEUZEWotZ6tHavmJJeU,42
@@ -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.28.2.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
26
- libentry-1.28.2.dist-info/METADATA,sha256=uM20K0CHXqJCStF-O5_s5lLE_7rptJDY0gdt4NvATCA,1135
27
- libentry-1.28.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
28
- libentry-1.28.2.dist-info/entry_points.txt,sha256=1v_nLVDsjvVJp9SWhl4ef2zZrsLTBtFWgrYFgqvQBgc,61
29
- libentry-1.28.2.dist-info/top_level.txt,sha256=u2uF6-X5fn2Erf9PYXOg_6tntPqTpyT-yzUZrltEd6I,9
30
- libentry-1.28.2.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
31
- libentry-1.28.2.dist-info/RECORD,,
25
+ libentry-1.28.4.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
26
+ libentry-1.28.4.dist-info/METADATA,sha256=AimMU3YMw_WgXPhnQTe-hp65BqId_vTWx1I6rtkLDHU,1135
27
+ libentry-1.28.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
28
+ libentry-1.28.4.dist-info/entry_points.txt,sha256=1v_nLVDsjvVJp9SWhl4ef2zZrsLTBtFWgrYFgqvQBgc,61
29
+ libentry-1.28.4.dist-info/top_level.txt,sha256=u2uF6-X5fn2Erf9PYXOg_6tntPqTpyT-yzUZrltEd6I,9
30
+ libentry-1.28.4.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
31
+ libentry-1.28.4.dist-info/RECORD,,