-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
gr.State breaks MCP parameter mapping
Repro: https://huggingface.co/spaces/multimodalart/mcp-breaking-state
Code:
import gradio as gr
def process(name: str, hidden_state: str, flag: bool, gallery_images: list = []):
"""
Process inputs and return a result.
Args:
name: A text input from user
hidden_state: A value from gr.State (hidden from MCP)
flag: A boolean checkbox
gallery_images: Gallery images list
Returns:
str: Result showing all received values
"""
return f"name={name}, hidden_state={hidden_state}, flag={flag}, gallery={gallery_images}"
with gr.Blocks() as demo:
gr.Markdown("# Gradio MCP Bug: gr.State breaks parameter order")
name_input = gr.Textbox(label="Name", value="test")
hidden_state = gr.State(value="hidden_value")
flag_input = gr.Checkbox(label="Flag", value=True)
gallery = gr.Gallery(label="Images", value=[])
output = gr.Textbox(label="Result")
btn = gr.Button("Process")
btn.click(
process,
inputs=[name_input, hidden_state, flag_input, gallery],
outputs=[output],
api_visibility="public",
)
if __name__ == "__main__":
demo.launch(mcp_server=True, show_error=True)
MCP schema shows 3 params (State is hidden):
- name: string
- flag: boolean
- gallery_images: array
Function expects 4 params:
- name: str
- hidden_state: str ← gr.State
- flag: bool
- gallery_images: list
When calling MCP with {"name": "hello", "flag": true, "gallery_images": []}:
| Parameter | Expected | Actual |
|---|---|---|
| name | "hello" | "hello" ✓ |
| hidden_state | "hidden_value" | "hidden_value" ✓ |
| flag | true | [] (gallery value) ✗ |
| gallery_images | [] | True (flag value) ✗ |
Error:
1 validation error for GalleryData
Input should be a valid list [type=list_type, input_value=True, input_type=bool]
The State default seems injected, but all parameters after the State are shifted by one position.
Have you searched existing issues? 🔎
- I have searched and found no existing issues
System Info
gradio==6.0.1Severity
I can work around it
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working