inspector icon indicating copy to clipboard operation
inspector copied to clipboard

return error: _b.throwIfAborted is not a function.

Open Lycnkd opened this issue 8 months ago • 3 comments

whatever I click (e.g. list resources/list templates/list prompts), It always return the error: _b.throwIfAborted is not a function.

However, when I am using cline + mcp server, it works pretty well and no errors have occured. further bug reports: Uncaught (in promise) TypeError: b. throwIfAborted is not a function at index-CgrYmEaq.js: 16291 at new Promise () at Client.request (index-CgrYmEaq.js: 16282) at makeRequest (index-CgrYmEaq.js: 17563) at sendMCPRequest (index-CgrYmEaq.js: 29090) at listPrompts (index-CgrYmEaq.js: 29174) at listPrompts (index-CgrYmEaq.js: 29397) at Object. Nb (index-CarVmFan is: 1281) at Tb (index-CgrYmEaqhttp://127.0.0.1:6274/assets/index-CgrYmEaq.js:29397 at Ub (index-CgrYmEaq.js: 1296)

the steps that I install mcp is: 0. powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

  1. uv init weather
  2. cd weather
  3. uv venv
  4. .venv\Scripts\activate
  5. uv add "mcp[cli]" httpx
  6. pip install fastmcp
  7. write weather.py
  8. mcp dev weather.py

Lycnkd avatar Apr 16 '25 06:04 Lycnkd

Hi, do you have the code that you're actually running for the weather.py server here?

olaservo avatar Apr 18 '25 04:04 olaservo

from typing import Any
import httpx
from mcp.server.fastmcp import FastMCP

# Initialize FastMCP server
mcp = FastMCP("weather")

# Constants
NWS_API_BASE = "https://api.weather.gov"
USER_AGENT = "weather-app/1.0"

async def make_nws_request(url: str) -> dict[str, Any] | None:
    """Make a request to the NWS API with proper error handling."""
    headers = {
        "User-Agent": USER_AGENT,
        "Accept": "application/geo+json"
    }
    async with httpx.AsyncClient() as client:
        try:
            response = await client.get(url, headers=headers, timeout=30.0)
            response.raise_for_status()
            return response.json()
        except Exception:
            return None

def format_alert(feature: dict) -> str:
    """Format an alert feature into a readable string."""
    props = feature["properties"]
    return f"""
Event: {props.get('event', 'Unknown')}
Area: {props.get('areaDesc', 'Unknown')}
Severity: {props.get('severity', 'Unknown')}
Description: {props.get('description', 'No description available')}
Instructions: {props.get('instruction', 'No specific instructions provided')}
"""

@mcp.tool()
async def get_alerts(state: str) -> str:
    """Get weather alerts for a US state.

    Args:
        state: Two-letter US state code (e.g. CA, NY)
    """
    url = f"{NWS_API_BASE}/alerts/active/area/{state}"
    data = await make_nws_request(url)

    if not data or "features" not in data:
        return "Unable to fetch alerts or no alerts found."

    if not data["features"]:
        return "No active alerts for this state."

    alerts = [format_alert(feature) for feature in data["features"]]
    return "\n---\n".join(alerts)

@mcp.tool()
async def get_forecast(latitude: float, longitude: float) -> str:
    """Get weather forecast for a location.

    Args:
        latitude: Latitude of the location
        longitude: Longitude of the location
    """
    # First get the forecast grid endpoint
    points_url = f"{NWS_API_BASE}/points/{latitude},{longitude}"
    points_data = await make_nws_request(points_url)

    if not points_data:
        return "Unable to fetch forecast data for this location."

    # Get the forecast URL from the points response
    forecast_url = points_data["properties"]["forecast"]
    forecast_data = await make_nws_request(forecast_url)

    if not forecast_data:
        return "Unable to fetch detailed forecast."

    # Format the periods into a readable forecast
    periods = forecast_data["properties"]["periods"]
    forecasts = []
    for period in periods[:5]:  # Only show next 5 periods
        forecast = f"""
{period['name']}:
Temperature: {period['temperature']}°{period['temperatureUnit']}
Wind: {period['windSpeed']} {period['windDirection']}
Forecast: {period['detailedForecast']}
"""
        forecasts.append(forecast)

    return "\n---\n".join(forecasts)

if __name__ == "__main__":
    # Initialize and run the server
    mcp.run(transport='stdio')

Lycnkd avatar Apr 18 '25 04:04 Lycnkd

Looks as if the request is possibly malformed. We need to do some troubleshooting here.

Some observations

  • throwIfAborted is being called in the request method of transport.ts class in the typescript-sdk.

  • The request method is called with three parameters: request (the JSON-RPC request object), resultSchema (a schema for validating the response), and optional options. If options includes an AbortSignal (via the signal property), the throwIfAborted is executed to check if the signal has already been aborted.

  • It seems to be think it has an options.signal that does not have a throwIfAborted method.

  • There is similar report in the python-sdk repo, but throwIfAborted does not appear in the python-sdk.

  • Both these issues are talking to a python server, and I haven't seen any indication that this issue is happening with servers based on other sdks

Some questions

  • Is there a bug in how the Inspector is forming requests?
  • Is the inspector creating a malformed request based on some off-spec conversation with the server?
  • Can we duplicate this issue with a server that isn't written in python?

cliffhall avatar Apr 18 '25 20:04 cliffhall

@claude please help suggest next steps for this open issue, including answering the open questions from the latest comment.

olaservo avatar Aug 18 '25 13:08 olaservo

Claude finished @olaservo's task —— View job


Analysis: "_b.throwIfAborted is not a function" Issue

Based on my investigation of the MCP Inspector codebase, I can provide answers to the open questions and suggest next steps.

Key Findings

Error Source: The error originates from the TypeScript SDK (@modelcontextprotocol/sdk v1.17.2), specifically in the Client.request() method at line 180 in client/src/lib/hooks/useConnection.ts. The minified variable name _b suggests this is coming from compiled/bundled SDK code, not the Inspector's source.

AbortSignal Handling in Inspector: The Inspector correctly creates AbortController instances and passes the signal to the MCP client:

// useConnection.ts:150
const abortController = new AbortController();
const mcpRequestOptions: RequestOptions = {
  signal: options?.signal ?? abortController.signal,
  // ...other options
};
response = await mcpClient.request(request, schema, mcpRequestOptions);

No Python-Specific Handling: I found no special handling for Python servers vs other SDK implementations in the Inspector codebase. All MCP servers are treated identically regardless of their implementation language.

Answering @cliffhall's Questions

Q: Is there a bug in how the Inspector is forming requests?
A: No. The Inspector correctly forms requests and passes valid AbortSignal objects. The issue appears to be within the SDK itself.

Q: Is the inspector creating a malformed request based on some off-spec conversation with the server?
A: No evidence suggests this. The Inspector uses standard MCP protocol methods (resources/list, prompts/list, tools/list) and follows the TypeScript SDK's documented patterns.

Q: Can we duplicate this issue with a server that isn't written in python?
A: This would be the most valuable diagnostic step. The error appears SDK-side, so it should occur regardless of server implementation language.

Suggested Next Steps

  1. Reproduce with Non-Python Server: Test the Inspector against servers built with the TypeScript, Go, or other SDKs to determine if this is Python-specific
  2. SDK Version Testing: Test with different versions of @modelcontextprotocol/sdk to identify when this regression was introduced
  3. Debug Build: Create a development build that preserves source maps to get a clearer stack trace showing the exact SDK location
  4. AbortSignal Polyfill: Consider adding explicit AbortSignal feature detection/polyfilling for environments that might have incomplete implementations
  5. Upstream Issue: If confirmed as an SDK bug, file an issue against the TypeScript SDK repository with reproduction steps

The evidence strongly suggests this is a regression in the TypeScript SDK's handling of AbortSignal, likely introduced in a recent version where the throwIfAborted method is being called on an object that doesn't implement it properly.

claude[bot] avatar Aug 18 '25 13:08 claude[bot]

Closing as this issue has been inactive for a while and have not seen other reports of this issue since this.

olaservo avatar Nov 11 '25 03:11 olaservo