biatoolkit 1.0.1__tar.gz → 1.0.3__tar.gz
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.
- {biatoolkit-1.0.1 → biatoolkit-1.0.3}/PKG-INFO +7 -7
- {biatoolkit-1.0.1 → biatoolkit-1.0.3}/README.md +4 -4
- biatoolkit-1.0.3/biatoolkit/basic_client.py +63 -0
- biatoolkit-1.0.3/biatoolkit/util.py +79 -0
- {biatoolkit-1.0.1 → biatoolkit-1.0.3}/biatoolkit.egg-info/PKG-INFO +7 -7
- {biatoolkit-1.0.1 → biatoolkit-1.0.3}/setup.py +1 -1
- biatoolkit-1.0.1/biatoolkit/basic_client.py +0 -34
- biatoolkit-1.0.1/biatoolkit/util.py +0 -52
- {biatoolkit-1.0.1 → biatoolkit-1.0.3}/biatoolkit/__init__.py +0 -0
- {biatoolkit-1.0.1 → biatoolkit-1.0.3}/biatoolkit/schema/__init__.py +0 -0
- {biatoolkit-1.0.1 → biatoolkit-1.0.3}/biatoolkit/schema/header.py +0 -0
- {biatoolkit-1.0.1 → biatoolkit-1.0.3}/biatoolkit.egg-info/SOURCES.txt +0 -0
- {biatoolkit-1.0.1 → biatoolkit-1.0.3}/biatoolkit.egg-info/dependency_links.txt +0 -0
- {biatoolkit-1.0.1 → biatoolkit-1.0.3}/biatoolkit.egg-info/top_level.txt +0 -0
- {biatoolkit-1.0.1 → biatoolkit-1.0.3}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: biatoolkit
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: Biblioteca para desenvolvedores que utilizam o BiaAgentBuilder
|
|
5
5
|
Author: Bia Platform Team
|
|
6
6
|
Author-email: data.platform@sankhya.com.br
|
|
@@ -128,7 +128,7 @@ Crie um novo arquivo chamado `local.py` com o seguinte conteúdo:
|
|
|
128
128
|
|
|
129
129
|
```python
|
|
130
130
|
import asyncio
|
|
131
|
-
from
|
|
131
|
+
from biatoolkit.basic_client import BasicClient
|
|
132
132
|
|
|
133
133
|
MCP_SERVER_URL = "http://0.0.0.0:8000/mcp"
|
|
134
134
|
client = BasicClient(MCP_SERVER_URL)
|
|
@@ -169,7 +169,7 @@ python local.py
|
|
|
169
169
|
|
|
170
170
|
Você deverá ver a saída no console semelhante a:
|
|
171
171
|
|
|
172
|
-

|
|
173
173
|
|
|
174
174
|
Caso deseje testar a execução de uma **tool**, basta alterar o método `main` conforme a seguir:
|
|
175
175
|
|
|
@@ -185,7 +185,7 @@ Veja que o método `call_tool` possui dois parâmetros:
|
|
|
185
185
|
|
|
186
186
|
Ao executar o arquivo `local.py`, você deverá ver a saída no console semelhante a:
|
|
187
187
|
|
|
188
|
-

|
|
189
189
|
|
|
190
190
|
### **Enviando parâmetros via header**
|
|
191
191
|
|
|
@@ -204,7 +204,7 @@ Se seu servidor MCP estiver sendo executado **localmente**, você conseguirá in
|
|
|
204
204
|
|
|
205
205
|
```python
|
|
206
206
|
import asyncio
|
|
207
|
-
from
|
|
207
|
+
from biatoolkit.basic_client import BasicClient
|
|
208
208
|
|
|
209
209
|
MCP_SERVER_URL = "http://0.0.0.0:8000/mcp"
|
|
210
210
|
|
|
@@ -258,7 +258,7 @@ Para recuperar os parâmetros no MCP Server que foram enviados por meio do `head
|
|
|
258
258
|
|
|
259
259
|
```python
|
|
260
260
|
from mcp.server.fastmcp import FastMCP
|
|
261
|
-
from
|
|
261
|
+
from biatoolkit.util import Util
|
|
262
262
|
|
|
263
263
|
mcp = FastMCP(host="0.0.0.0", stateless_http=True)
|
|
264
264
|
|
|
@@ -300,7 +300,7 @@ Para recuperar um valor sensível no seu MCP Server, utilize o método `get_para
|
|
|
300
300
|
|
|
301
301
|
```python
|
|
302
302
|
from mcp.server.fastmcp import FastMCP
|
|
303
|
-
from
|
|
303
|
+
from biatoolkit.util import Util
|
|
304
304
|
|
|
305
305
|
mcp = FastMCP(host="0.0.0.0", stateless_http=True)
|
|
306
306
|
|
|
@@ -141,7 +141,7 @@ Crie um novo arquivo chamado `local.py` com o seguinte conteúdo:
|
|
|
141
141
|
|
|
142
142
|
```python
|
|
143
143
|
import asyncio
|
|
144
|
-
from
|
|
144
|
+
from biatoolkit.basic_client import BasicClient
|
|
145
145
|
|
|
146
146
|
MCP_SERVER_URL = "http://0.0.0.0:8000/mcp"
|
|
147
147
|
client = BasicClient(MCP_SERVER_URL)
|
|
@@ -217,7 +217,7 @@ Se seu servidor MCP estiver sendo executado **localmente**, você conseguirá in
|
|
|
217
217
|
|
|
218
218
|
```python
|
|
219
219
|
import asyncio
|
|
220
|
-
from
|
|
220
|
+
from biatoolkit.basic_client import BasicClient
|
|
221
221
|
|
|
222
222
|
MCP_SERVER_URL = "http://0.0.0.0:8000/mcp"
|
|
223
223
|
|
|
@@ -271,7 +271,7 @@ Para recuperar os parâmetros no MCP Server que foram enviados por meio do `head
|
|
|
271
271
|
|
|
272
272
|
```python
|
|
273
273
|
from mcp.server.fastmcp import FastMCP
|
|
274
|
-
from
|
|
274
|
+
from biatoolkit.util import Util
|
|
275
275
|
|
|
276
276
|
mcp = FastMCP(host="0.0.0.0", stateless_http=True)
|
|
277
277
|
|
|
@@ -313,7 +313,7 @@ Para recuperar um valor sensível no seu MCP Server, utilize o método `get_para
|
|
|
313
313
|
|
|
314
314
|
```python
|
|
315
315
|
from mcp.server.fastmcp import FastMCP
|
|
316
|
-
from
|
|
316
|
+
from biatoolkit.util import Util
|
|
317
317
|
|
|
318
318
|
mcp = FastMCP(host="0.0.0.0", stateless_http=True)
|
|
319
319
|
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from mcp import ClientSession
|
|
2
|
+
from mcp.client.streamable_http import streamablehttp_client
|
|
3
|
+
|
|
4
|
+
class BiaClient:
|
|
5
|
+
"""
|
|
6
|
+
Cliente básico para interação com o MCP (Middleware de Comunicação de Processos).
|
|
7
|
+
Permite listar ferramentas disponíveis e executar ferramentas específicas via HTTP.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
def __init__(self, url: str = "http://0.0.0.0:8000/mcp", headers: dict = None):
|
|
11
|
+
"""
|
|
12
|
+
Inicializa o BasicClient.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
url (str): URL base do MCP. Se não terminar com '/mcp', será adicionado automaticamente.
|
|
16
|
+
headers (dict): Cabeçalhos HTTP opcionais para requisições.
|
|
17
|
+
"""
|
|
18
|
+
sufix = "/mcp"
|
|
19
|
+
# Garante que a URL termine com '/mcp'
|
|
20
|
+
self.url = url if url.endswith(sufix) else f"{url}{sufix}"
|
|
21
|
+
self.headers = headers
|
|
22
|
+
|
|
23
|
+
async def list_tools(self) -> dict:
|
|
24
|
+
"""
|
|
25
|
+
Lista as ferramentas disponíveis no MCP.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
dict: Dicionário contendo as ferramentas disponíveis.
|
|
29
|
+
"""
|
|
30
|
+
# Cria um cliente HTTP streamable para comunicação assíncrona
|
|
31
|
+
async with streamablehttp_client(self.url, self.headers, timeout=120, terminate_on_close=False) as (
|
|
32
|
+
read_stream,
|
|
33
|
+
write_stream,
|
|
34
|
+
_,
|
|
35
|
+
):
|
|
36
|
+
# Cria uma sessão de cliente MCP usando os streams
|
|
37
|
+
async with ClientSession(read_stream, write_stream) as session:
|
|
38
|
+
await session.initialize() # Inicializa a sessão
|
|
39
|
+
tool_result = await session.list_tools() # Solicita a lista de ferramentas
|
|
40
|
+
return tool_result
|
|
41
|
+
|
|
42
|
+
async def call_tool(self, tool_name: str, params: dict = None) -> dict:
|
|
43
|
+
"""
|
|
44
|
+
Executa uma ferramenta específica disponível no MCP.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
tool_name (str): Nome da ferramenta a ser executada.
|
|
48
|
+
params (dict, opcional): Parâmetros para a execução da ferramenta.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
dict: Resultado da execução da ferramenta.
|
|
52
|
+
"""
|
|
53
|
+
# Cria um cliente HTTP streamable para comunicação assíncrona
|
|
54
|
+
async with streamablehttp_client(self.url, self.headers, timeout=120, terminate_on_close=False) as (
|
|
55
|
+
read_stream,
|
|
56
|
+
write_stream,
|
|
57
|
+
_,
|
|
58
|
+
):
|
|
59
|
+
# Cria uma sessão de cliente MCP usando os streams
|
|
60
|
+
async with ClientSession(read_stream, write_stream) as session:
|
|
61
|
+
await session.initialize() # Inicializa a sessão
|
|
62
|
+
result = await session.call_tool(tool_name, params) # Executa a ferramenta
|
|
63
|
+
return result
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from mcp.server.fastmcp import FastMCP
|
|
2
|
+
from .schema.header import Header
|
|
3
|
+
|
|
4
|
+
import boto3
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
class BiaUtil():
|
|
8
|
+
|
|
9
|
+
HEADER_PREFIX = "x-amzn-bedrock-agentcore-runtime-custom"
|
|
10
|
+
|
|
11
|
+
def __init__(self, mcp: FastMCP):
|
|
12
|
+
"""
|
|
13
|
+
Inicializa o utilitário BiaUtil com uma instância do FastMCP.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
mcp (FastMCP): Instância do servidor FastMCP para obter contexto da requisição.
|
|
17
|
+
"""
|
|
18
|
+
self.mcp = mcp
|
|
19
|
+
|
|
20
|
+
def __get_from_ssm(self, parameter_name: str) -> str:
|
|
21
|
+
"""
|
|
22
|
+
Busca o valor de um parâmetro no AWS SSM Parameter Store.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
parameter_name (str): Nome do parâmetro a ser buscado.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
str: Valor do parâmetro, ou None se não encontrado.
|
|
29
|
+
"""
|
|
30
|
+
ctx = self.mcp.get_context() # Obtém o contexto da requisição atual
|
|
31
|
+
headers = ctx.request_context.request.headers # Acessa os headers da requisição
|
|
32
|
+
prefix = headers.get(f"{self.HEADER_PREFIX}-prefix", None) # Prefixo customizado do header
|
|
33
|
+
client = boto3.client('ssm', region_name="sa-east-1") # Cria cliente SSM na região especificada
|
|
34
|
+
try:
|
|
35
|
+
response = client.get_parameter(
|
|
36
|
+
Name=f"{prefix}/{parameter_name}",
|
|
37
|
+
WithDecryption=True
|
|
38
|
+
)
|
|
39
|
+
except client.exceptions.ParameterNotFound:
|
|
40
|
+
return None # Retorna None se o parâmetro não for encontrado
|
|
41
|
+
return response.get('Parameter').get('Value') # Retorna o valor do parâmetro
|
|
42
|
+
|
|
43
|
+
def get_header(self) -> Header:
|
|
44
|
+
"""
|
|
45
|
+
Retorna os parâmetros padrão contidos no header da requisição.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
Header: Objeto Header preenchido com os valores dos headers customizados.
|
|
49
|
+
"""
|
|
50
|
+
ctx = self.mcp.get_context() # Obtém o contexto da requisição atual
|
|
51
|
+
headers = ctx.request_context.request.headers # Acessa os headers da requisição
|
|
52
|
+
# Preenche o objeto Header com os valores dos headers customizados
|
|
53
|
+
return Header(
|
|
54
|
+
current_host=headers.get(f"{self.HEADER_PREFIX}-current-host", None),
|
|
55
|
+
user_email=headers.get(f"{self.HEADER_PREFIX}-user-email", None),
|
|
56
|
+
jwt_token=headers.get(f"{self.HEADER_PREFIX}-jwt-token", None),
|
|
57
|
+
jsessionid=headers.get(f"{self.HEADER_PREFIX}-jsessionid", None),
|
|
58
|
+
organization_id=int(headers.get(f"{self.HEADER_PREFIX}-organization-id", 0)),
|
|
59
|
+
codparc=int(headers.get(f"{self.HEADER_PREFIX}-codparc", 0)),
|
|
60
|
+
iam_user_id=int(headers.get(f"{self.HEADER_PREFIX}-iam-user-id", 0)),
|
|
61
|
+
gateway_token=headers.get(f"{self.HEADER_PREFIX}-gateway-token", None)
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
def get_parameter(self, parameter_name: str) -> str:
|
|
65
|
+
"""
|
|
66
|
+
Retorna o valor do parâmetro, buscando primeiro na variável de ambiente
|
|
67
|
+
e depois no AWS SSM Parameter Store caso não exista na variável de ambiente.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
parameter_name (str): Nome do parâmetro a ser buscado.
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
str: Valor do parâmetro, ou None se não encontrado.
|
|
74
|
+
"""
|
|
75
|
+
# Busca o valor na variável de ambiente, se não existir busca no SSM
|
|
76
|
+
return os.getenv(
|
|
77
|
+
parameter_name,
|
|
78
|
+
self.__get_from_ssm(parameter_name)
|
|
79
|
+
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: biatoolkit
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: Biblioteca para desenvolvedores que utilizam o BiaAgentBuilder
|
|
5
5
|
Author: Bia Platform Team
|
|
6
6
|
Author-email: data.platform@sankhya.com.br
|
|
@@ -128,7 +128,7 @@ Crie um novo arquivo chamado `local.py` com o seguinte conteúdo:
|
|
|
128
128
|
|
|
129
129
|
```python
|
|
130
130
|
import asyncio
|
|
131
|
-
from
|
|
131
|
+
from biatoolkit.basic_client import BasicClient
|
|
132
132
|
|
|
133
133
|
MCP_SERVER_URL = "http://0.0.0.0:8000/mcp"
|
|
134
134
|
client = BasicClient(MCP_SERVER_URL)
|
|
@@ -169,7 +169,7 @@ python local.py
|
|
|
169
169
|
|
|
170
170
|
Você deverá ver a saída no console semelhante a:
|
|
171
171
|
|
|
172
|
-

|
|
173
173
|
|
|
174
174
|
Caso deseje testar a execução de uma **tool**, basta alterar o método `main` conforme a seguir:
|
|
175
175
|
|
|
@@ -185,7 +185,7 @@ Veja que o método `call_tool` possui dois parâmetros:
|
|
|
185
185
|
|
|
186
186
|
Ao executar o arquivo `local.py`, você deverá ver a saída no console semelhante a:
|
|
187
187
|
|
|
188
|
-

|
|
189
189
|
|
|
190
190
|
### **Enviando parâmetros via header**
|
|
191
191
|
|
|
@@ -204,7 +204,7 @@ Se seu servidor MCP estiver sendo executado **localmente**, você conseguirá in
|
|
|
204
204
|
|
|
205
205
|
```python
|
|
206
206
|
import asyncio
|
|
207
|
-
from
|
|
207
|
+
from biatoolkit.basic_client import BasicClient
|
|
208
208
|
|
|
209
209
|
MCP_SERVER_URL = "http://0.0.0.0:8000/mcp"
|
|
210
210
|
|
|
@@ -258,7 +258,7 @@ Para recuperar os parâmetros no MCP Server que foram enviados por meio do `head
|
|
|
258
258
|
|
|
259
259
|
```python
|
|
260
260
|
from mcp.server.fastmcp import FastMCP
|
|
261
|
-
from
|
|
261
|
+
from biatoolkit.util import Util
|
|
262
262
|
|
|
263
263
|
mcp = FastMCP(host="0.0.0.0", stateless_http=True)
|
|
264
264
|
|
|
@@ -300,7 +300,7 @@ Para recuperar um valor sensível no seu MCP Server, utilize o método `get_para
|
|
|
300
300
|
|
|
301
301
|
```python
|
|
302
302
|
from mcp.server.fastmcp import FastMCP
|
|
303
|
-
from
|
|
303
|
+
from biatoolkit.util import Util
|
|
304
304
|
|
|
305
305
|
mcp = FastMCP(host="0.0.0.0", stateless_http=True)
|
|
306
306
|
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
from mcp import ClientSession
|
|
2
|
-
from mcp.client.streamable_http import streamablehttp_client
|
|
3
|
-
|
|
4
|
-
class BasicClient:
|
|
5
|
-
|
|
6
|
-
def __init__(self, url: str = "http://0.0.0.0:8000/mcp", headers: dict = None):
|
|
7
|
-
sufix = "/mcp"
|
|
8
|
-
self.url = url if url.endswith(sufix) else f"{url}{sufix}"
|
|
9
|
-
self.headers = headers
|
|
10
|
-
|
|
11
|
-
async def list_tools(self) -> dict:
|
|
12
|
-
"""Lista as ferramentas disponíveis no MCP"""
|
|
13
|
-
async with streamablehttp_client(self.url, self.headers, timeout=120, terminate_on_close=False) as (
|
|
14
|
-
read_stream,
|
|
15
|
-
write_stream,
|
|
16
|
-
_,
|
|
17
|
-
):
|
|
18
|
-
async with ClientSession(read_stream, write_stream) as session:
|
|
19
|
-
await session.initialize()
|
|
20
|
-
tool_result = await session.list_tools()
|
|
21
|
-
return tool_result
|
|
22
|
-
|
|
23
|
-
async def call_tool(self, tool_name: str, params: dict = None) -> dict:
|
|
24
|
-
"""Executa a ferramenta disponível no MCP"""
|
|
25
|
-
async with streamablehttp_client(self.url, self.headers, timeout=120, terminate_on_close=False) as (
|
|
26
|
-
read_stream,
|
|
27
|
-
write_stream,
|
|
28
|
-
_,
|
|
29
|
-
):
|
|
30
|
-
async with ClientSession(read_stream, write_stream) as session:
|
|
31
|
-
await session.initialize()
|
|
32
|
-
result = await session.call_tool(tool_name, params)
|
|
33
|
-
return result
|
|
34
|
-
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
from mcp.server.fastmcp import FastMCP
|
|
2
|
-
from .schema.header import Header
|
|
3
|
-
|
|
4
|
-
import boto3
|
|
5
|
-
import os
|
|
6
|
-
|
|
7
|
-
class Util():
|
|
8
|
-
|
|
9
|
-
HEADER_PREFIX = "x-amzn-bedrock-agentcore-runtime-custom"
|
|
10
|
-
|
|
11
|
-
def __init__(self, mcp: FastMCP):
|
|
12
|
-
self.mcp = mcp
|
|
13
|
-
|
|
14
|
-
def __get_from_ssm(self, parameter_name: str) -> str:
|
|
15
|
-
"""Busca o parâmetro no AWS SSM Parameter Store"""
|
|
16
|
-
ctx = self.mcp.get_context()
|
|
17
|
-
headers = ctx.request_context.request.headers
|
|
18
|
-
prefix = headers.get(f"{self.HEADER_PREFIX}-prefix", None)
|
|
19
|
-
client = boto3.client('ssm', region_name="sa-east-1")
|
|
20
|
-
try:
|
|
21
|
-
response = client.get_parameter(
|
|
22
|
-
Name=f"{prefix}/{parameter_name}",
|
|
23
|
-
WithDecryption=True
|
|
24
|
-
)
|
|
25
|
-
except client.exceptions.ParameterNotFound:
|
|
26
|
-
return None
|
|
27
|
-
return response.get('Parameter').get('Value')
|
|
28
|
-
|
|
29
|
-
def get_header(self) -> Header:
|
|
30
|
-
"""Retorna os parâmetros padrão contidos no header da requisição"""
|
|
31
|
-
ctx = self.mcp.get_context()
|
|
32
|
-
headers = ctx.request_context.request.headers
|
|
33
|
-
return Header(
|
|
34
|
-
current_host=headers.get(f"{self.HEADER_PREFIX}-current-host", None),
|
|
35
|
-
user_email=headers.get(f"{self.HEADER_PREFIX}-user-email", None),
|
|
36
|
-
jwt_token=headers.get(f"{self.HEADER_PREFIX}-jwt-token", None),
|
|
37
|
-
jsessionid=headers.get(f"{self.HEADER_PREFIX}-jsessionid", None),
|
|
38
|
-
organization_id=int(headers.get(f"{self.HEADER_PREFIX}-organization-id", 0)),
|
|
39
|
-
codparc=int(headers.get(f"{self.HEADER_PREFIX}-codparc", 0)),
|
|
40
|
-
iam_user_id=int(headers.get(f"{self.HEADER_PREFIX}-iam-user-id", 0)),
|
|
41
|
-
gateway_token=headers.get(f"{self.HEADER_PREFIX}-gateway-token", None)
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
def get_parameter(self, parameter_name: str) -> str:
|
|
45
|
-
"""
|
|
46
|
-
Retorna o valor do parâmetro, buscando primeiro na variável de
|
|
47
|
-
ambiente e depois no AWS SSM Parameter Store.
|
|
48
|
-
"""
|
|
49
|
-
return os.getenv(
|
|
50
|
-
parameter_name,
|
|
51
|
-
self.__get_from_ssm(parameter_name)
|
|
52
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|