Skip to content

Commit ab88b25

Browse files
committed
add logic to automated tool creation to add limit, table_format as arguments the mcp server knows about, but are not passed to the tool func
1 parent 206b76f commit ab88b25

File tree

8 files changed

+241
-68
lines changed

8 files changed

+241
-68
lines changed

src/fenic/api/mcp/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def create_mcp_server(
3030
session: Fenic session used to execute tools.
3131
server_name: Name of the MCP server.
3232
tools: Tools to register (optional).
33-
automated_tool_generation: Generate automated tools for one or more Dataframes
33+
automated_tool_generation: Generate automated tools for one or more Dataframes.
3434
concurrency_limit: Maximum number of concurrent tool executions.
3535
"""
3636
dynamic_tools: List[DynamicToolDefinition] = []
@@ -43,7 +43,7 @@ def create_mcp_server(
4343
tool_group_name=automated_tool_generation.tool_group_name,
4444
sql_max_rows=automated_tool_generation.sql_max_rows)
4545
)
46-
if not tools and not dynamic_tools:
46+
if not (tools or dynamic_tools):
4747
raise ConfigurationError("No tools provided. Either provide tools or set generate_automated_tools=True and provide datasets.")
4848
return FenicMCPServer(session._session_state, tools, dynamic_tools, server_name, concurrency_limit)
4949

src/fenic/api/mcp/tool_generation.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ def read_func(
110110
sort_ascending: Annotated[Optional[Union[bool, str]], "Sort ascending for all order_by columns"] = True,
111111
) -> LogicalPlan:
112112

113+
if df_name not in name_to_df:
114+
raise ValidationError(f"Unknown DataFrame '{df_name}'. Available: {', '.join(name_to_df.keys())}")
115+
df = name_to_df[df_name]
113116
limit = int(limit) if isinstance(limit, str) else limit
114117
offset = int(offset) if isinstance(offset, str) else offset
115118
sort_ascending = bool(sort_ascending) if isinstance(sort_ascending, str) else sort_ascending
116119
order_by = [c.strip() for c in order_by.split(",") if c.strip()] if order_by else None
117-
if df_name not in name_to_df:
118-
raise ValidationError(f"Unknown DataFrame '{df_name}'. Available: {', '.join(name_to_df.keys())}")
119-
df = name_to_df[df_name]
120120

121121
# order_by when not paginating via OFFSET (to avoid double sorting)
122122
if order_by and offset is None:
@@ -141,7 +141,7 @@ def read_func(
141141
name=tool_name,
142142
description=tool_description,
143143
func=read_func,
144-
result_limit=result_limit,
144+
max_result_limit=result_limit,
145145
)
146146

147147
"""
@@ -186,7 +186,7 @@ def search_summary(
186186
name=tool_name,
187187
description=tool_description,
188188
func=search_summary,
189-
result_limit=None,
189+
max_result_limit=None,
190190
)
191191

192192
def auto_generate_search_content_tool(
@@ -255,7 +255,7 @@ def search_rows(
255255
name=tool_name,
256256
description=tool_description,
257257
func=search_rows,
258-
result_limit=result_limit,
258+
max_result_limit=result_limit,
259259
)
260260

261261

@@ -322,7 +322,8 @@ def schema_func(
322322
name=tool_name,
323323
description=enhanced_description,
324324
func=schema_func,
325-
result_limit=None,
325+
max_result_limit=None,
326+
default_table_format="structured"
326327
)
327328

328329

@@ -387,7 +388,7 @@ def analyze_func(
387388
name=tool_name,
388389
description=enhanced_description,
389390
func=analyze_func,
390-
result_limit=result_limit,
391+
max_result_limit=result_limit,
391392
)
392393
return tool
393394

@@ -606,7 +607,8 @@ def profile_func(
606607
name=tool_name,
607608
description=enhanced_description,
608609
func=profile_func,
609-
result_limit=None,
610+
max_result_limit=None,
611+
default_table_format="structured"
610612
)
611613

612614

src/fenic/core/_serde/proto/serde_context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ def serialize_tool_definition(
932932
params=serialized_params,
933933
parameterized_view=self.serialize_logical_plan("parameterized_view",
934934
tool_definition._parameterized_view),
935-
result_limit=tool_definition.result_limit,
935+
result_limit=tool_definition.max_result_limit,
936936
)
937937
except Exception as e:
938938
self._handle_serde_error(e)
@@ -951,7 +951,7 @@ def deserialize_tool_definition(
951951
params=[self.deserialize_tool_parameter(tool_param) for tool_param in tool_definition_proto.params],
952952
_parameterized_view=self.deserialize_logical_plan("parameterized_view",
953953
tool_definition_proto.parameterized_view),
954-
result_limit=tool_definition_proto.result_limit,
954+
max_result_limit=tool_definition_proto.result_limit,
955955
)
956956
except Exception as e:
957957
self._handle_serde_error(e)

0 commit comments

Comments
 (0)