Metadata-Version: 2.4
Name: twenty-mcp
Version: 2.3.0
Summary: Twenty CRM REST/GraphQL MCP Server for Agentic AI!
Author-email: Project Maintainers <maintainers@users.noreply.github.com>
License: MIT
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Environment :: Console
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Requires-Python: <3.15,>=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: agent-connector-sdk[mcp]<1.0.0,>=0.3.0
Requires-Dist: gql[requests]>=4.4.0
Requires-Dist: requests>=2.34.2
Provides-Extra: mcp
Requires-Dist: agent-connector-sdk[mcp]<1.0.0,>=0.3.0; extra == "mcp"
Provides-Extra: gql
Requires-Dist: gql[requests]>=4.4.0; extra == "gql"
Provides-Extra: all
Requires-Dist: agent-connector-sdk[mcp]<1.0.0,>=0.3.0; extra == "all"
Requires-Dist: gql[requests]>=4.4.0; extra == "all"
Provides-Extra: test
Requires-Dist: pytest-xdist>=3.8.0; extra == "test"
Requires-Dist: pytest>=9.1.1; extra == "test"
Requires-Dist: pytest-asyncio>=1.4.0; extra == "test"
Requires-Dist: pytest-cov>=7.1.0; extra == "test"
Dynamic: license-file

# Twenty MCP

[![Status](https://img.shields.io/badge/status-active-success)](https://github.com/genius-agents/twenty-mcp)
[![Version](https://img.shields.io/badge/version-2.3.0-blue)](pyproject.toml)
[![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)

> **Documentation** — Installation, deployment, usage across the MCP, API, and agent
> interfaces, and guidance for provisioning the Twenty CRM platform are maintained in
> the [official documentation](https://knuckles-team.github.io/twenty-mcp/).

Twenty CRM Customer Relationship Management system orchestrator. Built with the highest architectural standards, incorporating dynamic facades, custom API routing, and FastMCP tool decoration.

## Table of Contents
- [Overview](#overview)
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Configuration](#configuration)
- [MCP Tools](#mcp-tools)
- [Architecture](#architecture)
- [Deployment](#deployment)
- [Contributing](#contributing)
- [License](#license)

---

## Overview

Twenty MCP provides a high-performance, model-optimized interface to Twenty capabilities. It isolates the model from underlying API transport complexity, ensuring safe, idempotent, and highly traceable system interactions.

---

## Features

- **Dynamic Facade Orchestration**: Integrates multi-inheritance clients cleanly under a single facade.
- **Battle-Tested Resilience**: Out-of-the-box credential authentication, connection polling, and request retry strategies.
- **FastMCP Declarative Tools**: Fast, native schema registration with full inline validation.
- **Complete Test Intent Diversity**: Deep, automated unit, integration, and mock tests ensuring high code coverage.

---

## ⚙️ Dynamic Tool Selection & Visibility

This MCP server supports dynamic toolset selection and visibility filtering at runtime. This allows the operator to restrict the set of exposed tools to prevent blowing up the LLM's context window.

The operator can configure tool filtering via multiple input channels:

- **CLI Arguments:** Pass `--tools` or `--toolsets` (or their disabled counterparts `--disabled-tools` and `--disabled-toolsets`) during startup.
- **Environment Variables:** Define standard environment variables:
  - `MCP_ENABLED_TOOLS` / `MCP_DISABLED_TOOLS`
  - `MCP_ENABLED_TAGS` / `MCP_DISABLED_TAGS`
- **HTTP SSE Request Headers:** Pass custom headers during transport initialization:
  - `x-mcp-enabled-tools` / `x-mcp-disabled-tools`
  - `x-mcp-enabled-tags` / `x-mcp-disabled-tags`
- **HTTP SSE Request Query Parameters:** Append query parameters directly to the operator's transport connection URL:
  - `?tools=tool1,tool2`
  - `?tags=tag1`

When query strings or parameters are provided, an LLM-free **Knowledge Graph resolution layer** (using `DynamicToolOrchestrator`) matches query intents against known tool tags, names, or descriptions, with safe fallback and automated 24-hour background cache refreshing.


---

## Installation

> **Install the connector-focused `[mcp]` extra.** Examples use `twenty-mcp[mcp]` to add
> FastMCP / FastAPI through `agent-connector-sdk`; the required Agent Connector SDK core
> enables model orchestration.

Pick the extra that matches what the operator want to run:

| Extra | Installs | Use when |
|-------|----------|----------|
| `twenty-mcp[mcp]` | Connector-focused MCP server (`agent-connector-sdk` — FastMCP/FastAPI + `epistemic-graph[full]`) | The operator only run the **MCP server** (smallest install / image) |
| `twenty-mcp[all]` | Everything (`mcp` + `agent` + `logfire` + `gql`) | Development / both surfaces |

```bash
# Connector-focused MCP server (includes the shared graph engine)
uv pip install "twenty-mcp[mcp]"

# Agent runtime (adds model orchestration to the shared graph engine)

# Everything (development)
uv pip install "twenty-mcp[all]"      # or: python -m pip install "twenty-mcp[all]"
```

### Container images (`:mcp`)

One multi-stage `docker/Dockerfile` builds the MCP-only image (`--target mcp`):

| Image tag | Build target | Contents | Entrypoint |
|-----------|--------------|----------|------------|
| `example/twenty-mcp:mcp` | `--target mcp` | `twenty-mcp[mcp]` — **connector-focused**, includes `epistemic-graph[full]`; no model-orchestration stack | `twenty-mcp` |

```bash
docker build --target mcp   -t example/twenty-mcp:mcp    docker/   # connector-focused MCP server
```

### Knowledge-graph database (`epistemic-graph`)

Agent Connector SDK core dependency (`epistemic-graph[full]`). The `[mcp]` extra keeps
deployments can use the bundled engine. For production or shared state, run
**epistemic-graph as a dedicated database service** and configure the runtime to use it.
Deployment recipes (single-node + Raft HA), connection configuration, and architecture
diagrams are documented in the
[epistemic-graph deployment guide](https://knuckles-team.github.io/epistemic-graph/deployment/).

---

## Usage

The operator can start the FastMCP server in stdio mode via Python module execution:

```python
import asyncio
from twenty_mcp.mcp_server import get_mcp_instance


async def main():
    mcp = get_mcp_instance()
    # Execute stdio loop or launch server
    print("MCP Server ready.")


if __name__ == "__main__":
    asyncio.run(main())
```

For direct shell start, run:

```bash
python -m twenty_mcp.mcp_server
```

---

## Configuration

The package is fully configurable via the environment variables listed below. A local
template is provided inside [.env.example](.env.example) — copy it to `.env` and fill in
the operator's service endpoint parameters before starting execution.

### Connection & credentials
| Variable | Description | Default |
|----------|-------------|---------|
| `TWENTY_URL` | Twenty CRM Base Server URL | `http://localhost:3000` |
| `TWENTY_TOKEN` | Developer authentication token | — |
| `TWENTY_MCP_BASE_URL` | Base API URL to query | `http://localhost:3000/api` |
| `TWENTY_API_PREFIX` | Twenty API custom path prefix | `http://localhost:3000/api/v1` |
| `TWENTY_MCP_USERNAME` | Auth username for service | `admin` |
| `TWENTY_MCP_PASSWORD` | Auth password for service | — |
| `TWENTY_TLS_PROFILE` | Named outbound TLS policy from AgentConfig | `system` |

### MCP server / transport
| Variable | Description | Default |
|----------|-------------|---------|
| `TRANSPORT` | `stdio`, `streamable-http`, or `sse` | `stdio` |
| `HOST` | Bind host (HTTP transports) | `0.0.0.0` |
| `PORT` | Bind port (HTTP transports) | `8000` |
| `MCP_TOOL_MODE` | Tool surface: `condensed`, `verbose`, or `both` | `condensed` |
| `MCP_ENABLED_TOOLS` / `MCP_DISABLED_TOOLS` | Comma-separated tool allow/deny list | — |
| `MCP_ENABLED_TAGS` / `MCP_DISABLED_TAGS` | Comma-separated tag allow/deny list | — |

### Tool toggles
Each action-routed tool can be disabled individually via its toggle env var (set to `false`).
The full list is in the [MCP Tools](#mcp-tools) table below
(`CRMTOOL`, `METADATATOOL`, `OAUTHTOOL`, `GRAPHQLTOOL`).

### Agent runtime (full `[agent]` runtime only)
| Variable | Description | Default |
|----------|-------------|---------|
| `MCP_URL` | URL of the MCP server the agent connects to | `http://localhost:8000/mcp` |
| `PROVIDER` | LLM provider (e.g. `openai`) | `openai` |
| `MODEL_ID` | Model id (e.g. `gpt-4o`) | `gpt-4o` |

---

## MCP Tools

_Auto-generated from the live MCP server — do not edit by hand._

<!-- MCP-TOOLS-TABLE:START -->

#### Condensed action-routed tools (default — `MCP_TOOL_MODE=condensed`)

| MCP Tool | Toggle Env Var | Description |
|----------|----------------|-------------|
| `twenty_discover_graphql_schema` | `GRAPHQLTOOL` | Discover Twenty's underlying object/field/relation metadata (meta-model). |
| `twenty_graphql` | `GRAPHQLTOOL` | Execute raw GraphQL queries and mutations natively on Twenty. |
| `twenty_mcp_crm` | `CRMTOOL` | Manage Twenty MCP crm operations. |
| `twenty_mcp_metadata` | `METADATATOOL` | Manage Twenty MCP metadata schema operations. |
| `twenty_mcp_oauth` | `OAUTHTOOL` | Manage Twenty MCP OAuth and Webhooks operations. |
| `twenty_provision_api_key` | `GRAPHQLTOOL` | Programmatically provision a long-lived Twenty API key from user credentials (login->token->createApiKey->generateApiKeyToken on /metadata). Day-0 provisioning primitive. |

#### Verbose 1:1 API-mapped tools (`MCP_TOOL_MODE=verbose` or `both`)

<details>
<summary>49 per-operation tools — one per public API method (click to expand)</summary>

| MCP Tool | Toggle Env Var | Description |
|----------|----------------|-------------|
| `twenty_batch_create_records` | `CRM_APITOOL` | Batch create up to 60 records for any object. |
| `twenty_batch_delete_records` | `CRM_APITOOL` | Batch delete up to 60 records by ID for any object. |
| `twenty_batch_update_records` | `CRM_APITOOL` | Batch update up to 60 records for any object. |
| `twenty_client_credentials_oauth_token` | `OAUTH_APITOOL` | Perform a server-to-server client credentials flow to get a workspace-scoped token. |
| `twenty_create_company` | `CRM_APITOOL` | Create a company in CRM. |
| `twenty_create_metadata_field` | `METADATA_APITOOL` | Create a custom field on a standard or custom object. |
| `twenty_create_metadata_object` | `METADATA_APITOOL` | Create a new custom object schema (e.g. Invoice). |
| `twenty_create_metadata_relation` | `METADATA_APITOOL` | Create a bidirectional relation between objects. |
| `twenty_create_opportunity` | `CRM_APITOOL` | Create opportunity. |
| `twenty_create_person` | `CRM_APITOOL` | Create a person in CRM. |
| `twenty_create_record` | `CRM_APITOOL` | Create a new record for any custom or built-in object. |
| `twenty_delete_company` | `CRM_APITOOL` | Delete a company by ID. |
| `twenty_delete_metadata_field` | `METADATA_APITOOL` | Delete a custom field from an object schema. |
| `twenty_delete_metadata_object` | `METADATA_APITOOL` | Delete a custom object schema. |
| `twenty_delete_metadata_relation` | `METADATA_APITOOL` | Delete an existing relation by relation ID. |
| `twenty_delete_opportunity` | `CRM_APITOOL` | Delete an opportunity by ID. |
| `twenty_delete_person` | `CRM_APITOOL` | Delete a contact by ID. |
| `twenty_delete_record` | `CRM_APITOOL` | Delete a record by ID for any custom or built-in object. |
| `twenty_exchange_oauth_token` | `OAUTH_APITOOL` | Exchange an authorization code for access and refresh tokens. |
| `twenty_execute_gql` | `CRM_APITOOL` | Execute arbitrary GraphQL queries on core and custom schemas. |
| `twenty_find_duplicates` | `CRM_APITOOL` | Find duplicate records for an object by data payload or record IDs. |
| `twenty_find_records` | `CRM_APITOOL` | Ergonomic record search wrapper mapping to Twenty REST query params. |
| `twenty_get_companies` | `CRM_APITOOL` | Get CRM companies. |
| `twenty_get_company` | `CRM_APITOOL` | Get a specific company by ID. |
| `twenty_get_metadata` | `METADATA_APITOOL` | Fetch complete workspace metadata schema. |
| `twenty_get_metadata_field` | `METADATA_APITOOL` | Fetch a specific field schema by ID. |
| `twenty_get_metadata_fields` | `METADATA_APITOOL` | Fetch all field schemas. |
| `twenty_get_metadata_object` | `METADATA_APITOOL` | Fetch a specific object schema by name or ID. |
| `twenty_get_metadata_objects` | `METADATA_APITOOL` | Fetch all object schemas. |
| `twenty_get_metadata_relation` | `METADATA_APITOOL` | Fetch a specific relation schema by ID. |
| `twenty_get_metadata_relations` | `METADATA_APITOOL` | Fetch all relation schemas. |
| `twenty_get_oauth_discovery` | `OAUTH_APITOOL` | Fetch the standard OAuth configuration server discovery metadata. |
| `twenty_get_opportunities` | `CRM_APITOOL` | Get opportunities. |
| `twenty_get_opportunity` | `CRM_APITOOL` | Get a specific opportunity by ID. |
| `twenty_get_people` | `CRM_APITOOL` | Get CRM contacts. |
| `twenty_get_person` | `CRM_APITOOL` | Get a specific contact by ID. |
| `twenty_get_record` | `CRM_APITOOL` | Fetch a specific record by ID for any custom or built-in object. |
| `twenty_get_records` | `CRM_APITOOL` | Fetch a list of records for any custom or built-in object. |
| `twenty_refresh_oauth_token` | `OAUTH_APITOOL` | Refresh an expired access token using a refresh token. |
| `twenty_register_oauth_client` | `OAUTH_APITOOL` | Register a new OAuth client dynamically per RFC 7591. |
| `twenty_request_metadata` | `METADATA_APITOOL` | Internal helper for Routing Metadata requests under /rest/metadata or /metadata. |
| `twenty_update_company` | `CRM_APITOOL` | Update a company's fields by ID. |
| `twenty_update_metadata_field` | `METADATA_APITOOL` | Update an existing field's metadata configuration. |
| `twenty_update_metadata_object` | `METADATA_APITOOL` | Update a custom object schema. |
| `twenty_update_metadata_relation` | `METADATA_APITOOL` | Update an existing relation by relation ID. |
| `twenty_update_opportunity` | `CRM_APITOOL` | Update an opportunity's fields by ID. |
| `twenty_update_person` | `CRM_APITOOL` | Update a contact's fields. |
| `twenty_update_record` | `CRM_APITOOL` | Update an existing record by ID for any custom or built-in object. |
| `twenty_validate_webhook_signature` | `OAUTH_APITOOL` | Validate an incoming webhook signature using HMAC SHA256 (timing safe). |

</details>

_6 action-routed tool(s) (default) · 49 verbose 1:1 tool(s). Each is enabled unless its `<DOMAIN>TOOL` toggle is set false; `MCP_TOOL_MODE` selects the surface (`condensed` default · `verbose` 1:1 · `both`). Auto-generated — do not edit._
<!-- MCP-TOOLS-TABLE:END -->

See [docs/overview.md](docs/overview.md) or [docs/concepts.md](docs/concepts.md) for deeper operational examples.

---

## Architecture

This package uses the standardized Agent-Utilities dynamic facade architecture:

```mermaid
graph TD
    User([User Agent]) --> Server[FastMCP Server]
    Server --> Facade[Api Dynamic Facade]
    Facade --> ClientBase[ApiClientBase]
    Facade --> Auth[Credentials Auth Handler]
    ClientBase --> Service([External Service API])
```

---

## Deployment

### Bare-Metal (Standard pip)
1. Set up the operator's Python virtual environment (>= 3.10).
2. Install the package: `pip install .[all]`
3. Export credentials:
   ```bash
   export TWENTY_URL="http://localhost:3000"
   ```
4. Run: `python -m twenty_mcp.mcp_server`

### Container (Docker Compose)
A standard compose structure is provided inside the `docker/` folder. Build and deploy:

```bash
docker compose -f docker/compose.yml up --build -d
```

---

<!-- BEGIN GENERATED: additional-deployment-options -->
### Additional Deployment Options

`twenty-mcp` can run as a local stdio process or container, or behind a remote
network boundary. The
[Deployment guide](https://knuckles-team.github.io/twenty-mcp/deployment/) carries
the detailed transport contract.

- **Local container** — launch a reviewed immutable image as a least-privilege
  stdio child with no listener or published port.
- **Remote URL** — connect through an operator-supplied authenticated HTTPS
  ingress. Keep its URL, outbound identity references, trust profile, and exact
  `MCP_ALLOWED_HOSTS` in `AgentConfig`.
<!-- END GENERATED: additional-deployment-options -->

## Documentation

The complete documentation is published as the
[official documentation site](https://knuckles-team.github.io/twenty-mcp/) and is the
recommended reference for installation, deployment, and day-to-day operation.

| Page | Contents |
|---|---|
| [Installation](https://knuckles-team.github.io/twenty-mcp/installation/) | pip, source, extras, prebuilt Docker image |
| [Deployment](https://knuckles-team.github.io/twenty-mcp/deployment/) | run the MCP and agent servers, Compose, Caddy + Technitium, env config |
| [Usage](https://knuckles-team.github.io/twenty-mcp/usage/) | the MCP tools, the `Api` client, the A2A agent |
| [Backing Platform](https://knuckles-team.github.io/twenty-mcp/platform/) | deploy Twenty CRM with Docker |
| [Overview](https://knuckles-team.github.io/twenty-mcp/overview/) | the dynamic facade architecture |
| [Concepts](https://knuckles-team.github.io/twenty-mcp/concepts/) | concept registry (`CONCEPT:TWENTY-*`) |

---

## Contributing

Please audit all code changes against the repository's contribution and review requirements, and run:

```bash
pre-commit run --all-files
```

---

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for complete details.



## Environment Variables

<!-- ENV-VARS-TABLE:START -->

#### Package environment variables

| Variable | Example | Description |
|----------|---------|-------------|
| `TWENTY_URL` | `http://localhost:3000` | Twenty CRM Base Server URL |
| `TWENTY_TOKEN` | secret-injected | Developer authentication token |
| `TWENTY_MCP_BASE_URL` | `http://localhost:3000/api` | Base API URL to query |
| `TWENTY_MCP_USERNAME` | `admin` | Auth username for service |
| `TWENTY_MCP_PASSWORD` | secret-injected | Auth password for service |
| `TWENTY_TLS_PROFILE` | — | SSL verification flag |
| `TWENTY_TLS_PROFILE_REF` | — |  |
| `CRMTOOL` | `True` | CRM Tool Enabled Flag |
| `METADATATOOL` | `True` | Metadata Tool Enabled Flag |
| `OAUTHTOOL` | `True` | OAuth Tool Enabled Flag |
| `GRAPHQLTOOL` | `True` | GraphQL Tool Enabled Flag |
| `TWENTY_API_PREFIX` | `http://localhost:3000/api/v1` | Twenty API custom path prefix (if needed) |

#### Inherited agent-connector-sdk variables (apply to every connector)

| Variable | Example | Description |
|----------|---------|-------------|
| `TRANSPORT` | `stdio` | MCP transport: `stdio` \| `streamable-http` \| `sse` |
| `HOST` | `127.0.0.1` | Loopback bind host (set an authenticated ingress explicitly) |
| `PORT` | `8000` | Bind port (HTTP transports) |
| `MCP_TOOL_MODE` | `intent` | Tool surface: `intent` \| `condensed` \| `verbose` \| `both` |
| `MCP_ENABLED_TOOLS` | — | Comma-separated tool allow-list |
| `MCP_DISABLED_TOOLS` | — | Comma-separated tool deny-list |
| `MCP_ENABLED_TAGS` | — | Comma-separated tag allow-list |
| `MCP_DISABLED_TAGS` | — | Comma-separated tag deny-list |
| `EUNOMIA_TYPE` | `none` | Authorization mode: `none` \| `embedded` \| `remote` |
| `EUNOMIA_POLICY_FILE` | `mcp_policies.json` | Embedded Eunomia policy file |
| `EUNOMIA_REMOTE_URL` | — | Remote Eunomia authorization server URL |
| `ENABLE_OTEL` | `False` | Enable OpenTelemetry export |
| `OTEL_EXPORTER_OTLP_ENDPOINT` | — | OTLP collector endpoint |
| `MCP_CLIENT_AUTH` | — | Outbound MCP child auth: `oidc-client-credentials` \| `basic` \| `none` |
| `OIDC_CLIENT_ID` | — | OIDC client id (service-account auth) |
| `OIDC_CLIENT_SECRET_REF` | `secret://identity/oidc-client-secret` | Runtime secret reference for the OIDC service account |
| `MCP_BASIC_AUTH_USERNAME` | — | HTTP Basic username (`MCP_CLIENT_AUTH=basic`) |
| `MCP_BASIC_AUTH_PASSWORD_REF` | `secret://identity/mcp-basic-password` | Runtime secret reference for HTTP Basic auth (`MCP_CLIENT_AUTH=basic`) |
| `DEBUG` | `False` | Verbose logging |
| `PYTHONUNBUFFERED` | `1` | Unbuffered stdout (recommended in containers) |
| `MCP_URL` | `http://localhost:8000/mcp` | URL of the MCP server the agent connects to |
| `PROVIDER` | `openai` | LLM provider for the agent |
| `MODEL_ID` | `gpt-4o` | Model id for the agent |
| `ENABLE_WEB_UI` | `True` | Serve the AG-UI web interface |

_12 package + 24 inherited variable(s). Auto-generated from `.env.example` + the shared agent-connector-sdk set — do not edit._
<!-- ENV-VARS-TABLE:END -->

<!-- GOVERNED-CAPABILITY:START -->
## Governed capability contract

This package ships a compact canonical skill surface with specialist procedures
kept as referenced workflows. The current MCP tools, skill metadata,
`connector_manifest.yml`, ontology, mappings, shapes, fixtures, migrations,
tool-schema fingerprints, and certification metadata form one versioned
capability contract. Validate them together; do not rely on stale tool names or
historical per-task skill wrappers.

Runtime endpoints, credentials, certificate trust, tenant identity, retention,
and observability policy are deployment inputs and are never packaged values.
See [Configuration, trust, and privacy](docs/configuration.md) before enabling a
network transport, connector ingestion, Arbora delegation, or trace export.
<!-- GOVERNED-CAPABILITY:END -->
