Skip to main content
Glama
HeetVekariya

Linear Regression MCP

by HeetVekariya

upload_file

Upload a CSV file to the Linear Regression MCP server to preprocess data, train a linear regression model, and evaluate its performance. Returns the shape of the uploaded dataset.

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 reads a CSV file, validates the path and extension, loads the data into a global DataContext using pandas, and returns the data shape 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)}"
  • server.py:36-36 (registration)
    The @mcp.tool() decorator registers the upload_file function as an MCP tool.
    @mcp.tool()
  • The DataContext class provides storage and access methods for the DataFrame used by the upload_file tool and other tools.
    @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

Other Tools

Related Tools

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