> For the complete documentation index, see [llms.txt](https://docs.talordata.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.talordata.com/serp-api/integration/mcp-integration/cloudflare-agents-sdk-integration.md).

# Cloudflare Agents SDK Integration

How to integrate Cloudflare's Agents SDK with TalorData's Web MCP server to build AI agents on Cloudflare Workers, featuring over 60 MCP tools.

### Hosted MCP

{% stepper %}
{% step %}

#### Get your API token

* Go to [SERP API-API Token](https://dashboard.talordata.com/scraping/serp-api/api-token/) to create an API token.
* Copy your API Token (format as: `sk_7qBRe***************************`）

{% endstep %}

{% step %}

#### Set up your Cloudflare environment

Please ensure you have Node.js 20 or later installed, then log in to Cloudflare:

```
npx wrangler login
```

{% endstep %}

{% step %}

#### Install the Agents Starter template.

```
npx create-cloudflare@latest mcp-demo --template cloudflare/agents-starter
cd mcp-example
npm install
```

{% endstep %}

{% step %}

#### Configure environment variables

Copy the example <kbd>.env</kbd> file and add your OpenAI API key:

```
cp .dev.vars.example .dev.vars
```

edit  `.dev.vars`：

```
OPENAI_API_KEY=sk-...
```

{% endstep %}

{% step %}

#### Connect TalorData MCP in your agent.

In `src/server.ts`，find the default, commented-out MCP connection `onChatMessage`:

```
// const mcpConnection = await this.mcp.connect(
//   "https://path-to-mcp-server/mcp"
// );
```

Replace it with the TalorData MCP connection:

```
// Connect to TalorData MCP server
const mcpConnection = await this.mcp.connect(
  "https://mcp.talordata.net/API_TOKEN/mcp"
);

// Merge MCP tools with local tools
const allTools = {
  ...tools,
  ...this.mcp.getAITools()
};
```

{% hint style="info" %}
Please ensure that `mcp.connect()` is called before `this.mcp.getAITools()` to avoid an error indicating that `jsonSchema` is uninitialized.
{% endhint %}

{% endstep %}

{% step %}

#### Testing to see if it works.

* Please replace <kbd>\<API\_TOKEN></kbd> with your actual **TalorData API token**.
* Start the development server:

  ```
  npm start
  ```
* Open the application in your browser and ask customer service a question, for example:

```
Find the latest 3 news items about Cloudflare Agents and summarize them in bullets with links.
```

You should be able to see agents using TalorData's web scraping tools to retrieve and aggregate real-time results:

<div align="left"><figure><img src="/files/tFNji4AK6SvKsup0Arku" alt=""><figcaption></figcaption></figure></div>

{% endstep %}

{% step %}

#### Monitor usage

View your API usage in the [TalorData SERP API usage logs](https://dashboard.talordata.com/scraping/serp-api/history).
{% endstep %}
{% endstepper %}
