Dev.to AI 🤖 Ai 👁 0 📖 3 min read

Letting AI assistants draft posts, but never publish them: building an MCP server with its own OAuth 2.1 server

I'm building SocialPost, a multi-tenant social media management platform for Facebook and Instagram, during my internship. It will be used in-office for real clients. The newest piece is an MCP server, so an AI assistan

Letting AI assistants draft posts, but never publish them: building an MCP server with its own OAuth 2.1 server

I'm building SocialPost, a multi-tenant social media management platform for Facebook and Instagram, during my internship. It will be used in-office for real clients.

The newest piece is an MCP server, so an AI assistant (like Claude) can work with SocialPost on behalf of a user. It is finished and off by default. This post covers the three decisions that mattered most.

What MCP is, in one paragraph

The Model Context Protocol (MCP) is a standard way for an AI assistant to connect to an outside app and use its tools. For SocialPost, that means an assistant can look at a client's calendar, brand profile and recent posts, and then write a draft post.

Rule 1: the AI can draft, but people stay in charge

In SocialPost, a post moves through drafts, review, approval and scheduling. Real people approve it. I wanted the AI to fit into this flow, not skip it.

So an agent can:

read clients, posts, the calendar, analytics, connected accounts and the media library
create and edit drafts
submit a draft for approval

An agent can never:

approve a post
publish a post
delete a post

These are not settings. The tools simply don't exist. An AI can't be talked into doing something it has no tool for. A person always makes the final call.

Rule 2: check the plan before writing code

Before writing any code, I spent a whole milestone (I called it M0) auditing my own codebase. No changes, only questions: what do I already have, and what is really new?

The good news was that users, roles, client isolation, history, rate limiting and hashing could all carry agents with small hooks. The real new work was the OAuth server.

Rule 3: build the OAuth server myself

For an AI assistant to act for a user, the user has to sign in and give permission. MCP uses OAuth 2.1 for this. There are two ways a client can introduce itself to the server:

DCR (Dynamic Client Registration): every client registers itself first. The MCP spec now treats this as deprecated.
CIMD (Client ID Metadata Documents): the client's ID is a URL that points to a document describing it. This is the direction the spec is going.

I wanted CIMD, not only DCR. My plan was Spring Authorization Server, with a 1-2 day spike to test it. It didn't support CIMD, so I built my own OAuth 2.1 server instead. Finding that out early, on paper, was the point of the audit.

What the OAuth server does:

PKCE with S256 on every authorization
Short-lived access tokens (15 minutes)
Refresh tokens that rotate, stored only as hashes
Reuse detection: if an old refresh token is used again, the whole chain is revoked, because that suggests it was stolen
Checks on every call: each tool call re-checks that the user still has access, so removing someone takes effect right away

There was one more wrinkle. The SocialPost web app keeps its login token in the browser and has no server session, so I needed a small consent step to connect "the person logged in" with "the assistant asking for access".

MCP DIAGRAM

What I learned

Audit first. A milestone of reading my own code saved me from building on a wrong assumption.
Limit what the AI can do by design. Leaving the dangerous tools out is simpler and safer than trying to block them later.
A library can be the wrong choice. Spring Authorization Server is good, but it didn't fit this requirement, and a short spike showed that quickly.

What's next

I'm now working on a WhatsApp channel, so teams can draft and approve posts from chat. I'll write about that once it's built.

If you've built an MCP server or an OAuth flow, I'd like to hear what surprised you. Leave a comment.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.