inspector icon indicating copy to clipboard operation
inspector copied to clipboard

Generate the corresponding CLI command when calling a tool

Open wang-qa opened this issue 7 months ago • 2 comments

Is your feature request related to a problem? Please describe. no

Describe the solution you'd like

The user can execute on the UI page, but does not know how to use CLI to execute, resulting in command errors When the user correctly executes the tool, it can be automatically converted into the CLI command

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

wang-qa avatar May 13 '25 08:05 wang-qa

Can you please elaborate and add more context to the feature request by including an example ? @wang-qa

Kavyapriya-1804 avatar May 18 '25 07:05 Kavyapriya-1804

I have a service

hello-mcp.py
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import datetime

from typing import Optional
from mcp.server.fastmcp import FastMCP
import requests

# 初始化FastMCP服务器
mcp = FastMCP("hello-world", protocol_version="1.2")


@mcp.tool()
async def hello(name: Optional[str] = None) -> str:
    """
    返回一个简单的问候语。
    Args:
        name: 要问候的名称(可选)
    Returns:
        str: 问候语
    """
    if name:
        return f"这是tool, Hello, {name}!"
    else:
        return "这是tool, Hello, World!"


@mcp.tool()
async def reverse_text(text: str) -> str:
    """文本反转工具示例"""
    return text[::-1]


@mcp.tool()
async def holiday(text: str = datetime.date.today()) -> str:
    """
    节假日工具
    :argument text: 2025-05-05
    :return status: 0普通工作日 1周末双休日 2需要补班的工作日 3法定节假日
    """

    response = requests.request("get", f"http://api.haoshenqi.top/holiday?date={text}")
    return response.json()


if __name__ == "__main__":
    # # 初始化并运行服务器
    mcp.run(transport='stdio')


Execute the following through GUI

Image

Image

Corresponding CLI command

Image

npx @modelcontextprotocol/inspector --cli ~/hello-mcp/.venv/bin/python ~/hello-mcp/hello_server.py --method tools/call --tool-name holiday --tool-arg text='2025-03-01' 

I hope to automatically generate the corresponding CLI command in 'history' for easy CLI execution, as sometimes I don't know how to fill in the parameters

Alternatively, you can simply copy the content of the requests and run them directly, but the actual operation fails


npx @modelcontextprotocol/inspector --cli ~/hello-mcp/.venv/bin/python ~/hello-mcp/hello_server.py {"method":"tools/call","params":{"name":"holiday","arguments":{"text":"2025-05-18"},"_meta":{"progressToken":0}}}

npx @modelcontextprotocol/inspector --cli ~/hello-mcp/.venv/bin/python ~/hello-mcp/hello_server.py --method tools/call {"method":"tools/call","params":{"name":"holiday","arguments":{"text":"2025-05-18"},"_meta":{"progressToken":0}}}

Image

expect Choose either one

  • commond run success npx @modelcontextprotocol/inspector --cli ~/hello-mcp/.venv/bin/python ~/hello-mcp/hello_server.py {"method":"tools/call","params":{"name":"holiday","arguments":{"text":"2025-05-18"},"_meta":{"progressToken":0}}}
  • Generate corresponding CLI commands through historical records

wang-qa avatar May 18 '25 08:05 wang-qa

Closing as not planned since we're planning to separate the cli from the UI mode.

olaservo avatar Nov 11 '25 03:11 olaservo