feat: smart parameter resolution for execute_card#9
Conversation
Add automatic parameter format resolution for execute_card tool.
Users can now pass simplified {name: value} objects instead of
constructing the full Metabase parameter array manually.
The tool inspects the card's template tags to determine parameter
types (text, date, dimension, number) and builds the correct
native Metabase parameter format automatically.
This is especially useful for dimension-type parameters which
require a specific format that differs from text parameters.
Both simplified object format and native array format are
supported for backwards compatibility.
|
Hi @Courtneychow88, just wanted to ping here — would appreciate a review when you get a chance. Happy to address any feedback! |
|
Thanks for this — the approach of fetching template tag metadata to resolve the correct parameter format is exactly right, and the type dispatch (text/date/dimension/number) is a significant improvement over hardcoding. PR #7 has been closed in favour of this one. Before we merge, four things to address: 1. Guard against non-native cards If if (card?.dataset_query?.type !== "native") {
throw new McpError(
ErrorCode.InvalidParams,
"Simplified parameters are only supported for native (SQL) cards"
);
}2. Unknown parameter should throw, not silently fall back The current fallback constructs a throw new McpError(
ErrorCode.InvalidParams,
`Unknown parameter: "${name}". Known parameters: ${Object.keys(templateTags).join(", ")}`
);3. Restore The current diff removes the parameters: {
description: "...",
oneOf: [
{ type: "object" },
{ type: "array", items: { type: "object" } }
]
}4. Document the All date template tags are currently mapped to Happy to help with any of these if useful. The core logic is solid — these are the remaining gaps before it's production-safe. |
|
This is great! Much better approach than mine. =) |
Summary
This PR adds automatic parameter format resolution for the
execute_cardtool, making it significantly easier to pass query parameters — especiallydimension-type parameters.Problem
Currently, users must construct the full native Metabase parameter array manually to filter card results. This is especially painful for
dimension-type parameters which require a specific format:{ "type": "string/=", "target": ["dimension", ["template-tag", "module_lv1"]], "value": ["L4"] }Most MCP clients (AI agents) don't know this format and end up passing parameters incorrectly, resulting in unfiltered results.
Solution
The
execute_cardtool now accepts two parameter formats:1. Simplified format (new, recommended)
Pass a plain
{name: value}object:{ "card_id": 28342, "parameters": { "site_name": "guangzhou", "module_lv1": "L4", "module_lv2": "XDriving" } }The tool automatically:
2. Native array format (existing, preserved)
The original array format continues to work for backwards compatibility:
{ "card_id": 28342, "parameters": [ {"type": "string/=", "target": ["dimension", ["template-tag", "module_lv1"]], "value": ["L4"]} ] }Parameter type mapping
text{type: "category", target: ["variable", ...], value: [...]}date{type: "date/single", target: ["variable", ...], value: "..."}dimension{type: "string/=", target: ["dimension", ...], value: [...]}number{type: "number/=", target: ["variable", ...], value: [...]}Testing
Tested against a real Metabase instance with a card containing all parameter types (text, date, dimension):
{name: value}format — correctly filters dimension parametersChanges
src/handlers/card-tools.ts: Enhancedexecute_cardschema and addedresolveSimplifiedParameters()method