Skip to content

Commit 3956dc9

Browse files
committed
More details
1 parent 87f5d4c commit 3956dc9

File tree

9 files changed

+123
-43
lines changed

9 files changed

+123
-43
lines changed
199 KB
Loading
118 KB
Loading
68.7 KB
Loading

src/content/docs/agents/model-context-protocol/mcp-server/authorization/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Authorization
33
sidebar:
4-
order: 2
4+
order: 3
55
group:
66
hideIndex: false
77
---

src/content/docs/agents/model-context-protocol/mcp-server/examples/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Examples
33
pcx_content_type: navigation
44
sidebar:
5-
order: 4
5+
order: 6
66
group:
77
hideIndex: true
88
---
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
## Deploy your first MCP server
36+
37+
{/* TODO: Update deploy to Workers button */}
38+
The best way to get started is to deploy an [example MCP server](https://github.com/geelen/mcp-remote-examples/tree/main/02-user-password) to your Cloudflare account. You can then customize this example to suit your needs.
39+
40+
### Option 1: Deploy your MCP server first, then develop locally
41+
42+
{/* TODO: Update link to example */}
43+
The link below will guide you through everything you need to do to deploy an [example MCP server](https://github.com/geelen/mcp-remote-examples/tree/main/02-user-password) to your Cloudflare account:
44+
45+
{/* TODO: Update deploy to Workers button */}
46+
[![Deploy to Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/mcp-server-example)
47+
48+
At the end of this process, you will have a new git repository on your GitHub or GitLab account for your MCP server that is configured to automatically deploy Cloudflare each time you push a change or merge a pull request to the main branch of the repository. You can then clone this repository, [develop locally](/agents/model-context-protocol/mcp-server/getting-started/#local-development), and customize the code to suit your needs.
49+
50+
### Option 2: Create a new MCP Server via the CLI
51+
52+
Alternatively, you can use the command line as shown below to create a new MCP Server on your local machine.
53+
54+
{/* TODO: Update path to example */}
55+
56+
<PackageManagers
57+
type="create"
58+
pkg="cloudflare@latest"
59+
args={"my-mcp-server --template=geelen/mcp-remote-examples/02-user-password"}
60+
/>
61+
62+
Now, you have the MCP server setup, with dependencies installed. Move into that project folder:
63+
64+
```sh
65+
cd my-mcp-server
66+
```
67+
68+
### Local development
69+
70+
In the directory of your new project, run the following command to start the development server:
71+
72+
```sh
73+
npm start
74+
```
75+
76+
Your MCP server is now running on `http://localhost:8787/sse`.
77+
78+
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.
79+
80+
```sh
81+
npx @modelcontextprotocol/inspector@latest
82+
```
83+
84+
Open the MCP inspector in your web browser:
85+
86+
```sh
87+
open http://localhost:5173
88+
```
89+
90+
In the inspector, enter the URL of your MCP server, `http://localhost:8787/sse`, and click **Connect**:
91+
92+
![MCP inspector — where to enter the URL of your MCP server](~/assets/images/agents/mcp-inspector-enter-url.png)
93+
94+
You will be redirected to an example OAuth login page. Enter any username and password and click "Log in and approve" to continue. (you can add your own authentication and/or authorization provider to replace this. Refer to the [authorization](/agents/model-context-protocol/mcp-server/authorization/) section for details on how to do this.)
95+
96+
![MCP OAuth Login Page](~/assets/images/agents/mcp-demo-oauth-flow.png)
97+
98+
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.
99+
100+
![MCP inspector — authenticated](~/assets/images/agents/mcp-inspector-authenticated.png)
101+
102+
### Deploy your MCP server
103+
104+
You can deploy your MCP server to Cloudflare using the following [Wrangler CLI command](/workers/wrangler) within the example project:
105+
106+
```sh
107+
npx wrangler@latest deploy
108+
```
109+
110+
If you have already [connected a git repository](/workers/ci-cd/builds/) to the Worker with your MCP server, you can deploy your MCP server by pushing a change or merging a pull request to the main branch of the repository.
111+
112+
### Next Steps
113+
114+
- Add [tools](/agents/model-context-protocol/mcp-server/tools/) to your MCP server.
115+
- Customize your MCP Server's [authentication and authorization](/agents/model-context-protocol/mcp-server/authorization/).
116+
- Try other [example MCP servers](/agents/model-context-protocol/mcp-server/examples/)

src/content/docs/agents/model-context-protocol/mcp-server/index.mdx

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,5 @@ pcx_content_type: navigation
44
sidebar:
55
order: 1
66
group:
7-
hideIndex: false
7+
hideIndex: true
88
---
9-
10-
import { DirectoryListing } from "~/components";
11-
12-
<DirectoryListing />
13-
14-
[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.
15-
16-
### MCP Terminology
17-
18-
- **MCP Hosts**: AI assistants (like [Claude](http://claude.ai) or [Cursor](http://cursor.com)), AI agents, or applications that need to access external capabilities.
19-
- **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.
20-
- **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.
21-
22-
### Remote MCP
23-
24-
Remote MCP enables AI agents to securely connect to services running anywhere on the Internet. These are the key elements that make Remote MCP possible:
25-
26-
#### Authentication and authorization
27-
28-
When AI interacts with services on a user's behalf, proper security is essential. Authentication confirms the identity of the connecting client, while authorization determines what they can access. Together, these mechanisms ensure AI agents only access specific tools and resources they have permission to use, keeping sensitive data protected.
29-
30-
#### Long lived connections
31-
32-
Remote MCP uses WebSockets and Server-Sent Events (SSE) as transport methods that enable real-time data exchange between clients and servers over long-lived connections, eliminating the need to establish new connections for each interaction.
33-
34-
#### Stateful connections
35-
36-
It's helpful to track state across MCP interactions. This allows your AI to maintain conversation context, remember user preferences, and continue from previous interactions without requiring users to repeat information.
37-
38-
#### Service discovery
39-
40-
MCP directories provide a way to discover available MCP servers. Remote MCP makes use of server metadata exposed on well-known endpoints, allowing MCP servers to become discoverable to clients that may want to use their capabilities.
41-
42-
### An evolving standard
43-
44-
MCP is an actively evolving standard, with ongoing development to expand its capabilities and improve interoperability. The Remote MCP features described above—authentication, state management, transport options, and service discovery—are all in active development by the standards community. You can follow the discussion and development of MCP [here](https://github.com/orgs/modelcontextprotocol/discussions).

src/content/docs/agents/model-context-protocol/mcp-server/tools.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
pcx_content_type: concept
33
title: Tools
44
sidebar:
5-
order: 3
5+
order: 4
66
---
77

88
import { Render } from "~/components";
99

10-
{/* Need to note that you must use Wrangler v4 since this uses decorators */}
11-
1210
Model Context Protocol (MCP) tools are functions that a [MCP Server](/agents/model-context-protocol/mcp-server) provides and MCP clients can call.
1311

1412
When you build MCP Servers with the `@cloudflare/model-context-protocol` package, you can define tools by writing JavaScript or TypeScript methods and decorating them with the `@mcp.tool` [decorator](https://github.com/tc39/proposal-decorators). This removes the need to manually implement the tool discovery, serialization, and invocation logic.
1513

1614
For example, the following code defines a simple MCP server that adds two numbers together:
1715

16+
{/* TODO: Reference code in Github, link to a runnable example, use Deploy to Workers button */}
17+
1818
```ts
1919
import { WorkerEntrypoint, env } from "cloudflare:workers";
2020
import { WorkersMCP, mcp } from "@cloudflare/model-context-protocol";

src/content/docs/agents/model-context-protocol/mcp-server/transport.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pcx_content_type: concept
33
title: Transport
44
sidebar:
5-
order: 4
5+
order: 5
66
---
77

88
import { Render } from "~/components";

0 commit comments

Comments
 (0)