Skip to content

KeyError: 'command' in add_mcp_server when running tiny-agent due to incorrect params structure #3203

@mihirdeo16

Description

@mihirdeo16

Describe the bug

When attempting to run tiny-agent, the following error is thrown:

An unexpected error occurred: 'command'
Traceback (most recent call last):
  ...
  File "huggingface_hub/inference/_mcp/mcp_client.py", line 162, in add_mcp_server
    logger.info(f"Connecting to stdio MCP server with command: {params['command']} {params.get('args', [])}")
                                                                ~~~~~~^^^^^^^^^^^
KeyError: 'command'

The issue occurs because the function add_mcp_server expects params to be structured as: {'command': 'npx', 'args': ['@playwright/mcp@latest']}
However, the actual input passed is: {'config': {'command': 'npx', 'args': ['@playwright/mcp@latest']}} This causes the function to attempt accessing params['command'], which results in a KeyError.

Reproduction

Run tiny-agent with a config containing:

{
    "model": "Qwen/Qwen2.5-72B-Instruct",
    "provider": "nebius",
    "servers": [
        {
            "type": "stdio",
            "config": {
                "command": "npx",
                "args": ["@playwright/mcp@latest"]
            }
        }
    ]
}

Observe the KeyError: 'command'

Logs

An unexpected error occurred: 'command'
Traceback (most recent call last):
  File "/Users/userx/Code/mcp_server_test/.venv/lib/python3.11/site-packages/huggingface_hub/inference/_mcp/cli.py", line 134, in run_agent
    await agent.load_tools()
  File "/Users/userx/Code/mcp_server_test/.venv/lib/python3.11/site-packages/huggingface_hub/inference/_mcp/agent.py", line 58, in load_tools
    await self.add_mcp_server(**cfg)
  File "/Users/md/Code/mcp_server_test/.venv/lib/python3.11/site-packages/huggingface_hub/inference/_mcp/mcp_client.py", line 162, in add_mcp_server
    logger.info(f"Connecting to stdio MCP server with command: {params['command']} {params.get('args', [])}")
                                                                ~~~~~~^^^^^^^^^^^
KeyError: 'command'

An unexpected error occurred: 'command'

System info

- huggingface_hub version: 0.33.2
- Platform: macOS-15.5-arm64-arm-64bit
- Python version: 3.11.13
- Running in iPython ?: No
- Running in notebook ?: No
- Running in Google Colab ?: No
- Running in Google Colab Enterprise ?: No
- Token path ?: /Users/userx/.cache/huggingface/token
- Has saved token ?: True
- Who am I ?: mihirdeo16
- Configured git credential helpers: osxkeychain, store
- FastAI: N/A
- Tensorflow: N/A
- Torch: N/A
- Jinja2: N/A
- Graphviz: N/A
- keras: N/A
- Pydot: N/A
- Pillow: N/A
- hf_transfer: N/A
- gradio: N/A
- tensorboard: N/A
- numpy: N/A
- pydantic: 2.11.7
- aiohttp: 3.12.13
- hf_xet: 1.1.5
- ENDPOINT: https://huggingface.co
- HF_HUB_CACHE: /Users/userx/.cache/huggingface/hub
- HF_ASSETS_CACHE: /Users/userx/.cache/huggingface/assets
- HF_TOKEN_PATH: /Users/muserxd/.cache/huggingface/token
- HF_STORED_TOKENS_PATH: /Users/userx/.cache/huggingface/stored_tokens
- HF_HUB_OFFLINE: False
- HF_HUB_DISABLE_TELEMETRY: False
- HF_HUB_DISABLE_PROGRESS_BARS: None
- HF_HUB_DISABLE_SYMLINKS_WARNING: False
- HF_HUB_DISABLE_EXPERIMENTAL_WARNING: False
- HF_HUB_DISABLE_IMPLICIT_TOKEN: False
- HF_HUB_ENABLE_HF_TRANSFER: False
- HF_HUB_ETAG_TIMEOUT: 10
- HF_HUB_DOWNLOAD_TIMEOUT: 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions