|
| 1 | +--- |
| 2 | +pcx_content_type: concept |
| 3 | +title: Getting Started |
| 4 | +sidebar: |
| 5 | + order: 2 |
| 6 | +--- |
| 7 | + |
| 8 | +import { Details, Render, PackageManagers } from "~/components"; |
| 9 | + |
| 10 | +# Deploy an MCP Server to Cloudflare |
| 11 | + |
| 12 | +You can build and deploy MCP servers on Cloudflare, using the `@cloudflare/model-context-protocol` package, which provides an SDK for [authorization](/agents/model-context-protocol/mcp-server/authorization/), [transport](/agents/model-context-protocol/mcp-server/transport/), and [tool definition and discovery](/agents/model-context-protocol/mcp-server/tools/). |
| 13 | + |
| 14 | +This guide and the accompanying [examples](/agents/model-context-protocol/mcp-server/examples/) will help you get started. |
| 15 | + |
| 16 | +### What is the Model Context Protocol (MCP)? |
| 17 | + |
| 18 | +[Model Context Protocol (MCP)](https://modelcontextprotocol.io) is an open standard that connects AI systems with external applications. Think of MCP like a USB-C port for AI applications. Just as USB-C provides a standardized way to connect your devices to various accessories, MCP provides a standardized way to connect AI agents to different services. |
| 19 | + |
| 20 | +#### MCP Terminology |
| 21 | + |
| 22 | +- **MCP Hosts**: AI assistants (like [Claude](http://claude.ai) or [Cursor](http://cursor.com)), AI agents, or applications that need to access external capabilities. |
| 23 | +- **MCP Clients**: Clients embedded within the MCP hosts that connect to MCP servers and invoke tools. Each MCP client instance has a single connection to an MCP server. |
| 24 | +- **MCP Servers**: Applications that expose [tools](/agents/model-context-protocol/mcp-server/tools/), [prompts](https://modelcontextprotocol.io/docs/concepts/prompts), and [resources](https://modelcontextprotocol.io/docs/concepts/resources) that MCP clients can use. |
| 25 | + |
| 26 | +#### Remote vs. local MCP connections |
| 27 | + |
| 28 | +The MCP standard supports two modes of operation: |
| 29 | + |
| 30 | +- **Remote MCP connections**: MCP clients connect to MCP servers over the Internet, establishing a [long-lived connection using HTTP and Server-Sent Events (SSE)](/agents/model-context-protocol/mcp-server/transport/), and authorizing the MCP client access to resources on the user's account using [OAuth](/agents/model-context-protocol/mcp-server/authorization/). |
| 31 | +- **Local MCP connections**: MCP clients connect to MCP servers on the same machine, using [stdio](https://spec.modelcontextprotocol.io/specification/draft/basic/transports/#stdio) as a local transport method. |
| 32 | + |
| 33 | +Cloudflare's MCP Server SDK, is designed to support remote MCP connections. Remote MCP connections allow MCP clients that run in web browsers, mobile apps, and other environments outside of the end-user's machine to connect to your MCP server, such as [Claude.ai](https://www.anthropic.com/claude), and other AI agents. |
| 34 | + |
| 35 | +## Your first MCP server |
| 36 | + |
| 37 | +The button below will take you to the Cloudflare dashboard, create a new Worker and an associated git repository with code for an MCP server, and deploy the Worker to your Cloudflare account. |
| 38 | + |
| 39 | +{/* TODO: Update deploy to Workers button */} |
| 40 | +[](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/mcp-server-example) |
| 41 | + |
| 42 | +You can also do this using the command line as shown below. |
| 43 | + |
| 44 | +### Get Started — command line with Wrangler CLI |
| 45 | + |
| 46 | +{/* TODO: Update path to example */} |
| 47 | + |
| 48 | +<PackageManagers |
| 49 | + type="create" |
| 50 | + pkg="cloudflare@latest" |
| 51 | + args={"my-mcp-server --template=geelen/mcp-remote-examples/02-user-password"} |
| 52 | +/> |
| 53 | + |
| 54 | +Now, you have a new project set up. Move into that project folder. |
| 55 | + |
| 56 | +```sh |
| 57 | +cd my-mcp-server |
| 58 | +``` |
| 59 | + |
| 60 | +Then, start the development server: |
| 61 | + |
| 62 | +```sh |
| 63 | +npm start |
| 64 | +``` |
| 65 | + |
| 66 | +In a new terminal, run the [MCP inspector](https://github.com/modelcontextprotocol/mcp-inspector). The MCP inspector is an interactive MCP client that allows you to connect to your MCP server and invoke tools from a web browser.. |
| 67 | + |
| 68 | +```sh |
| 69 | +npx @modelcontextprotocol/inspector@latest |
| 70 | +``` |
| 71 | + |
| 72 | +```sh |
| 73 | +open http://localhost:5173 |
| 74 | +``` |
| 75 | + |
| 76 | +In the inspector, enter the URL of your MCP server, and click **Connect**: |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | +You will be redirected to an example OAuth login page. Enter any username and password and click "Log in and approve" to continue. (in the next section, you will add your own authentication and/or authorization provider to replace this) |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | +Once you have logged in, you will be redirected back to the inspector. You should see the "List Tools" button, which will list the tools that your MCP server exposes. |
| 85 | + |
| 86 | + |
0 commit comments