Motivation / problem
Every other connector in AskMyDocs (Google Drive, IMAP, …) does the same thing: download → chunk → embed. That is exactly right for knowledge — policies, runbooks, wikis, mail threads — content that is meaningful to vectorise and ages slowly. It is exactly wrong for transactional, fast-moving data. The status of order#10293, today’s stock for SKU A-1, the live tracking of a shipment —
embedding any of that is pointless: it is stale the moment it is indexed, and the
authoritative copy already lives behind the customer’s API.
The API connector (“Connettore API”) closes that gap. It inverts the
paradigm: instead of pulling data in, it lets the model reach out. Each
configured HTTP endpoint (Rotta) becomes a tool the LLM can call during
the chat turn. So a single question — “is order 10293 shipped, and what does
our returns policy say?” — is answered from two sources at once: RAG over the
indexed returns policy and a live get_orders call to the customer’s ERP.
Scope — Fase 1. This page covers the live-tool path. Fase 2 (bulk ingest
from the same routes, reusing the existing ingestion pipeline) is designed into
the data model via the
mode column but is not implemented yet.Theory & background
A “tool” (a.k.a. function call) is a contract the LLM understands: aname, a
description telling it when to use the tool, and an input_schema (JSON
Schema) describing the arguments. When the model decides a tool is relevant it
emits a tool call with concrete argument values; the host executes it and
feeds the result back; the model then writes the natural-language answer.
The API connector’s job is to turn a plain HTTP endpoint into that contract
without the operator hand-writing JSON Schema. It does so from a single
test call: it performs the request, reads the response, and infers both the
input schema (from the parameters the operator declared) and the output shape
(from the JSON body). The operator reviews and edits; on confirm the route goes
active and its tool is live.
The crucial safety property is the LLM never sees the wiring. It is handed
only {name, description, input_schema} and only ever supplies the values of
the parameters marked llm. The URL, the headers, the fixed params, the secrets
and the auth are all resolved server-side at call time. The model cannot
exfiltrate a key it never receives.
Record identity in response settings
In an endpoint’s Risposta tab, set Campi identificativi to the exact field names that identify each returned record, separated by commas. For example, GESCAT orders useord_codiceweb; ord_ID can also be declared.
Names are case-sensitive and refer to fields on the record itself, rather than
nested customer or shipment fields. Up to twelve fields are supported.
The setting is available for list and detail responses in every endpoint mode
(tool, ingest, and both). It persists across connection tests, automatic
configuration, and connector import/export. Leave it empty to use automatic
identity detection. For API clients, write an array to
config.response.identity_fields or to the flat identity_fields field.
When an endpoint is used as a live tool, grounding matches the requested
identifier against these record fields before validating generated claims.
The setting does not add parameters to the outbound API request.
The two parameter axes
Every route parameter has two independent axes — this is the heart of the model:
Only
source = llm parameters enter the tool schema the model sees. fixed
carry an operator-set constant (e.g. version=v1); secret are pulled from the
encrypted auth profile and are never exposed or logged.
Design
The orchestrator gives the model both capabilities in parallel: retrieval (unchanged) and the API tools (new). The model decides, per question, whether to ground on indexed knowledge, call one or more tools for fresh data, or both. The tool-call → tool-result loop runs up to a bounded number of iterations.Services (all server-side, in padosoft/askmydocs-connector-api)
Host integration
The package cannot inject chat tools by itself — the chat loop (McpToolCallingService) is host code. The host merges
ApiToolRegistry::activeToolsForTenant() into buildToolIndex() alongside the
external MCP tools (the index entry carries an api_route_id instead of a
server) and routes those calls to ApiToolExecutor. This mirrors how
HostIngestionBridge wires the ingest connectors in — the package supplies the
capability, the host wires it. The merge is gated by
connector-api.chat_tools.enabled (safe in both states) and decoupled from
mcp.enabled, so API tools work even with no MCP server configured.
Data model
Five tenant-aware tables (every row carriestenant_id; uniques are
tenant-scoped):
api_routes.project_key is denormalised from its connector (NOT NULL, ''
when unset) so the rule “a tool slug is unique per KB” is enforceable as a DB
unique (tenant_id, project_key, slug) without the NULL-distinct gap.
Decision rationale
See ADR 0023. The load-bearing choices:- A standalone package, not a
ConnectorInterfaceimplementation. That contract is ingest-shaped (syncFull/syncIncremental/OAuth/health) and does not model “endpoint → tool”; forcing it through would distort both. The package reusesconnector-baseonly for the tenant primitives. - One chat loop, two tool sources. Rather than a parallel chat path, the
existing
McpToolCallingServicegained a second source. Less surface, uniform audit and metering. - Anthropic + Gemini joined the tool loop. ADR 0015
had left them SDK-only with no tool path; v8.27 adds a raw-
Http::with-tools branch to each (translating the OpenAI-shaped tools+history to the native Messages /generateContentprotocol and back), so all four hybrid providers can drive API tools — single-metered via the finops bridge.
Worked example — an “orders” tool
-
Connector “Gestionale Cliente X” with
base_url https://api.clientex.comand anapi_keyauth profile (the key encrypted in the vault). -
Route “Ordini”:
GET https://api.clientex.com/v1/orders, parametersorder_id(query, llm, string, optional),status(query, llm, enum),version(query, fixed,v1),api_key(header, secret,secret_ref: api_key). -
Test connessione with
order_id=10293. The response{ "orders": [ { "id": "10293", "status": "shipped", "total": 42 } ] }yields an inferred output schema and a generated tool: -
Activate. In chat, “is order 10293 shipped?” → the model calls
get_orders({order_id:"10293"}); the executor addsversion=v1, injects theapi_keyheader from the vault, checks the URL throughUrlGuard, calls the API, caps the output, logs a sanitised row (no key, noversionsecret), and returns the JSON — the model answers “Order 10293 has shipped.”
Choose the HTTP User-Agent
The connector’s create/edit form includes a User-Agent menu with Chrome, Firefox, Safari, AskMyDocs and a custom value. New connectors start with Chrome. Existing connectors retain their saved header, or HTTP client default (Guzzle) when no User-Agent was configured. Choose a profile and save to change it. The selection is stored as the connector’s sharedUser-Agent header and applies
to connection tests and runtime tool calls. Manage other shared headers in the
separate headers field. Endpoint header parameters and authentication headers can
override shared headers. Export/import preserves the selected User-Agent.
Export and import a complete connector
Use Export API on an API connector card, either in the unified Connectors page or in API Connectors. The downloaded ZIP contains a versionedconnector.json with the connector
settings, authentication profiles, every endpoint and parameter, schemas and tool
definitions, status, operational limits, output transformations, pagination and
list/detail relations. Runtime logs and test response bodies are excluded.
Use Import API and select a JSON configuration or ZIP package (up to 5 MiB). AskMyDocs validates it and shows
the endpoint and relation counts, then asks only for missing credentials. API key
and Bearer profiles ask for their key or token; Basic preserves the username and
asks for the password; OAuth2 preserves the client ID and token endpoint and asks
for the client secret; custom headers and secret route parameters ask for their
omitted values. Public endpoints require no credentials.
Profile credentials are excluded from exports and encrypted again on import. Shared
authentication headers are also omitted and requested again. Imports create a
new connector in the current tenant and restore profile and endpoint references
with new local IDs. Existing names and tool slugs get a numeric suffix when needed.
The entire import succeeds together; missing credentials or invalid references
leave no partial connector behind.
The portable package contract, JSON Schema and external agent handoff explain how to generate importable files directly from endpoint specifications. ZIPs contain only connector.json and optionally README.md; contents are validated without extraction or execution.
Gotchas
- JSON only in Fase 1. A non-JSON / empty response is surfaced as a structured error to the model (and shown as a diagnostic in the test panel), not silently swallowed.
- SSRF guard is on by default and load-bearing. It blocks private / loopback /
link-local targets and the cloud-metadata endpoint, enforces https, and supports
an optional per-tenant domain allowlist (
API_CONNECTOR_DOMAIN_ALLOWLIST). Do not weaken it to reach an internal host — add that host to the allowlist on a network you trust instead. - Provider matters. The tool loop runs on OpenAI, OpenRouter, Anthropic and Gemini. If your chat provider is none of these, API tools won’t fire.
- Tenant + project scope. A route is invocable only within its own tenant, and
only in conversations of its bound
project_key(or globally when unset). A route is never reachable from another tenant’s chat. - Output cap. Large responses are truncated with a note. Use the route’s field
selection (
output_transform) to return only what the model needs.