Designing Resilient AI Publishing Agents with Model Context Protocol (MCP) & Scoped Keys
How we built a secure stdio and HTTP Model Context Protocol (MCP) publishing server that allows AI coding assistants to draft, review, and schedule CMS articles safely.
The emergence of the Model Context Protocol (MCP) by Anthropic and open ecosystem tooling has enabled AI assistants (like Claude, Cursor, and custom agent loops) to move from passive autocomplete to active pair programmers capable of calling structured API tools directly.
In this article, we explore the architecture of our @portfolio/mcp server, which enables autonomous drafting, content auditing, and publishing while maintaining strict authorization boundaries.
1. The MCP Tool Contract
An MCP server exposes standardized tools via JSON-RPC over stdio or SSE. Our server exports tools for:
draft_blog: Creates a draft article with markdown body and tags.update_blog: Modifies an existing draft with optimistic concurrency locking.schedule_blog: Enqueues an article for automatic publication at a designated future instant.list_media: Queries available image assets in Supabase Storage.
// MCP Tool Registration Definition
export const draftBlogTool = {
name: 'draft_blog',
description: 'Drafts a new blog post in the portfolio CMS',
inputSchema: {
type: 'object',
properties: {
title: { type: 'string', description: 'Article title' },
content: { type: 'string', description: 'Full Markdown content' },
tags: { type: 'array', items: { type: 'string' } },
excerpt: { type: 'string' },
},
required: ['title', 'content', 'tags'],
},
};
2. Scoped API Key Authentication (pf_live_*)
Giving an autonomous agent full admin credentials is a massive security hazard. Instead, we issue scoped API keys prefixed with pf_live_:
- Cryptographic Hashing: Keys are generated with 256 bits of entropy and stored in the database exclusively as Argon2/SHA-256 hashes.
- Granular Scopes:
blogs:draft,blogs:publish,media:upload,projects:read. - Automatic Audit Trail: Every write operation records the exact Actor ID, timestamp, IP address, and changed fields.
// API Scope Guard in NestJS
@Injectable()
export class ScopeGuard implements CanActivate {
constructor(private reflector: Reflector) {}
canActivate(context: ExecutionContext): boolean {
const requiredScopes = this.reflector.get<string[]>('scopes', context.getHandler());
const request = context.switchToHttp().getRequest();
const key = request.publisherKey;
if (!key || !requiredScopes.every((scope) => key.scopes.includes(scope))) {
throw new ForbiddenException('Insufficient publisher key permissions.');
}
return true;
}
}
3. Human-in-the-Loop Safety
Even with autonomous drafting capabilities, our publishing protocol mandates:
- All AI-originated content is marked with
createdByAI: true. - Content defaults to
DRAFTstatus. - Final publication requires either explicit admin approval or pre-authorized scheduled release times.
This architecture delivers high velocity while guaranteeing that human editorial standards and security controls are never bypassed.


