mpl_mcp_plot_barchart
Generate bar charts by plotting numerical data with customizable labels, titles, axis labels, colors, and orientation on the Fermat MCP server.
Instructions
Plots barchart of given datavalues
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| color | No | skyblue | |
| dpi | No | ||
| labels | No | ||
| orientation | No | vertical | |
| save | No | ||
| title | No | ||
| values | Yes | ||
| xlabel | No | ||
| ylabel | No |
Implementation Reference
- fmcp/mpl_mcp/core/bar_chart.py:8-54 (handler)The main handler function plot_barchart that generates vertical or horizontal bar charts using matplotlib and returns a PNG image via FastMCP Image object.def plot_barchart( values: List[Union[float, int]], labels: Optional[List[str]] = None, title: str = "", xlabel: str = "", ylabel: str = "", color: str = "skyblue", save: bool = False, dpi: int = 200, orientation: Literal["vertical", "horizontal"] = "vertical", ) -> Image: """ Plot a bar chart (vertical or horizontal) with optional labels (defaults to empty strings). Args: values: List of bar heights (values: float or int) labels: List of bar labels (categories) or None for empty labels title: Plot title xlabel: Label for the x-axis ylabel: Label for the y-axis color: Color for the bars (default: "skyblue") save: If True, save the figure to a buffer dpi: Output image resolution (dots per inch, default: 100) orientation: "vertical" or "horizontal" (default: "vertical") Returns: FastMCP Image object with the plotted chart """ plt.figure(dpi=dpi) if labels is None: labels = [""] * len(values) if orientation == "vertical": plt.bar(labels, values, color=color) else: plt.barh(labels, values, color=color) plt.title(title) plt.xlabel(xlabel) plt.ylabel(ylabel) plt.xticks(rotation=45) plt.tight_layout() buf = io.BytesIO() plt.savefig(buf, format="png", dpi=dpi) plt.close() buf.seek(0) return Image(data=buf.read(), format="png")
- fmcp/mpl_mcp/server.py:19-19 (registration)Registers the plot_barchart function as the MCP tool 'mpl_mcp_plot_barchart' using FastMCP's tool decorator with a description.mpl_mcp.tool(plot_barchart, description="Plots barchart of given datavalues")
- fmcp/mpl_mcp/server.py:2-2 (registration)Imports the plot_barchart handler into the server for registration.from .core.bar_chart import plot_barchart