MCP and bots
Defthand offers an MCP server. AI clients (Claude, ChatGPT, your own agent) call Defthand tools through this server with a person’s permissions. The connection steps for end users are in the AI assistants section; this page is for developers writing their own client or script.
The server
Section titled “The server”| Property | Value |
|---|---|
| Address | https://<api-address>/mcp (the How to connect page in the panel shows it) |
| Transport | Streamable HTTP, stateless: each POST stands alone; there is no Mcp-Session-Id. There is no GET stream (405, Allow: POST). |
| Protocol | JSON-RPC 2.0; initialize, tools/list, tools/call. |
| Request size | The body is at most 2 MB. |
| Response | A single SSE event (event: message, data: {…}) or JSON; send Accept: application/json, text/event-stream. |
Authentication (OAuth 2.1)
Section titled “Authentication (OAuth 2.1)”A request without a token gets 401 and this header:
WWW-Authenticate: Bearer resource_metadata="https://<api-address>/.well-known/oauth-protected-resource/mcp", scope="mcp"From there the client discovers the authorization server and runs the standard OAuth 2.1 flow (authorization code with PKCE):
- Client registration: the client can register itself dynamically or come with a published client ID metadata document (a client ID in the form of an address). No client ID or secret is handed out.
- Scope:
mcp. This scope reaches every tool within the person’s permissions. - Sign-in and consent: the person signs in on Defthand’s own sign-in page with the organization code and their account, and clicks Allow access on the Give your assistant access screen. The person can disconnect at any time from My connected apps; an administrator can switch off access for the organization.
- The token is sent with
Authorization: Bearer <token>. The panel’s own session token is not accepted at/mcp.
If access is refused (switched off for the organization, no permission, no module), 401, 403 or 503 is returned at HTTP level.
tools/listreturns only tools that belong to the organization’s modules and whose permissions the person holds in full. A tool not in the list does not exist fortools/calleither and returns JSON-RPC-32602 Unknown tool(a hidden tool and a missing tool get the same answer).- Each tool has a description, an input schema and an effect: read-only, additive or destructive (
destructiveHint). Clients ask the user before destructive tools. - Full list: The assistant’s tools. For a first try, call
assistant_whoami.
Tool errors
Section titled “Tool errors”Business-rule errors come back not as JSON-RPC errors but as tool errors (an error flag and text in the result, with a code at the end of the text). Common codes:
| Code | Meaning |
|---|---|
Mcp.InvalidArguments |
The arguments do not match the schema; an unknown argument name is also refused. The model fixes it and tries again. |
Mcp.ValidationFailed |
The module’s validation refused it (in the request’s language). |
Mcp.Forbidden |
The person has no permission for this. |
Mcp.Conflict |
The record’s state changed. |
Mcp.RateLimited |
The tool call limit was passed; the text says after how many seconds to try again. |
| Module codes | For example Error.Forms.FormNotFound, Error.AiWorkspace.NodeNotFound, Error.AiWorkspace.UsageLimitReached. |
An unexpected error comes back only as “Internal error (trace …)”.
Limits
Section titled “Limits”A connection’s /mcp requests and tool calls are limited per minute; there is a separate tool call limit across all of a person’s
connections. Refused calls also count toward the limit. The panel’s general rate limit does not apply to /mcp.
Record
Section titled “Record”Every tool call is written to the audit trail: tool name, module, client, connection, result, error code, duration. Arguments, results and tokens are not written.
AI Workspace bots are for scripts that run without a person. A bot key is generated on the AI Workspace → Administration → Bots
screen (see Bots); the key starts with twb_.
1. Swap the key for a token
Section titled “1. Swap the key for a token”POST /oauth/bot-tokenContent-Type: application/json
{ "key": "<bot key>", "expires_in": 60 }expires_in is 60–3600 seconds (default 60). Use the access_token in the response. The token is not refreshed; take a new one when it
expires. Do not put the key in the address bar; the server refuses such a request.
2. Call a tool
Section titled “2. Call a tool”TOKEN=$(jq -n '{key: env.DEFTHAND_BOT_KEY, expires_in: 60}' \ | curl -s -X POST https://<api-address>/oauth/bot-token -H "Content-Type: application/json" --data @- \ | jq -r .access_token)
curl -s -X POST https://<api-address>/mcp \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -H "Accept: application/json, text/event-stream" \ -H "MCP-Protocol-Version: 2025-11-25" \ -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"workspace_insert_rows","arguments":{"tableId":"TABLE_ID","requestId":"gece-raporu-2026-12-03","rows":[{"ekipman":"Forklift","durum":"Açık"}]}}}'The curl example does not put the key on the command line (other users could see it with ps): jq reads the key from the
DEFTHAND_BOT_KEY environment variable and curl takes the body from standard input. If requestId stays the same, a retry after a timeout
does not write the rows twice.
Python:
import os, requests
API = "https://<api-address>"key = os.environ["DEFTHAND_BOT_KEY"]token = requests.post(f"{API}/oauth/bot-token", json={"key": key, "expires_in": 60}, timeout=10).json()["access_token"]
answer = requests.post( f"{API}/mcp", headers={"Authorization": f"Bearer {token}", "Accept": "application/json, text/event-stream", "MCP-Protocol-Version": "2025-11-25"}, json={"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "workspace_insert_rows", "arguments": {"tableId": "TABLE_ID", "requestId": "gece-raporu-2026-12-03", "rows": [{"ekipman": "Forklift", "durum": "Açık"}]}}}, timeout=30,)answer.raise_for_status()print(answer.text)Bot rules
Section titled “Bot rules”- A bot sees only the
workspace_tools, except renaming, retyping and deleting columns. Other modules’ tools andassistant_whoamiare closed to bots. - It sees only what is shared with it or with the whole organization; it deletes and moves only what it created.
- Limits: 60 tool calls a minute per key, 120 a minute per bot; key swaps 10 a minute per key. Keys refused one after another from an address make that address wait for a while (a correct key still gets through).
- A token of a revoked key gets
401on its next request.