https://github.com/hiddenpath/ai-protocol-mock
Unified mock server for AI-Protocol runtimes - HTTP provider and MCP JSON-RPC mocking
https://github.com/hiddenpath/ai-protocol-mock
Last synced: 4 months ago
JSON representation
Unified mock server for AI-Protocol runtimes - HTTP provider and MCP JSON-RPC mocking
- Host: GitHub
- URL: https://github.com/hiddenpath/ai-protocol-mock
- Owner: hiddenpath
- License: apache-2.0
- Created: 2026-02-17T19:09:32.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2026-02-18T14:49:14.000Z (4 months ago)
- Last Synced: 2026-02-18T18:22:45.795Z (4 months ago)
- Language: Python
- Size: 22.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# 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
- **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
```bash
# 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:
```bash
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 /mcp` - MCP JSON-RPC (tools/list, tools/call, capabilities)
- `GET /health` - Health check
- `GET /status` - Status with manifest sync metadata
## Using with ai-lib-python
```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)
```
## Using with ai-lib-rust
```bash
export MOCK_HTTP_URL=http://localhost:4010
cargo run --example basic_usage
```
Or in code:
```rust
let client = AiClientBuilder::new()
.base_url_override("http://localhost:4010")
.build("openai/gpt-4o")
.await?;
```
## Manifest Sync
Sync manifests from the ai-protocol repository:
```bash
python scripts/sync_manifests.py [--force] [--url URL]
```
Run before starting the server to ensure manifests are up to date. Docker Compose runs sync automatically on startup.
## License
MIT OR Apache-2.0