Skip to content

API v2: /v2/mcp with a generic v2 executor - #147

Draft
Gintm wants to merge 4 commits into
developfrom
feat/v2-mcp
Draft

Gintm wants to merge 4 commits into
developfrom
feat/v2-mcp

Conversation

@Gintm

@Gintm Gintm commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Do not merge before the v2 opening (December 7, 2026). A merge to develop redeploys mcp.zernio.com. The orchestrator merges it together with the v2 opening.

Why

API v2 needs an MCP surface that does not go through the v1 SDK. /v2/mcp is a third FastMCP instance in the same process. It reads the v2 OpenAPI spec, so every v2 operation can be called without generated code.

What

  • /v2/mcp is grafted like /chatgpt: its own tool index, its own /.well-known/oauth-protected-resource/v2/mcp (resource: https://mcp.zernio.com/v2/mcp, authorization_servers: ["https://zernio.com"]) and its own 401 resource_metadata challenge. It also gets the Origin guard, telemetry surface: "v2" and User-Agent zernio-mcp (v2; <client>).
  • Auth is the same as /mcp (ZernioTokenVerifier, /api/v1/auth/verify). The caller's bearer (an API key or a late_at_ OAuth token) goes unchanged to https://api.zernio.com/v2, which ZERNIO_V2_API_URL can override.
  • The spec loads at start from ZERNIO_V2_SPEC_URL (default https://zernio.com/openapi-v2.json). If the fetch fails, or the live spec cannot build the tools, the server uses the gzipped snapshot in the package (243 KB, 946 operations). /health and / report v2_spec (the URL or snapshot), and the source is logged at start. Loading and building take about 0.2 s and about 13 MB RSS per worker.
  • Executor: each operation's arguments are its path, query and header parameters plus body. They are checked against the full schema with jsonschema before anything is sent. A refusal names each failing field (inside oneOf destinations it follows the matching platform) and lists the top-level arguments, not the whole schema.
  • HTTP limits: 30 s per attempt, at most 3 attempts, and 55 s in total for one tool call, waits included. Retry-After is honoured up to 10 s.
  • Retries:
    • 429 is retried for GETs, for writes sent with an idempotency key, and when error.details.scope shows a Zernio limit refused the call.
    • 503 and retryable: true are retried only for GETs and keyed writes.
    • A provider 429 on a write without a key, or such a write whose answer was lost, is never re-sent.
  • Idempotency: operations with x-idempotency: required send Idempotency-Key, either the agent's idempotencyKey or a UUID.
  • 202 answers never wait:
    • A job body answers the job's id, type, status and progress.
    • The post from createPost keeps its body and takes the job id from the /jobs/{id} Location header.
    • A staged ad change is returned as sent.
    • get_job follows a job.
  • Other answers: binary answers give status, content type and size. Errors give the compact v2 envelope. Output goes through the v1 format_payload.
  • Telemetry: v2 API errors log status_code and error_code, and call_operation logs operation_id.
  • Hints: GETs and /validations operations are read-only. Every other write is destructive (create_post can publish now, as v1 posts_create).
  • Limit default: no limit is sent unless the agent passes one, so lists use the API's default page size (50 for most lists, max 100). That keeps pages compact and leaves the choice with the API.
  • search_operations(query) calls the live GET /v2/operations?q= with the caller's token. It answers up to 25 rows (operationId, method, path, summary, costClass) and counts the rest. Rows the loaded spec does not have are marked callable: false.
  • call_operation(operation_id, arguments) takes an operationId or a snake_case name.
  • 23 pinned tools: list_posts, get_post, create_post, delete_post, validate_post_job, create_post_retry, list_profiles, list_accounts, get_account, list_conversations, list_conversation_messages, send_message, list_post_comments, list_commented_posts, create_comment_reply, get_post_metrics, get_account_metrics, get_metrics_catalog, get_job, get_job_result, validate_media, create_media_upload, complete_media_upload. updatePost, validatePost and listOperations are reachable through call_operation. search_operations is the catalog.
  • tools/list is 50,696 characters for 25 tools, down from about 215,000. create_post lists a short destination shape (platform enum and accountId, other fields open) and still validates the full one. The largest tool left is send_message at 21,560.
  • jsonschema is declared in the mcp extra (uv lock).
  • /v2/mcp is added to server.json, the server card, /server.json, the root info, the README and docs/MCP.md, marked "available from December 7, 2026". scripts/smoketest_streamable_http.py v2 checks the 401 challenge and tools/list.

Follow-ups

  • /health and / print ZERNIO_V2_SPEC_URL verbatim: report only live or snapshot (an override URL with a token would show).
  • docs/HTTP_DEPLOYMENT.md: list operation_id and v2_spec.
  • send_message (21.5K chars) is the next tool to slim.
  • OAuth callers depend on Schedule-Posts-API #12739 (v2 accepting late_at_ tokens). Until it merges, only API keys work on v2.
  • /v2/mcp appears in the published remotes as soon as this merges. That is fine because it merges with the opening.
  • Refresh the snapshot when the v2 spec changes, until the public URL serves it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JN8CzMsMVdDxsec9nWZxwq

Gintm and others added 4 commits December 3, 2026 14:58
…ke test mode

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JN8CzMsMVdDxsec9nWZxwq
…ints, flag operations newer than the spec, snapshot fallback when the live spec breaks tool building

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JN8CzMsMVdDxsec9nWZxwq
…t hints, v2 error and spec telemetry, declare jsonschema

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JN8CzMsMVdDxsec9nWZxwq
@Gintm

Gintm commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Review (pr-verdict supports only Schedule-Posts-API, so verdicts are recorded here)

Round Head Verdict Must-fix Advisory
code-review high --fix 243a9dd 9 findings, 7 fixed
code-reviewer r1 243a9dd fail 1 (PR body belonged to another PR) 10 (tools/list size, 429 on keyless writes, hints, telemetry, time cap, ...)
fix round 9bbbd9d all 8 items applied
code-reviewer r2 9bbbd9d pass 0 4 (body wording fixed; 3 in Follow-ups)

QA (head 9bbbd9d, local server, real auth against zernio.com, staff key, read tools only, nothing written)

Call Result
/health v2_spec: snapshot (live spec 404 before the opening)
tools/list 25 tools, 50,696 chars
list_accounts, list_posts, list_profiles limit 2 2 rows each, pagination present, 0.6 to 1.2 s
list_conversations limit 2 2 rows, 7.0 s (API side: Worker logged 7,459 ms; 7-day p50 581 ms)
get_metrics_catalog ok, 1.1 s
search_operations("posts") 25 rows, 0.8 s
call_operation listPosts {limit: 1} 1 row
call_operation listPosts {page: 1} refused locally invalid_arguments, nothing sent (0.01 s)
call_operation getJob unknown id API error envelope passed through (404)

Metrics

Item Before After
tools/list payload 228,437 chars (r1) 50,696 chars (v1 /mcp: 88.7K, /chatgpt: 328K)
Spec load per worker about 0.2 s, +13 MB RSS (snapshot)
API calls per tool call 1 (plus retries only for GETs, keyed writes, or 429 with details.scope)
SQL none in this repo none

This branch has not been deployed

No deployments
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.

1 participant