SuanLinFang MCP Server
# SuanLinFang MCP Server — Pay-as-you-go AI capabilities
Official website: **[https://suanlinfang.cn](https://suanlinfang.cn)** — create an API key at [API Key Management](https://suanlinfang.cn/consume-web/api-keys.html) (new accounts get a free trial credit).
Remote MCP server with **12 tools** in four capability families, Chinese-optimized, pay-as-you-go (failed calls are never billed):
| Family | Tools | Highlights |
|---|---|---|
| Image Generation | `generate_image`, `get_image_task`, `list_image_models` | text-to-image & image-to-image (edit) in a single call — submit, wait and get the result URL; 1024×1024 PNG, model auto-selected by default, billed per image |
| Speech-to-Text (STT) | `transcribe_audio`, `submit_transcription_task`, `get_transcription_task` | ≤2h audio, hot-word correction, auto detection for Mandarin/English + 22 Chinese dialects |
| Text-to-Speech (TTS) | `synthesize_speech`, `submit_speech_task`, `get_speech_task`, `list_tts_voices` | 21 voices, ≤200k chars per task, wav/mp3 |
| OCR (documents) | `submit_document_task`, `get_document_task` | full scanned PDFs up to 500 pages — whole-document jobs agents can't ingest into their own context; standard/accurate tiers, custom prompt (accurate tier) |
## Connect (remote, recommended)
Works with any MCP client that supports Streamable HTTP:
```json
{
"mcpServers": {
"suanlinfang": {
"type": "streamableHttp",
"url": "https://suanlinfang.cn/mcp",
"headers": {
"X-SLF-Api-Key": "nk-YOUR_API_KEY"
}
}
}
}
```
Claude Code one-liner:
```bash
claude mcp add --transport http suanlinfang https://suanlinfang.cn/mcp \
--header "X-SLF-Api-Key: nk-YOUR_API_KEY"
```
Browse the tool catalog without a key: the endpoint answers `initialize` and `tools/list` publicly — tool **calls** require your key.
## Install (local stdio)
Published on PyPI as [`suanlinfang-mcp`](https://pypi.org/project/suanlinfang-mcp/):
```bash
pip install suanlinfang-mcp
export SUANLINFANG_API_KEY="nk-YOUR_API_KEY"
suanlinfang-mcp # stdio entry for Claude Desktop / Cursor / etc.
```
or run without installing: `uvx suanlinfang-mcp`
Environment variables:
| Variable | Purpose | Default |
|---|---|---|
| `SUANLINFANG_API_KEY` | your API key (`nk-` prefix) for stdio/local use | required for stdio |
| `SUANLINFANG_BASE_URL` | API base override | `https://suanlinfang.cn/v1` |
| `SUANLINFANG_MCP_PORT` | listen port for the HTTP entry | `8090` |
The Python SDK lives in `packages/suanlinfang-sdk/` — a dependency-free REST client (`pip install suanlinfang-sdk`) you can use without MCP.
## Get an API key
1. Register at [suanlinfang.cn](https://suanlinfang.cn) (new accounts get trial credit)
2. Console → [API Key Management](https://suanlinfang.cn/consume-web/api-keys.html) → create key (`nk-` prefix)
3. Put the key in the `X-SLF-Api-Key` header (remote) or `SUANLINFANG_API_KEY` env (stdio)
Reference pricing: image generation billed per image (model-tiered, see `list_image_models` for live prices), transcription ≈ ¥0.5/hour of audio, TTS ≈ ¥2/10k chars, OCR ≈ ¥0.005–0.015/page. Failed calls are never billed.
## Docker
Docker image distribution is planned (`mcp/suanlinfang` via the Docker MCP Catalog) — see TODO.
## Development
```bash
cd mcp-server
uv sync # workspace: sdk + mcp packages + dev deps
uv run pytest # all tests
uv run fastmcp dev packages/suanlinfang-mcp/suanlinfang_mcp/server.py # MCP Inspector
uv run python -m suanlinfang_mcp.entry_http # local HTTP entry (127.0.0.1:8090/mcp)
```
Repo layout:
- `packages/suanlinfang-sdk/` — REST client SDK (no MCP concepts; reusable by CLIs and other hosts)
- `packages/suanlinfang-mcp/` — MCP protocol shell exposing the 12 tools
- `server.json` — official [MCP Registry](https://registry.modelcontextprotocol.io) metadata (`cn.suanlinfang/stt-tts-ocr-decision`)
## License
[Apache-2.0](LICENSE). The MCP server is open source; the AI inference, billing and scheduling core runs server-side at suanlinfang.cn and is not part of this repo.
TDQS
Scored across 12 tools
Each tool maps to a distinct resource+action, and the four domains (image, transcription, TTS, document OCR) are cleanly separated. The main overlap risk is the sync/async pairs (transcribe_audio vs submit_transcription_task, synthesize_speech vs submit_speech_task), but the descriptions sharply bound them by size limits (≤3 min/20MB vs ≤2 h/500MB; ≤1000 chars vs ≤200k), so an agent can choose correctly. generate_image's built-in wait plus get_image_task as a timeout fallback is documented but is the one place where a newcomer might double-poll.
All names are snake_case verb_noun with a coherent scheme: sync operations use a bare verb (generate_image, transcribe_audio, synthesize_speech), async ones use submit_*_task plus a matching get_*_task, and lookups use list_*. Minor deviations: generate_image has no submit_image_task counterpart yet still has get_image_task, and the two list tools name the resource differently (list_image_models vs list_tts_voices).
Twelve tools for four sub-services is well-proportioned: roughly three per domain (submit/sync, poll, and a catalog lookup). No tool is redundant, and the async-poll trio repeats only because the underlying platform genuinely requires it.
Each domain has a workable lifecycle: submit/sync, poll for status, and model-or-voice discovery for image and TTS. Gaps are real but survivable — document OCR has no equivalent catalog lookup or sync path despite the prompt mentioning quality tiers, and there is no task-cancel tool. Most notably, billing is emphasized everywhere ('余额不足会在提交时被拒绝', per-page/per-character pricing) yet no balance or quota query tool exists, forcing agents to discover insufficient funds by failure.