Skip to main content

Unified mock server for AI-Protocol runtimes - HTTP provider and MCP JSON-RPC mocking

Project description

ai-protocol-mock

Unified mock server for AI-Protocol runtimes. Provides HTTP provider mock (OpenAI and Anthropic formats) and MCP JSON-RPC mock for testing ai-lib-python, ai-lib-rust, and other runtimes.

Features

  • Manifest-driven HTTP mock: Generates responses in OpenAI or Anthropic format based on provider manifests
  • STT / TTS / Rerank mock: Simulates speech-to-text, text-to-speech, and document reranking endpoints (OpenAI/Cohere compliant)
  • MCP JSON-RPC mock: Implements tools/list, tools/call, capabilities, initialize
  • Configurable: Response delay, error rate, mock content via environment variables
  • Docker: One-command startup with docker-compose up

Quick Start

# Install and run
pip install -e .
python scripts/sync_manifests.py --force  # Sync manifests from ai-protocol
uvicorn ai_protocol_mock.main:app --host 0.0.0.0 --port 4010

Or with Docker:

docker-compose up -d

Configuration

Variable Default Description
HTTP_PORT 4010 Port for HTTP and MCP (MCP at /mcp)
MANIFEST_DIR manifests Directory for synced manifests
MANIFEST_SYNC_URL https://raw.githubusercontent.com/hiddenpath/ai-protocol/main/ Source for manifest sync
RESPONSE_DELAY 0 Delay in seconds before responding
ERROR_RATE 0 Probability (0-1) of returning 429/500/503
MOCK_CONTENT Mock response from ai-protocol-mock Default response content

Endpoints

  • POST /v1/chat/completions - OpenAI-format chat
  • POST /v1/messages - Anthropic-format chat
  • POST /v1/audio/transcriptions - STT (OpenAI Whisper format), returns {"text": "..."}
  • POST /v1/audio/speech - TTS (OpenAI format), returns audio/mpeg bytes
  • POST /v2/rerank - Rerank (Cohere v2 format), request {query, documents, top_n}, returns {results, id, meta}
  • POST /mcp - MCP JSON-RPC (tools/list, tools/call, capabilities, initialize)
  • GET /health - Health check
  • GET /status - Status with manifest sync metadata
  • GET /providers - Provider contracts from manifests (provider_id, api_style, chat_path)

Using with ai-lib-python

import os
os.environ["MOCK_HTTP_URL"] = "http://localhost:4010"

from ai_lib_python.client import AiClient
from ai_lib_python.types.message import Message

client = await AiClient.create(
    "openai/gpt-4o",
    api_key="sk-test",
    base_url="http://localhost:4010"
)
response = await client.chat().messages([Message.user("Hi")]).execute()
print(response.content)

Or run tests with mock:

MOCK_HTTP_URL=http://localhost:4010 MOCK_MCP_URL=http://localhost:4010/mcp pytest tests/ -v

Using with ai-lib-rust

export MOCK_HTTP_URL=http://localhost:4010
cargo run --example basic_usage

Or run mock integration tests:

MOCK_HTTP_URL=http://localhost:4010 cargo test -- --ignored --nocapture

Or in code:

let client = AiClientBuilder::new()
    .base_url_override("http://localhost:4010")
    .build("openai/gpt-4o")
    .await?;

Manifest Sync

Sync manifests from the ai-protocol repository:

python scripts/sync_manifests.py [--force] [--url URL] [--tag REF]
  • --force - Overwrite existing files
  • --tag REF - Pin to a specific ai-protocol ref (e.g. v0.7.1, main)
  • --url URL - Custom base URL (default: ai-protocol main)

Run before starting the server to ensure manifests are up to date. Docker Compose runs sync automatically on startup. A GitHub Action runs sync daily to validate the script.

Development

pip install -e ".[dev]"
pytest tests/ -v
ruff check src tests scripts

License

MIT OR Apache-2.0

Project details


Download files

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

Source Distribution

ai_protocol_mock-0.1.3.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

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

ai_protocol_mock-0.1.3-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file ai_protocol_mock-0.1.3.tar.gz.

File metadata

  • Download URL: ai_protocol_mock-0.1.3.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for ai_protocol_mock-0.1.3.tar.gz
Algorithm Hash digest
SHA256 3c5fee1c71ffd6715b26bcfcab2491b51a24cd036ea2365ce5ce5071bda47b34
MD5 e1488a7729d948b7baa81640731ddd82
BLAKE2b-256 a1a4313b42c2149e02c1719f495031a3a74831219e4c4eac604414439c5fd1e9

See more details on using hashes here.

File details

Details for the file ai_protocol_mock-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for ai_protocol_mock-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 48aa7f652fa12e8a484820b3d26e142694f8d7a4dc44916fbec2018f9934088d
MD5 6870dd2cc278df1f7183a03d916be107
BLAKE2b-256 f7f60df757b41079ae9eebbf70c03f81a272ec02679f5c4a350ea96ad7ae0206

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page