> ## Documentation Index
> Fetch the complete documentation index at: https://docs.compozy.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Usage

> MCP servers are defined and implemented using the following structure and patterns.

## Structure

MCP servers in Compozy follow a standardized structure that includes server configuration and implementation patterns:

```yaml theme={"dark"}
mcp_servers:
  - id: string # Unique identifier for the MCP server
    use: string | object # Server reference (shorthand or detailed)
    command: string # Command to execute the server
    config: object # Server-specific configuration
    env: object # Server-specific environment variables
```

## Basic Usage

MCP servers can be used in two main ways:

<CodeGroup>
  ```yaml Simple Package theme={"dark"}
  mcp_servers:
    - id: telegram
      use: compozy/mcp-servers:telegram@1.0.0
      command: "npx -y @compozy/mcp-telegram"
  ```

  ```yaml Detailed Package theme={"dark"}
  mcp_servers:
    - id: blockchain_scanner
      use:
        repo: compozy/mcp-servers
        package: blockchain-scanner
        version: 0.2.1
      command: "docker run -i --rm mcp/blockchain-scanner"
  ```
</CodeGroup>

Each server can be configured using the `config` property, environment variables, and execution commands:

```yaml theme={"dark"}
mcp_servers:
  - id: github
    use: compozy/mcp-servers:github
    command: "npx -y @modelcontextprotocol/server-github"
    config:
      token: "{{ env.GITHUB_TOKEN }}"
    env:
      GITHUB_TOKEN: "your-github-token"
```

## Best Practices

<Steps>
  <Step title="Server Configuration" icon="gear">
    Define server settings and credentials using the config schema
  </Step>

  <Step title="File Structure" icon="folder">
    Organize server implementation in separate files with clear configuration
  </Step>

  <Step title="Context Management" icon="brain">
    Implement proper context and memory handling through schema definitions
  </Step>

  <Step title="Memory System" icon="database">
    Use the built-in memory system for state persistence
  </Step>

  <Step title="Task Integration" icon="puzzle">
    Integrate servers with tasks using mcp() function
  </Step>
</Steps>

## Using MCP Servers in Tasks

MCP servers can be used directly in tasks using the `mcp()` function:

```yaml theme={"dark"}
tasks:
  - id: notify_team
    use: mcp(slack)
    with:
      channel: engineering
      message: "{{ workflow.output.alert }}"

  - id: process_support
    use: mcp(zendesk)
    with:
      ticket_id: "{{ trigger.ticket_id }}"
      status: "in_progress"
```

## References

* [MCP Specification](https://modelcontextprotocol.io)
* [Server Implementation Guide](https://modelcontextprotocol.io/quickstart/server)
* [Client Integration Guide](https://modelcontextprotocol.io/quickstart/client)
* [Context Management](https://modelcontextprotocol.io/quickstart/user)
* [Compozy MCP Servers](/core/mcp/servers)
