gllm-tools-binary 0.1.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.
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ from gllm_tools.mcp.client.client import MCPClient as MCPClient
2
+
3
+ __all__ = ['MCPClient']
@@ -0,0 +1,105 @@
1
+ from _typeshed import Incomplete
2
+ from abc import ABC
3
+ from gllm_tools.mcp.client.config import MCPConfiguration as MCPConfiguration
4
+ from gllm_tools.mcp.client.resource import MCPResource as MCPResource, load_mcp_resources as load_mcp_resources
5
+ from gllm_tools.mcp.client.session import create_session as create_session
6
+ from gllm_tools.mcp.client.tool import MCPTool as MCPTool, load_mcp_tools as load_mcp_tools
7
+ from typing import Any
8
+
9
+ logger: Incomplete
10
+
11
+ class MCPClient(ABC):
12
+ """The MCP (Model Context Protocol) Client handler.
13
+
14
+ Responsible for creating MCP client sessions, managing its lifecycle, and
15
+ connecting generating the tools, resources, and all server features MCP
16
+ has to offer.
17
+
18
+ Attributes:
19
+ servers: A dictionary of MCP server configurations.
20
+ """
21
+ servers: dict[str, MCPConfiguration]
22
+ def __init__(self, servers: dict[str, MCPConfiguration]) -> None:
23
+ """Creates a new MCP client.
24
+
25
+ Args:
26
+ servers (dict[str, MCPConfiguration]): A dictionary of MCP server
27
+ configurations.
28
+
29
+ Example: how to get the tools from the MCP servers.
30
+
31
+ ```python
32
+ client = MCPClient(servers)
33
+ tools = await client.get_tools()
34
+ ```
35
+ """
36
+ def get_servers(self) -> list[str]:
37
+ '''Returns a list of available MCP servers.
38
+
39
+ This function retrieves the names of the available MCP servers from the
40
+ MCP servers configuration dictionary.
41
+
42
+ Returns:
43
+ list[str]: A list of available MCP servers.
44
+
45
+ Example: getting the available MCP servers:
46
+
47
+ ```python
48
+ servers = {
49
+ "github": MCPConfiguration(...),
50
+ "slack": MCPConfiguration(...),
51
+ }
52
+ client = MCPClient(servers)
53
+ servers = await client.get_servers()
54
+ print(servers)
55
+ # Output: ["github", "slack"]
56
+ ```
57
+ '''
58
+ async def get_tools(self, server: str | None = None) -> list[MCPTool | Any]:
59
+ """Returns a list of available tools.
60
+
61
+ This function retrieves the names of the available tools from the
62
+ MCP servers configuration dictionary.
63
+
64
+ NOTE: a new session is created for each tool call.
65
+
66
+ Args:
67
+ server (str | None): The name of the MCP server to connect to.
68
+
69
+ Returns:
70
+ list[MCPTool | Any]: A list of available tools. The tool can be adapted to a specific
71
+ framework's tool using `tool_adapter`.
72
+ """
73
+ async def get_resources(self, server: str | None = None) -> list[MCPResource]:
74
+ """Returns a list of available resources.
75
+
76
+ This function retrieves the names of the available resources from the
77
+ MCP servers configuration dictionary. Note that this function only
78
+ returns the metadata of the resources, not the actual content. For the
79
+ content, use the `get_resource` function.
80
+
81
+ NOTE: a new session is created for each resource call.
82
+
83
+ Args:
84
+ server (str | None): The name of the MCP server to connect to.
85
+
86
+ Returns:
87
+ list[MCPResource]: A list of available resources. Only the metadata of the
88
+ resources is returned.
89
+ """
90
+ async def get_resource(self, server: str, resource_uri: str) -> Any:
91
+ """Returns a resource's entire content.
92
+
93
+ This function retrieves the resource from the MCP servers configuration dictionary.
94
+ Be careful with this function, as it will return the entire content of the resource,
95
+
96
+ NOTE: a new session is created for each resource call.
97
+
98
+ Args:
99
+ server (str): The name of the MCP server to connect to.
100
+ resource_uri (str): The URI of the resource to retrieve.
101
+
102
+ Returns:
103
+ Any: The resource's entire content. The resource can be adapted to a specific
104
+ framework's resource using `resource_adapter`.
105
+ """
@@ -0,0 +1,54 @@
1
+ from _typeshed import Incomplete
2
+ from typing import Any, Literal, TypedDict
3
+
4
+ STDIO_TRANSPORT: str
5
+ SSE_TRANSPORT: str
6
+ STREAMABLE_HTTP_TRANSPORT: str
7
+ EncodingErrorHandler: Incomplete
8
+
9
+ class MCPConfiguration(TypedDict):
10
+ """Base MCP Configuration class. Not intended to be used directly."""
11
+ transport: Literal['stdio', 'sse', 'streamable_http']
12
+ session_kwargs: dict[str, Any] | None
13
+
14
+ class StdioConfiguration(MCPConfiguration):
15
+ """Configuration for STDIO-based MCP.
16
+
17
+ STDIO-based MCP uses the `subprocess` module to execute commands.
18
+ More information can be found here:
19
+ https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#stdio
20
+ """
21
+ transport: Literal['stdio']
22
+ command: str
23
+ args: list[str]
24
+ env: dict[str, str]
25
+ cwd: str
26
+ encoding: str
27
+ encoding_error_handler: EncodingErrorHandler
28
+
29
+ class SseConfiguration(MCPConfiguration):
30
+ """Configuration for SSE-based MCP.
31
+
32
+ The SSE MCP Transport is a deprecated transport that uses Server-Sent
33
+ Events to send messages to the client. More information can be found
34
+ here:
35
+ https://modelcontextprotocol.io/specification/2024-11-05/basic/transports#http-with-sse
36
+ """
37
+ transport: Literal['sse']
38
+ url: str
39
+ headers: dict[str, str]
40
+ timeout: float | None
41
+ sse_read_timeout: float | None
42
+
43
+ class StreamConfiguration(MCPConfiguration):
44
+ """The configuration for connecting to a Streamable HTTP server.
45
+
46
+ The Streamable HTTP server is a HTTP Protocol that replaces the
47
+ Server-Sent Events transport. More information can be found here:
48
+ https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http
49
+ """
50
+ transport: Literal['streamable_http']
51
+ url: str
52
+ headers: dict[str, str]
53
+ timeout: float | None
54
+ sse_read_timeout: float | None
@@ -0,0 +1,3 @@
1
+ from gllm_tools.mcp.client.langchain.client import LangchainMCPClient as LangchainMCPClient
2
+
3
+ __all__ = ['LangchainMCPClient']
@@ -0,0 +1,17 @@
1
+ from gllm_tools.mcp.client.client import MCPClient as MCPClient
2
+ from gllm_tools.mcp.client.config import MCPConfiguration as MCPConfiguration
3
+ from gllm_tools.mcp.client.resource import MCPResource as MCPResource
4
+ from gllm_tools.mcp.client.session import create_session as create_session
5
+ from gllm_tools.mcp.client.tool import MCPTool as MCPTool
6
+ from mcp.types import CallToolResult as CallToolResult, EmbeddedResource, ImageContent
7
+ from pydantic import AnyUrl as AnyUrl
8
+
9
+ NonTextContent = ImageContent | EmbeddedResource
10
+
11
+ class LangchainMCPClient(MCPClient):
12
+ """Langchain MCP Client.
13
+
14
+ This client is a wrapper around the MCPClient that converts MCP tools and resources
15
+ into Langchain tools and resources. It is used to integrate MCP with Langchain.
16
+ """
17
+ RESOURCE_FETCH_TIMEOUT: int
@@ -0,0 +1,41 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_tools.mcp.client.config import MCPConfiguration as MCPConfiguration
3
+ from gllm_tools.mcp.client.session import create_session as create_session
4
+ from mcp.types import Annotations as Annotations
5
+ from pydantic import AnyUrl as AnyUrl, UrlConstraints as UrlConstraints
6
+ from typing import Annotated
7
+
8
+ logger: Incomplete
9
+
10
+ class MCPResource:
11
+ """The MCP (Model Context Protocol) Resource."""
12
+ uri: Annotated[AnyUrl, None]
13
+ name: str
14
+ description: str | None
15
+ mime_type: str | None
16
+ size: int | None
17
+ annotations: Annotations | None
18
+ def __init__(self, name: str, description: str | None = None, uri: AnyUrl | None = None, mime_type: str | None = None, size: int | None = None, annotations: Annotations | None = None) -> None:
19
+ """Constructs a new MCP resource.
20
+
21
+ Args:
22
+ name (str): The name of the resource.
23
+ description (str | None): The description of the resource.
24
+ uri (AnyUrl | None): The URI of the resource.
25
+ mime_type (str | None): The MIME type of the resource.
26
+ size (int | None): The size of the resource in bytes.
27
+ annotations (Annotations | None): The annotations of the resource.
28
+ """
29
+
30
+ async def load_mcp_resources(*, config: MCPConfiguration) -> list[MCPResource]:
31
+ """Load all available MCP resources and convert them to resource objects.
32
+
33
+ This function only returns the metadata of the resources, not the actual
34
+ content.
35
+
36
+ Args:
37
+ config (MCPConfiguration): The MCP server configuration.
38
+
39
+ Returns:
40
+ list[MCPResource]: A list of MCP resources.
41
+ """
@@ -0,0 +1,21 @@
1
+ from _typeshed import Incomplete
2
+ from contextlib import asynccontextmanager
3
+ from gllm_tools.mcp.client.config import EncodingErrorHandler as EncodingErrorHandler, MCPConfiguration as MCPConfiguration, SSE_TRANSPORT as SSE_TRANSPORT, STDIO_TRANSPORT as STDIO_TRANSPORT, SseConfiguration as SseConfiguration, StdioConfiguration as StdioConfiguration, StreamConfiguration as StreamConfiguration
4
+ from mcp import ClientSession
5
+ from typing import AsyncIterator
6
+
7
+ logger: Incomplete
8
+ DEFAULT_ENCODING: str
9
+ DEFAULT_ENCODING_ERROR_HANDLER: EncodingErrorHandler
10
+ DEFAULT_HTTP_TIMEOUT: int
11
+ DEFAULT_SSE_READ_TIMEOUT: Incomplete
12
+ DEFAULT_STREAMABLE_HTTP_TIMEOUT: Incomplete
13
+ DEFAULT_STREAMABLE_HTTP_SSE_READ_TIMEOUT: Incomplete
14
+
15
+ @asynccontextmanager
16
+ async def create_session(config: MCPConfiguration) -> AsyncIterator[ClientSession]:
17
+ """Create a new session to an MCP server.
18
+
19
+ Args:
20
+ config: MCP configuration
21
+ """
@@ -0,0 +1,43 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_tools.mcp.client.config import MCPConfiguration as MCPConfiguration
3
+ from gllm_tools.mcp.client.session import create_session as create_session
4
+ from mcp.types import ToolAnnotations as ToolAnnotations
5
+ from typing import Any, Callable
6
+
7
+ logger: Incomplete
8
+
9
+ class MCPTool:
10
+ """Represents an MCP tool.
11
+
12
+ The MCP tool is an agnostic representation of a tool created by an MCP
13
+ server. It is not intended to be used directly, but rather to be used as
14
+ a base class for other tools.
15
+ """
16
+ name: str
17
+ description: str | None
18
+ parameters: dict[str, Any]
19
+ annotations: ToolAnnotations | None
20
+ model_config: Incomplete
21
+ def __init__(self, *, name: str, parameters: dict[str, Any], description: str | None = None, annotations: ToolAnnotations | None = None) -> None:
22
+ """Constructs a new MCP tool.
23
+
24
+ Args:
25
+ name (str): The name of the tool.
26
+ parameters (dict[str, Any]): The parameters of the tool.
27
+ description (str | None): The description of the tool.
28
+ annotations (ToolAnnotations | None): The annotations of the tool.
29
+ """
30
+
31
+ async def load_mcp_tools(*, config: MCPConfiguration, tool_adapter: Callable[[MCPTool, MCPConfiguration], Any] | None = None) -> list[Any]:
32
+ """Load all available MCP tools and convert them to tool objects.
33
+
34
+ Args:
35
+ config (MCPConfiguration): The MCP server configuration.
36
+ tool_adapter (Callable[[MCPTool, MCPConfiguration], Any] | None): The adapter to use to
37
+ convert the MCP tools to a specific framework's tool. If not provided, the
38
+ MCP tools are returned as is.
39
+
40
+ Returns:
41
+ list[Any]: A list of MCP tools. The tool can be adapted to a specific
42
+ tool using `tool_adapter`.
43
+ """
@@ -0,0 +1,87 @@
1
+ Metadata-Version: 2.1
2
+ Name: gllm-tools-binary
3
+ Version: 0.1.3
4
+ Summary: A library for managing tools in Gen AI applications.
5
+ Author: Raymond Christopher
6
+ Author-email: raymond.christopher@gdplabs.id
7
+ Requires-Python: >=3.11,<3.14
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Requires-Dist: e2b-code-interpreter (>=1.5.2,<2.0.0)
12
+ Requires-Dist: gllm-inference-binary[anthropic,openai] (>=0.5.5,<0.6.0)
13
+ Requires-Dist: langchain-core (>=0.3.63,<0.4.0)
14
+ Requires-Dist: mcp (>=1.9.1,<2.0.0)
15
+ Requires-Dist: pydantic (>=2.9.1,<3.0.0)
16
+ Description-Content-Type: text/markdown
17
+
18
+ # GLLM Tools
19
+
20
+ ## Description
21
+
22
+ A library providing a collection of utility tools and functions for Generative AI applications.
23
+
24
+ ## Installation
25
+
26
+ ### Prerequisites
27
+ - Python 3.11+ - [Install here](https://www.python.org/downloads/)
28
+ - Pip (if using Pip) - [Install here](https://pip.pypa.io/en/stable/installation/)
29
+ - Poetry 1.8.1+ (if using Poetry) - [Install here](https://python-poetry.org/docs/#installation)
30
+ - Git (if using Git) - [Install here](https://git-scm.com/downloads)
31
+ - For artifact registry installation:
32
+ - Google Cloud CLI - [[installed](https://cloud.google.com/sdk/docs/) and [authenticated](https://cloud.google.com/docs/authentication/gcloud)]
33
+ - Access to the [GDP Labs SDK artifact registry](https://console.cloud.google.com/artifacts/python/gdp-labs/asia-southeast2/gen-ai?project=gdp-labs)
34
+ - For git installation:
35
+ - Access to the [GDP Labs SDK github repository](https://github.com/GDP-ADMIN/gen-ai-internal)
36
+
37
+ ### 1. Installation from Artifact Registry
38
+ Choose one of the following methods to install the package:
39
+
40
+ #### Using pip
41
+ ```bash
42
+ pip install keyring keyrings.gl-artifactregistry-auth
43
+ pip install gllm-tools-binary --index-url https://glsdk.gdplabs.id/gen-ai/simple
44
+ ```
45
+
46
+ #### Using Poetry
47
+ ```bash
48
+ poetry source add --priority=explicit gen-ai https://glsdk.gdplabs.id/gen-ai/simple
49
+ poetry config http-basic.gen-ai oauth2accesstoken "$(gcloud auth print-access-token)"
50
+ poetry add --source gen-ai gllm-tools-binary
51
+ ```
52
+
53
+ ### 2. Development Installation (Git)
54
+ For development purposes, you can install directly from the Git repository:
55
+ ```bash
56
+ poetry add "git+ssh://git@github.com/GDP-ADMIN/gen-ai-internal.git#subdirectory=libs/gllm-tools"
57
+ ```
58
+
59
+ ## Managing Dependencies
60
+ 1. Go to root folder of `gllm-tools` module, e.g. `cd libs/gllm-tools`.
61
+ 2. Run `poetry shell` to create a virtual environment.
62
+ 3. Run `poetry lock` to create a lock file if you haven't done it yet.
63
+ 4. Run `poetry install` to install the `gllm-tools` requirements for the first time.
64
+ 5. Run `poetry update` if you update any dependency module version at `pyproject.toml`.
65
+
66
+ ## Contributing
67
+ Please refer to this [Python Style Guide](https://docs.google.com/document/d/1uRggCrHnVfDPBnG641FyQBwUwLoFw0kTzNqRm92vUwM/edit?usp=sharing)
68
+ to get information about code style, documentation standard, and SCA that you need to use when contributing to this project
69
+
70
+ 1. Activate `pre-commit` hooks using `pre-commit install`
71
+ 2. Run `poetry shell` to create a virtual environment.
72
+ 3. Run `poetry lock` to create a lock file if you haven't done it yet.
73
+ 4. Run `poetry install` to install the `gllm-tools` requirements for the first time.
74
+ 5. Run `which python` to get the path to be referenced at Visual Studio Code interpreter path (`Ctrl`+`Shift`+`P` or `Cmd`+`Shift`+`P`)
75
+ 6. Try running the unit test to see if it's working:
76
+ ```bash
77
+ poetry run pytest -s tests/unit_tests/
78
+ ```
79
+
80
+ ## Components
81
+
82
+ The main components of the GLLM Tools are listed here alongside their documentations.
83
+
84
+ ### MCP (Model Context Protocol)
85
+
86
+ The MCP documentation can be found [here](./gllm_tools/mcp/README.md).
87
+
@@ -0,0 +1,13 @@
1
+ gllm_tools/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ gllm_tools/mcp/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ gllm_tools/mcp/client/__init__.pyi,sha256=kPg839SRWEoiWiVRoTpWuTyGVFknI9qu8pUi9PfPj-4,92
4
+ gllm_tools/mcp/client/client.pyi,sha256=CN1sH3P66uolQD082AMCUGToC767fVXLMtLOTA87uzs,4012
5
+ gllm_tools/mcp/client/config.pyi,sha256=0Siou1etCyn-m6XFhDP7WK4tI3eV3jAmj6bAS8abnt4,1881
6
+ gllm_tools/mcp/client/langchain/__init__.pyi,sha256=4tTZkg7HrVlzvqUhg9TMxMevFB0ChLo78HwG14Wi8XI,129
7
+ gllm_tools/mcp/client/langchain/client.pyi,sha256=vqWQOs6QJdIfUWhdLuqTFurnjvHy3f8g5rKojEpMkHg,817
8
+ gllm_tools/mcp/client/resource.pyi,sha256=bGYI3KWVyURUd7fnVuGxrlJbTJN3BcU3DaKvSp4buYo,1685
9
+ gllm_tools/mcp/client/session.pyi,sha256=4KPe_krISKPZWeT_cNKKJNIn2NlRffXiECrPLC2iMvw,936
10
+ gllm_tools/mcp/client/tool.pyi,sha256=-wN90ZOGdtl6s0WqLsrQq6dUoWtJHZWQ43Qt_6IHRWQ,1846
11
+ gllm_tools_binary-0.1.3.dist-info/METADATA,sha256=MygHHpvwCfABHSjBczxq1xohshUbBydvaqfBxYg1ozg,3735
12
+ gllm_tools_binary-0.1.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
13
+ gllm_tools_binary-0.1.3.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 1.9.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any