yikart/AiToEarn · error · McpError

ErrorCode.MethodNotFound

ErrorCode.MethodNotFound

Error message

Unknown resource: ${uri}

What it means

The MCP resources handler in nest-mcp builds a methodName from a registered resource looked up by URI. When no resource info is found in the registry for the requested URI, it throws McpError with MethodNotFound, mirroring the JSON-RPC -32601 semantics of the MCP protocol.

Source

Thrown at project/aitoearn-backend/libs/nest-mcp/src/services/handlers/mcp-resources.handler.ts:97

          if (resourceTemplateInfo) {
            providerClass = resourceTemplateInfo.resourceTemplate.providerClass
            params = {
              ...resourceTemplateInfo.params,
              ...request.params,
            }
            methodName = resourceTemplateInfo.resourceTemplate.methodName
          }
          else if (resourceInfo) {
            providerClass = resourceInfo.resource.providerClass

            params = {
              ...resourceInfo.params,
              ...request.params,
            }
            methodName = resourceInfo.resource.methodName
          }
          else {
            throw new McpError(
              ErrorCode.MethodNotFound,
              `Unknown resource: ${uri}`,
            )
          }
          return await this.handleRequest(
            httpRequest,
            providerClass,
            uri,
            this.createContext(mcpServer, request),
            params,
            methodName,
          )
        }
        catch (error) {
          this.logger.error(error)
          const errorMessage = getErrorMessage(error)
          return {
            contents: [{ uri, mimeType: 'text/plain', text: errorMessage }],

View on GitHub (pinned to d3aa8bea5b)

Solutions

  1. Check the URI in the client request against the URIs produced by @McpResource decorators in the loaded providers
  2. Ensure the provider class containing the resource is registered in the module for this mcpModuleId
  3. List resources first (resources/list) and use exactly the URIs returned
  4. Fix URI typos or scheme mismatches (e.g. file:// vs app://)

Example fix

// before
await client.readResource({ uri: 'docs://user-guide' });
// after
const { resources } = await client.listResources();
await client.readResource({ uri: resources[0].uri });
Defensive patterns

Strategy: try-catch

Validate before calling

const { resources } = await client.listResources();
const known = resources.some(r => r.uri === uri);
if (!known) throw new Error(`URI ${uri} not offered by server`);

Type guard

function isKnownResource(uri: string, resources: { uri: string }[]): boolean {
  return resources.some(r => r.uri === uri);
}

Try / catch

try {
  await client.readResource({ uri });
} catch (e) {
  if (e.code === ErrorCode.MethodNotFound) await refreshResourceList();
  else throw e;
}

Prevention

When it happens

Trigger: A client sends resources/read (or a resource-related request) with a URI that is not registered via @McpResource in any provider for this mcpModuleId, or the URI has a typo or wrong scheme.

Common situations: Client caching an old resource URI after a server rename; resource decorators not applied because the provider class was not registered; environment mismatch where the module hosting the resource is not loaded.

Related errors


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