Skip to content

create_card tool fails with 500 errors while direct API calls succeed #9

@bryanpost

Description

@bryanpost

Summary

The create_card tool consistently fails with 500 errors when attempting to create new Metabase cards, even when the payload is correctly formatted and the Metabase API is functioning properly. Direct curl requests to the same endpoint with identical payloads succeed without issues.

It seems possible this is the result of untested AI code, and other commands will similarly fail.

Steps to Reproduce

  1. Configure MCP server with valid Metabase URL and API key:
{
  "mcpServers": {
    "metabase-all": {
      "command": "npx",
      "args": ["@cognitionai/metabase-mcp-server", "--all"],
      "env": {
        "METABASE_URL": "https://your-metabase-instance.com/",
        "METABASE_API_KEY": "mb_your_api_key"
      }
    }
  }
}
  1. Attempt to create a card using the create_card tool with the following parameters:
{
  "name": "Sample Card Name",
  "description": "Top 10 rows from random table",
  "visualization_settings": {},
  "collection_id": 63,
  "dataset_query": {
    "database": 2,
    "type": "native",
    "native": {
      "query": "SELECT * FROM schema.table LIMIT 10",
      "template-tags": {}
    }
  },
  "display": "table"
}
  1. Observe the error response

Expected Behavior

The card should be created successfully and return the card object with HTTP 200/201 status.

Actual Behavior

The tool fails with:

Tool 'create_card' execution failed: Failed to create card: Request failed with status code 500

Note: The error message does not include the response body from Metabase, which would normally contain detailed error information.

Workaround

Direct API calls using curl work correctly with the exact same payload:

curl -X POST "https://your-metabase-instance.com/api/card" \
  -H "Content-Type: application/json" \
  -H "X-API-KEY: mb_your_api_key" \
  -d '{
    "name": "Sample Card Name",
    "description": "Top 10 rows from random table",
    "visualization_settings": {},
    "collection_id": 63,
    "dataset_query": {
      "database": 2,
      "type": "native",
      "native": {
        "query": "SELECT * FROM schema.table LIMIT 10",
        "template-tags": {}
      }
    },
    "display": "table"
  }'

This returns HTTP 200 with the created card object.

Error response body not exposed

The MCP tool only returns the HTTP status code without the response body. This makes debugging difficult because:

  • Metabase API typically returns detailed error messages in the response body
  • The error message format is: Failed to create card: Request failed with status code 500
  • No additional details about what went wrong are provided

Suggested Fix

  1. Investigate the request formation in metabase-client.ts createCard() method to identify why it differs from a working curl request
  2. Expose full error responses in the MCP tool error messages to aid debugging
  3. Add error body to error message - even if the root cause is fixed, including the response body in error messages would help with future issues

Related Code

The implementation is in src/client/metabase-client.ts#L321:

async createCard(card: Partial<Card>): Promise<Card> {
    const response = await this.axiosInstance.post("/api/card", card);
    return response.data;
}

The Metabase API documentation for this endpoint: POST /api/card

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions