Using MCP from code (AI APIs and HTTP)
How to call the BLACKBOX MCP server from your own scripts or agents: through the Anthropic and OpenAI APIs or directly over HTTP.
On this page
You can use the BLACKBOX MCP server (https://api.app.blackbox.md/mcp) not only from apps such as Claude or Cursor, but also from your own scripts and agents. You can let an AI provider's API (Anthropic or OpenAI) connect to the server, or send JSON-RPC requests over HTTP yourself. To check the connection, use MCP Inspector. You create the token on blackbox.md, in “Contul meu” (My account) → “Token-uri API” (API tokens); the page is titled “Token-uri de acces (API)” (Access tokens (API)) and is at blackbox.md/account/api-tokens.
Available to: the blackbox.md account holder who has an API token (bbx_pat_…). What your code can do depends on the token's permissions.
The blackbox.md website is available in Romanian and Russian; this article quotes the Romanian labels with their English meaning.
Connection details
| Parameter | Value |
|---|---|
| Address | https://api.app.blackbox.md/mcp |
| Transport | Streamable HTTP (not the legacy SSE and not stdio) |
| Authentication | the Authorization: Bearer bbx_pat_… header |
| Server name in configurations | blackbox |
| Maximum duration of a request | about 5 minutes |
There is no REST interface for customers: the token works only at /mcp, and the other API addresses reject it. Everything your code can do (servers, SSH keys, balance, orders) goes through the MCP tools: List of MCP tools.
Keep the token in an environment variable, not in your code. The examples below use the BBX_PAT variable. In bash (Linux, macOS, WSL):
export BBX_PAT="bbx_pat_…"In PowerShell:
$env:BBX_PAT = "bbx_pat_…"Important When an AI provider's API calls the tools on its own, no one asks for your confirmation before each call. The exception is OpenAI with
"require_approval": "always". For such scripts, use a read-only token (the three permissions checked by default when you create a token) or restrict the list of tools, as in the examples below. The token and everything the tools return, including passwords, keys and command output, pass through the AI provider. Details: Token permissions (scopes).
Anthropic Messages API (MCP connector)
Anthropic's API connects to the BLACKBOX server by itself and calls the tools on your behalf. In the request, you send two things:
- in
mcp_servers, an entry with"type": "url",url,"name": "blackbox"andauthorization_tokenset to your token; - in
tools, an entry of typemcp_toolsetwith"mcp_server_name": "blackbox".
The feature is in beta and requires the anthropic-beta header. As of October 9, 2026, its value is mcp-client-2025-11-20; check the current value in the Anthropic documentation.
Example in Python (the anthropic SDK), with only three read-only tools enabled:
import os
import anthropic
client = anthropic.Anthropic()
response = client.beta.messages.create(
model="claude-opus-5",
max_tokens=4096,
betas=["mcp-client-2025-11-20"],
mcp_servers=[{
"type": "url",
"url": "https://api.app.blackbox.md/mcp",
"name": "blackbox",
"authorization_token": os.environ["BBX_PAT"],
}],
tools=[{
"type": "mcp_toolset",
"mcp_server_name": "blackbox",
"default_config": {"enabled": False},
"configs": {
"whoami": {"enabled": True},
"list_servers": {"enabled": True},
"get_server": {"enabled": True},
},
}],
messages=[{"role": "user", "content": "Show me my BLACKBOX servers and their status"}],
)
for block in response.content:
if block.type == "text":
print(block.text)"default_config": {"enabled": False}disables all tools, andconfigsenables only the ones it names. Without these two fields, the model gets every tool the token allows.- Besides text, the response contains
mcp_tool_useblocks (which tool the model called and with which parameters) andmcp_tool_resultblocks (what the BLACKBOX server answered). - The model name is only an example; use the model you want.
OpenAI Responses API
In the Responses API, you add the BLACKBOX server as a tool of type mcp, with "server_label": "blackbox", server_url, the token in headers.Authorization and "require_approval": "always", so that each tool call waits for your approval.
import os
from openai import OpenAI
client = OpenAI()
blackbox = {
"type": "mcp",
"server_label": "blackbox",
"server_url": "https://api.app.blackbox.md/mcp",
"headers": {"Authorization": "Bearer " + os.environ["BBX_PAT"]},
"require_approval": "always",
}
response = client.responses.create(
model="gpt-5",
tools=[blackbox],
input="Show me my BLACKBOX servers and their status",
)How to approve a call:
Look in
response.outputfor items of typemcp_approval_request. Each one contains the tool name (name) and the parameters (arguments).Check the call.
Send a new request with
previous_response_id=response.id, the sametoolslist and, ininput, your answer:{"type": "mcp_approval_response", "approve": true, "approval_request_id": "mcpr_…"}To reject the call, send
"approve": false.
With every request, send the tool definition again, together with the Authorization header: OpenAI does not keep it between requests. With allowed_tools (for example ["whoami", "list_servers", "get_server"]), you limit the tools the model sees. Details in the OpenAI documentation.
Directly over HTTP (JSON-RPC)
Without an SDK, send POST requests in JSON-RPC 2.0 format to the same address, with the following headers:
| Header | Value | When |
|---|---|---|
Content-Type |
application/json |
always |
Accept |
application/json, text/event-stream |
always |
Authorization |
Bearer bbx_pat_… |
always |
mcp-session-id |
the ID received from initialize |
after initialize |
MCP-Protocol-Version |
the version from the initialize response, for example 2025-06-18 |
after initialize |
The examples are written for bash (Linux, macOS); on Windows, run them in WSL.
Open the session with
initialize:curl -i https://api.app.blackbox.md/mcp \ -H "Content-Type: application/json" \ -H "Accept: application/json, text/event-stream" \ -H "Authorization: Bearer $BBX_PAT" \ -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"script","version":"1.0"}}}'The response has status 200 and the
mcp-session-idheader. The body comes as an event stream; the JSON-RPC result is on the line that starts withdata::event: message data: {"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2025-06-18","serverInfo":{"name":"blackbox",…},"instructions":"…",…}}The
instructionsfield contains the server's instructions for the AI assistant. If you build your own agent, pass them to the model.Save the session ID (the value of the
mcp-session-idheader) in theMCP_SIDvariable:export MCP_SID="SESSION_ID"Then confirm the initialization:
curl https://api.app.blackbox.md/mcp \ -H "Content-Type: application/json" \ -H "Accept: application/json, text/event-stream" \ -H "Authorization: Bearer $BBX_PAT" \ -H "mcp-session-id: $MCP_SID" \ -H "MCP-Protocol-Version: 2025-06-18" \ -d '{"jsonrpc":"2.0","method":"notifications/initialized"}'The response is
202 Accepted, with no content.With the same headers as in step 3, request the list of tools. It contains only the tools the token allows, plus
whoamiandlist_vm_plans, which require no permissions:{"jsonrpc":"2.0","id":2,"method":"tools/list"}Call a tool with
tools/call:{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"whoami","arguments":{}}}The result is in
result.content, as JSON text. If the tool rejects the call, the HTTP status is still 200, but the result has"isError": true, and the text contains the error code (for examplemissing_scopeorrate_limited).When you are done, you can close the session with a
DELETErequest to the same address, with theAuthorizationandmcp-session-idheaders.
The session stays tied to the account that opened it. Use the same token for the whole session, and write your code so that it can reopen the session with initialize at any time.
| Situation | Server response | What to do |
|---|---|---|
mcp-session-id is missing after initialize |
400 “Bad Request: Missing session ID” | Add the header. |
| The session ID is unknown or no longer valid | 404 (for example “Session not found”) | Open a new session with initialize. |
| The session ID was opened with another account's token | 404 “Session not found” | Each account opens its own session. |
The Accept header does not contain both types |
406 “Not Acceptable: Client must accept both application/json and text/event-stream” | Send application/json, text/event-stream. |
A request with another site's Origin header (for example, from a web page's JavaScript) |
403 “Invalid Origin header”; in the browser you usually see only a CORS error | Call the server from your backend, not from the web page. |
| The token is missing, wrong or revoked | 401, with the reason in error_description |
See MCP limits and error codes. |
Testing with MCP Inspector
MCP Inspector is the official tool for testing MCP servers. It requires Node.js.
Start it:
npx @modelcontextprotocol/inspectorIn the interface that opens in your browser, choose the “Streamable HTTP” transport and enter the address
https://api.app.blackbox.md/mcp.Add the
Authorizationheader with the valueBearer bbx_pat_….Connect, open the tool list and call
whoami. The response shows the account ID, the token's permissions and the permissions it is missing (missing_scopes).
The Inspector also has a command-line mode, useful in scripts and automated checks:
npx @modelcontextprotocol/inspector --cli https://api.app.blackbox.md/mcp \
--transport http \
--header "Authorization: Bearer $BBX_PAT" \
--method tools/listNote AI providers' APIs and MCP Inspector change often. The names of the fields, the beta header and the options in the examples are valid as of October 9, 2026; check them in the official documentation before you use them.
Response times and limits
- A request can take up to about 5 minutes, for example a long command run with
run_server_command(300 seconds at most) or paying for an order withpay_order. In your HTTP client or SDK, set a read timeout slightly above 5 minutes. - If
pay_orderseems to have timed out, check the order withlist_ordersbefore you retry: Orders, payments, cancellations and upgrades via AI. - Start longer jobs on the server in the background (
nohup,systemd-run) and check the result later: Running commands on the server through AI. - Limits apply per account, to all tokens together: 120 tool calls per minute, plus separate limits for some tools. Calls made while you are rate-limited also count, so wait instead of retrying right away. Details: MCP limits and error codes.
Frequently asked questions
Is there a REST API for BLACKBOX?
No. The only programmatic interface for customers is the MCP server. A bbx_pat_… token sent to other API addresses is rejected.
Can I call the MCP server from a website's JavaScript? No. The server rejects requests sent from a browser on other sites (403 “Invalid Origin header”), and the token would be visible to anyone who opens the page. Call the server from your backend.
My script used to work, and now it gets 401. Why? The token was revoked, or you changed your blackbox.md account password, which stops all tokens created before the change. Create a new token: API tokens: creating, copying and revoking.
Does it also work with other SDKs or agent frameworks? Yes, with any MCP client that supports the Streamable HTTP transport and custom headers, for example the official MCP SDKs. Use the address and header from the “Connection details” table.