Skip to content

Architecture

ToolMesh is a Go middleware that orchestrates, authorizes, and secures the execution of tool calls between AI agents and backend infrastructure.

Every tool call passes through a fail-closed pipeline:

Agent ──▶ MCP Server ──▶ Auth ──▶ Executor
│ │
│ ├─▶ OpenFGA: Check(user, can_execute, tool)
OAuth 2.1/PKCE │ └─ denied → Error: unauthorized
API Key │
Password ├─▶ CredentialStore: Get(credential, tenant)
│ │
▼ ├─▶ Gate pre: Evaluate(input)
UserContext │
(user, plan, ├─▶ Backend: Execute(tool, params)
roles, │ ├─ MCP Client → external MCP server
callerID) │ └─ REST Proxy → HTTP call via DADL
├─▶ Gate post: Evaluate(output)
└─▶ Audit: Record(entry)

If any step rejects (AuthZ, Gate), the entire execution stops. No partial results leak through.

PillarImplementationBacked by
Any BackendMCP servers (HTTP/STDIO) + REST APIs via DADLGo MCP SDK + DADL parser
Code Modelist_tools + execute_code — LLMs write JS instead of JSONAST-parsed tool calls
AuditEvery tool call logged structurallyslog (write-only) or SQLite (queryable)
AuthorizationUser → Plan → Tool relationshipsOpenFGA
Credential StoreSecrets injected at runtime, never in promptsEnv vars (CREDENTIAL_*), extensible
Output GateJS policies validate input/outputgoja (Go JS engine)

Three components are extensible via a registry pattern (inspired by Go’s database/sql drivers):

ComponentRegistry FunctionBuilt-inConfig
Credential Storecredentials.Register()embedded (env vars)CREDENTIAL_STORE=<name>
Tool Backendbackend.Register()mcp, rest (DADL), echoconfig/backends.yaml
Gate Evaluatorgate.RegisterEvaluator()goja (JavaScript)GATE_EVALUATORS=<list>

Extensions register via init() functions. Enterprise extensions live in a separate module and are included via Go build tags:

Terminal window
go build -tags enterprise ./cmd/toolmesh
ComponentExtensionDescription
Credential StoreInfisicalStoreInfisical Secrets Manager integration
Credential StoreVaultStoreHashiCorp Vault / OpenBao integration
Gate EvaluatorCompliance-LLMLLM-based content classification
Audit StoreTemporalDurable audit for failure-prone backends
toolmesh/
├── cmd/
│ ├── toolmesh/ # Main entrypoint (MCP server)
│ └── tm-bootstrap/ # CLI: load OpenFGA model, write example tuples
├── internal/
│ ├── mcp/ # MCP server (Streamable HTTP + STDIO)
│ ├── backend/ # ToolBackend interface + MCPAdapter + RESTAdapter
│ ├── executor/ # ExecuteTool pipeline (AuthZ → Creds → Gate → Exec → Audit)
│ ├── audit/ # Audit store interface + log/sqlite implementations
│ ├── authz/ # OpenFGA authorization
│ ├── credentials/ # Credential store interface + EmbeddedStore
│ ├── gate/ # Output gate (goja policy engine)
│ ├── userctx/ # UserContext propagation
│ └── config/ # Environment-based configuration
├── config/ # Backend config (backends.yaml, users.yaml, apikeys.yaml)
├── tools/ # TypeScript tool definitions (canonical source)
├── policies/ # JavaScript gate policies
└── docs/ # Documentation