Skip to content

Implement Tasks capability for MCP spec 2025-11-25 #656

@ezynda3

Description

@ezynda3

Summary

Implement the Tasks capability for MCP specification version 2025-11-25. This feature is mentioned in the spec but requires further investigation to understand the complete requirements.

Specification Reference

Current Implementation

Status: Not implemented

No references to "tasks" or "Tasks" capability found in the codebase except in example comments.

Spec References from Lifecycle Section

From the initialization example in the spec:

Client Capabilities

{
  "capabilities": {
    "tasks": {
      "requests": {
        "elicitation": {
          "create": {}
        },
        "sampling": {
          "createMessage": {}
        }
      }
    }
  }
}

Server Capabilities

{
  "capabilities": {
    "tasks": {
      "list": {},
      "cancel": {},
      "requests": {
        "tools": {
          "call": {}
        }
      }
    }
  }
}

Interpretation from Spec

Based on the capability structure, the Tasks feature appears to enable:

  1. Task Management:

    • list: Enumerate active tasks
    • cancel: Cancel a running task
  2. Task-Augmented Requests:

    • Servers can make requests (like tool calls) that return immediately with a task ID
    • Clients can make requests (like elicitation, sampling) that return immediately with a task ID
    • Progress can be tracked via task ID
    • Results delivered asynchronously when task completes

This would enable long-running operations to be non-blocking.

Investigation Needed

Before implementation, we need to:

  • Review the full Tasks specification at https://modelcontextprotocol.io/specification/2025-11-25/basic/utilities/tasks
  • Understand the relationship between tasks and existing Progress/Cancellation features
  • Determine the task lifecycle (created, running, completed, failed, cancelled)
  • Define the task identifier format
  • Understand how tasks relate to request IDs
  • Clarify notification flow for task state changes

Potential Type Definitions

Based on the capability structure, here's a preliminary sketch:

// Task lifecycle states
const (
    TaskStatePending   = "pending"
    TaskStateRunning   = "running"
    TaskStateCompleted = "completed"
    TaskStateFailed    = "failed"
    TaskStateCancelled = "cancelled"
)

// Task represents an asynchronous operation
type Task struct {
    ID       string         `json:"id"`
    State    string         `json:"state"`
    Progress *ProgressInfo  `json:"progress,omitempty"`
    Result   any            `json:"result,omitempty"`
    Error    *JSONRPCError  `json:"error,omitempty"`
}

// List tasks request
type ListTasksRequest struct {
    Method string              `json:"method"`
    Params ListTasksParams     `json:"params"`
}

type ListTasksParams struct {
    Meta *Meta `json:"_meta,omitempty"`
}

type ListTasksResult struct {
    Tasks []Task `json:"tasks"`
}

// Cancel task request
type CancelTaskRequest struct {
    Method string           `json:"method"`
    Params CancelTaskParams `json:"params"`
}

type CancelTaskParams struct {
    Meta   *Meta  `json:"_meta,omitempty"`
    TaskID string `json:"taskId"`
}

// Task state change notification
type TaskStateChangedNotification struct {
    Method string                          `json:"method"`
    Params TaskStateChangedNotificationParams `json:"params"`
}

type TaskStateChangedNotificationParams struct {
    TaskID string `json:"taskId"`
    State  string `json:"state"`
}

Capability Definition

// Client capabilities
type TasksClientCapability struct {
    Requests *TasksRequestsCapability `json:"requests,omitempty"`
}

type TasksRequestsCapability struct {
    Elicitation *ElicitationTasksCapability `json:"elicitation,omitempty"`
    Sampling    *SamplingTasksCapability    `json:"sampling,omitempty"`
}

type ElicitationTasksCapability struct {
    Create *struct{} `json:"create,omitempty"`
}

type SamplingTasksCapability struct {
    CreateMessage *struct{} `json:"createMessage,omitempty"`
}

// Server capabilities
type TasksServerCapability struct {
    List     *struct{}                `json:"list,omitempty"`
    Cancel   *struct{}                `json:"cancel,omitempty"`
    Requests *TasksRequestsCapability `json:"requests,omitempty"`
}

type ToolTasksCapability struct {
    Call *struct{} `json:"call,omitempty"`
}

Files to Create/Modify

Once the spec is fully understood:

  • New file: mcp/tasks.go - Task types and constants
  • Update: mcp/types.go - Add Tasks capabilities to ClientCapabilities and ServerCapabilities
  • New file: server/tasks.go - Server-side task management
  • Update: server/server.go - Add task handlers (list, cancel)
  • New file: client/tasks.go - Client-side task tracking
  • Update: client/client.go - Handle task-related notifications

Implementation Considerations

  1. Task Storage: How/where to store task state (in-memory, persistent?)
  2. Task IDs: Format and uniqueness guarantees
  3. Cleanup: When to remove completed tasks
  4. Concurrency: Thread-safety for task state updates
  5. Relationship to existing features:
    • How tasks interact with Progress notifications
    • How tasks interact with Cancellation
    • Whether tasks replace or complement these features

Testing Requirements

  • Unit tests for task lifecycle state machine
  • Test task list pagination (if supported)
  • Test task cancellation
  • Test task-augmented tool calls
  • Test task-augmented sampling/elicitation
  • Integration tests for async operation flows

Implementation Priority

Priority: Low - This feature requires more spec investigation and may not be critical for basic MCP 2025-11-25 compliance. Mark as "help wanted" for community contribution.

Next Steps

  1. Thoroughly review the Tasks specification section
  2. Create a design document outlining the implementation approach
  3. Get feedback from maintainers on design
  4. Implement based on approved design

Current implementation status: Not implemented (as of commit 670a95a)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: mcp specIssues related to MCP specification compliancegood first issueGood for new contributorshelp wantedExtra attention is neededtype: enhancementNew feature or enhancement request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions