MCP Server Architecture: Connecting Your Business API to Claude and ChatGPT
An MCP server is a small service that lets AI assistants such as Claude and ChatGPT discover and call your tools and data through the Model Context Protocol. The best architecture for most businesses is a thin, stateless MCP layer in front of the API you already have: a handful of well-described tools, clear read and write boundaries, OAuth 2.1 for anything that changes data, and structured errors the model can recover from. This guide walks through each decision, using the MCP server behind fofefa.com as the example.
Where does an MCP server sit in your architecture?
The MCP server should not contain business logic. It translates between the protocol and your existing API or database:
Claude / ChatGPT / other agent
│ JSON-RPC over HTTPS (Streamable HTTP)
▼
MCP server ── tool definitions, input validation, auth checks
│
▼
Your API / database / SaaS ── the actual business logic
Keeping the layer thin means the rules stay in one place, and the MCP server can be replaced or extended without touching the core system.
Which transport should you use?
For a remote server on the public internet, use Streamable HTTP: the client sends JSON-RPC messages with POST to one endpoint, such as https://fofefa.com/mcp. If none of your tools stream progress, the server can answer every request with a plain JSON response and keep no session state. That makes it a good fit for serverless platforms like Vercel, where each request may hit a different instance.
The fofefa.com server handles initialize, ping, tools/list and tools/call, negotiates the protocol version from a list of supported versions, and answers GET with 405 because it offers no server-sent event stream.
// app/mcp/route.js (simplified)
export async function POST(req) {
const msg = await req.json();
switch (msg.method) {
case 'initialize':
return json({ jsonrpc: '2.0', id: msg.id, result: {
protocolVersion: negotiate(msg.params?.protocolVersion),
capabilities: { tools: { listChanged: false } },
serverInfo: { name: 'fofefa', version: '1.0.0' },
} });
case 'tools/list':
return json({ jsonrpc: '2.0', id: msg.id, result: { tools: publicToolDefs() } });
case 'tools/call':
return json({ jsonrpc: '2.0', id: msg.id, result: await callTool(msg.params, auth) });
}
}
How should you design the tools?
Tools are the part the model actually sees, so they deserve the most care.
- Design for tasks, not endpoints. Wrap what a user wants to do, such as "find an order" or "submit a request", instead of mirroring every REST endpoint one to one.
- Write descriptions for the model. Say when to use the tool, what it returns and what it does not do. The description is the only documentation the model reads.
- Use strict JSON Schemas. Required fields, enums and limits catch bad calls before they reach your API.
- Add annotations. Mark read-only tools with
readOnlyHint: trueand say whether a write is destructive or idempotent, so clients can decide when to ask the user for confirmation. - Return compact, structured results. Return the fields the model needs and a link to the source, not a full database row.
Here is one of the fofefa.com tools:
{
name: 'get_project',
title: 'Get a project',
description: 'Get one Fofefa project by slug: book-of-good, movie or game. Returns not_found for unknown slugs.',
inputSchema: {
type: 'object',
properties: { slug: { type: 'string', enum: ['book-of-good', 'movie', 'game'], description: 'Project slug' } },
required: ['slug'],
additionalProperties: false,
},
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
}
How do you authenticate agents?
Read-only public data can stay open. Anything that writes data or reads private data needs authentication, and the MCP specification uses OAuth 2.1 for that. The pieces are:
- Protected resource metadata (RFC 9728) at
/.well-known/oauth-protected-resource, which tells the client which authorization server protects the MCP endpoint. - Authorization server metadata (RFC 8414) at
/.well-known/oauth-authorization-server, with the authorize, token, registration and JWKS endpoints. - Dynamic client registration (RFC 7591), so an agent can register itself without a human creating API keys.
- Authorization code with PKCE (S256) for agents acting for a person, and client credentials for agents acting for themselves.
- Short-lived signed access tokens. fofefa.com issues ES256 JWTs and publishes the public key as JWKS.
When a protected tool is called without a valid token, the server answers HTTP 401 with a header that tells the client where to start:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://fofefa.com/.well-known/oauth-protected-resource", scope="fofefa:request"
On fofefa.com, the submit_request tool requires the fofefa:request scope. It is how an agent can tell us, on behalf of a person, what they want built.
How should errors work?
Distinguish protocol errors from tool errors. A malformed JSON-RPC message gets a JSON-RPC error. A tool that fails because of bad input returns a normal result with isError: true and a message the model can act on, such as "slug must be one of book-of-good, movie, game". The model can then correct itself instead of giving up.
How do clients find your MCP server?
Publish a server card at /.well-known/mcp/server-card.json, link to it from your HTTP Link headers and llms.txt, and list the server in public MCP directories. fofefa.com also lists it in its API catalog and AI catalog.
Hosting and security checklist
- Validate every input against the schema before calling your API.
- Keep write tools behind OAuth scopes, and keep secrets in server-side environment variables only.
- Put the MCP server on the same domain as your site, so its metadata and your brand reinforce each other.
- Log tool calls without logging tokens or personal data you do not need.
- Allow CORS only for what browser-based clients need.
Try it
You can call the fofefa.com server directly:
curl https://fofefa.com/mcp \
-H 'content-type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
The companion guide, How We Built an Agent-Ready Website, covers the rest of the site. If you want an MCP server for your own API, see MCP server development or tell us about your project.