yikart/AiToEarn · error

-32603

-32603

Error message

Internal server error

What it means

The server's handlePostRequest caught an unexpected exception while dispatching an MCP JSON-RPC POST and returned a generic JSON-RPC -32603 internal error with HTTP 500. This is the library's catch-all: the actual cause is only visible in the server log line `[<sessionId>] Error handling MCP request: <error>`. It means request parsing, transport creation, or protocol handling threw before a JSON-RPC response could be produced.

Source

Thrown at project/aitoearn-backend/libs/nest-mcp/src/services/mcp-streamable-http.service.ts:118

    this.logger.debug(
      `[${sessionId || 'No-Session'}] Received MCP request: ${JSON.stringify(body)}`,
    )

    try {
      if (this.isStatelessMode) {
        return this.handleStatelessRequest(adaptedReq, adaptedRes, body)
      }
      else {
        return this.handleStatefulRequest(adaptedReq, adaptedRes, body)
      }
    }
    catch (error) {
      this.logger.error(
        `[${sessionId || 'No-Session'}] Error handling MCP request: ${error}`,
      )
      if (!adaptedRes.headersSent) {
        adaptedRes.status(500).json({
          jsonrpc: '2.0',
          error: {
            code: -32603,
            message: 'Internal server error',
          },
          id: null,
        })
      }
    }
  }

  /**
   * Handle requests in stateless mode
   */
  async handleStatelessRequest(
    req: any,
    res: HttpResponse,
    body: unknown,

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Read the server log line starting with `[<sessionId>] Error handling MCP request:` to get the real underlying error.
  2. Confirm the request has a parsed JSON body (express.json()/Nest body-parser) before it reaches the MCP controller.
  3. Verify you are passing framework-native req/res objects that HttpAdapterFactory supports (Express or Fastify), not wrapped or proxied objects.
  4. Fix or add error handling in the specific MCP tool/handler that threw.
  5. Pin/upgrade the nest-mcp library version if the crash originates inside library code.

Example fix

// before
app.use('/mcp', mcpController.handlePostRequest)
// after
app.use(express.json())
app.use('/mcp', mcpController.handlePostRequest)
Defensive patterns

Strategy: try-catch

Validate before calling

if (typeof req.body !== 'object' || req.body === null) throw new Error('MCP POST requires a parsed JSON body')

Type guard

function isJsonRpcRequest(v: unknown): v is { jsonrpc: '2.0'; id: string | number | null; method: string } {
  return typeof v === 'object' && v !== null && (v as any).jsonrpc === '2.0' && typeof (v as any).method === 'string'
}

Try / catch

try {
  await mcpService.handlePostRequest(req, res)
} catch (err) {
  logger.error('MCP POST failed', err)
  if (!res.headersSent) res.status(500).json({ jsonrpc: '2.0', error: { code: -32603, message: 'Internal server error' }, id: null })
}

Prevention

When it happens

Trigger: Any uncaught exception inside handlePostRequest: malformed body that survives earlier checks, HttpAdapterFactory.getAdapter failing for an unsupported req/res shape, transport.handleRequest throwing, or a tool/resource handler inside the MCP server throwing synchronously during dispatch.

Common situations: Custom MCP tools crashing on bad input, incompatible Express/Fastify req/res objects passed in from the host framework, JSON body parser middleware missing so `body` is a raw stream, or a bug introduced after a library upgrade.

Understand the failure class

Related errors


AI-assisted analysis of yikart/AiToEarn@d3aa8bea5b (2026-08-31). Data as JSON: /api/errors/948e2013f48d0c2d. Report an issue: GitHub.