Metadata-Version: 2.5
Name: longcall
Version: 0.1.0
Summary: Fix MCP tool calls that time out ("MCP error -32001: Request timed out", Claude Desktop's 4-minute limit): a stdio proxy for any MCP server that answers slow calls with a job id and lets the model fetch the result later, or cancels them with an error the model can read, with per-tool timeouts
Project-URL: Homepage, https://github.com/srikrishnaL/kitforge/tree/main/packages/longcall
Project-URL: Source, https://github.com/srikrishnaL/kitforge
Project-URL: Issues, https://github.com/srikrishnaL/kitforge/issues
Project-URL: Changelog, https://github.com/srikrishnaL/kitforge/blob/main/packages/longcall/CHANGELOG.md
Author: Sri Krishna Lingamaneni
License-Expression: MIT
License-File: LICENSE
Keywords: -32001,agents,async tool calls,background jobs,claude code,claude desktop,codex,cursor,llm,long-running tools,mcp,mcp proxy,mcp server,model context protocol,per-tool timeout,request timed out,timeout,tool calling
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.9
Provides-Extra: test
Requires-Dist: mcp>=1.10; (python_version >= '3.10') and extra == 'test'
Requires-Dist: pytest>=7; extra == 'test'
Description-Content-Type: text/markdown

# longcall

MCP clients give up on a tool call after a fixed time: 60 seconds in many clients built on the
TypeScript SDK (`MCP error -32001: Request timed out`), 4 minutes in Claude Desktop
(`No result received from the Claude Desktop app after waiting 4 minutes`), and most of them have
no per-tool setting. Tools that run a long query, a build, a scan or a backup fail every time,
though the server is fine and would have answered.

longcall is a stdio proxy that sits in front of any MCP server and answers a slow call before the
client gives up. The call keeps running on the server; the model gets a job id and fetches the
real result later with a `longcall_result` tool that the proxy adds. Or, with `--mode error`, the
call is cancelled and the model gets an error it can read and act on, instead of a broken session.
No change to the server or the client, any language.

```bash
pip install longcall
```

## Quick start

Put `longcall proxy --` in front of the server command in your client's config:

```json
{
  "mcpServers": {
    "warehouse": {
      "command": "longcall",
      "args": ["proxy", "--timeout", "50", "--", "npx", "-y", "@acme/warehouse-mcp"]
    }
  }
}
```

Or with `uvx`, nothing to install first: `"command": "uvx", "args": ["longcall", "proxy", "--", ...]`.

What the model sees when `run_report` takes three minutes:

```text
> run_report {"quarter": "Q3"}
The tool run_report is still running (over 50s), so its result is not here yet. Get it by
calling the tool longcall_result with job_id "job-5f0c2a91". Each call waits up to 50s for the
result; call it again if the job is still running. Don't start run_report again for the same
request.

> longcall_result {"job_id": "job-5f0c2a91"}
Job job-5f0c2a91 (run_report) is still running (100s so far). Call longcall_result again ...

> longcall_result {"job_id": "job-5f0c2a91"}
<run_report's own result, exactly as the server sent it>
```

Each step is reported on stderr (most clients show it in their MCP log):

```text
longcall: run_report still running after 50s; answered with job job-5f0c2a91
longcall: run_report finished after 183.2s (job job-5f0c2a91)
```

Calls that finish within the timeout are passed on unchanged, so fast tools behave exactly as
before.

## Options

| Option | What it does |
|---|---|
| `--timeout SECONDS` | Answer a call still running after this long. Default `50`, under the 60-second timeout of many clients. Set it a little under your client's limit. |
| `--tool NAME=SECONDS` | A different timeout for one tool. `--tool NAME=off` passes that tool's calls through untouched. Repeatable. |
| `--mode error` | Don't keep the call: tell the server to cancel it (`notifications/cancelled`) and give the model an error result that says it timed out after N seconds. Use this for per-tool timeouts the model can understand, with no extra tool. |
| `--cancel-after SECONDS` | Background mode: cancel a call that is still running after this long in all. Default: never. |
| `--wait SECONDS` | Longest time one `longcall_result` call waits for the result. Default and maximum: `--timeout`, so the wait never trips the client's timeout either. |
| `--keep N` | Finished results kept for the model to fetch. Default `100`. Running jobs are always kept. |
| `--result-tool NAME` | Name of the added tool. Default `longcall_result`. |
| `--quiet` | Don't report on stderr. |
| `--log FILE` | Append reports to a file instead of stderr. |

Example: a database server whose `export` tool takes minutes, while every other tool should fail
fast with a clear error:

```bash
longcall proxy --mode error --timeout 20 --tool export=off -- python -m my_db_server
```

## From Python

```python
from longcall import run

run(["npx", "-y", "@acme/warehouse-mcp"], timeout=50, tools={"export": 600, "ping": None})
```

`longcall.Keeper` holds the message logic on its own (`to_server`, `to_client` hooks and
`send_client`, `send_server` callbacks) if you relay MCP messages yourself.

## How it works

- Each `tools/call` goes to the server under an id of the proxy's own, so the proxy can answer the
  client and still recognise the server's late reply. A deadline starts with it.
- Answer in time: the client gets it with its own id. Progress notifications pass through while
  the client waits.
- Deadline first (background mode): the client gets a "still running" result with a job id
  (also in `_meta.longcall`), and later progress notifications for that call are dropped. The
  server's result is stored when it arrives, and `longcall_result` returns it as the server sent
  it, `structuredContent` and `isError` included. A JSON-RPC error from the server comes back as
  an error result with its message.
- `longcall_result` is appended to the last page of `tools/list`, marked read-only and
  idempotent. If the server already has a tool by that name, nothing is added and a warning is
  printed: pick another name with `--result-tool`.
- Deadline first (error mode): the server gets `notifications/cancelled` for the call, the client
  gets an `isError` result naming the timeout.
- A client that cancels a call it is still waiting for cancels it on the server too.
- Results to clients on the 2026-07-28 protocol carry `resultType: "complete"`.

## Limits

- stdio servers only. For a remote (Streamable HTTP) server, run it through a local stdio bridge
  first.
- Jobs live in the proxy's memory: when the client restarts the server, running jobs and their
  results are lost.
- For tools that declare an `outputSchema`, the "still running" answer is marked `isError`,
  because clients reject a normal result without `structuredContent`. The text still tells the
  model to fetch the result.
- The model has to follow the instruction to call `longcall_result`. A model that ignores it will
  report the job as pending, so the text is written to be followed.
- It does not change a client's own timeout. It only answers before that timeout runs out, so
  set `--timeout` below it.
- Servers built on old releases of the MCP Python SDK (1.10 to 1.12 tested; 1.25 is fine) stop
  answering after any cancelled request, so with those use background mode without
  `--cancel-after`.
- A call answered with a job id keeps running on the server. Tools with side effects still take
  effect, even if the model never fetches the result. Use `--mode error` or `--cancel-after` when
  that is not what you want.

## Why this exists

Long tool calls failing on a client timeout is one of the most reported MCP problems, and most
clients have one global timeout or none you can set:

- [anthropics/claude-code#65643](https://github.com/anthropics/claude-code/issues/65643): Claude
  Desktop ends any call after 4 minutes, and the bridge wedges after a few timeouts.
- [modelcontextprotocol/typescript-sdk#245](https://github.com/modelcontextprotocol/typescript-sdk/issues/245):
  the client times out after 60 seconds whatever the timeout option says.
- [anthropics/claude-code#16837](https://github.com/anthropics/claude-code/issues/16837):
  `MCP_TIMEOUT` over 60 seconds is ignored.
- [kirodotdev/Kiro#126](https://github.com/kirodotdev/Kiro/issues/126): MCP request timeouts.
- [livekit/agents#8523](https://github.com/livekit/agents/issues/8523) and
  [QwenLM/qwen-code#18323](https://github.com/QwenLM/qwen-code/issues/18323): per-tool timeouts,
  and timeouts the model and the caller can tell apart from other failures.
- [infiniflow/ragflow#23003](https://github.com/infiniflow/ragflow/issues/23003): a tool timeout
  should reach the model as a result, not fail the whole run.

The MCP Tasks extension solves this properly for clients and servers that support it. longcall
is for the many that don't yet.

## License

MIT
