How Is an MCP Server Put Together?
An MCP server is built from a transport, a protocol layer, capability registries and handlers. Here is how the parts fit and what to watch when you build one.
On this page
Short answer
An MCP server is a small service built in layers: a transport carries JSON-RPC messages, a protocol layer handles the lifecycle and capability handshake, registries hold the tools, resources and prompts it offers, and handlers run the work behind each capability. The server sits between an AI client and your own systems, checking permissions and returning structured results.
What is an MCP server architecture?
An MCP server architecture is the layered design of a server that exposes tools, resources and prompts through the Model Context Protocol: a transport carries messages, a protocol layer manages the connection lifecycle, registries hold the capabilities, and handlers run the work behind each one.
The layers matter because each one fails in its own way. A transport problem drops the connection, a protocol problem breaks the handshake, a registry problem hides a tool the model needs, and a handler problem returns a wrong answer. Keeping the layers separate means a fix in one place does not disturb the others.
The five parts are:
- Transport. How messages travel between client and server.
- Protocol layer. The message format, lifecycle and capability handshake.
- Capability registries. The lists of tools, resources and prompts the server offers.
- Handlers. The code that runs when a capability is called.
- Backends. The databases, APIs and file stores behind the handlers.
The server never runs the model. It sits beside your own systems and offers a controlled set of operations, so the model can act on real data without direct access to those systems. The guide to building an MCP server covers the first working version; this article covers how the parts fit together.
How does the transport layer work?
The transport layer carries JSON-RPC messages between the client and the server, and the choice of transport decides whether the server runs as a local process or as a service on the network.
| Transport | How it works | Best for |
|---|---|---|
| Standard input and output | Server runs as a child process of the client | Local tools and desktop assistants |
| Streamable HTTP | Server runs on the network, many clients connect | Team servers and products |
| Server-sent events | Older streaming transport, still seen in some clients | Existing clients that require it |
With standard input and output, the server runs as a child process of the client. Messages travel over the process pipes, there is no network port to secure, and each client gets its own server process. It is the simplest choice for a server that runs on one machine, such as a developer tool or a desktop assistant.
With Streamable HTTP, the server runs on the network and many clients can reach it. The server needs authentication, session handling and a deployment plan, which is more work, but it is the right choice when the server serves a team or a product. The older server-sent events transport still appears in some clients, but new servers should use Streamable HTTP.
How do the lifecycle and capability handshake work?
The lifecycle starts when the client sends an initialize request with its protocol version and the capabilities it supports. The server replies with its own version and capabilities, and the client then sends an initialized notification. Only after that exchange can the client list tools and call them.
Capability negotiation is the point of the handshake. Each side declares what it supports, such as tools, resources, prompts, sampling and logging, and each side only uses what the other declared. A client that cannot handle sampling will never be asked for it, and a server that offers no prompts will never be asked to list them.
Requests expect a reply, while notifications do not. The server uses notifications to report progress or log messages, and the client uses them to cancel a request or signal that something changed. The session ends when the transport closes or the client disconnects, and a remote server should treat a lost connection as a closed session rather than waiting forever.
What do the tool, resource and prompt registries hold?
The registries are the server's catalogues of what it offers. Each entry has a name, a plain description and, for tools, a typed input schema. The client reads the registries to learn what it can call, and the model reads the descriptions to decide when to call each one.
The tool registry holds callable actions, such as searching records or creating a ticket. The resource registry holds read-only data addressed by URI, such as documents or reports. The prompt registry holds reusable task templates, such as a weekly summary. A fourth capability, sampling, lets the server ask the model to judge or summarise something in return.
Keep each registry small and strict. Give every tool one job and a verb-first name, define the input schema with required fields and types, and reject anything that does not fit. The best practices for MCP servers cover tool design in depth; the architecture point is that the registry is the contract between the server and every client that connects to it.
How does a request flow through the server?
A request flows from the client through the transport to the protocol layer, which parses the message and hands it to a dispatcher. The dispatcher finds the capability in the registry, checks permissions, runs the handler and returns a structured result the same way it came in.
The flow has six stages:
- Parse. Read the JSON-RPC message and check it is well formed.
- Route. Match the method name to a tool, resource or prompt in the registry.
- Validate. Check the arguments against the input schema and reject anything that does not fit.
- Authorise. Confirm the client and the current user may run this capability.
- Run. Call the handler, with a timeout so a slow backend cannot hang the server.
- Respond. Return a short summary plus the raw fields, or a clear error that names the problem.
Errors deserve the same care as successes. Return an error that names the missing field or the failed check, and keep stack traces and internal details out of the reply. A model that receives a clear error can ask the user for the missing detail; a model that receives a crash dump cannot.
How do authentication and sessions fit in?
Authentication happens before a client can list tools or read resources. A local server can rely on the operating system and the fact that only one user runs it, but a remote server must check a token on every connection and scope each client to the tools it needs.
Authorisation is checked per call, not just per connection. The same client may serve different users, so the server must check what the current user is allowed to do before running a tool that reads or changes data. A support client should not be able to call a billing tool, even if the model asks it to.
Sessions track state for remote transports. The server gives each connection a session id, keeps any per-session data small, and treats a lost connection as a closed session. Tokens should expire and rotate, and the server should have its own scoped login to each backend system, never the main application's admin account.
How do you lay out an MCP server in 6 steps?
You lay out an MCP server by working from the outside in: transport first, then the capability list, then the handlers, then the operational pieces. The steps below keep the layers separate from the start.
- Pick the transport. Use standard input and output for a local client, or Streamable HTTP for a remote one.
- List the capabilities. Write down the tools, resources and prompts, and cut the list to the smallest set that does the job.
- Define the schemas. Give each tool a verb-first name, a plain description and typed inputs with required fields marked.
- Write the handlers. Each handler validates its inputs, calls one backend system and returns structured results or a clear error.
- Add authentication and logging. Require a token, scope clients to the tools they need, and log every call with its inputs, duration and outcome.
- Deploy as its own service. Give the server health checks, timeouts and a rollback plan, and keep the previous version ready to restore.
Test the layout with a real client before adding more capabilities. Connect an MCP client, call every tool with good and bad inputs, and confirm that errors are clear and permissions hold. The production practices for MCP servers cover the deployment details.
Example (hypothetical): a sales team looks up orders
Example (hypothetical): a sales team of 12 people looks up order status for customers. Each person makes about 25 lookups a day, so the team makes 300 lookups a day. By hand, each lookup takes about 3 minutes in the order system, which is 300 times 3, or 900 minutes, about 15 hours a day across the team.
The team builds an MCP server with one tool, search_orders, and one resource for the order status page. A lookup through the model takes about 20 seconds, so 300 lookups take 300 times 20 seconds, or 6,000 seconds, which is 100 minutes, or about 1 hour and 40 minutes. The saving is 900 minus 100, or 800 minutes, about 13 hours and 20 minutes a day.
The server is read-only, so a bad call cannot change an order. After two weeks of testing, the team adds a second tool for flagging a delayed order, with a human approval step before the flag is sent. The transport is Streamable HTTP, because the sales team works from different offices, and each client uses its own token.
What are the common mistakes?
The most common MCP server architecture mistakes are mixing the layers together, exposing too much, and shipping without authentication or logging.
- One server, too many tools. A server with 40 tools is hard to test and hard for a model to choose between. Split by domain and keep each server focused.
- Handlers that know about the transport. A handler that reads the transport directly cannot be tested alone. Keep handlers behind the dispatcher.
- Vague tool descriptions. If the description does not say what the tool returns, the model will guess, and the guess will be wrong.
- No authentication on a remote server. A server without a token check is open to anyone who finds its address.
- No timeouts. One slow backend call without a timeout can hang the whole server for every client.
- Shared credentials. The server should have its own scoped login, not the main application's admin account.
- Changing a tool schema without a version. Clients break when a schema changes without warning, so version the server and keep old behaviour until clients move.
Key takeaways
- An MCP server has five layers: transport, protocol, registries, handlers and backends
- Use standard input and output for a local client and Streamable HTTP for a remote one
- The handshake negotiates capabilities, so each side only uses what the other declared
- Registries are the contract: one job per tool, plain names, strict schemas
- Check permissions per call and give the server its own scoped credentials
Frequently asked questions
What is the difference between an MCP server and an API?
An API is called directly by code you control, with fixed endpoints you write by hand. An MCP server exposes capabilities that a model discovers through the protocol and calls by name, with typed inputs and descriptions. The server adds discovery, a standard message format and per-call permission checks on top of the same backend systems.
Which transport should I choose for an MCP server?
Use standard input and output when the server runs on the same machine as the client, such as a developer tool or a desktop assistant. Use Streamable HTTP when the server runs on the network and serves a team or a product. The older server-sent events transport still works with some clients, but new servers should use Streamable HTTP.
What is the capability handshake?
The handshake is the opening exchange of a connection. The client sends an initialize request with its protocol version and capabilities, the server replies with its own, and the client sends an initialized notification. After that, each side only uses the capabilities the other declared, and tools can be listed and called.
How many tools should an MCP server expose?
Start with one to three tools that do one job well, and add more only when the same workflow repeats. A server with dozens of tools is hard to test and hard for a model to choose between. When the list grows past about ten tools, split the server by domain and keep each one focused.
Do MCP servers need authentication?
A local server can rely on the operating system, since only one user runs it. A remote server must check a token before a client can list tools or read resources, and it must scope each client to the tools it needs. Authorisation is checked per call, because the same client may serve different users.
Can one MCP server wrap several backend systems?
Yes, and most useful servers do. Each handler calls one backend system, such as a database, an API or a file store, and the dispatcher routes calls to the right handler. Keep the handlers separate and give the server its own scoped login to each backend, never a shared admin account.