Skip to content

feat(deps): support mcp 2 alongside mcp 1 - #274

Merged
glebedel merged 8 commits into
mainfrom
s2d2/audit-mcp-2
Nov 11, 2026
Merged

glebedel merged 8 commits into
mainfrom
s2d2/audit-mcp-2

Conversation

@glebedel

@glebedel glebedel commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What

The SDK now runs on mcp 2 as well as mcp 1. pyproject.toml allows mcp>=1.30.0,!=2.0.*,!=2.1.*,<3.0.0 and the lockfile pins mcp 2.3.0. This replaces the Dependabot bump in #208, which cannot merge as is: on mcp 2.3.0, every fetch_tools() and tool call on main fails.

  • stackone_ai/tools.py: _mcp_http is httpx2 when mcp 2 is installed and httpx otherwise, and the MCP transport client, timeouts and error types come from it. GET /accounts stays on httpx.
  • The transport yields two streams on both majors (mcp 2 yields two, mcp 1 three).
  • _mcp_field reads model fields by their snake_case name (mcp 2) or wire name (mcp 1): inputSchema, nextCursor, structuredContent, isError.
  • A failed POST other than a 404 raises HTTPStatusError with its status and body, as mcp 1 does. mcp 2 would turn it into a JSON-RPC error with neither. A 404 is still handed to mcp, which reports a lost session.
  • call_mcp_tool passes CallToolRequest to send_request directly, which both majors accept.
  • CI runs the suite a second time against mcp 1.30.0, the oldest version the range allows.

Why, with evidence

  • main on mcp 2.3.0: ToolsetLoadError: ... ValueError: not enough values to unpack (expected 3, got 2) on every list and call, because streamable_http_client changed its yield.
  • mcp 2.0.x and 2.1.x carry four published advisories that 2.2.0 fixes (GHSA-w4fh-qvv9-3v23, GHSA-5h93-6whr-6q8j, GHSA-rwrf-2pqf-9j8j, GHSA-84m7-p3x7-pcfv). Below 1.30.0 the same advisories apply, so the range excludes both.

How verified

  • ruff check, ruff format --check, ty check stackone_ai examples: clean.
  • pytest: 879 passed on mcp 2.3.0 (locked), on 2.2.0 and on 1.30.0 (uv run --with).
  • scripts/validate.sh: PASS 6/6 (examples, conformance --strict-schema, SDK smoke, Pydantic AI 1.x and 2.x, Google ADK plugin).
  • Demo against the repo's MCP mock (tests/mocks/serve.ts): list two accounts (one valid, one the mock refuses with 400), then call a listed tool and an unknown one.
Run list acc1 list refused account call listed tool call unknown tool
main, mcp 1.30.0 3 tools StackOneAPIError 400 with server body ok StackOneAPIError "Unknown tool"
main, mcp 2.3.0 ToolsetLoadError (unpack) ToolsetLoadError (unpack) ToolsetLoadError ToolsetLoadError
this PR, mcp 2.3.0 3 tools StackOneAPIError 400 with server body ok StackOneAPIError "Unknown tool"
this PR, mcp 1.30.0 3 tools StackOneAPIError 400 with server body ok StackOneAPIError "Unknown tool"

Good citizen

Retry counts, backoff, Retry-After handling, timeouts and concurrency are unchanged. TLS still uses the same verified SSL context. No new network calls and no new dependencies: httpx2 is imported only when mcp 2, which requires it, is installed.

Gates (head 5429c2b)

Gate Result
Forge meter on own diff: 7 comment lines, longest block 2, 0 copies; two stale comments fixed, no other findings
Security scan (security and dependency reviewers) no Critical, High or Medium; uv lock --check ok; no OSV/GHSA entries for the new versions
Codex security pass no new findings. Noted a pre-existing one: error bodies are buffered without a size cap (_buffer_error_body, unchanged from main)
Aikido open issues 0 critical, 0 high; the 1 medium and 2 low are pre-existing and outside the changed lines
/security-review checklist secrets and injection pass; the service sections (routes, DB, webhooks) do not apply to a library
/code-review 10 findings, none needing a change: notification and 404 handling match mcp 1, the mcp 1 lane imports httpx not httpx2, Tool.inputSchema is a required dict on both majors, the toolset.py items belong to #261
Codex review (e11c60f) no bugs; its two test gaps are closed in 5429c2b

Merge order

This branch is built on #261 and includes its commits, so merge #261 first. This PR then supersedes #208, which can be closed.

Post-merge validation

  • release-please opens a feat (minor) release PR; after it publishes, install the release with mcp 2.3.0 and with mcp 1.30.0 and run the quickstart example against a real key.
  • Then check that downstream consumers of the SDK resolve and pass with the new release before bumping them.

Requested by guillaume@stackone.com in Slack (repo audit thread).

🤖 Generated with Claude Code


Summary by cubic

The SDK now runs on mcp 2 as well as mcp 1, so installs next to packages that require mcp 2 no longer conflict while projects pinned to mcp 1 keep resolving. On main, mcp 2 made every fetch_tools() call and tool invocation fail with a ToolsetLoadError.

  • The range is now mcp>=1.30.0,!=2.0.*,!=2.1.*,<3.0.0 and the lockfile pins mcp 2.3.0; 2.0.x and 2.1.x are excluded because they carry four published advisories.
  • MCP requests use the HTTP library the installed mcp takes: httpx on mcp 1, httpx2 on mcp 2. GET /accounts stays on httpx.
  • Tool definitions and results read their fields by snake-case name on mcp 2 and wire name on mcp 1 (inputSchema, nextCursor, structuredContent, isError); on mcp 2 the wire names silently read every failed call as a success.
  • Non-404 failed POSTs raise HTTPStatusError with their status and body, as mcp 1 does; mcp 2 would otherwise turn them into a JSON-RPC error carrying neither. A 404 is still left to mcp as a lost session.
  • CI runs the suite a second time against mcp 1.30.0, the oldest allowed version.
  • This builds on the shared MCP plumbing refactor and supersedes the earlier Dependabot bump, which cannot merge as is.

Written for commit 5429c2b. Summary will update on new commits.

View guided diff Turn on auto-fix

s2d2-s1 and others added 8 commits November 10, 2026 20:51
fetch_mcp_tools and call_mcp_tool each opened the transport, built a
ClientSession, initialized it under the same deadline and mapped
failures through _raise_mcp_failure. That now lives in one
_run_mcp_session helper, import guard included; each function keeps
only its own exchange.

The retry-once-with-the-looked-up-end-user logic was written three
times (per-account listing, search/execute listing, tool execution).
It is now retry_for_end_user, with the same rules: only a 400 naming an
account that was sent without an end user, and only if the lookup finds
one.

No behaviour change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
The retry condition is documented once, on retry_for_end_user, as the
toolset callers already rely on; the copy above the tool's call site
restated it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
retry_for_end_user already checks is_end_user_refusal before it calls the
look-up, and every caller goes through it, so the look-up's own check was a
second copy that could drift.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
Main changed the two MCP session bodies this branch folds into
_run_mcp_session. The shared helper stays, with main's edits carried over:
tools/list pages with list_tools(params=PaginatedRequestParams(...)), the
mcp imports drop their ty ignores, and the shared SSL context merged on its
own. The types import in fetch_mcp_tools sits inside _list, so it runs after
the helper's guarded import and a broken install still raises
ToolsetConfigError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
The pagination test only counted calls, so a regression to the old
positional cursor argument would still pass. Assert the first call sends
params=None and the second carries the next cursor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
Widen the mcp range to >=1.30.0,<3.0.0 and lock mcp 2.3.0, so installs
next to packages that need mcp 2 (fastmcp 4, newer agent frameworks) no
longer conflict, while projects pinned to mcp 1 (langchain-mcp-adapters
caps mcp<2) keep resolving.

mcp 2 changed four things the SDK relied on:
- its transport takes an httpx2 client, not an httpx one, and yields two
  streams instead of three;
- model attributes are snake_case only (is_error, structured_content,
  input_schema, next_cursor), so getattr(result, "isError", False)
  silently read every failed tool call as a success;
- a failed POST becomes a JSON-RPC error with no HTTP status or body, which
  lost the 400/412/429 status that end-user recovery, rate limiting and
  error messages read;
- ClientRequest is a typing union, so the request is passed directly.

The MCP client now uses whichever HTTP library the installed mcp takes,
reads fields under either name, and raises a non-404 POST error status
itself, as mcp 1 does. GET /accounts keeps using httpx. CI also runs the
suite against mcp 1.30.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
mcp 2.0.x and 2.1.x carry four published advisories that 2.2.0 fixes
(GHSA-w4fh-qvv9-3v23, GHSA-5h93-6whr-6q8j, GHSA-rwrf-2pqf-9j8j,
GHSA-84m7-p3x7-pcfv), so the range excludes them as it already excludes
mcp 1 below 1.30.0.

The pagination test now builds the installed mcp's own ListToolsResult
and Tool models, so it reads the field names that major really uses. The
async client tests assert that a failed POST raises with its body readable,
and that a 404 POST, a GET and a DELETE are handed back to mcp unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Guillaume Lebedel <10488548+glebedel@users.noreply.github.com>
@glebedel glebedel self-assigned this Nov 11, 2026
@glebedel
glebedel merged commit 7dfbf28 into main Nov 11, 2026
14 checks passed
@glebedel
glebedel deleted the s2d2/audit-mcp-2 branch November 11, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants