Skip to content

fix(tool-call): convert INVALID_PARAMS to soft error for Devin/Windsu… - #1410

Merged
yvgude merged 1 commit into
yvgude:mainfrom
altasol:fix/devin-model-mcp-call-connection-reset
Aug 3, 2026
Merged

fix(tool-call): convert INVALID_PARAMS to soft error for Devin/Windsu…#1410
yvgude merged 1 commit into
yvgude:mainfrom
altasol:fix/devin-model-mcp-call-connection-reset

Conversation

@altasol

@altasol altasol commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

fix(tool-call): convert INVALID_PARAMS to soft error for Devin/Windsurf compatibility

Summary

Some MCP clients (Devin/Windsurf) treat hard JSON-RPC -32602 errors as transport failures, disconnect and respawn the server, hiding the actual parameter validation message from the agent. Convert INVALID_PARAMS to CallToolResult with isError=true so agents see validation messages and can fix parameter names.

Test plan

  • cd rust && cargo test -- --test-threads=1 (the suite shares process-global state; CI serializes it too)
  • cd rust && cargo clippy --all-targets --all-features -- -D warnings
  • cd rust && cargo fmt --check
  • If cookbook/packages changed: relevant npm test / build steps

Notes for reviewers

Fixes Devin MCP connection reset issue on Devin local mode.

Failed to call ctx_patch from lean-ctx
Failed to connect to MCP server 'lean-ctx'. Please try again.

thus model stops using ctx_* because of continues failures and not reliable tools.
Resulting soft error, allows model to get response and understand issue, and MCP connection stays in tact.

Contributor License Agreement

First-time contributors: a bot will ask you to sign our one-time
CLA (it keeps lean-ctx
Apache-2.0 and free for individual developers — see §8). You sign once by
replying to this PR with: I have read the CLA Document and I hereby sign the CLA

I have read the CLA Document and I hereby sign the CLA

…rf compatibility

Some MCP clients (Devin/Windsurf) treat hard JSON-RPC -32602 errors as transport failures, disconnect and respawn the server, hiding the actual parameter validation message from the agent. Convert INVALID_PARAMS to CallToolResult with isError=true so agents see validation messages and can fix parameter names.
@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@altasol

altasol commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Relates to and resolves #1409 also, reduces mcp connection restarts and contention.

@altasol

altasol commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Aug 2, 2026
@altasol

altasol commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

lean-ctx MCP: Validation Errors Misreported as Connection Failures

Summary

Devin/Windsurf's MCP client misreports JSON-RPC -32602 (INVALID_PARAMS) error
responses from the lean-ctx MCP server as "Failed to connect to MCP server",
making parameter validation errors look like infrastructure/transport failures.

This causes agents to retry, respawn MCP processes, and waste turns debugging
connectivity instead of fixing the parameter names.

Encountered Errors Example

ctx_patch with wrong params (anchor/content instead of line/hash/new_text)

Called:

{
  "name": "ctx_patch",
  "arguments": {
    "op": "insert_after",
    "path": "/path/to/file.md",
    "anchor": "some text",
    "content": "new text"
  }
}

Server response (JSON-RPC error):

{
  "jsonrpc": "2.0",
  "id": 2,
  "error": {
    "code": -32602,
    "message": "missing 'line'"
  }
}

Devin MCP client log:

[warning] MCP operation failed on cached service for 'lean-ctx',
  retrying with fresh connection: Mcp error: -32602: missing 'line'
[info] Connecting to MCP server 'lean-ctx'
[info] Starting stdio MCP server 'lean-ctx': "/opt/homebrew/bin/lean-ctx" []
[info] MCP server 'lean-ctx' connected successfully
[warning] Failed to connect to 'lean-ctx' for tool call: Mcp error: -32602: missing 'line'

Agent sees: Failed to connect to MCP server 'lean-ctx'. Please try again.

What should have happened: Agent sees: missing 'line' — insert_after requires line (integer) + hash (string) + new_text (string). Use ctx_read(mode="anchored") to get line:hash anchors.

and similar, when model is not aware how to exactly call the tools.

@altasol

altasol commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

real life test:

now after error:

MCP tool 'ctx_patch' returned an error: [ { "type": "text", "text": "replace_unique requires non-empty old_text (old_string also accepted)" } ] Available tools on server `lean-ctx`: [ {…

Model corrects it self:
Let me use the correct parameter names for ctx_patch.

@yvgude
yvgude merged commit 2944b9f into yvgude:main Aug 3, 2026
1 of 2 checks passed
@yvgude

yvgude commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Merged to main — thanks @altasol! 🎉

The fix is clean and the real-world Devin testing confirms the improvement. I trimmed the comment block slightly for consistency with our code style, but the logic is unchanged.

This will ship in the next release.

@github-actions github-actions Bot locked and limited conversation to collaborators Aug 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants