Skip to content

Commit d41f806

Browse files
committed
simplify names further to UserDefinedTool and SystemTool
1 parent a205df9 commit d41f806

File tree

16 files changed

+94
-97
lines changed

16 files changed

+94
-97
lines changed

src/fenic/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@
108108
StructField,
109109
StructType,
110110
StructuredOutputStrategy,
111-
SystemToolDefinition,
111+
SystemTool,
112112
ToolParam,
113113
TranscriptType,
114-
UserDefinedToolDefinition,
114+
UserDefinedTool,
115115
)
116116
from fenic.core.error import InvalidExampleCollectionError
117117
from fenic.core.types.semantic import ModelAlias
@@ -237,8 +237,8 @@
237237
# MCP
238238
"ToolParam",
239239
"BoundToolParam",
240-
"UserDefinedToolDefinition",
241-
"SystemToolDefinition",
240+
"UserDefinedTool",
241+
"SystemTool",
242242
"ToolGenerationConfig",
243243
"create_mcp_server",
244244
"run_mcp_server_asgi",

src/fenic/_backends/cloud/catalog.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
TableAlreadyExistsError,
5252
TableNotFoundError,
5353
)
54-
from fenic.core.mcp.types import ToolParam, UserDefinedToolDefinition
54+
from fenic.core.mcp.types import ToolParam, UserDefinedTool
5555
from fenic.core.types import DatasetMetadata, Schema
5656
from fenic.core.types.schema import ColumnField
5757

@@ -341,7 +341,7 @@ def set_view_description(self, view_name: str, description: str) -> bool:
341341
"Set view description not implemented for cloud catalog"
342342
)
343343

344-
def describe_tool(self, tool_name: str) -> UserDefinedToolDefinition:
344+
def describe_tool(self, tool_name: str) -> UserDefinedTool:
345345
"""Find and return the tool from the current database."""
346346
# TODO: Implement get tool for the cloud
347347
raise NotImplementedError(
@@ -368,7 +368,7 @@ def drop_tool(self, tool_name: str, ignore_if_not_exists: bool = True) -> bool:
368368
"Drop tool not implemented for cloud catalog"
369369
)
370370

371-
def list_tools(self) -> List[UserDefinedToolDefinition]:
371+
def list_tools(self) -> List[UserDefinedTool]:
372372
"""Get a list of all tools in the current database."""
373373
raise NotImplementedError(
374374
"List tools not implemented for cloud catalog"

src/fenic/_backends/local/catalog.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
ToolNotFoundError,
3131
)
3232
from fenic.core.mcp._tools import bind_tool
33-
from fenic.core.mcp.types import ToolParam, UserDefinedToolDefinition
33+
from fenic.core.mcp.types import ToolParam, UserDefinedTool
3434
from fenic.core.metrics import QueryMetrics
3535
from fenic.core.types import (
3636
DatasetMetadata,
@@ -506,7 +506,7 @@ def set_view_description(self, view_name: str, description: Optional[str]) -> bo
506506
) from e
507507

508508

509-
def describe_tool(self, tool_name: str) -> Optional[UserDefinedToolDefinition]:
509+
def describe_tool(self, tool_name: str) -> Optional[UserDefinedTool]:
510510
"""Get a tool's metadata from the system table."""
511511
cursor = self.db_conn.cursor()
512512
existing_tool = self.system_tables.describe_tool(cursor, tool_name)
@@ -534,7 +534,7 @@ def create_tool(
534534
self.system_tables.save_tool(cursor, tool_definition)
535535
return True
536536

537-
def list_tools(self) -> List[UserDefinedToolDefinition]:
537+
def list_tools(self) -> List[UserDefinedTool]:
538538
"""List all tools in the current catalog."""
539539
cursor = self.db_conn.cursor()
540540
return self.system_tables.list_tools(cursor)

src/fenic/_backends/local/system_table_client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from fenic.core._serde.proto.serde_context import SerdeContext
2020
from fenic.core._serde.proto.types import ToolDefinitionProto
2121
from fenic.core.error import CatalogError
22-
from fenic.core.mcp.types import UserDefinedToolDefinition
22+
from fenic.core.mcp.types import UserDefinedTool
2323
from fenic.core.metrics import QueryMetrics
2424
from fenic.core.types import ColumnField, DatasetMetadata, Schema
2525
from fenic.core.types.datatypes import (
@@ -465,7 +465,7 @@ def delete_database_views(self, cursor: duckdb.DuckDBPyConnection, database_name
465465
f"Failed to delete views metadata for database {database_name}"
466466
) from e
467467

468-
def save_tool(self, cursor: duckdb.DuckDBPyConnection, tool: UserDefinedToolDefinition) -> None:
468+
def save_tool(self, cursor: duckdb.DuckDBPyConnection, tool: UserDefinedTool) -> None:
469469
"""Save a tool's metadata to the system table.
470470
Raises:
471471
CatalogError: If the tool metadata cannot be saved.
@@ -486,7 +486,7 @@ def save_tool(self, cursor: duckdb.DuckDBPyConnection, tool: UserDefinedToolDefi
486486
f"Failed to save tool metadata for {tool.name}"
487487
) from e
488488

489-
def describe_tool(self, cursor: duckdb.DuckDBPyConnection, tool_name: str) -> Optional[UserDefinedToolDefinition]:
489+
def describe_tool(self, cursor: duckdb.DuckDBPyConnection, tool_name: str) -> Optional[UserDefinedTool]:
490490
"""Get a tool's metadata from the system table.
491491
Raises:
492492
CatalogError: If the tool metadata cannot be retrieved.
@@ -508,7 +508,7 @@ def describe_tool(self, cursor: duckdb.DuckDBPyConnection, tool_name: str) -> Op
508508
f"Failed to retrieve tool metadata for {tool_name}"
509509
) from e
510510

511-
def list_tools(self, cursor: duckdb.DuckDBPyConnection) -> List[UserDefinedToolDefinition]:
511+
def list_tools(self, cursor: duckdb.DuckDBPyConnection) -> List[UserDefinedTool]:
512512
"""List all tools in the system table.
513513
Raises:
514514
CatalogError: If the tools metadata cannot be retrieved.
@@ -815,7 +815,7 @@ def _initialize_tools_metadata(self, cursor: duckdb.DuckDBPyConnection) -> None:
815815
f"Failed to initialize tools and {TOOLS_METADATA_TABLE} table"
816816
) from e
817817

818-
def _deserialize_and_resolve_tool(self, row: tuple) -> UserDefinedToolDefinition:
818+
def _deserialize_and_resolve_tool(self, row: tuple) -> UserDefinedTool:
819819
decoded_tool = base64.b64decode(row[0])
820820
proto_tool = ToolDefinitionProto.FromString(decoded_tool)
821821
return self.serde_context.deserialize_tool_definition(proto_tool)

src/fenic/api/catalog.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from fenic.api.dataframe.dataframe import DataFrame
88
from fenic.core._interfaces.catalog import BaseCatalog
9-
from fenic.core.mcp.types import ToolParam, UserDefinedToolDefinition
9+
from fenic.core.mcp.types import ToolParam, UserDefinedTool
1010
from fenic.core.types import DatasetMetadata, Schema
1111

1212

@@ -654,7 +654,7 @@ def drop_view(self, view_name: str, ignore_if_not_exists: bool = True) -> bool:
654654
return self.catalog.drop_view(view_name, ignore_if_not_exists)
655655

656656
@validate_call(config=ConfigDict(strict=True))
657-
def describe_tool(self, tool_name: str) -> UserDefinedToolDefinition:
657+
def describe_tool(self, tool_name: str) -> UserDefinedTool:
658658
"""Returns the tool with the specified name from the current catalog.
659659
660660
Args:
@@ -747,7 +747,7 @@ def drop_tool(self, tool_name: str, ignore_if_not_exists: bool = True) -> bool:
747747
"""
748748
return self.catalog.drop_tool(tool_name, ignore_if_not_exists)
749749

750-
def list_tools(self) -> List[UserDefinedToolDefinition]:
750+
def list_tools(self) -> List[UserDefinedTool]:
751751
"""Lists the tools available in the current catalog."""
752752
return self.catalog.list_tools()
753753

src/fenic/api/mcp/server.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
from fenic.api.session.session import Session
1414
from fenic.core.error import ConfigurationError
1515
from fenic.core.mcp._server import FenicMCPServer, MCPTransport
16-
from fenic.core.mcp.types import SystemToolDefinition, UserDefinedToolDefinition
16+
from fenic.core.mcp.types import SystemTool, UserDefinedTool
1717

1818

1919
def create_mcp_server(
2020
session: Session,
2121
server_name: str,
2222
*,
23-
user_defined_tools: Optional[List[UserDefinedToolDefinition]] = None,
23+
user_defined_tools: Optional[List[UserDefinedTool]] = None,
24+
system_tools: Optional[List[SystemTool]] = None,
2425
automated_tool_generation: Optional[ToolGenerationConfig] = None,
2526
concurrency_limit: int = 8,
2627
) -> FenicMCPServer:
@@ -29,13 +30,13 @@ def create_mcp_server(
2930
Args:
3031
session: Fenic session used to execute tools.
3132
server_name: Name of the MCP server.
33+
system_tools: List of system tools to register (optional).
3234
user_defined_tools: Tools to register (optional).
3335
automated_tool_generation: Generate automated tools for one or more Dataframes.
3436
concurrency_limit: Maximum number of concurrent tool executions.
3537
"""
36-
system_tools: List[SystemToolDefinition] = []
37-
if user_defined_tools is None:
38-
user_defined_tools = []
38+
system_tools = system_tools or []
39+
user_defined_tools = user_defined_tools or []
3940
if automated_tool_generation:
4041
system_tools.extend(auto_generate_system_tools_from_tables(
4142
automated_tool_generation.table_names,

src/fenic/api/mcp/tool_generation.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,10 @@
1111

1212
from __future__ import annotations
1313

14-
import asyncio
15-
import functools
1614
import hashlib
17-
import inspect
1815
import re
1916
from dataclasses import dataclass
20-
from inspect import iscoroutinefunction
2117
from typing import (
22-
Any,
23-
Callable,
24-
Coroutine,
2518
Dict,
2619
List,
2720
Literal,
@@ -45,7 +38,7 @@
4538
from fenic.core._logical_plan.plans.base import LogicalPlan
4639
from fenic.core._utils.schema import convert_custom_dtype_to_polars
4740
from fenic.core.error import ConfigurationError, ValidationError
48-
from fenic.core.mcp.types import SystemToolDefinition, TableFormat
41+
from fenic.core.mcp.types import SystemTool
4942
from fenic.core.types.datatypes import (
5043
BooleanType,
5144
DoubleType,
@@ -92,7 +85,7 @@ def auto_generate_system_tools_from_tables(
9285
*,
9386
tool_group_name: str,
9487
max_result_limit: int = 100,
95-
) -> List[SystemToolDefinition]:
88+
) -> List[SystemTool]:
9689
"""Generate Schema/Profile/Read/Search/Analyze tools from catalog tables.
9790
9891
Validates that each table exists and has a non-empty description in catalog metadata.
@@ -112,7 +105,7 @@ def _auto_generate_read_tool(
112105
tool_description: str,
113106
*,
114107
result_limit: int = 50,
115-
) -> SystemToolDefinition:
108+
) -> SystemTool:
116109
"""Create a read tool over one or many datasets."""
117110
if len(datasets) == 0:
118111
raise ConfigurationError("Cannot create read tool: no datasets provided.")
@@ -165,7 +158,7 @@ async def read_func(
165158
sort_ascending=sort_ascending,
166159
)
167160

168-
return SystemToolDefinition(
161+
return SystemTool(
169162
name=tool_name,
170163
description=tool_description,
171164
func=read_func,
@@ -179,7 +172,7 @@ def _auto_generate_search_summary_tool(
179172
session: Session,
180173
tool_name: str,
181174
tool_description: str,
182-
) -> SystemToolDefinition:
175+
) -> SystemTool:
183176
"""Create a grep-like summary tool over one or many datasets (string columns)."""
184177
if len(datasets) == 0:
185178
raise ValueError("Cannot create search summary tool: no datasets provided.")
@@ -205,7 +198,7 @@ async def search_summary(
205198
pl_df = pl.DataFrame(rows)
206199
return InMemorySource.from_session_state(pl_df, session._session_state)
207200

208-
return SystemToolDefinition(
201+
return SystemTool(
209202
name=tool_name,
210203
description=tool_description,
211204
func=search_summary,
@@ -220,7 +213,7 @@ def _auto_generate_search_content_tool(
220213
tool_description: str,
221214
*,
222215
result_limit: int = 100,
223-
) -> SystemToolDefinition:
216+
) -> SystemTool:
224217
"""Create a content search tool for a single dataset (string columns)."""
225218
if len(datasets) == 0:
226219
raise ValidationError("Cannot create search content tool: no datasets provided.")
@@ -276,7 +269,7 @@ async def search_rows(
276269
sort_ascending=sort_ascending,
277270
)
278271

279-
return SystemToolDefinition(
272+
return SystemTool(
280273
name=tool_name,
281274
description=tool_description,
282275
func=search_rows,
@@ -290,7 +283,7 @@ def _auto_generate_schema_tool(
290283
session: Session,
291284
tool_name: str,
292285
tool_description: str,
293-
) -> SystemToolDefinition:
286+
) -> SystemTool:
294287
"""Create a schema tool over one or many datasets.
295288
296289
- Returns one row per dataset with a column `schema` containing a list of
@@ -337,7 +330,7 @@ async def schema_func(
337330
session._session_state,
338331
)
339332

340-
return SystemToolDefinition(
333+
return SystemTool(
341334
name=tool_name,
342335
description=tool_description.strip(),
343336
func=schema_func,
@@ -352,7 +345,7 @@ def _auto_generate_sql_tool(
352345
tool_description: str,
353346
*,
354347
result_limit: int = 100,
355-
) -> SystemToolDefinition:
348+
) -> SystemTool:
356349
"""Create an Analyze tool that executes DuckDB SELECT SQL across datasets.
357350
358351
- JOINs between the provided datasets are allowed.
@@ -389,7 +382,7 @@ async def analyze_func(
389382
)
390383
enhanced_description = "\n".join(lines)
391384

392-
tool = SystemToolDefinition(
385+
tool = SystemTool(
393386
name=tool_name,
394387
description=enhanced_description,
395388
func=analyze_func,
@@ -485,7 +478,7 @@ def _auto_generate_profile_tool(
485478
tool_description: str,
486479
*,
487480
topk_distinct: int = 10,
488-
) -> SystemToolDefinition:
481+
) -> SystemTool:
489482
"""Create a cached Profile tool for one or many datasets.
490483
491484
Output columns include:
@@ -525,7 +518,7 @@ async def profile_func(
525518

526519
return profile_df._logical_plan
527520

528-
return SystemToolDefinition(
521+
return SystemTool(
529522
name=tool_name,
530523
description=tool_description,
531524
func=profile_func,
@@ -700,7 +693,7 @@ def _auto_generate_system_tools(
700693
*,
701694
tool_group_name: str,
702695
max_result_limit: int = 100,
703-
) -> List[SystemToolDefinition]:
696+
) -> List[SystemTool]:
704697
"""Generate core tools spanning all datasets: Schema, Profile, Analyze.
705698
706699
- Schema: list columns/types for any or all datasets

src/fenic/core/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from fenic.core.mcp import (
44
BoundToolParam,
5-
SystemToolDefinition,
5+
SystemTool,
66
ToolParam,
7-
UserDefinedToolDefinition,
7+
UserDefinedTool,
88
)
99
from fenic.core.metrics import (
1010
LMMetrics,
@@ -105,6 +105,6 @@
105105
# MCP
106106
"ToolParam",
107107
"BoundToolParam",
108-
"UserDefinedToolDefinition",
109-
"SystemToolDefinition",
108+
"UserDefinedTool",
109+
"SystemTool",
110110
]

src/fenic/core/_interfaces/catalog.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
if TYPE_CHECKING:
99
from fenic.core._logical_plan.plans.base import LogicalPlan
10-
from fenic.core.mcp.types import ToolParam, UserDefinedToolDefinition
10+
from fenic.core.mcp.types import ToolParam, UserDefinedTool
1111

1212

1313
class BaseCatalog(ABC):
@@ -145,7 +145,7 @@ def describe_view(self, view_name: str) -> DatasetMetadata:
145145
pass
146146

147147
@abstractmethod
148-
def describe_tool(self, tool_name: str) -> UserDefinedToolDefinition:
148+
def describe_tool(self, tool_name: str) -> UserDefinedTool:
149149
"""Find and return the tool from the current catalog."""
150150
pass
151151

@@ -168,6 +168,6 @@ def drop_tool(self, tool_name: str, ignore_if_not_exists: bool = True) -> bool:
168168
pass
169169

170170
@abstractmethod
171-
def list_tools(self) -> List[UserDefinedToolDefinition]:
171+
def list_tools(self) -> List[UserDefinedTool]:
172172
"""Get a list of all tools in the current catalog."""
173173
pass

0 commit comments

Comments
 (0)