Skip to main content
Glama
binhtrongg

Tavily News Search MCP Server

by binhtrongg
README.md
# Building a Remote MCP Server on Cloudflare (Without Auth)

This example allows you to deploy a remote MCP server that doesn't require authentication on Cloudflare Workers. 

## Get started: 

[![Deploy to Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/ai/tree/main/demos/remote-mcp-authless)

This will deploy your MCP server to a URL like: `remote-mcp-server-authless.<your-account>.workers.dev/sse`

Alternatively, you can use the command line below to get the remote MCP Server created on your local machine:
```bash
npm create cloudflare@latest -- my-mcp-server --template=cloudflare/ai/demos/remote-mcp-authless
```

## Customizing your MCP Server

To add your own [tools](https://developers.cloudflare.com/agents/model-context-protocol/tools/) to the MCP server, define each tool inside the `init()` method of `src/index.ts` using `this.server.tool(...)`. 

## Tavily News Search Tool

This MCP server includes a news search tool powered by the [Tavily API](https://tavily.com/). To use it:

1. Sign up for a Tavily API key at [tavily.com](https://tavily.com/)
2. Add your API key to the `wrangler.jsonc` file in the `"vars"` section:
   ```json
   "vars": { "TAVILY_API_KEY": "your-actual-api-key" }
   ```
3. For production, it's recommended to use [Cloudflare Workers Secrets](https://developers.cloudflare.com/workers/configuration/secrets/) instead:
   ```bash
   npx wrangler secret put TAVILY_API_KEY
   ```

### News Search Response Format

The `searchNews` tool returns news results in a structured text format:

```
Here are the top {N} {topic} news results for "{query}" (time range: {timeRange}):

1. {Title}
   {URL}
   {Content snippet}

2. {Title}
   {URL}
   {Content snippet}
...
```

To parse these results into JSON in your client application, you can extract the information from the formatted text response.

## Connect to Cloudflare AI Playground

You can connect to your MCP server from the Cloudflare AI Playground, which is a remote MCP client:

1. Go to https://playground.ai.cloudflare.com/
2. Enter your deployed MCP server URL (`remote-mcp-server-authless.<your-account>.workers.dev/sse`)
3. You can now use your MCP tools directly from the playground!

## Connect Claude Desktop to your MCP server

You can also connect to your remote MCP server from local MCP clients, by using the [mcp-remote proxy](https://www.npmjs.com/package/mcp-remote). 

To connect to your MCP server from Claude Desktop, follow [Anthropic's Quickstart](https://modelcontextprotocol.io/quickstart/user) and within Claude Desktop go to Settings > Developer > Edit Config.

Update with this configuration:

```json
{
  "mcpServers": {
    "calculator": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "http://localhost:8787/sse"  // or remote-mcp-server-authless.your-account.workers.dev/sse
      ]
    }
  }
}
```

Restart Claude and you should see the tools become available. 

## Available Tools

This MCP server includes these tools:

1. **add** - Simple addition of two numbers
2. **calculate** - Calculator with multiple operations (add, subtract, multiply, divide)
3. **searchNews** - Search for news articles on a specific topic using Tavily's API
   - Parameters:
     - `query` (string, required): The news topic to search for
     - `topic` (string, required): The type of news topic ("general", "news", or "finance")
     - `maxResults` (number, optional): Maximum number of news results to return (default: 5)
     - `timeRange` (string, optional): Time range for news results ("year", "month", "week", or "day", default: "day")