/byteforge-claude-skills:mcp-async-upgradefrom byteforge-claude-skills
Migrate an existing Python MCP server and its blocking SDK calls to native async I/O, preserving tool contracts, synchronous SDK consumers, caller isolation, and transport lifecycle. Use when slow backend requests serialize MCP tools or block the event loop; includes executable examples and a local concurrency benchmark.
Ships in byteforge-claude-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Audit the actual call path, migrate network I/O, prove isolation and resource
cleanup, then release using the project's established deployment workflow.
Changing def to async def while retaining requests, blocking database calls,
or synchronous decorators does not make the path non-blocking.
Inspect the repository and existing decisions first. Ask only for missing facts:
Record the installed Python/framework/HTTP-client versions, dependency locks, source revisions and current image digest when applicable. Inspect installed framework dispatch, not just its documentation or function annotations. Some framework/version combinations call synchronous tools directly on the event loop; others offload them. Do not assert identical dispatch across MCP variants.
Trace each registered tool through decorators, gates, identity enrichment, pagination and HTTP/database clients. Record all blocking I/O and CPU-heavy work. On reruns, reuse existing async clients and lifecycle hooks; reconcile gaps without installing duplicate pools or wrapping tools repeatedly. Save the existing tool schemas and an endpoint contract matrix: arguments, defaults, typed result, backend status mapping and side effects. Benchmark the current path before changing it. Keep CPU-bound work for a separate worker or executor design; async syntax does not parallelize Python computation.
The included examples are tested with Python 3.13 and mcp==1.29.1 (the SDK's
mcp.server.fastmcp, not the separate fastmcp package). They are an executable
reference, not a reason to upgrade a target project. Keep a compatible installed
version when it supports async tools. Re-audit dispatch and lifecycle on other
versions, especially major upgrades.
Read the implementation notes and adapt the client example to the target SDK.
functools.wraps where appropriate and compare generated schemas afterward.aclose().If a dependency has no async API, use an explicit bounded offload as an interim
design: anyio.to_thread.run_sync(..., limiter=..., abandon_on_cancel=False).
Choose the limiter per process, not per call. The worker still blocks a thread;
cancelling the await cannot forcibly stop it. Set underlying I/O timeouts and
account for work that continues or delays cancellation. Do not describe this as
native async, or silently increase thread counts to hide saturation.
Adapt the server example.
Keep the existing endpoint and stateless transport. Preserve host/origin checks,
authentication middleware, proxy conventions and observability. Configure logging
using byteforge-loki-logging if available; do not overwrite a project's existing
logging setup with the example's demonstration logger.
Use per-call SDK wrappers with explicit credentials. Never mutate shared client
Authorization defaults. Middleware must set both transport context and caller
identity and reset the ContextVar token in finally after success, error or
cancellation. A missing/Basic/empty bearer on HTTP must fail before backend
forwarding; it must not select the stdio process credential.
Construct explicit httpx.Request objects and send with auth=None and
follow_redirects=False when borrowing a client. This avoids merging shared
cookies, headers and query defaults into another caller's request. Test real
HTTPX merging behavior, including cookies learned from earlier responses; a mock
that checks only the explicit Authorization argument is insufficient. Keep the
backend URL trusted service configuration, not caller-provided input. Preserve
the project's actual token validation and authorization rules.
Replace EXAMPLE_API_KEY / EXAMPLE_BACKEND_URL in the example with
{PROJECT_NAME}_API_KEY / {PROJECT_NAME}_BACKEND_URL, substituting the uppercase
project prefix. Replace the async_example module and synthetic /work endpoint
with {project_name} and the real SDK contract. Never copy fixture identities
into a deployed configuration. The environment credential is a stdio-only
fallback; all HTTP entrypoints must pass through the context middleware.
Use the validation guide to run and adapt the included regressions and benchmark. From this skill's directory:
uv venv /tmp/mcp-async-validation
uv pip install --python /tmp/mcp-async-validation/bin/python -r requirements-test.txt
PYTHONDONTWRITEBYTECODE=1 /tmp/mcp-async-validation/bin/python -m pytest -q -p no:cacheprovider tests
PYTHONDONTWRITEBYTECODE=1 /tmp/mcp-async-validation/bin/python scripts/benchmark.py --repeat 2 > /tmp/mcp-async-benchmark.jsonl
These versions constrain the isolated harness, not the application's lock. The backend binds an ephemeral loopback port and uses only fixture credentials. No production URL is accepted by the benchmark. Adapt the dispatch adapter to the actual project, retaining registered-tool validation and the real SDK path.
Required evidence before declaring the migration complete:
The runnable benchmark measures registered tool dispatch plus SDK and loopback HTTP. It does not measure proxy ingress or production backend capacity, and concurrent requests are not a count of human users. Report slowdowns as well as improvements; cold single-call overhead can increase. Never turn a single run's speedup into a general capacity promise.
Keep the existing dependency lock and transport deployment conventions. Reuse
mcp-docker-deployment, uv-supply-chain-hardening, and
mcp-server-nginx-gatekeeper when those skills are available and relevant; avoid
duplicating or replacing their workflows here.
Before publishing, verify in the built artifact the actual dependency versions, imports, registered tool schemas/async flags, and pool startup/shutdown. Make failed registration/lifecycle smoke checks block publication. The validation guide distinguishes package tests from checks of the actual service image.
If the service pins its SDK by immutable commit, publish the reviewed SDK first, then update the service pin, rebuild and test that service. With deployment authorization, record the exact image digest and rollback reference, deploy, verify digest/health, run lightweight authenticated and anonymous reads and inspect service logs. Keep synthetic load tests isolated. Do not claim multiple production identities were tested if only one was available.
If you find a bug or stale instruction while using this skill:
byteforge-skills-maintainer-agent is available,
file a ticket with that agent. Use discover_agents to find its project ID.Include the skill name, plugin version if known, the instruction followed, expected and actual results, relevant errors/runtime versions, and any fix or workaround that worked. Omit credentials and private data.
Address the user's immediate problem first; report the skill defect afterward.
assets/async_example/__init__.py (opens in a new tab)assets/async_example/client.py (opens in a new tab)assets/async_example/server.py (opens in a new tab)references/implementation.md (opens in a new tab)references/validation.md (opens in a new tab)requirements-test.txt (opens in a new tab)scripts/benchmark.py (opens in a new tab)scripts/loopback.py (opens in a new tab)scripts/sync_reference.py (opens in a new tab)tests/conftest.py (opens in a new tab)tests/test_async_upgrade.py (opens in a new tab)tests/test_benchmark.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub jmazzahacks/byteforge-claude-skills --plugin byteforge-skills16 skills in this plugin
/aegis-nextjs-frontendThis skill should be used when the user asks to "create a new website", "spin up a frontend", "set up a Next.js site with aegis auth", "scaffold a new web app with authentication", "create a site with login and i18n", or needs a production-ready Next.js frontend integrated with ByteForge Aegis authentication. Provides complete project scaffolding with auth pages, internationalization, Docker deployment, and a design system./byteforge-loki-loggingConfigure Grafana Loki logging using byteforge-loki-logging library for Python/Flask applications. Use when setting up Loki logging, configuring centralized logging, or adding structured JSON logging to any Python project./byteforge-prometheus-metricsConfigure Prometheus metrics for Python/Flask applications with multi-worker gunicorn safety and optional Redis-backed business metrics. Use when adding a /metrics endpoint, instrumenting a Flask app, or fixing inflated metrics from multi-worker gunicorn./codync-tailscale-hostInstall a Codync host (persistent coding-agent bots driven from a phone or desktop app) on Linux or macOS so it is reachable ONLY over the user's Tailscale tailnet, with the Codync cloud relay off, pinned to host v2.53.0 with automatic updates off (2.54.0+ move bots out of their project folders), and chosen environment variables (agent auth tokens etc.) passed into the background service. Use when the user asks to install, set up, harden or replicate a Codync host, make Codync tailnet-only, turn off the Codync cloud relay, fix bots that can't see env vars or tokens under the codync-host service, or roll a host on 2.54.0+ back to 2.53.0 and return its bots to their project folders./flask-docker-deploymentSet up Docker deployment for Flask applications with Gunicorn, automated versioning, and container registry publishing. Use when dockerizing a Flask app, containerizing for production, or setting up CI/CD with Docker./flask-smorest-apiSet up Flask REST API with flask-smorest, OpenAPI docs, blueprint architecture, and dataclass models. Use when creating a new Flask API server, building REST endpoints, or setting up a production API.