Skip to content

Commit b5d9b3d

Browse files
committed
KAB-871 refactor(tools/comp): use KeboolaClient.from_state with context in tools
1 parent 480654e commit b5d9b3d

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/keboola_mcp_server/component_tools.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ def add_component_tools(mcp: FastMCP) -> None:
8181

8282
async def list_components(ctx: Context) -> List[Component]:
8383
"""List all available components."""
84-
client = ctx.session.state["sapi_client"]
85-
assert isinstance(client, KeboolaClient)
84+
client = KeboolaClient.from_state(ctx.session.state)
8685

8786
r_components = client.storage_client.components.list()
8887
logger.info(f"Found {len(r_components)} components.")
@@ -96,8 +95,7 @@ async def list_component_configurations(
9695
ctx: Context,
9796
) -> List[ComponentConfiguration]:
9897
"""List all configurations for a given component."""
99-
client = ctx.session.state["sapi_client"]
100-
assert isinstance(client, KeboolaClient)
98+
client = KeboolaClient.from_state(ctx.session.state)
10199

102100
component = await get_component_details(component_id, ctx)
103101
r_configs = client.storage_client.configurations.list(component_id)
@@ -116,8 +114,7 @@ async def get_component_configuration_details(
116114
ctx: Context,
117115
) -> ComponentConfiguration:
118116
"""Detail a given component configuration."""
119-
client = ctx.session.state["sapi_client"]
120-
assert isinstance(client, KeboolaClient)
117+
client = KeboolaClient.from_state(ctx.session.state)
121118

122119
component = await get_component_details(component_id, ctx)
123120
r_config = client.storage_client.configurations.detail(component_id, configuration_id)
@@ -131,8 +128,7 @@ async def get_component_details(
131128
ctx: Context,
132129
) -> Component:
133130
"""Retrieve detailed information about a original Keboola component object given component ID."""
134-
client = ctx.session.state["sapi_client"]
135-
assert isinstance(client, KeboolaClient)
131+
client = KeboolaClient.from_state(ctx.session.state)
136132

137133
endpoint = "branch/{}/components/{}".format(client.storage_client._branch_id, component_id)
138134
r_component = await client.get(endpoint)

0 commit comments

Comments
 (0)