lima icon indicating copy to clipboard operation
lima copied to clipboard

MCP: support async tasks

Open AkihiroSuda opened this issue 2 months ago • 8 comments

https://github.com/lima-vm/lima/blob/412133cf0beb0e5ebd7cf09ef817b31b74a48003/pkg/mcp/msi/shell.go#L13-L29 https://github.com/lima-vm/lima/blob/412133cf0beb0e5ebd7cf09ef817b31b74a48003/pkg/mcp/msi/filesystem.go#L84-L97

MCP tools should be redesigned to support async tasks (introduced in version 2025-11-25 of the MCP specification) https://modelcontextprotocol.io/extensions/tasks/overview

AkihiroSuda avatar Sep 15 '26 23:09 AkihiroSuda

Hi, I’d like to work on this if nobody is already investigating it. I’ll start by reviewing Lima’s current MCP tool handlers and the MCP tasks specification, then propose a design for task execution, status reporting, result retrieval, and cancellation.Would it make sense to start with run_shell_command in a focused PR, then extend the approach to other tools? I’d include tests for task completion, errors, and cancellation. Could you assign this issue to me if that scope sounds appropriate? I’ll share the design here for feedback before implementing it.

Shreevats4 avatar Sep 19 '26 05:09 Shreevats4

Hi, I’d like to work on this if nobody is already investigating it.

Thanks for your interest. Do you have prior experience with MCP?

AkihiroSuda avatar Sep 19 '26 15:09 AkihiroSuda

Thanks, @AkihiroSuda. I’m familiar with the MCP protocol and have experience building concurrent backend systems in Go. I’d like two days to review Lima’s MCP implementation and the task specification in detail. I’ll then share a design proposal here for your feedback before starting the implementation.

Shreevats4 avatar Sep 19 '26 19:09 Shreevats4

Hey @AkihiroSuda I'll be collaborating with @Shreevats4 on this. I have spoken to him. Thanks

iAmAdheil avatar Sep 20 '26 08:09 iAmAdheil

Thanks @AkihiroSuda . I reviewed Lima’s current MCP implementation, the original 2025-11-25 Tasks specification, the current Tasks extension, and the MCP Go SDK version used by Lima.

I found two design decisions that should be confirmed before implementation.

First, the issue says Tasks were introduced in MCP 2025-11-25, while the linked documentation now describes the stable io.modelcontextprotocol/tasks extension for 2026-07-28. These designs are not wire-compatible:

  • In 2025-11-25, the requestor initiated task execution by augmenting the request. The protocol provided tasks/get, tasks/result, tasks/list, and tasks/cancel.
  • In the current extension, task creation is server-directed. It provides tasks/get, tasks/update, and tasks/cancel; terminal results are returned directly by tasks/get, and tasks/list and tasks/result no longer exist.

I recommend targeting the current 2026-07-28 extension unless compatibility with the older experimental design is specifically required.

Second, Lima master currently uses github.com/modelcontextprotocol/go-sdk v1.8.0. This release has no first-class Tasks implementation: it does not define Task/CreateTaskResult types, built-in tasks/* handlers, or a task lifecycle/store.

However, a Lima-local implementation appears technically possible through the SDK’s existing public extension points:

  • server capabilities can advertise io.modelcontextprotocol/tasks;
  • mcp.AddReceivingCustomMethod can register tasks/get, tasks/update, and tasks/cancel;
  • receiving middleware and a custom mcp.Result type can return a task-shaped result from tools/call.

This would be hand-written protocol support in Lima and may need rework when the Go SDK gains official Tasks support. Upstream work is tracked in go-sdk#626. The open go-sdk#755 currently covers capability negotiation only; task execution and lifecycle management are still not implemented there.

If a Lima-local implementation is acceptable, I propose the following initial scope:

  • Target run_shell_command first.
  • Advertise the Tasks extension.
  • When the request’s client capabilities include the extension, create a task and return a CreateTaskResult immediately. Clients without the extension retain the current synchronous behavior.
  • Maintain a concurrency-safe, process-local task registry containing an unguessable task ID, state, timestamps, TTL, final result or JSON-RPC error, and a cancellation function.
  • Run the command in a background worker using a task-owned context rather than the original tools/call request context.
  • Keep RunShellCommandResult as the final tool result.
  • Treat a non-zero command exit as a completed tool call containing stdout, stderr, error, and exit_code. Under the current specification, failed is reserved for JSON-RPC-level failures.
  • Handle cancellation cooperatively. tasks/cancel acknowledges the request and signals the worker; the task may become cancelled or may still become completed if execution finishes first. Terminal states must remain immutable.
  • Keep the synchronous command-execution logic in an internal helper so both the synchronous path and asynchronous worker use the same implementation. SearchFileContent, which invokes shell-command execution internally, should continue using the synchronous helper rather than creating a nested task.
  • Implement TTL-based cleanup and bounded task/result retention.

The initial implementation would register tasks/get, tasks/update, and tasks/cancel. Shell commands would not use input_required initially, but the tasks/update endpoint would still need protocol-compliant capability and task-ID handling.

Proposed tests:

  • a capable client receives a task handle;
  • a client without the extension retains synchronous behavior;
  • working → completed and retrieval of the original CallToolResult;
  • a non-zero command exit produces a completed task;
  • cancellation racing with normal completion;
  • invalid and expired task IDs;
  • missing-extension errors for task-management requests;
  • TTL cleanup, unique task IDs, concurrent polling, and race safety.

I would leave task-status notifications, input_required, persistence across limactl mcp serve restarts, and conversion of additional tools to follow-up work. search_file_content would be the next likely candidate.

Could you confirm:

  1. Should Lima target only the current 2026-07-28 Tasks extension?
  2. Would you prefer a Lima-local implementation using custom methods and middleware, or should this wait for first-class support in the MCP Go SDK?
  3. For the initial stdio implementation, is process-local task storage with bounded TTL acceptable, or must task state survive restarting limactl mcp serve?

Shreevats4 avatar Sep 21 '26 04:09 Shreevats4

Hi @AkihiroSuda , just following up on the design proposal above.

I’ve gone through the MCP Tasks specification and Lima’s current MCP implementation, and I’m ready to start implementing the initial run_shell_command scope once the direction is confirmed.

Would the proposed approach targeting the current Tasks extension with a Lima-local implementation and process-local task storage with bounded TTL work for you?

If the direction looks good, I’d be happy to proceed with the implementation and open the PR.

Shreevats4 avatar Sep 23 '26 06:09 Shreevats4

Thanks @Shreevats4

  1. Should Lima target only the current 2026-07-28 Tasks extension?

You can just support the current one, assuming it is already implemented by well-known harnesses

  1. Would you prefer a Lima-local implementation using custom methods and middleware, or should this wait for first-class support in the MCP Go SDK?

Why not submit your work to the upstream?

  1. For the initial stdio implementation, is process-local task storage with bounded TTL acceptable, or must task state survive restarting limactl mcp serve?

Acceptable

AkihiroSuda avatar Sep 24 '26 07:09 AkihiroSuda

@AkihiroSuda Sure will check out upstream as well.

@Shreevats4 Upstream related work:

  • https://github.com/modelcontextprotocol/go-sdk/pull/755
  • https://github.com/modelcontextprotocol/go-sdk/issues/626

iAmAdheil avatar Sep 24 '26 11:09 iAmAdheil