"""Explore table tool."""
from typing import Any, Optional
from fastmcp import Context
from .base import MCPTool
class ExploreTableService(MCPTool):
"""Service to get sample data from a table."""
@property
def name(self) -> str:
return "explore_table"
@property
def description(self) -> str:
return "Get sample data from a specified table"
async def execute(
self,
ctx: Context,
table: str,
database: Optional[str] = None,
server_name: Optional[str] = None,
limit: int = 5,
user: Optional[str] = None,
password: Optional[str] = None,
driver: Optional[str] = None,
port: Optional[int] = None
) -> list[dict[str, Any]]:
"""Explore table data.
Args:
ctx: FastMCP context
table: Table name to explore
database: Database name
server_name: Server hostname/address
limit: Maximum number of rows (default 5, max 100)
user: Database username
password: Database password
driver: ODBC driver name
port: Server port
Returns:
list[dict]: Sample data or error dictionary
"""
creds = self.creds_manager.get_from_context(
ctx, user, password, server_name, database, driver, port
)
if not creds.database or not table:
return [{"error": "Database and table names are required"}]
if not creds.is_valid():
return [{"error": "Missing credentials"}]
return self.executor.explore_table(creds, table, limit)