modelcontextprotocol/servers · error · Error

Invalid resourceId: ${args?.resourceId}. Must be a finite po

Error message

Invalid resourceId: ${args?.resourceId}. Must be a finite positive integer.

What it means

Thrown by the `resource-prompt` handler when `resourceId` cannot be coerced into a finite, positive integer. Because prompt arguments are strings, the handler runs `Number(args.resourceId)` and then checks finiteness, integrality, and `>= 1`. Failing any branch raises this error.

Source

Thrown at src/everything/prompts/resource.ts:58

      const resourceType = args.resourceType;
      if (
        !RESOURCE_TYPES.includes(
          resourceType as typeof RESOURCE_TYPE_TEXT | typeof RESOURCE_TYPE_BLOB
        )
      ) {
        throw new Error(
          `Invalid resourceType: ${args?.resourceType}. Must be ${RESOURCE_TYPE_TEXT} or ${RESOURCE_TYPE_BLOB}.`
        );
      }

      // Validate resourceId argument
      const resourceId = Number(args?.resourceId);
      if (
        !Number.isFinite(resourceId) ||
        !Number.isInteger(resourceId) ||
        resourceId < 1
      ) {
        throw new Error(
          `Invalid resourceId: ${args?.resourceId}. Must be a finite positive integer.`
        );
      }

      // Get resource based on the resource type
      const uri =
        resourceType === RESOURCE_TYPE_TEXT
          ? textResourceUri(resourceId)
          : blobResourceUri(resourceId);
      const resource =
        resourceType === RESOURCE_TYPE_TEXT
          ? textResource(uri, resourceId)
          : blobResource(uri, resourceId);

      return {
        messages: [
          {
            role: "user",

View on GitHub (pinned to 76d64c822f)

Solutions

  1. Provide `resourceId` as a string encoding of a positive integer, e.g. `"1"` or `"42"`.
  2. Validate/normalize the id client-side: `String(parseInt(id, 10))` and ensure the result is `> 0`.
  3. Use the completer to confirm the id is accepted before issuing the prompt call.

Example fix

// before
{ resourceType: 'Text', resourceId: '0' }
// after
{ resourceType: 'Text', resourceId: '1' }
Defensive patterns

Strategy: validation

Validate before calling

function isValidResourceId(v: unknown): boolean {
  const n = Number(v);
  return Number.isFinite(n) && Number.isInteger(n) && n >= 1;
}
if (!isValidResourceId(args.resourceId)) {
  args.resourceId = '1';
}

Type guard

function isPositiveIntString(v: unknown): v is string {
  if (typeof v !== 'string') return false;
  const n = Number(v);
  return Number.isFinite(n) && Number.isInteger(n) && n > 0;
}

Prevention

When it happens

Trigger: Calling `resource-prompt` with a `resourceId` that is `"0"`, `"-5"`, `"3.5"`, `"abc"`, `"Infinity"`, `"NaN"`, an empty string, or omitted (Number(undefined) = NaN).

Common situations: Passing a zero-based index, a floating point id, a non-numeric placeholder, or forgetting that prompt args are strings and passing a JSON number that the transport still serializes as a non-coercible value.

Related errors


AI-assisted analysis of modelcontextprotocol/servers@76d64c822f (2026-08-12). Data as JSON: /api/errors/7818452e4898a2d4. Report an issue: GitHub.