To build a remote MCP server for Claude, you expose your product's capabilities as resources, tools and prompts over an HTTP endpoint, then put OAuth in front of it so every call is tied to a consenting user with limited scopes. The transport and deployment are the easy part. The authorization model is where most teams get into trouble, so I design it first and write handlers second. Here is the full build, in the order I do it for clients.

What Is a Remote MCP Server, and Why Does OAuth Matter?

MCP, the Model Context Protocol, is the open protocol that lets an LLM client such as Claude discover and call capabilities you define. A remote MCP server is one that runs over HTTP and is reachable across the network, as opposed to a local process the client launches on the same machine. Since Anthropic's announcement in November 2024, MCP has gained support from OpenAI, Google DeepMind, Microsoft Copilot and numerous development tools, which means a server you build once can serve many clients.
The catch is that a remote endpoint is a door into your API. If it has no authentication, anyone who finds the URL can call whatever you exposed. OAuth closes that door properly: each user consents, tokens carry scopes, and access can be revoked without rotating a shared key. That is why I settle the auth model before writing a single tool handler.
stdio vs SSE vs Streamable HTTP: which transport should you use?
Use stdio only for local servers that the client starts itself. For anything remote, use Streamable HTTP. It is the transport the current Cloudflare guide deploys, and it works with ordinary HTTP infrastructure such as load balancers, logging and auth middleware. SSE-based setups still exist in older tutorials, but I would not start a new project on them.
Why "no auth" is fine for a demo and never for production
Many quick-start templates ship without authentication so you can see a tool call work in minutes. That is a sensible way to learn. It is also exactly the configuration you must never leave running against real customer data. Treat the authless version as a scaffold and plan the OAuth layer as part of the first release, not a later hardening pass.
Prerequisites and Project Setup Before You Write Code
You need very little to start. If you build in Python, the official tutorial requires Python 3.10 or higher and the Python MCP SDK 2.0.0 or higher. If you deploy to Cloudflare Workers, you need Node and the Agents SDK. Pick one stack and stay on it. Mixing runtimes in the first week costs more than any framework difference.
Local dev environment
Keep local development and production configuration separate from the start. Local runs use a throwaway OAuth client and test data. Production secrets live in your platform's secret store and never in the repository. I add the ignore rules before the first commit, because a credential that has been committed once should be treated as leaked.
Repository and CI/CD wiring
Put the project in a git repository and connect it to automatic deployment. The Cloudflare template does this for you: it sets up a new git repository on your GitHub or GitLab account, configured to deploy automatically on each push or merge to the main branch. That gives you a reviewable history and a deploy you can roll back, which matters once real users depend on the server.
Core MCP Capabilities: Resources, Tools, and Prompts
MCP servers can provide three main types of capabilities: Resources, Tools and Prompts. Knowing which one to use for each part of your API is the main design decision in the whole build.
- Resources are file-like data that clients can read, such as API responses or file contents.
- Tools are functions the LLM can call, with user approval.
- Prompts are pre-written templates that help users accomplish specific tasks.
Choosing between a resource and a tool
A simple rule works well for a REST API. Read-only GET endpoints usually become resources. Anything that changes state, such as creating an order or updating a record, becomes a tool. Keeping that split clean makes your scopes easy to design later: read scopes cover resources, write scopes cover mutating tools.
Writing tool schemas the model won't misuse
Tool names and descriptions are read by the model, not just by humans. Be specific. "create_invoice" with a precise description of required fields beats "do_billing". Define strict input schemas with types, enums and required fields so the model cannot pass free-form text where an ID belongs. When a tool is destructive, say so in the description. Clear schemas are the cheapest safety feature you will ever add.
How Do You Deploy a Remote MCP Server with Streamable HTTP?
Cloudflare's guide shows how to deploy a remote MCP server using Streamable HTTP transport, and its templates build the server with createMcpHandler from the Agents SDK. I use this path when a client wants something running fast and cheap at the edge. The core steps look like this:
- Create the project from the Cloudflare MCP template, which also creates your git repository.
- Define your tools, resources and prompts inside the server factory function.
- Deploy, either from the dashboard or the CLI.
- Confirm the endpoint responds at your workers.dev subdomain ending in /mcp.
- Push to main to ship every later change automatically.
By the end of these steps you should have a live, unauthenticated demo endpoint. The next section turns it into something you can safely put real data behind.
Stateless handler, stateful data
The handler is stateless. Each request gets a fresh McpServer from a factory function, so the server needs no Durable Object or session. That keeps scaling simple. Anything that has to outlive a single request belongs in a binding such as KV, D1 or a Durable Object, not in memory inside the handler.
Verifying the deployed /mcp endpoint
Once deployed, the example server is live at a workers.dev subdomain, with the path ending in /mcp. Check it with an MCP-aware inspector or client before you add auth. If the unauthenticated version does not list your tools, adding OAuth will only make the failure harder to read.
If you would like a second pair of eyes on your design at this point, you can book a free 30-minute call at calendly.com/alisaleem252 and we can walk through your API together.
How Do You Add OAuth Authentication and Scoped Authorization?
Put OAuth in front of the /mcp endpoint so every request carries a token you can validate. The goal is simple: no anonymous calls, and no call that can do more than its user agreed to. I build this in three layers: the consent flow, the scope model and per-request validation.
Scope design that matches your API
Map scopes to the capabilities from the previous section. A read scope grants access to resources. A separate write scope grants access to mutating tools. If your API has distinct areas, such as billing and content, give each its own scope so a user can approve one without the other. Start narrow. Adding a scope later is easy; taking back an over-broad one after users have granted it is not.
Token validation on every request
Validate the token server-side on every request. Never trust a user ID or role that the client sends in the payload. Return a 401 when the token is missing or expired, and a 403 when the token is valid but lacks the scope for that tool, so the MCP client can prompt the user to reconnect or re-consent. Keep tokens short-lived and revocable per user, and make sure revoking a user in your own system also cuts off their MCP access.
How Do You Connect Claude to Your Remote Server?
Connecting Claude is the quick part once the endpoint and auth work. You give the client the full /mcp URL, complete the OAuth consent screen once, and then confirm the tools appear.
First connection and consent
Point the client at the complete /mcp address on your domain. Claude will send the user through your OAuth flow. Check that the consent screen lists the scopes you intended and nothing more. Then confirm the issued token carries exactly those scopes. This is the moment to catch a scope that is wider than you planned.
Smoke-testing each capability
Test in order of risk. First call a read-only resource and check the data. Then call a mutating tool and confirm that Claude asks for approval, because tools are called by the LLM with user approval. Finally confirm that the client lists your tools, resources and prompts. When something fails, work out whether it is an auth failure or a schema failure. They look different in the client, and fixing the wrong one wastes hours.
Logging, Security, and Lessons Learned in Production
Logging rules depend on the transport. For stdio servers, never write to stdout, because it will corrupt the JSON-RPC messages and break your server. For HTTP servers, standard output logging is fine since it doesn't interfere with HTTP responses. Since this build is remote, you can log normally, but you still need to decide what goes into those logs.
STDIO vs HTTP logging rules
Log each tool invocation with the user identity, the tool name and the scope used. Do not log payload secrets, tokens or full request bodies that may contain customer data. If you ever move a server to stdio for local use, switch logging to stderr or a file before you do.
Security checklist before you ship
Before release, I run through the same short list on every server:
- Treat every tool as an attack surface and validate all inputs against the schema.
- Rate-limit by user and by tool, so one runaway agent cannot flood your API.
- Confirm that write scopes cannot be obtained without explicit consent.
- Check that no secret exists in the repository history.
- Make sure errors do not leak internal details to the client.
Owning the auth, transport and API plumbing yourself is real work. If you would rather hand it off, that is exactly the end-to-end work I do.
Why Teams Bring Me In to Build and Harden MCP Servers
I have been developing since 2013, with 10+ years of WordPress experience, and I have delivered 400+ projects to 400+ happy clients. My average rating is 4.9/5 with a 95% repeat client rate. I am a Top Rated freelancer on multiple platforms, with 405+ reviews on Fiverr and Top Rated status on Upwork. Listed clients include Benzinga, BitTorrent Inc, Boston University, BYJUS and Case Western Reserve University.
I don't just wire up a protocol. I build custom, AI-powered integrations: API development, custom AI workflows, headless WordPress with ReactJS frontends, and WooCommerce payment gateways. There are no off-the-shelf plugins pretending to be an integration here, only clean code that drives real business results.
What an end-to-end build looks like
It starts with your API and the actions you want Claude to take. I design the scope model with you, build the server and the OAuth layer, deploy it with a git-based pipeline, and test every tool against real consent flows. You end up with a secure and scalable endpoint, not a demo.
What to send me to get started
Send your API documentation or an OpenAPI file, a list of the three to five actions you want Claude to perform first, and a note on who your users are and how they sign in today. That is enough for me to propose a build plan.
Your Next Step: Ship the Server, Then Secure It
Build the endpoint, wire in OAuth, scope your tools narrowly, test with real consent, and log with care. That sequence gets Claude connected to your API without handing it more access than a user agreed to.
If you want that done end to end, visit Ali Saleem to see my services, or book a free 30-minute call at calendly.com/alisaleem252 and bring your API docs.
Frequently Asked Questions
Can I use a local stdio server and a remote HTTP server in the same project?
The article recommends picking one stack and staying on it, and warns that mixing runtimes in the first week costs more than any framework difference. It frames stdio as suitable only for local servers the client starts itself, while remote work should use Streamable HTTP.
Should read-only endpoints become resources or tools?
The article's rule of thumb is that read-only GET endpoints usually become resources, while anything that changes state becomes a tool. Keeping that split clean also makes scopes easier to design, since read scopes cover resources and write scopes cover mutating tools.
Where should state live if the MCP handler is stateless?
Because each request gets a fresh server from a factory function, the handler needs no Durable Object or session. Anything that must outlive a single request belongs in a binding such as KV, D1 or a Durable Object rather than in memory inside the handler.
Is it acceptable to launch with no authentication and add OAuth later?
No. The article treats the authless version as a scaffold only, suitable for learning, and says it must never run against real customer data. OAuth should be planned as part of the first release, not a later hardening pass.
What should I check before adding OAuth to a deployed endpoint?
Verify the unauthenticated deployment first with an MCP-aware inspector or client, confirming the endpoint responds at the path ending in /mcp and lists your tools. If the authless version does not list them, adding OAuth will only make the failure harder to read.
0 comments:
Post a Comment