Skip to main content

Cloudflare Workers

Give agents tools to call the tools your MCP server exposes in Cloudflare Workers through Mastra Connect. Cloudflare Workers serves these tools from a hosted Model Context Protocol (MCP) server. Your application never stores Cloudflare Workers credentials.

Connect
Direct link to Connect

Before you start, complete the Connect setup to install @mastra/connect and configure your platform project.

note

This provider connects to an MCP server you deploy on Cloudflare Workers, not to the Cloudflare API. When you connect, enter the full URL of your Worker, such as https://my-mcp.my-account.workers.dev/mcp. The Worker must use OAuth, as the Cloudflare guide for remote MCP servers sets up.

Connect an account
Direct link to Connect an account

Run this command from the directory that contains your .env file:

mastra connect add cloudflare-mcp

The CLI guides you through Cloudflare Workers' authorization and waits until the connection is active.

Add tools to an agent
Direct link to Add tools to an agent

Pass tools() to the agent and select the cloudflare-mcp provider:

src/mastra/agents/cloudflare-mcp-agent.ts
import { Agent } from '@mastra/core/agent'
import { tools } from '@mastra/connect'

export const cloudflareMcpAgent = new Agent({
id: 'cloudflare-mcp-agent',
name: 'Cloudflare Workers agent',
instructions: 'You help people call the tools your MCP server exposes in Cloudflare Workers.',
model: 'openai/gpt-6-luna',
tools: tools({ providers: ['cloudflare-mcp'] }),
})

Mastra discovers Cloudflare Workers' tools from its MCP server when the agent runs. The available tools depend on the server and the connected account, not on your @mastra/connect version. Tool keys start with cloudflare-mcp_.

To see which tools Cloudflare Workers provides, read the Build a remote MCP server documentation. To require approval before a call runs, see MCP providers in the tools() reference.

On this page