Skip to main content
1

Install the package

Add @phake/mcp to your project:
npm install @phake/mcp
2

Create the KV namespace

Run the following command to create a KV namespace for token storage:
wrangler kv namespace create TOKENS
Copy the namespace ID printed in the output — you’ll need it in the next step.
3

Bind KV in your Wrangler config

Add the KV namespace binding to your Wrangler configuration file. Use the namespace ID from the previous step.
[[kv_namespaces]]
binding = "TOKENS"
id = "<your-kv-namespace-id>"
4

Generate an encryption key

Tokens at rest are encrypted with AES-256-GCM. Generate a 32-byte key using one of the following commands:
openssl rand -base64 32 | tr '+/' '-_' | tr -d '='
Save the output — you’ll use it in the next step.
5

Set the encryption key

Set RS_TOKENS_ENC_KEY in your environment.Production — add it as a Wrangler secret so it’s encrypted at rest:
wrangler secret put RS_TOKENS_ENC_KEY
# paste the generated key when prompted
Local development — add it to .dev.vars in your project root:
.dev.vars
RS_TOKENS_ENC_KEY=<your-generated-key>
Never commit .dev.vars or your encryption key to version control.
6

Create your Worker

Create your main Worker file. Import createMCPServer from @phake/mcp, define your tools, and export the server as the default export:
src/index.ts
import { createMCPServer } from "@phake/mcp";

const server = createMCPServer({
  tools: [
    // your tool definitions
  ],
});

export default server;
Use defineTool to create type-safe tools with Zod input/output schemas. See the tool definition docs for the full field reference.
7

Deploy

Deploy your Worker to Cloudflare:
wrangler deploy
Your MCP server will be available at your Worker’s URL (e.g., https://your-worker.your-subdomain.workers.dev/mcp).