Skip to main content
Glama
abutbul

Gatherings MCP Server

by abutbul

calculate_reimbursements

Calculate expense reimbursements for social gatherings to settle balances between participants. Input a gathering ID to process payments.

Instructions

Calculate reimbursements for a gathering

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
gathering_idYesID of the gathering

Implementation Reference

  • Core handler function that implements the reimbursement calculation logic: retrieves the gathering, computes for each member (expense_per_member - total_expenses + total_payments), and returns dict of member_name to amount (negative=gets reimbursed).
    def calculate_reimbursements(self, gathering_id: str) -> Dict[str, float]:
        """
        Calculate reimbursements for a gathering.
        
        Args:
            gathering_id: The ID of the gathering
            
        Returns:
            A dictionary mapping member names to reimbursement amounts
            (negative values mean the member gets reimbursed, positive values mean they owe money)
            
        Raises:
            ValueError: If the gathering doesn't exist
        """
        gathering = self.get_gathering(gathering_id)
        if not gathering:
            raise ValueError(f"Gathering '{gathering_id}' not found")
        
        # Calculate how much each member has paid and should pay
        expense_per_member = gathering.expense_per_member
        
        # Calculate reimbursements
        reimbursements = {}
        for member in gathering.members:
            # Amount to pay = total share - expenses + payments
            # If negative, member gets reimbursed; if positive, member owes money
            to_pay = expense_per_member - member.total_expenses + member.total_payments
            reimbursements[member.name] = to_pay
        
        return reimbursements
  • MCP tool schema definition: name, description, and inputSchema requiring a single 'gathering_id' string property.
    {
      name: 'calculate_reimbursements',
      description: 'Calculate reimbursements for a gathering',
      inputSchema: {
        type: 'object',
        properties: {
          gathering_id: {
            type: 'string',
            description: 'ID of the gathering',
          },
        },
        required: ['gathering_id'],
      },
    },
  • MCP CallToolRequest handler case for calculate_reimbursements: validates input using isGatheringIdArg type guard and constructs the Python CLI subcommand.
    case 'calculate_reimbursements':
      if (!isGatheringIdArg(args)) {
        throw new McpError(ErrorCode.InvalidParams, 'Invalid calculate_reimbursements arguments');
      }
      command += ` calculate "${args.gathering_id}"`;
      break;
  • CLI handler for 'calculate' command (invoked by MCP via python CLI): calls service.calculate_reimbursements, enhances output with types and totals, prints JSON or human-readable format.
    def handle_calculate(service, args):
        """Handle the calculate command."""
        try:
            reimbursements = service.calculate_reimbursements(args.gathering_id)
            gathering = service.get_gathering(args.gathering_id)
            
            result = {
                "success": True,
                "calculation": {
                    "total_expenses": gathering.total_expenses,
                    "expense_per_member": gathering.expense_per_member,
                    "reimbursements": {
                        name: {"amount": amount, "type": "gets_reimbursed" if amount < 0 else "needs_to_pay"}
                        for name, amount in reimbursements.items()
                    }
                }
            }
            
            if args.json:
                print(json.dumps(result))
            else:
                print(f"Total expenses: ${gathering.total_expenses:.2f}")
                print(f"Expense per member: ${gathering.expense_per_member:.2f}")
                print("Reimbursements:")
                for name, amount in reimbursements.items():
                    if amount < 0:
                        print(f"  {name} gets reimbursed ${abs(amount):.2f}")
                    else:
                        print(f"  {name} needs to pay ${amount:.2f}")
            return True
        except ValueError as e:
            error = {"success": False, "error": str(e)}
            if args.json:
                print(json.dumps(error))
            else:
                print(f"Error: {e}")
            return False
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool calculates reimbursements, implying a read-only or computational operation, but does not specify if it requires specific permissions, whether it modifies data, what the output format is, or any rate limits. For a tool with zero annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence: 'Calculate reimbursements for a gathering'. It is front-loaded with the core action and resource, with no unnecessary words or redundancy. Every part of the sentence earns its place by conveying the essential purpose without waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (involving financial calculations) and the lack of annotations and output schema, the description is incomplete. It does not explain what the calculation is based on (e.g., expenses, payments), what the output looks like, or any behavioral traits. For a tool with no structured data to supplement it, the description should provide more context to be fully helpful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the single parameter 'gathering_id' documented as 'ID of the gathering'. The description does not add any meaning beyond this, such as explaining what a gathering entails or how the ID is used. With high schema coverage, the baseline score is 3, as the schema handles the parameter documentation adequately.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Calculate reimbursements for a gathering' states a clear verb ('calculate') and resource ('reimbursements'), but it lacks specificity about what the calculation entails (e.g., based on expenses, payments, or member contributions) and does not distinguish it from sibling tools like 'record_payment' or 'close_gathering', which might involve financial operations. It avoids tautology by not restating the tool name, but remains vague on the exact purpose.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It does not mention prerequisites (e.g., whether expenses or payments must be recorded first), exclusions, or comparisons to sibling tools like 'record_payment' or 'close_gathering', leaving the agent to infer usage from context alone. This lack of explicit when/when-not instructions limits its utility.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/abutbul/gatherings-mcp'

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