libentry 1.24.9__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/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, ToolProperty, \
25
- ToolSchema, ToolsCapability
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
- host: str = "0.0.0.0",
911
- port: int = 8888,
912
- num_workers: int = 1,
913
- num_threads: int = 20,
914
- num_connections: Optional[int] = 1000,
915
- backlog: Optional[int] = 1000,
916
- worker_class: str = "gthread",
917
- timeout: int = 60,
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
  Metadata-Version: 2.2
2
2
  Name: libentry
3
- Version: 1.24.9
3
+ Version: 1.25
4
4
  Summary: Entries for experimental utilities.
5
5
  Home-page: https://github.com/XoriieInpottn/libentry
6
6
  Author: xi
@@ -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=qA6I9Mi-eudRYwVGhff1_aAImK424bhASlsWaHP8XNI,34971
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.24.9.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
26
- libentry-1.24.9.dist-info/METADATA,sha256=LttWBo7s_rfqrsHN336XQWPOMKeHggHufl2q8i4ieos,1135
27
- libentry-1.24.9.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
28
- libentry-1.24.9.dist-info/entry_points.txt,sha256=1v_nLVDsjvVJp9SWhl4ef2zZrsLTBtFWgrYFgqvQBgc,61
29
- libentry-1.24.9.dist-info/top_level.txt,sha256=u2uF6-X5fn2Erf9PYXOg_6tntPqTpyT-yzUZrltEd6I,9
30
- libentry-1.24.9.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
31
- libentry-1.24.9.dist-info/RECORD,,
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,,