libentry 1.24.8__py3-none-any.whl → 1.25__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 +21 -3
- libentry/mcp/service.py +117 -27
- {libentry-1.24.8.dist-info → libentry-1.25.dist-info}/METADATA +1 -1
- {libentry-1.24.8.dist-info → libentry-1.25.dist-info}/RECORD +9 -9
- {libentry-1.24.8.dist-info → libentry-1.25.dist-info}/LICENSE +0 -0
- {libentry-1.24.8.dist-info → libentry-1.25.dist-info}/WHEEL +0 -0
- {libentry-1.24.8.dist-info → libentry-1.25.dist-info}/entry_points.txt +0 -0
- {libentry-1.24.8.dist-info → libentry-1.25.dist-info}/top_level.txt +0 -0
- {libentry-1.24.8.dist-info → libentry-1.25.dist-info}/zip-safe +0 -0
libentry/argparse.py
CHANGED
@@ -14,9 +14,10 @@ __all__ = [
|
|
14
14
|
|
15
15
|
import argparse
|
16
16
|
import ast
|
17
|
+
import json
|
17
18
|
import re
|
18
19
|
from dataclasses import fields, is_dataclass
|
19
|
-
from typing import Optional, Sequence, Type, Union, get_args, get_origin
|
20
|
+
from typing import Dict, List, Optional, Sequence, Type, Union, get_args, get_origin
|
20
21
|
|
21
22
|
import yaml
|
22
23
|
from pydantic import BaseModel
|
@@ -158,12 +159,29 @@ class ArgumentParser(argparse.ArgumentParser):
|
|
158
159
|
instance=default_value
|
159
160
|
)
|
160
161
|
else:
|
162
|
+
desc = info.description + " " if info.description else ""
|
163
|
+
if info.is_required():
|
164
|
+
desc += "(required)"
|
165
|
+
else:
|
166
|
+
if default_value is None:
|
167
|
+
desc += "(default=None)"
|
168
|
+
elif isinstance(default_value, (str, int, float, bool)):
|
169
|
+
desc += f"(default={default_value})"
|
170
|
+
elif isinstance(default_value, (Dict, List)):
|
171
|
+
try:
|
172
|
+
desc += f"(default={json.dumps(default_value)})"
|
173
|
+
except TypeError:
|
174
|
+
default_type = type(default_value).__name__
|
175
|
+
desc += f"(default={default_type} object)"
|
176
|
+
else:
|
177
|
+
default_type = type(default_value).__name__
|
178
|
+
desc += f"(default={default_type} object)"
|
179
|
+
|
161
180
|
self.add_argument(
|
162
181
|
f"--{prefix}.{name}",
|
163
182
|
type=literal_eval,
|
164
183
|
default=DefaultValue(default_value),
|
165
|
-
|
166
|
-
help=info.description
|
184
|
+
help=desc
|
167
185
|
)
|
168
186
|
|
169
187
|
def parse_args(self, args=None, namespace=None):
|
libentry/mcp/service.py
CHANGED
@@ -10,10 +10,10 @@ from dataclasses import dataclass
|
|
10
10
|
from queue import Empty, Queue
|
11
11
|
from threading import Lock
|
12
12
|
from types import GeneratorType
|
13
|
-
from typing import Any, Callable, Dict, Generator, Iterable, List, Optional, Type, Union
|
13
|
+
from typing import Any, Callable, Dict, Generator, Iterable, List, Literal, Optional, Type, Union
|
14
14
|
|
15
15
|
from flask import Flask, request as flask_request
|
16
|
-
from pydantic import BaseModel, TypeAdapter
|
16
|
+
from pydantic import BaseModel, Field, TypeAdapter
|
17
17
|
|
18
18
|
from libentry import json, logger
|
19
19
|
from libentry.mcp import api
|
@@ -21,8 +21,8 @@ from libentry.mcp.api import APIInfo, list_api_info
|
|
21
21
|
from libentry.mcp.types import BlobResourceContents, CallToolRequestParams, CallToolResult, Implementation, \
|
22
22
|
InitializeRequestParams, InitializeResult, JSONRPCError, JSONRPCNotification, JSONRPCRequest, JSONRPCResponse, \
|
23
23
|
ListResourcesResult, ListToolsResult, MIME, ReadResourceRequestParams, ReadResourceResult, Resource, SSE, \
|
24
|
-
ServerCapabilities, SubroutineError, SubroutineResponse, TextContent, TextResourceContents, Tool,
|
25
|
-
|
24
|
+
ServerCapabilities, SubroutineError, SubroutineResponse, TextContent, TextResourceContents, Tool, ToolSchema, \
|
25
|
+
ToolsCapability
|
26
26
|
from libentry.schema import APISignature, get_api_signature, query_api
|
27
27
|
|
28
28
|
try:
|
@@ -904,26 +904,116 @@ class GunicornApplication(BaseApplication):
|
|
904
904
|
return FlaskServer(service)
|
905
905
|
|
906
906
|
|
907
|
+
class RunServiceConfig(BaseModel):
|
908
|
+
"""Run service config."""
|
909
|
+
|
910
|
+
host: str = Field(
|
911
|
+
title="Hostname",
|
912
|
+
description=(
|
913
|
+
"The hostname of the server that runs the service. "
|
914
|
+
"IP address or domain name."
|
915
|
+
),
|
916
|
+
default="0.0.0.0"
|
917
|
+
)
|
918
|
+
port: int = Field(
|
919
|
+
title="Port number",
|
920
|
+
description="The port that the service listened to.",
|
921
|
+
)
|
922
|
+
num_workers: int = Field(
|
923
|
+
title="Number of workers",
|
924
|
+
description="The number of workers (processes) to run the service.",
|
925
|
+
default=1
|
926
|
+
)
|
927
|
+
num_threads: int = Field(
|
928
|
+
title="Number of threads",
|
929
|
+
description="The number of threads for each worker.",
|
930
|
+
default=20
|
931
|
+
)
|
932
|
+
num_connections: Optional[int] = Field(
|
933
|
+
title="Max number of connections",
|
934
|
+
description="The maximum number of simultaneous clients (or socket connections).",
|
935
|
+
default=1024
|
936
|
+
)
|
937
|
+
backlog: Optional[int] = Field(
|
938
|
+
title="The maximum number of pending connections",
|
939
|
+
description="The maximum number of pending connections.",
|
940
|
+
default=2048
|
941
|
+
)
|
942
|
+
worker_class: Literal["sync", "gthread", "eventlet", "gevent", "tornado"] = Field(
|
943
|
+
title="The type of workers to use",
|
944
|
+
description="The type of workers to use.",
|
945
|
+
default="gthread"
|
946
|
+
)
|
947
|
+
timeout: int = Field(
|
948
|
+
title="Worker timeout",
|
949
|
+
description="Workers silent for more than this many seconds are killed and restarted.",
|
950
|
+
default=60
|
951
|
+
)
|
952
|
+
keyfile: Optional[str] = Field(
|
953
|
+
title="SSL key file",
|
954
|
+
description="SSL key file.",
|
955
|
+
default=None
|
956
|
+
)
|
957
|
+
keyfile_password: Optional[str] = Field(
|
958
|
+
title="SSL key file password",
|
959
|
+
description="SSL key file password.",
|
960
|
+
default=None
|
961
|
+
)
|
962
|
+
certfile: Optional[str] = Field(
|
963
|
+
title="SSL certificate file",
|
964
|
+
description="SSL certificate file.",
|
965
|
+
default=None
|
966
|
+
)
|
967
|
+
|
968
|
+
|
907
969
|
def run_service(
|
908
970
|
service_type: Union[Type, Callable],
|
909
971
|
service_config=None,
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
972
|
+
run_config: Optional[RunServiceConfig] = None,
|
973
|
+
*,
|
974
|
+
host: Optional[str] = None,
|
975
|
+
port: Optional[int] = None,
|
976
|
+
num_workers: Optional[int] = None,
|
977
|
+
num_threads: Optional[int] = None,
|
978
|
+
num_connections: Optional[int] = None,
|
979
|
+
backlog: Optional[int] = None,
|
980
|
+
worker_class: Optional[str] = None,
|
981
|
+
timeout: Optional[int] = None,
|
918
982
|
keyfile: Optional[str] = None,
|
919
983
|
keyfile_password: Optional[str] = None,
|
920
984
|
certfile: Optional[str] = None
|
921
|
-
):
|
985
|
+
) -> None:
|
986
|
+
kwargs = {}
|
987
|
+
if host is not None:
|
988
|
+
kwargs["host"] = host
|
989
|
+
if port is not None:
|
990
|
+
kwargs["port"] = port
|
991
|
+
if num_workers is not None:
|
992
|
+
kwargs["num_workers"] = num_workers
|
993
|
+
if num_threads is not None:
|
994
|
+
kwargs["num_threads"] = num_threads
|
995
|
+
if num_connections is not None:
|
996
|
+
kwargs["num_connections"] = num_connections
|
997
|
+
if backlog is not None:
|
998
|
+
kwargs["backlog"] = backlog
|
999
|
+
if worker_class is not None:
|
1000
|
+
kwargs["worker_class"] = worker_class
|
1001
|
+
if timeout is not None:
|
1002
|
+
kwargs["timeout"] = timeout
|
1003
|
+
if keyfile is not None:
|
1004
|
+
kwargs["keyfile"] = keyfile
|
1005
|
+
if keyfile_password is not None:
|
1006
|
+
kwargs["keyfile_password"] = keyfile_password
|
1007
|
+
if certfile is not None:
|
1008
|
+
kwargs["certfile"] = certfile
|
1009
|
+
|
1010
|
+
if run_config is None:
|
1011
|
+
run_config = RunServiceConfig(**kwargs)
|
1012
|
+
else:
|
1013
|
+
for name, value in kwargs.items():
|
1014
|
+
setattr(run_config, name, value)
|
1015
|
+
|
922
1016
|
logger.info("Starting gunicorn server.")
|
923
|
-
if num_connections is None or num_connections < num_threads * 2:
|
924
|
-
num_connections = num_threads * 2
|
925
|
-
if backlog is None or backlog < num_threads * 2:
|
926
|
-
backlog = num_threads * 2
|
927
1017
|
|
928
1018
|
def ssl_context(config, _default_ssl_context_factory):
|
929
1019
|
import ssl
|
@@ -931,21 +1021,21 @@ def run_service(
|
|
931
1021
|
context.load_cert_chain(
|
932
1022
|
certfile=config.certfile,
|
933
1023
|
keyfile=config.keyfile,
|
934
|
-
password=keyfile_password
|
1024
|
+
password=run_config.keyfile_password
|
935
1025
|
)
|
936
1026
|
context.minimum_version = ssl.TLSVersion.TLSv1_3
|
937
1027
|
return context
|
938
1028
|
|
939
1029
|
options = {
|
940
|
-
"bind": f"{host}:{port}",
|
941
|
-
"workers": num_workers,
|
942
|
-
"threads": num_threads,
|
943
|
-
"timeout": timeout,
|
944
|
-
"worker_connections": num_connections,
|
945
|
-
"backlog": backlog,
|
946
|
-
"keyfile": keyfile,
|
947
|
-
"certfile": certfile,
|
948
|
-
"worker_class": worker_class,
|
1030
|
+
"bind": f"{run_config.host}:{run_config.port}",
|
1031
|
+
"workers": run_config.num_workers,
|
1032
|
+
"threads": run_config.num_threads,
|
1033
|
+
"timeout": run_config.timeout,
|
1034
|
+
"worker_connections": run_config.num_connections,
|
1035
|
+
"backlog": run_config.backlog,
|
1036
|
+
"keyfile": run_config.keyfile,
|
1037
|
+
"certfile": run_config.certfile,
|
1038
|
+
"worker_class": run_config.worker_class,
|
949
1039
|
"ssl_context": ssl_context
|
950
1040
|
}
|
951
1041
|
for name, value in options.items():
|
@@ -1,6 +1,6 @@
|
|
1
1
|
libentry/__init__.py,sha256=ko2YBIIx5H3dD0tedBkialzJGEDczFaP_PZmT1cIlak,148
|
2
2
|
libentry/api.py,sha256=UkXdBv9oqQhaSESRReLWEPj8venBUoCBppIg-FAXqKA,24146
|
3
|
-
libentry/argparse.py,sha256=
|
3
|
+
libentry/argparse.py,sha256=0_0_EJzLEgE8UFD8fEWCddGnDW1qxyMYMvcD3cuChvY,8882
|
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
|
@@ -13,7 +13,7 @@ libentry/utils.py,sha256=O7P6GadtUIjq0N2IZH7PhHZDUM3NebzcqyDqytet7CM,683
|
|
13
13
|
libentry/mcp/__init__.py,sha256=1oLL20yLB1GL9IbFiZD8OReDqiCpFr-yetIR6x1cNkI,23
|
14
14
|
libentry/mcp/api.py,sha256=GDErVCz_hh_ZeMxLS8bTPyBUhCTHw3Mm-nGFMV2W2yo,3669
|
15
15
|
libentry/mcp/client.py,sha256=3HmKAsFenPlDk1lfSdXL9GJwfCSU92uQS04zvZGeJfQ,23065
|
16
|
-
libentry/mcp/service.py,sha256=
|
16
|
+
libentry/mcp/service.py,sha256=VTLA9dS85NJ64OCf1zBKLWvvE9l76I-U8WV5crCmBlM,37943
|
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.
|
26
|
-
libentry-1.
|
27
|
-
libentry-1.
|
28
|
-
libentry-1.
|
29
|
-
libentry-1.
|
30
|
-
libentry-1.
|
31
|
-
libentry-1.
|
25
|
+
libentry-1.25.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
26
|
+
libentry-1.25.dist-info/METADATA,sha256=mlgd255AfSGCHpiUuPqHMVipyfRm-Xal71qb5dQAJlg,1133
|
27
|
+
libentry-1.25.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
28
|
+
libentry-1.25.dist-info/entry_points.txt,sha256=1v_nLVDsjvVJp9SWhl4ef2zZrsLTBtFWgrYFgqvQBgc,61
|
29
|
+
libentry-1.25.dist-info/top_level.txt,sha256=u2uF6-X5fn2Erf9PYXOg_6tntPqTpyT-yzUZrltEd6I,9
|
30
|
+
libentry-1.25.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
31
|
+
libentry-1.25.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|