Skip to content

Conversation

@dinasaur404
Copy link
Contributor

Summary

New page in Agents documentation that explains how to build an MCP server on Workers. It includes setup instructions for creating an MCP server on Workers, example code, configuration instructions for MCP clients, and what's coming soon!

Screenshots (optional)

Screenshot 2025-03-07 at 1 36 17 PM

Documentation checklist

  • [X ] The documentation style guide has been adhered to.
  • If a larger change - such as adding a new page- an issue has been opened in relation to any incorrect or out of date information that this PR fixes.
  • Files which have changed name or location have been allocated redirects.

@github-actions github-actions bot added the product:agents Build and deploy AI-powered Agents on Cloudflare that can act autonomously. label Mar 7, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2025

@github-actions github-actions bot added the size/m label Mar 7, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2025

Howdy and thanks for contributing to our repo. We review internal PRs within 1 week. If it's something urgent or has been sitting without a comment, start a thread in the Developer Docs space internally.

import { MetaInfo, Render, Type, TypeScriptExample, WranglerConfig } from "~/components";
import { Aside } from '@astrojs/starlight/components';

[Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) is an open standard that allows AI assistants & LLMs to interact with services directly. If you want users to access your service or product straight from their AI assistant, you can enable this by spinning up an MCP server for your application.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

their AI assistant

Can we name some to orient people to what we mean?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i think some examples would be useful.

## Building an MCP Server on Cloudflare Workers

Normally, setting up an MCP server requires writing boilerplate code to handle routing, define types, and standing up a server that implements the MCP protocol. But with [Cloudflare Workers](/workers/), all the heavy lifting is done for you, so all you need to do is define your service's functionality as TypeScript methods on your Worker
Once deployed, your Worker becomes an MCP server that AI assistants (as long as they support MCP) can connect to and use to interact with your service.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

support MCP

Think saying "MCP client" helps orient the reader?

Once deployed, your Worker becomes an MCP server that AI assistants (as long as they support MCP) can connect to and use to interact with your service.

<Aside type="caution">
Remote MCP servers are not supported yet. The workers-mcp tooling creates a local proxy that forwards requests to your Worker, allowing the server to be used by an MCP client.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary callout at least as of today given there aren't really remote MCP clients?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO worthwhile otherwise it's confusing what actually happens here

- Shared-secret security using Wrangler Secrets
- Installs a local proxy so you can access it from your MCP desktop clients (like Claude Desktop)

### Set up the MCP Server
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would help to find a way to bring the code way up to the top as a kind of:

  1. MCP =
  2. On Workers, it's simple and TypeScript-native, it looks like this:
  3. Explain the code you just saw (the jsdoc == the tool description (link to MCP spec), the boilerplate is handled (link to workers-mcp library so someone can read source code and understand)

Think faster we can show "here is code" and get someone saying "okay i get it, that is simple" — then after doing the step by step — then we don't bury the example

/Users/username/path/to/my-new-worker/node_modules/.bin/workers-mcp run my-new-worker https://my-new-worker.username.workers.dev /Users/username/path/to/my-new-worker
```

#### Other MCP clients
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { MetaInfo, Render, Type, TypeScriptExample, WranglerConfig } from "~/components";
import { Aside } from '@astrojs/starlight/components';

[Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) is an open standard that allows AI assistants & LLMs to interact with services directly. If you want users to access your service or product straight from their AI assistant, you can enable this by spinning up an MCP server for your application.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

substitute assitants with agents?

import { MetaInfo, Render, Type, TypeScriptExample, WranglerConfig } from "~/components";
import { Aside } from '@astrojs/starlight/components';

[Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) is an open standard that allows AI assistants & LLMs to interact with services directly. If you want users to access your service or product straight from their AI assistant, you can enable this by spinning up an MCP server for your application.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i think some examples would be useful.


## Building an MCP Server on Cloudflare Workers

Normally, setting up an MCP server requires writing boilerplate code to handle routing, define types, and standing up a server that implements the MCP protocol. But with [Cloudflare Workers](/workers/), all the heavy lifting is done for you, so all you need to do is define your service's functionality as TypeScript methods on your Worker
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't start here.

I would start with "In this guide, we will show you how to XYZ"

* @return {string} The greeting message.
*/
sayHello(name: string) {
return `Hello from an MCP Worker, ${name}!`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be really good to have some other step that allows you to call an API. even like the weather one that's in the MCP docs. but really showing what this allows you to do which is integrate with stuff

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this is worthwhile


In this guide, you will learn how to build and deploy a Model Context Protocol (MCP) server on Cloudflare Workers.

[Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) is an open standard that allows AI agents and assistants (like [Claude Desktop](https://claude.ai/download), [Cursor](https://www.cursor.com/), or [Anthropic's Claude](https://www.anthropic.com/claude)) to interact with services directly. If you want users to access your service through an AI agent, you can spin up an MCP server for your application.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this page could be helpful link: https://modelcontextprotocol.io/clients

**How it works:**
* **TypeScript methods as MCP tools:** Each public method in your class is exposed as an MCP tool that agents can call. In this example, getWeather is the tool that fetches data from an external weather API.
* **Automatic tool documentation:** JSDoc comments define the tool description, parameters, and return values, so Claude knows exactly how to call your method and interpret the response.
* **Build-in MCP compatibility:** The `ProxyToSelf` class handles all MCP protocol requirements
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite true and I think might misleads people — ProxyToSelf translates incoming requests into relevant JS RPC methods, but the actual handling of the MCP protocol, tool discovery, happens totally outside of the Worker, in the Node.js local proxy layer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @return {string} The greeting message.
*/
sayHello(name: string) {
return `Hello from an MCP Worker, ${name}!`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this is worthwhile



### Deploy the MCP server
Update your wrangler.toml with the appropriate configuration then deploy your Worker:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there's anything you actually need in your wrangler.toml can you include it here and have wrangler.jsonc and wrangler.toml such as here:
https://developers.cloudflare.com/workers/static-assets/binding/

@hyperlint-ai
Copy link
Contributor

hyperlint-ai bot commented Mar 10, 2025

PR Change Summary

Added a new documentation page for building an MCP server on Cloudflare Workers, providing comprehensive setup instructions and example code.

  • Introduced a tutorial on building an MCP server using Cloudflare Workers.
  • Included setup instructions and example code for creating an MCP server.
  • Outlined configuration steps for MCP clients and future enhancements.

Added Files

  • src/content/docs/agents/examples/build-mcp-server.mdx

How can I customize these reviews?

Check out the Hyperlint AI Reviewer docs for more information on how to customize the review.

If you just want to ignore it on this PR, you can add the hyperlint-ignore label to the PR. Future changes won't trigger a Hyperlint review.

What is Hyperlint?

Hyperlint is an AI agent that helps you write, edit, and maintain your documentation.

Learn more about the Hyperlint AI reviewer and the checks that we can run on your documentation.

@dinasaur404 dinasaur404 merged commit 4286f49 into production Mar 10, 2025
11 checks passed
@dinasaur404 dinasaur404 deleted the add-mcp-docs branch March 10, 2025 20:18
RebeccaTamachiro pushed a commit that referenced this pull request Apr 21, 2025
Add MCP server documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:agents Build and deploy AI-powered Agents on Cloudflare that can act autonomously. size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants