Cloudflare MCP Logging
A template for deploying MCP servers as Cloudflare Workers with integrated LogPush and R2 storage for detailed execution logging. It enables remote tool execution and provides utilities for retrieving logs directly from Cloudflare R2 buckets.
README
Setup
- Start up container
docker compose up -d - Initialize package.json
-
npm init -y(First time to create package.json) -
npm install
-
MCP Server Creation
- Create from CF template
-
npm create cloudflare@latest -- mcp-logging --template=cloudflare/ai/demos/remote-mcp-authless - If clone template failed, git clone cloudflare/ai repo below, then recreate
git clone https://github.com/cloudflare/ai.git
-
- Start dev server
- Update to use
wrangler dev --ip 0.0.0.0IP in package.json - Port mapping
8787:8787in docker-compose.yml npm startORwrangler dev --ip 0.0.0.0- Access via
localhost:8787/sse
- Update to use
Deploy CF Worker
- Set CF account ID to wrangler.jsonc
"account_id": "<EDIT-HERE>" - Set CF API key in env
- API's permission template:
Edit Cloudflare Workers - ENV:
CLOUDFLARE_API_TOKEN=<EDIT-HERE>
- API's permission template:
- Deploy worker to CF
npm run deployORnpx wrangler deploy
MCP Inspector
- Start inspector
npx @modelcontextprotocol/inspector@latest
Connect via MCP Host/Client
-
mcp-remote
{ "mcpServers": { "CF Remote MCP": { "command": "npx", "args": [ "-y", "mcp-remote", "https://<MCP_SERVER_URL>/sse" ] } } } -
supergateway
{ "mcpServers": { "Basic Calculator": { "command": "npx", "args": [ "-y", "supergateway", "--sse", "http://localhost:8787/sse", "--header", "X-UserID:USERID_123", "--header", "X-SecretKey:SKEY_456" ] } } }
LogPush
- Enable
logpushfor CF worker- Set
"logpush": truein wrangler.jsonc - Deploy to CF & check settings
- Set
- Create R2 API token
- Create R2 bucket
- Create LogPush job
- Set env (edit the value)
R2_BUCKET_NAME="EDIT: R2 BUCKET NAME"
R2_LOG_BASE_PREFIX="EDIT: R2 FOLDER NAME"
CF_R2_ACCESS_KEY_ID="EDIT: R2 ACCESS KEY ID"
CF_R2_SECRET_ACCESS_KEY="EDIT: R2 ACCESS SECRET"
- Run
utils/download_r2_logs.jsscript to get logsnode utils/download_r2_logs.js --start-date "2025-06-27 07:00:00" --end-date "2025-06-27 08:00:00"
Pass Variable to Tool Function
-
Set
ctx.propsin fetch entrypoint.export default { fetch(request: Request, env: Env, ctx: ExecutionContext) { const userId: string | null = request.headers.get('X-UserID'); const secretKey: string | null = request.headers.get('X-SecretKey'); ctx.props = { userId, secretKey }; // add this -
Use
this.props.<VARIABLE_NAME>in tool.this.server.tool( "calculate", { operation: z.enum(["add", "subtract", "multiply", "divide"]), a: z.number(), b: z.number() }, async ({ operation, a, b,}) => { try { // retrieve here const userId: string | null = this.props.userId as string; const secretKey: string | null = this.props.secretKey as string;
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.