Skip to content

Commit f3c8bb2

Browse files
committed
feat: add pingfederate remote mcp server
1 parent 65ba88f commit f3c8bb2

38 files changed

Lines changed: 6038 additions & 0 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.vscode/
2+
**/node_modules
3+
**/dist
4+
**/build
5+
**/lib
6+
**/coverage
7+
**/*.tsbuildinfo
8+
.wrangler
9+
worker-configuration.d.ts
10+
.dev.vars
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Model Context Protocol (MCP) Server + PingFederate
2+
3+
This is a [Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) server that supports remote MCP connections, with PingFederate built in.
4+
5+
Powered by [Cloudflare Workers](https://developers.cloudflare.com/workers/), the MCP server functions as a resource server within the OAuth architecture. It validates incoming requests and facilitate token exchange, ensuring secure communication between the MCP client and downstream APIs.
6+
7+
> [!WARNING]
8+
> This is a demo template designed to help you get started quickly. While we have implemented several security controls, **you must implement all preventive and defense-in-depth security measures before deploying to production**. Please review the MCP spec: [Security Best Practices](https://modelcontextprotocol.io/specification/2025-11-25/basic/security_best_practices)
9+
10+
## Getting Started
11+
12+
This demo shows how an MCP server can securely call a protected API on behalf of an end user. To begin:
13+
14+
1. Deploy the [Todo API](./api/)
15+
2. Deploy the [MCP server](./mcp/)
16+
17+
> [!NOTE]
18+
> The API used here could be any PingFederate-secured API. We use a Cloudflare workers API for this example, but the goal is to demonstrate how any API can be connected to an MCP server using this architecture.
19+
20+
### Access the remote MCP server from the Cloudflare Workers AI LLM Playground
21+
22+
Navigate to [https://playground.ai.cloudflare.com](https://playground.ai.cloudflare.com) and connect to your MCP server using the following URL pattern:
23+
24+
```
25+
https://remote-mcp-ping-federate.<your-subdomain>.workers.dev/mcp
26+
```
27+
28+
<img src="_docs/workers_ai_playground_demo.png" width="60%" alt="MCP server demo with workers ai playground">
29+
30+
### Access the remote MCP server from Claude Desktop
31+
32+
Open Claude Desktop and navigate to Settings -> Developer -> Edit Config. This opens the configuration file that controls which MCP servers Claude can access.
33+
34+
Replace the content with the following configuration. Once you restart Claude Desktop, a browser window will open showing your OAuth login page. Complete the authentication flow to grant Claude access to your MCP server. After you grant access, the tools will become available for you to use.
35+
36+
```
37+
{
38+
"mcpServers": {
39+
"todo-mcp": {
40+
"command": "npx",
41+
"args": [
42+
"mcp-remote",
43+
"https://remote-mcp-ping-federate.<ENV>.workers.dev/mcp"
44+
]
45+
}
46+
}
47+
}
48+
```
49+
50+
Once the Tools (under 🔨) show up in the interface, you can ask Claude to use them. For example: "Could you tell me what is in my Todo list?". Claude should invoke the tool and show the result generated by the MCP server.
51+
52+
## How does it work?
53+
54+
This architecture bridges the stateless nature of Cloudflare workers with the stateful requirements of an authenticated MCP session.
55+
56+
### Authentication & Client Bootstrapping
57+
58+
When an unregistered MCP client tries to connect to the MCP server without a token, the server provides the necessary details for the client to perform Dynamic Client Registration (DCR) on the fly. This allows the client to handle the user login and consent via PingFederate automatically, provisioning the tokens required to both connect to the MCP server and for the MCP server to execute delegated token exchanges.
59+
60+
> [!NOTE]
61+
> This implementation utilizes Dynamic Client Registration (DCR) to handle client onboarding. While the MCP protocol recommends CIMD as the new standard, DCR remains the only production-ready option currently supported by enterprise identity providers like PingFederate. Future versions of this architecture may transition to CIMD as support becomes available.
62+
63+
### Cloudflare Agents (State & Transport)
64+
65+
The MCP server extends the McpAgent class, which automatically wraps the MCP logic in a durable object. This handles the complex infrastructure requirements:
66+
- **Session Persistence:** It creates a dedicated, isolated environment for each MCP connection and securely persists the PingFederate tokens in the durable object's storage (`this.props`).
67+
- **Network Transport:** The agent manages the raw HTTP connection. It accepts incoming requests and keeps the response open as a Server-Sent Events (SSE) stream, enabling the Durable Object to push real-time updates back to the client over the single endpoint.
68+
69+
### MCP SDK (Tool Logic)
70+
71+
The official `@modelcontextprotocol/sdk` is used to define the actual capabilities of the MCP server. Inside the agent, an McpServer instance:
72+
- **Handles Protocol:** Manages the serialization of JSON-RPC messages and tool definitions.
73+
74+
## Use Cases & Extensibility
75+
76+
This architecture demonstrates a pattern for connecting AI agents to APIs protected by PingFederate. The remote MCP server enables LLMs to interact with APIs on behalf of an authenticated user, without requiring modifications to the target API's existing permission models. By leveraging standard OAuth 2.0 patterns like Dynamic Client Registration (DCR) and Token Exchange, this project provides a blueprint for enabling natural language interactions with enterprise data while enforcing identity-based access controls and consent.
119 KB
Loading
309 KB
Loading
156 KB
Loading
171 KB
Loading
62.2 KB
Loading
92.1 KB
Loading
67.2 KB
Loading
52 KB
Loading

0 commit comments

Comments
 (0)