Skip to main content

code-analysis-client

Async Python client for the code-analysis server. It wraps mcp-proxy-adapter’s JsonRpcClient, so you get the adapter’s built-in methods (queue, transfer, help, health, …) plus thin helpers to run any registered server command.

Install

pip install code-analysis-client

Usage

import asyncio
from code_analysis_client import CodeAnalysisAsyncClient


async def main() -> None:
    client = CodeAnalysisAsyncClient(
        protocol="https",
        host="127.0.0.1",
        port=15001,
        cert="/path/client.crt",
        key="/path/client.key",
        ca="/path/ca.crt",
        timeout=120.0,
    )
    async with client:
        h = await client.rpc.help()
        r = await client.call("list_projects", {"include_deleted": False})
    print(h, r)


asyncio.run(main())

Build client settings from the same JSON shape as the pipeline adapter settings (host, port, protocol, optional ssl with cert / key / ca or *_path aliases), or from a full server config.json object.

from code_analysis_client import CodeAnalysisAsyncClient

client = CodeAnalysisAsyncClient.from_server_config(config_dict, timeout=60.0)

Queued commands are handled automatically

Every entry point — call, call_validated, client.commands.<name>, and the file_sessions / universal_files facades built on call_validated — routes through one queue-aware core. If the server's immediate response is a queued-job envelope (either deployed shape: poll_with/store: "queuemgr", or queued_after_timeout), the client polls queue_get_job_status for you until the job reaches a terminal state, then returns the unwrapped inner result — the same shape you'd get from a synchronous call. You never see the raw envelope.

# No special handling needed: queued or not, this returns the real result.
out = await client.call("some_long_running_command", {...})

Failures raise instead of returning an error envelope:

  • CommandFailedError — the job completed but the command itself failed (inner result {"success": false} / command_success is False / completed_with_error). Carries .command, .job_id, .error.
  • JobFailedError — the job failed/stopped/cancelled, or reported error. Carries .job_id, .error, .status.
  • JobTimeoutError — only raised when you pass an explicit timeout and it elapses; the job keeps running server-side. By default (timeout=None) the client polls until the job finishes, however long that takes.

Optional keyword args on call / call_validated (and their call_unified* counterparts): timeout (seconds, default None = wait until terminal), poll_interval (seconds between polls, default 1.0), status_hook (sync or async callable invoked with each poll's status dict).

call / call_validated also take auto_poll (default True, matching the behavior above exactly). Pass auto_poll=False to opt out of automatic polling: a non-queued response still comes back as the plain domain result, but a queued-job response comes back immediately as a QueuedJob handle instead of blocking until the job finishes.

from code_analysis_client import QueuedJob

result = await client.call("some_long_running_command", {...}, auto_poll=False)
if isinstance(result, QueuedJob):
    # do other work here, then block on it whenever you're ready
    result = await result.wait()
# `result` is now the same dict shape a default (auto_poll=True) call returns

QueuedJob exposes .job_id, .envelope (the raw queue-service response), and two async methods: .wait(timeout=None, poll_interval=1.0, status_hook=None) — polls to completion and returns/raises exactly like the default path — and .status() — a single queue_get_job_status fetch without polling to completion.

call_unified / call_unified_validated are kept as deprecated aliases of call / call_validated for backward compatibility and emit DeprecationWarning on every call. expect_queue remains accepted-and-ignored (documented no-op). auto_poll is the one canonical switch and is forwarded straight through to call / call_validatedauto_poll=False on an alias returns a QueuedJob the same way it does on the non-deprecated method. Prefer call / call_validated directly.

Validation using the server schema

The authoritative input schema is whatever the running server returns from help with cmdname set to the command. The client calls that, optionally caches the result, performs the same shallow checks as the server’s BaseMCPCommand (types, required, enum, additionalProperties), then runs the command.

async with CodeAnalysisAsyncClient(host="127.0.0.1", port=15001) as client:
    # Explicit
    out = await client.call_validated(
        "list_projects",
        {"include_deleted": False},
    )
    # Dynamic wrapper: same as call_validated("list_projects", {...})
    out = await client.commands.list_projects(include_deleted=False)
    # After server reload
    client.clear_command_schema_cache()

Pass refresh_schema=True on a single call to bypass the in-memory schema cache.

High-level facades (aligned with live server registry)

The client does not wrap CST commands (cst_load_file, …) or legacy file I/O (universal_file_read, read_project_text_file, …). Those commands are removed from the server registry. Use the facades below or generic call / commands.*.

Facade Property Server commands
Client DB sessions + transfer client.file_sessions session_*, subordinate_session_*, project_file_transfer_*, project_file_advisory_lock_batch
Universal file preview client.universal_files universal_file_preview (read-only)
Any registered command client.call / client.commands.<name> schema from live help()

Canonical command lists: code_analysis_client.server_api — exported as FILE_SESSION_COMMANDS, FILE_SESSION_FACADE_METHODS, CLIENT_FACADE_COMMANDS, REMOVED_COMMANDS.

Scope boundary: this client manipulates files only as whole units — transfer, locks, sessions, and structured read-only preview — and analyzes them. Content editing (open/edit/write/close draft sessions) is not served by this project's code-analysis server; use the ai-editor client for that.

Sync checks (in-process registry):

pytest tests/test_client_server_api_sync.py tests/test_code_analysis_client.py -k session

Package version is in the root pyproject.toml; before a client wheel build run python scripts/sync_code_analysis_client_version.py (also done by release_build.sh).

Examples (this repository)

Runnable scripts live under client/examples/. Long-form “man page” style documentation is embedded in the module docstrings of those Python files (see client/examples/README.md for how to read them).

Script Purpose
run_all_examples.py Full API tour + runs all live sibling scripts
ex_minimal_validated.py Smallest validated RPC example
ex_universal_files.py UniversalFileClient.preview (read-only structured preview)
ex_session_view_subordinates.py session_view and subordinate CRUD
ex_file_sessions.py Sessions, locks, transfer roundtrip
ex_config_only.py Parse config.json without TCP
casmgr --config config.json start
python client/examples/run_all_examples.py

Development

From the repository root:

pip install -e ./client
pytest tests/test_code_analysis_client.py

Releasing to PyPI (version = root code-analysis project)

The client wheel version is read from client/code_analysis_client/version.txt. That file must match [project].version in the repository root pyproject.toml. Sync before build:

python scripts/sync_code_analysis_client_version.py
cd client && python -m build && twine check dist/* && twine upload dist/*

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

code_analysis_client-1.6.167.tar.gz (31.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

code_analysis_client-1.6.167-py3-none-any.whl (34.5 kB view details)

Uploaded Python 3

File details

Details for the file code_analysis_client-1.6.167.tar.gz.

File metadata

  • Download URL: code_analysis_client-1.6.167.tar.gz
  • Upload date:
  • Size: 31.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.4

File hashes

Hashes for code_analysis_client-1.6.167.tar.gz
Algorithm Hash digest
SHA256 69fe714f13fef00cc60730e820652d6446a8e7225101d9194c6c1bdab53c4cf6
MD5 720ec4b9ed22bce604cc7d6762cfabb8
BLAKE2b-256 76d222393cd1a7722be5a6748ad364eca647e591b991109829961865581b64ac

See more details on using hashes here.

File details

Details for the file code_analysis_client-1.6.167-py3-none-any.whl.

File metadata

File hashes

Hashes for code_analysis_client-1.6.167-py3-none-any.whl
Algorithm Hash digest
SHA256 aaf140690cf47cbc152f419c888408e1b07c3b2f0b33bceedf821862ce75ed11
MD5 0f26fe0cdcff05752c4fa4a41a283505
BLAKE2b-256 f629b9096cc1fec44fee591baded01323ffe138046e2f08fd0be6d1eb63e4b8d

See more details on using hashes here.

Release history Release notifications | RSS feed

1.6.173

2 files

1.6.172

2 files

1.6.171

2 files

1.6.170

2 files

1.6.169

2 files

1.6.168

2 files

This release

1.6.167 This release

2 files

1.6.166

2 files

1.6.165

2 files

1.6.164

2 files

1.6.163

2 files

1.6.162

2 files

1.6.161

2 files

1.6.160

2 files

1.6.159

2 files

1.6.158

2 files

1.6.153

2 files

1.6.151

2 files

1.6.150

2 files

1.6.148

2 files

1.6.147

2 files

1.6.146

2 files

1.6.145

2 files

1.6.144

2 files

1.6.138

2 files

1.6.137

2 files

1.6.136

2 files

1.6.134

2 files

1.6.132

2 files

1.6.128

2 files

1.6.126

2 files

1.6.122

2 files

1.6.119

2 files

1.6.118

2 files

1.6.115

2 files

1.6.114

2 files

1.6.113

2 files

1.6.112

2 files

1.6.111

2 files

1.6.110

2 files

1.6.108

2 files

1.6.107

2 files

1.6.106

2 files

1.6.105

2 files

1.6.104

2 files

1.6.103

2 files

1.6.102

2 files

1.6.101

2 files

1.6.100

2 files

1.6.99

2 files

1.6.98

2 files

1.6.97

2 files

1.6.96

2 files

1.6.95

2 files

1.6.94

2 files

1.6.93

2 files

1.6.92

2 files

1.6.91

2 files

1.6.90

2 files

1.6.89

2 files

1.6.88

2 files

1.6.80

2 files

1.6.79

2 files

1.6.78

2 files

1.6.77

2 files

1.6.76

2 files

1.6.75

2 files

1.6.74

2 files

1.6.73

2 files

1.6.72

2 files

1.6.71

2 files

1.6.70

2 files

1.6.69

2 files

1.6.68

2 files

1.6.67

2 files

1.6.66

2 files

1.6.65

2 files

1.6.64

2 files

1.6.63

2 files

1.6.62

2 files

1.6.61

2 files

1.6.60

2 files

1.6.59

2 files

1.6.58

2 files

1.6.57

2 files

1.6.56

2 files

1.6.54

2 files

1.6.53

2 files

1.6.52

2 files

1.6.45

2 files

1.6.43

2 files

1.6.42

2 files

1.6.41

2 files

1.6.40

2 files

1.6.39

2 files

1.0.9

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page