fastmcp icon indicating copy to clipboard operation
fastmcp copied to clipboard

Incompatibility between FastMCP output for Enum types versus MCP inspector expectations

Open pamelafox opened this issue 1 month ago • 2 comments

Description

Currently, when you use an Enum type for a tool argument, the MCP inspector does not understand that type as an enum, due to FastMCP using refs/defs in the schame for them. This issue is discussed here in the inspector repo: https://github.com/modelcontextprotocol/inspector/issues/755 The inspector only has support for enums via outputType/enum list. I'm trying to figure out the path forward to be able to inspect FastMCP-generated tools.

Is there a way with FastMCP to output enums that does not use defs/refs and uses the simpler schema instead? Would it make sense to always do so?

Example Code

import csv
import logging
from datetime import date
from enum import Enum
from pathlib import Path
from typing import Annotated

from fastmcp import FastMCP

logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(message)s")
logger = logging.getLogger("ExpensesMCP")


SCRIPT_DIR = Path(__file__).parent
EXPENSES_FILE = SCRIPT_DIR / "expenses.csv"


mcp = FastMCP("Expenses Tracker")


class PaymentMethod(Enum):
  AMEX = "amex"
  VISA = "visa"
  CASH = "cash"


class Category(Enum):
  FOOD = "food"
  TRANSPORT = "transport"
  ENTERTAINMENT = "entertainment"
  SHOPPING = "shopping"
  GADGET = "gadget"
  OTHER = "other"


@mcp.tool
async def add_expense(
  date: Annotated[date, "Date of the expense in YYYY-MM-DD format"],
  amount: Annotated[float, "Positive numeric amount of the expense"],
  category: Annotated[Category, "Category label"],
  description: Annotated[str, "Human-readable description of the expense"],
  payment_method: Annotated[PaymentMethod, "Payment method used"],
):
  """Add a new expense to the expenses.csv file."""
  if amount <= 0:
    return "Error: Amount must be positive"

  date_iso = date.isoformat()
  logger.info(f"Adding expense: ${amount} for {description} on {date_iso}")

  try:
    file_exists = EXPENSES_FILE.exists()

    with open(EXPENSES_FILE, "a", newline="", encoding="utf-8") as file:
      writer = csv.writer(file)

      if not file_exists:
        writer.writerow(
          ["date", "amount", "category", "description", "payment_method"]
        )

      writer.writerow(
        [date_iso, amount, category.value, description, payment_method.name]
      )

    return f"Successfully added expense: ${amount} for {description} on {date_iso}"

  except Exception as e:
    logger.error(f"Error adding expense: {str(e)}")
    return "Error: Unable to add expense"


if __name__ == "__main__":
  logger.info("MCP Expenses server starting (HTTP mode on port 8000)")
  mcp.run(transport="http", host="0.0.0.0", port=8000)

Version Information

FastMCP version:                                                                2.12.5
MCP version:                                                                    1.16.0
Python version:                                                                 3.13.0
Platform:                                          macOS-14.8.1-arm64-arm-64bit-Mach-O
FastMCP root path: /Users/pamelafox/python-mcp-demo/.venv/lib/python3.13/site-packages

pamelafox avatar Oct 24 '25 19:10 pamelafox