Skip to main content
Glama
HeetVekariya

Linear Regression MCP

by HeetVekariya

upload_file

Upload CSV data to prepare for linear regression analysis, reading file content and returning dataset shape information.

Instructions

This function read the csv data and stores it in the class variable.

Args: Absolute path to the .csv file.

Returns: String which shows the shape of the data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • server.py:36-68 (handler)
    The main handler function for the 'upload_file' tool. It loads a CSV file using pandas, stores the DataFrame in a global DataContext instance, and returns the shape of the data or an error message.
    @mcp.tool() def upload_file(path: str) -> str: """ This function read the csv data and stores it in the class variable. Args: Absolute path to the .csv file. Returns: String which shows the shape of the data. """ if not os.path.exists(path): return f"Error: The file at '{path}' does not exist." # Check if file has a .csv extension if not path.lower().endswith('.csv'): return "Error: The file must be a CSV file." try: # Try to read the CSV file using pandas data = pd.read_csv(path) # Store the data in the DataContext class context.set_data(data) # Store the shape of the data (rows, columns) data_shape = context.get_data().shape return f"Data successfully loaded. Shape: {data_shape}" except Exception as e: return f"An unexpected error occured: {str(e)}"
  • Helper class DataContext used by upload_file to store and retrieve the loaded DataFrame globally.
    @dataclass class DataContext(): """ A class that stores the DataFrame in the context. """ _data: pd.DataFrame = None def set_data(self, new_data: pd.DataFrame): """ Method to set or update the data. """ self._data = new_data def get_data(self) -> pd.DataFrame: """ Method to get the data from the context. """ return self._data # Initialize the DataContext instance globally context = DataContext()
  • server.py:36-36 (registration)
    Decorator that registers the upload_file function as an MCP tool.
    @mcp.tool()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/HeetVekariya/Linear-Regression-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server