5 min read
Your First MCP Server: A Practical Guide Without the Hype
A plain-words guide to building your first MCP server: what it is, when you actually need one, and how to ship a safe, read-only version your AI agent can rely on.

On this page
Most teams I talk to have the same question right now. They have an AI assistant or agent that sounds smart, but it can't see their real data. It can't check an order, look up a product, or read a policy doc. So it guesses.
An MCP server is one clean way to fix that. This guide walks through building a first one, the boring and safe way.
What an MCP server is, in plain words
MCP stands for Model Context Protocol. It is an open standard for letting an AI client (Claude Desktop, Cursor, a custom agent) talk to your systems.
An MCP server is a small program that tells the AI: "Here are the things you can do and read." Each of those things has a name, a description, and a defined input shape. The AI decides when to call them. Your server does the real work and returns the result.
That's it. It is not a model, and it is not magic. It's a well-described menu of actions sitting in front of your existing code.
When you need one vs a simple API
You don't always need MCP. A normal REST endpoint is fine when:
- Your own code decides exactly when to call it
- There's one app consuming it
- No AI is choosing which action to take
MCP starts to make sense when:
- An AI agent needs to choose between several actions on its own
- You want the same tools to work across different AI clients without rewriting glue code
- You want tool descriptions, input schemas, and results in one standard format
A good rule: if you'd otherwise write custom "function calling" glue for every AI tool you use, an MCP server saves you from doing that over and over.
The minimal architecture
An MCP server exposes three kinds of things.
Tools. Actions the AI can call with arguments. For example get_order_status(order_id). Tools are where most of the value is.
Resources. Read-only data the client can load as context, like a returns policy document or a product category list. Think of them as files the AI can open.
Prompts. Reusable prompt templates the user can pick, like "Summarize this customer's recent orders." Optional for a first server.
Then there's the transport, which is how the client and server talk:
- stdio: the client starts your server as a local process and talks over standard input and output. Simple, great for local tools and development.
- HTTP (Streamable HTTP): your server runs as a web service. Use this when the server needs to be shared, deployed, or reached by remote agents.
Start with stdio while building. Move to HTTP when other people or hosted agents need it.
A simple example shape
Say you run an online store and want an agent to answer support questions. A first server might expose:
search_products(query, limit)returns name, price, stock status, URLget_product(product_id)returns full details for one productget_order_status(order_id, email)returns status, items, and tracking link- Resource:
policies/returnswith your returns policy text
Using the official TypeScript SDK, a tool looks roughly like this:
server.tool(
"get_order_status",
"Look up an order's status. Requires the order ID and the customer's email.",
{ order_id: z.string(), email: z.string().email() },
async ({ order_id, email }) => {
const order = await orders.findForCustomer(order_id, email);
if (!order) {
return { content: [{ type: "text", text: "No order found for that ID and email." }], isError: true };
}
return { content: [{ type: "text", text: JSON.stringify(summarize(order)) }] };
}
);Notice two things. The description is written for the model, so it says what the tool needs. And the result is a trimmed summary, not your whole database row.
Auth and secrets: the model never sees raw keys
This is the part people get wrong first.
Your database credentials, Shopify tokens, or Stripe keys live in the server's environment variables. They never go into tool descriptions, tool arguments, or tool results. The model only sees what you return.
A few habits that help:
- Load secrets from env or a secrets manager at startup
- Scope each key to the minimum it needs (read-only DB user, read-only API token)
- For HTTP servers, require auth on the server itself (OAuth or a bearer token) so random clients can't call it
- Check per-user permissions inside the tool. The order lookup above requires the email to match, so the agent can't fetch anyone's order just by guessing IDs
- Strip sensitive fields (full addresses, payment details) from results unless they're truly needed
Error handling and timeouts agents actually hit
Agents are less patient and less forgiving than humans. These are the failures I see most:
- Slow upstream APIs. Set a timeout on every outbound call, a few seconds is usually right. Return a clear error instead of hanging.
- Bad inputs. The model will sometimes send a malformed ID. Validate with a schema and return a message the model can act on: "order_id should look like #12345."
- Empty results. Say "No products matched 'blue hoodie'" instead of returning an empty array with no context. The model handles words better than silence.
- Huge results. Cap list sizes and paginate. Dumping 500 products into context wastes tokens and confuses the agent.
- Thrown exceptions. Catch them and return
isError: truewith a short explanation. Never leak stack traces or connection strings.
Good error messages are part of your tool's interface. Write them like you're explaining to a new teammate.
The common failure: too many write tools, too early
The temptation is to expose everything: create orders, issue refunds, update stock, send emails. Please don't, at least not on day one.
Start read-only. Let the agent search, look up, and summarize. Watch how it actually uses the tools for a while.
When you do add write tools:
- Make each one narrow (
add_order_note, notupdate_order) - Require confirmation for anything involving money or customers
- Make them idempotent where you can, so a retry doesn't double the action
- Log every call with inputs, user, and outcome
A read-only server that's trusted beats a powerful server nobody dares turn on.
Testing before you wire up an agent
Don't test your server by chatting with an agent. When something goes wrong, you won't know if it's the model, the prompt, or your code.
Test the tools directly first:
- Use the MCP Inspector (
npx @modelcontextprotocol/inspector) to list your tools and call each one by hand - Call every tool with fixed known inputs: a real order, a missing order, a bad ID, an empty search
- Check the outputs are small, readable, and contain no secrets
- Simulate a slow upstream to confirm timeouts work
- Only then connect a real client and try natural questions
Keep those fixed inputs as automated tests. They'll catch regressions every time you change a tool.
Your first MCP server checklist
- Clear reason to use MCP over a plain API
- 3 to 5 well-named tools with model-friendly descriptions
- Input schemas validated on every tool
- Secrets in env only, scoped to minimum access
- Per-user permission checks inside tools
- Timeouts on every external call
- Helpful error and empty-result messages
- Capped, trimmed results
- Read-only to start; write tools added slowly and logged
- Every tool tested with fixed inputs in the Inspector before connecting an agent
That's a first MCP server worth trusting. Small, read-only, well-described, and tested.
If you're thinking about connecting an AI agent to your store, product catalog, or internal tools and want a second pair of eyes on the design, I'm happy to talk it through. You can find me at ahmadraza365.com.


