Expose mistralrs as an MCP server
mistral.rs can expose the loaded model as an MCP (Model Context Protocol) server: a chat tool over JSON-RPC 2.0 that any MCP client can call.
mistralrs serve -m Qwen/Qwen3-4B --mcp-port 4321--mcp-port starts an additional listener. The port rules:
- It shares
--hostwith the main HTTP API. - The OpenAI-compatible API on
--port(default 1234) still runs alongside. --mcp-portmust differ from--port.- The bind is validated at startup, so failures surface before serving.
In a TOML config, the equivalent is mcp_port under [server]:
command = "serve"
[server]port = 1234mcp_port = 4321Clients connect to http://<host>:<mcp_port>/mcp. Each call is a POST /mcp with a JSON-RPC 2.0 body.
Methods
Section titled “Methods”initialize: returns{"capabilities":{"tools":{}},"instructions":...,"protocolVersion":"2025-11-25","serverInfo":{"name":"mistralrs","version":...}}.ping: returns{}.tools/list: returns thechattool. The list is empty if the loaded model does not have text input and output modalities.tools/call: runs thechattool.
Anything else returns JSON-RPC error -32601 (method not found). A body with jsonrpc other than "2.0" returns -32600; tool execution failures return -32603.
The chat tool
Section titled “The chat tool”You can pass any OpenAI ChatCompletionRequest field in arguments; the advertised schema only documents the common ones. The schema:
- Requires
messages: an array of{role, content}objects with rolesuser,assistant, orsystem. - Documents
max_tokensandtemperature. - Defaults
modelto"default".
curl http://localhost:4321/mcp \ -H "Content-Type: application/json" \ -d '{ "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "chat", "arguments": { "messages": [{"role": "user", "content": "Hello!"}], "max_tokens": 50 } } }'The result is MCP tool-call content:
{"content": [{"type": "text", "text": "Hello! How can I help?"}]}Authentication
Section titled “Authentication”The MCP endpoint has no built-in authentication. For non-localhost use, place an authenticating proxy in front.
See also
Section titled “See also”- Connect to an MCP server: the opposite direction, using external MCP tools from mistral.rs.
- Serve CLI reference.