eyaltoledano/claude-task-master · error

DIRECT_FUNCTION_ERROR

DIRECT_FUNCTION_ERROR

Error message

${error.message}

What it means

DIRECT_FUNCTION_ERROR is a generic catch-all error returned by the models_direct MCP direct function when an unexpected exception escapes the main try block. It wraps the underlying error message and stack trace in the standard MCP response shape. It indicates a bug, bad environment, or an unexpected failure inside the models logic rather than a validation rejection.

Source

Thrown at mcp-server/src/core/direct-functions/models.js:123

			if (modelSetResult) {
				return modelSetResult;
			}

			// Default action: get current configuration
			return await getModelConfiguration({
				session,
				mcpLog,
				projectRoot
			});
		} finally {
			disableSilentMode();
		}
	} catch (error) {
		log.error(`Error in models_direct: ${error.message}`);
		return {
			success: false,
			error: {
				code: 'DIRECT_FUNCTION_ERROR',
				message: error.message,
				details: error.stack
			}
		};
	}
}

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Read the `details` field (error.stack) in the response to find the underlying exception and its origin.
  2. Verify the project's .taskmaster directory and tasks.json exist and contain valid JSON.
  3. Check file permissions on .taskmaster files so the MCP server process can read them.
  4. Reproduce the underlying error by running the equivalent `task-master models` CLI command and fix the root cause (or report a bug if the core logic itself is throwing).

Example fix

// before: response hides root cause
{ success: false, error: { code: 'DIRECT_FUNCTION_ERROR', message: err.message } }
// after: inspect details.stack in the response to locate the real failing call
const resp = await modelsDirect(args, log);
if (!resp.success) {
  console.error(resp.error.details); // stack trace of the real cause
}
Defensive patterns

Strategy: try-catch

Validate before calling

import fs from 'fs';
if (!fs.existsSync('.taskmaster/tasks/tasks.json')) {
  throw new Error('.taskmaster/tasks/tasks.json not found');
}
JSON.parse(fs.readFileSync('.taskmaster/tasks/tasks.json', 'utf8'));

Type guard

function isDirectFunctionError(resp) {
  return resp && resp.success === false && resp.error?.code === 'DIRECT_FUNCTION_ERROR';
}

Try / catch

const resp = await modelsDirect(args, log);
if (!resp.success) {
  if (resp.error.code === 'DIRECT_FUNCTION_ERROR') {
    console.error('Underlying cause:', resp.error.details);
  }
  throw new Error(resp.error.message);
}

Prevention

When it happens

Trigger: Any uncaught exception thrown inside modelsDirect (e.g. reading task files fails, a utility throws, log/summary computation crashes) is caught at mcp-server/src/core/direct-functions/models.js:123 and converted to this error with the exception's message and stack as details.

Common situations: Corrupt or missing .taskmaster/tasks directory, unreadable tasks.json (bad JSON), permission problems on the project files, or an internal bug in a refactored helper used by models_direct.

Related errors


AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/156c9d34dfd57ff3. Report an issue: GitHub.