docs/mcp-provider-guide.md
Task Master provides a unified MCP provider for AI operations:
MCP Provider (mcp) - Modern AI SDK-compatible provider with full structured object generation support
The MCP provider enables Task Master to act as an MCP client, using MCP servers as AI providers alongside traditional API-based providers. This integration follows the existing provider pattern and supports all standard AI operations including structured object generation for PRD parsing and task creation.
The MCP Provider (mcp) provides:
✅ Full AI SDK Compatibility - Complete LanguageModelV1 interface implementation
✅ Structured Object Generation - Schema-driven outputs for PRD parsing and task creation
✅ Enhanced Error Handling - Robust JSON extraction and validation
✅ Session Management - Automatic session detection and context handling
✅ Schema Validation - Type-safe object generation with Zod validation
# Set MCP provider for main role
task-master models set-main --provider mcp --model claude-3-5-sonnet-20241022
For detailed information, see MCP Provider Documentation.
The MCP provider allows Task Master to:
Add MCP provider to your .taskmaster/config.json:
{
"models": {
"main": {
"provider": "mcp",
"modelId": "claude-3-5-sonnet-20241022",
"maxTokens": 50000,
"temperature": 0.2
},
"research": {
"provider": "mcp",
"modelId": "claude-3-5-sonnet-20241022",
"maxTokens": 8700,
"temperature": 0.1
},
"fallback": {
"provider": "anthropic",
"modelId": "claude-3-5-sonnet-20241022"
}
}
}
MCP Provider Models:
claude-3-5-sonnet-20241022 - High-performance model for general tasks
claude-3-opus-20240229 - Enhanced reasoning model for complex tasks
mcp-sampling - General text generation using MCP client sampling
claude-3-opus-20240229 - Enhanced reasoning model for complex tasks
Basic MCP Provider Models:
mcp-sampling - General text generation using MCP client samplingmcp-sampling - General text generation using MCP client sampling
MCP model IDs use a simple format:
claude-3-5-sonnet-20241022 - Uses Claude 3.5 Sonnet via MCP samplingclaude-3-opus-20240229 - Uses Claude 3 Opus via MCP samplingmcp-sampling - Uses MCP client's sampling capability for text generationThe MCP provider requires an active MCP session with sampling capabilities:
session: {
clientCapabilities: {
sampling: {} // Client supports sampling requests
}
}
import { generateTextService } from './scripts/modules/ai-services-unified.js';
const result = await generateTextService({
role: 'main',
session: mcpSession, // Required for MCP provider
prompt: 'Explain MCP integration',
systemPrompt: 'You are a helpful AI assistant'
});
console.log(result.text);
import { generateObjectService } from './scripts/modules/ai-services-unified.js';
const result = await generateObjectService({
role: 'main',
session: mcpSession,
prompt: 'Create a task breakdown',
schema: {
type: 'object',
properties: {
tasks: {
type: 'array',
items: { type: 'string' }
}
}
}
});
console.log(result.object);
const research = await generateTextService({
role: 'research',
session: mcpSession,
prompt: 'Research the latest developments in AI',
systemPrompt: 'You are a research assistant'
});
The MCP provider works seamlessly with Task Master CLI commands when running in an MCP context:
# Generate tasks using MCP provider (if configured as main)
task-master add-task "Implement user authentication"
# Research using MCP provider (if configured as research)
task-master research "OAuth 2.0 best practices"
# Parse PRD using MCP provider
task-master parse-prd requirements.txt
MCPProvider (mcp-server/src/providers/mcp-provider.js)
When running as an MCP server, Task Master automatically:
// On MCP session connect
server.on("connect", (event) => {
// Check session capabilities
if (session.clientCapabilities?.sampling) {
// Create and register MCP provider
const mcpProvider = new MCPProvider();
mcpProvider.setSession(session);
// Auto-register with provider registry
providerRegistry.registerProvider('mcp', mcpProvider);
}
});
This enables seamless self-referential AI operations within MCP contexts.
The MCP provider follows the same pattern as other providers:
class MCPProvider extends BaseAIProvider {
// Implements generateText, generateObject
// Uses session context instead of API keys
// Maps operations to MCP sampling requests
}
The provider automatically detects MCP sampling capability when sessions connect:
// On MCP session connect
if (session.clientCapabilities?.sampling) {
// Auto-register MCP provider for use
const mcpProvider = new MCPProvider();
mcpProvider.setSession(session);
}
AI operations use MCP sampling with different levels of support:
generateText() → MCP requestSampling() with messages (2-minute timeout) ✅ Full SupportstreamText() → Limited/No Support ⚠️ See streaming limitations belowgenerateObject() → MCP requestSampling() with JSON schema instructions (2-minute timeout) ✅ Full SupportTimeout Configuration: All MCP sampling requests use a 2-minute (120,000ms) timeout to accommodate complex AI operations.
Important: The MCP provider has no support for text streaming:
MCPProvider:
generateText() instead of streamText() with this providerRecommendation: For streaming functionality, configure a non-MCP fallback provider (like Anthropic or OpenAI) in your fallback role.
The MCP provider includes comprehensive error handling:
clientCapabilities.sampling)Always configure a non-MCP fallback provider, especially for streaming operations:
{
"models": {
"main": {
"provider": "mcp",
"modelId": "mcp-sampling"
},
"fallback": {
"provider": "anthropic",
"modelId": "claude-3-5-sonnet-20241022"
}
}
}
Do not use streamTextService() with MCP provider. Use generateTextService() instead:
// ❌ Don't do this with MCP provider
const result = await streamTextService({
role: 'main', // MCP provider
session: mcpSession,
prompt: 'Generate content'
});
// ✅ Do this instead
const result = await generateTextService({
role: 'main', // MCP provider
session: mcpSession,
prompt: 'Generate content'
});
Ensure your MCP session remains active throughout Task Master operations:
// Check session health before operations
if (!session || !session.capabilities) {
throw new Error('MCP session not available');
}
Verify required capabilities are available in your MCP session:
// Check session health and capabilities
if (session && session.clientCapabilities && session.clientCapabilities.sampling) {
console.log('MCP sampling available');
} else {
console.log('MCP sampling not available');
}
Handle MCP-specific errors gracefully:
try {
const result = await generateTextService({
role: 'main',
session: mcpSession,
prompt: 'Generate content'
});
} catch (error) {
if (error.message.includes('MCP')) {
// Handle MCP-specific error
console.log('MCP error, falling back to alternate provider');
}
}
"MCP provider requires session context"
session parameter is passed to service calls"MCP session must have client sampling capabilities"
session.clientCapabilities.sampling existsrequestSampling() method"MCP Provider does not support streaming text, use generateText instead"
streamTextService() with MCP providergenerateTextService() instead of streamTextService()"MCP sampling failed" or Timeout errors
"Model ID is required for MCP Remote Provider"
modelId is specified in configurationmcp-sampling as the standard model IDAuto-registration failures
Error: streamTextService() calls fail with MCP provider
Cause: MCP provider has no streaming support
Solutions:
generateTextService() for all MCP-based text generationEnable debug logging to see MCP provider operations:
// Set debug flag in config or environment
process.env.DEBUG = 'true';
// Or in .taskmasterconfig
{
"debug": true,
"models": { /* ... */ }
}
Test MCP provider functionality:
// Check if MCP provider is properly registered
import { MCPProvider } from './mcp-server/src/providers/mcp-provider.js';
// Test session capabilities
if (session && session.clientCapabilities && session.clientCapabilities.sampling) {
console.log('MCP sampling available');
// Test provider creation
const provider = new MCPProvider();
provider.setSession(session);
console.log('MCP provider created successfully');
} else {
console.log('MCP session lacks required capabilities');
}
When using Task Master in VS Code with MCP support:
.vscode/mcp.json.taskmaster/config.jsonExample VS Code MCP Configuration:
{
"servers": {
"task-master-dev": {
"command": "npx",
"args": ["-y", "task-master-ai"],
"cwd": "/path/to/your/task-master-project",
"env": {
"NODE_ENV": "development",
"ANTHROPIC_API_KEY": "${env:ANTHROPIC_API_KEY}",
"TASK_MASTER_PROJECT_ROOT": "/path/to/your/project"
}
}
}
}
When using Task Master through Claude Desktop's MCP integration:
The MCP provider works with any MCP-compatible development environment:
Advanced users can use MCP sampling for all roles:
// MCP sampling for all roles
{
"models": {
"main": {
"provider": "mcp",
"modelId": "mcp-sampling"
}
}
}
Configure MCP sampling for different roles:
{
"models": {
"main": {
"provider": "mcp",
"modelId": "mcp-sampling"
},
"research": {
"provider": "mcp",
"modelId": "mcp-sampling"
},
"fallback": {
"provider": "mcp",
"modelId": "backup-server:simple-generation"
}
}
}
generateText(params) - Generate text using MCP sampling ✅ SupportedstreamText(params) - Stream text ❌ Not supported (throws error)generateObject(params) - Generate structured objects ✅ SupportedsetSession(session) - Update provider sessionvalidateAuth(params) - Validate session capabilitiesgetClient() - Returns null (not applicable for MCP)All MCP operations require:
session - Active MCP session object (auto-provided when registered)modelId - MCP model identifier (typically "mcp-sampling")messages - Array of message objectstemperature - Creativity control (if supported by MCP client)maxTokens - Maximum response length (if supported)schema - JSON schema for structured output (generateObject only)Planned improvements for MCP provider:
Note: True streaming support depends on future MCP protocol enhancements. Current implementation provides text generation without streaming capabilities.