Skip to main content
Glama
marckwei

MCP Yahoo Finance

by marckwei

cmd_run

Execute shell commands to retrieve financial data from Yahoo Finance, enabling stock price queries, company information access, and financial comparisons.

Instructions

Execute an arbitrary shell command and return its output.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cmdYesThe command string to run.

Implementation Reference

  • The cmd_run method of YahooFinance class implements the tool logic by running the shell command with subprocess.run, capturing stdout/stderr, and returning appropriate output or error message.
    def cmd_run(self, cmd: str) -> str:
        """Execute an arbitrary shell command and return its output.
        
        Args:   
            cmd (str): The command string to run.
        """
        try:
            result = subprocess.run(
                cmd,
                shell=True,     
                capture_output=True,        
                text=True,                  
                timeout=60                  
            )
            if result.returncode == 0:
                return result.stdout or "(命令无标准输出)"
            return (
                f"命令执行失败,退出码 {result.returncode}\n"
                f"stderr:\n{result.stderr}"
            )
        except Exception as e:
            return f"执行命令时出错: {e}"
  • Registers the cmd_run tool in the MCP server's tool list using generate_tool on the handler method.
    generate_tool(yf.cmd_run),
  • The MCP server.call_tool dispatcher invokes the cmd_run handler with arguments and returns the result as TextContent.
    case "cmd_run":
        output = yf.cmd_run(**args)
        return [TextContent(type="text", text=output)]
  • The generate_tool function inspects the cmd_run handler to automatically generate the MCP Tool schema including inputSchema based on function signature and docstring.
    def generate_tool(func: Any) -> Tool:
        """Generates a tool schema from a Python function."""
        signature = inspect.signature(func)
        docstring = inspect.getdoc(func) or ""
        param_descriptions = parse_docstring(docstring)
    
        schema = {
            "name": func.__name__,
            "description": docstring.split("Args:")[0].strip(),
            "inputSchema": {
                "type": "object",
                "properties": {},
            },
        }
    
        for param_name, param in signature.parameters.items():
            param_type = (
                "number"
                if param.annotation is float
                else "string"
                if param.annotation is str
                else "string"
            )
            schema["inputSchema"]["properties"][param_name] = {
                "type": param_type,
                "description": param_descriptions.get(param_name, ""),
            }
    
            if "required" not in schema["inputSchema"]:
                schema["inputSchema"]["required"] = [param_name]
            else:
                if "=" not in str(param):
                    schema["inputSchema"]["required"].append(param_name)
    
        return Tool(**schema)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states basic functionality. It doesn't disclose important behavioral traits like security implications, permission requirements, execution environment, error handling, timeout behavior, or whether commands run synchronously/asynchronously. 'Execute an arbitrary shell command' implies significant power but lacks necessary warnings or constraints.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise - a single sentence that directly states the tool's function. Every word earns its place with zero redundancy. It's front-loaded with the core purpose immediately apparent.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with no annotations, no output schema, and significant security implications (arbitrary shell execution), the description is dangerously incomplete. It doesn't address return format, error conditions, execution limits, or safety considerations that are critical for responsible tool usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds minimal value beyond the schema, which already has 100% coverage with a clear parameter description. The description mentions 'shell command' which provides some context about the expected content of the 'cmd' parameter, but doesn't elaborate on format, shell type, or special considerations.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('Execute') and resource ('shell command'), making it immediately understandable. However, it doesn't differentiate from sibling tools, which are all financial data retrieval tools, while this is a general shell execution tool - a missed opportunity for clearer distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. Given that all sibling tools are financial data retrieval functions, there's no indication that this tool serves a completely different purpose (shell execution) or when it would be appropriate versus using the specialized financial tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/marckwei/no-use-tools'

If you have feedback or need assistance with the MCP directory API, please join our Discord server