Building a minimal MCP server
A minimal server exposes one narrow capability with predictable arguments and results.
What you will learn
- Explain: host, client and server
- Apply the idea in an example: Building a minimal MCP server
- Recognize limitations and verify the exercise outcome
A minimal server exposes one narrow capability with predictable arguments and results. Start with fictional stock and no writes.
This is a conceptual or external lab. It does not assume the application exposes every control described.
How it works, step by step
Demonstration handler and tests
The demonstration handler below uses only fictional data. For an actual MCP server, register it with your chosen SDK and transport, then test discovery and calls with a compatible client. stdio suits local subprocesses; Streamable HTTP suits remote endpoints. Check compatibility with legacy SSE or newer revisions explicitly.
const stock = new Map([['LX-240', 3], ['P-12', 5], ['A-7', 2]]);
function getProductStock(input) {
if (!input || typeof input.sku !== 'string' || !input.sku.trim())
throw new TypeError('A nonempty sku is required.');
const sku = input.sku.trim();
return stock.has(sku)
? { status: 'found', sku, quantity: stock.get(sku), synthetic: true }
: { status: 'not_found', sku, synthetic: true };
}
console.log(getProductStock({ sku: 'LX-240' }));
// { status: 'found', sku: 'LX-240', quantity: 3, synthetic: true }
The visual map
Follow the solid arrows for the main flow. Dashed blue arrows supply data or context; dashed pink arrows show feedback or returning results. Colors and shapes distinguish models, stores, decisions and outputs. On smaller screens, scroll horizontally to follow the entire diagram.
A complete example
get_product_stock accepts a string sku. LX-240 returns quantity=3; unknown SKU returns not_found rather than zero. A real server also checks catalog permissions.
{"name":"get_product_stock","description":"Read fictional stock; never reserve it","inputSchema":{"type":"object","properties":{"sku":{"type":"string","minLength":1}},"required":["sku"],"additionalProperties":false}}
Try it yourself
- Implement the contract using the fixture and test missing, unknown and valid input.
- Record the input, source and expected outcome before running the experiment. Use only the fictional data in the example.
- Follow the diagram stages. At every step record what information is received and produced; do not confuse intermediate output with the final outcome.
- Repeat after removing necessary information or making the input ambiguous. Check whether the system clarifies, stops or invents an answer.
- Compare with the explained solution. Keep the configuration, date, result and an explanation for differences. Change one thing and retest.
An explained solution
The contract distinguishes found, not found and failure so clients need not guess. A successful exercise lets you show the connection between input, stages and outcome. When information is missing, a cautious answer is more useful than invented details. Compare more than style: check conditions, sources and operations too.
When it helps and what can go wrong
Pin SDK and protocol revision; a contract example is not a complete handshake. Choose this approach when it improves a measured need. Keep a simple baseline and compare outcomes using identical inputs. One successful example does not establish reliability in every situation.
Check your understanding
Does a server with tools automatically offer resources and prompts?
No. Capabilities are optional and must be discovered and checked.
Who executes a call proposed by the model?
The application or host service after validation. The model does not automatically gain unrestricted access.
What outcome should this exercise produce?
The contract distinguishes found, not found and failure so clients need not guess.
Words to remember
- MCP server: A service exposing capabilities through Model Context Protocol.
- Tool calling: A structured request to use an external capability.
- Autorizare / Authorization: Checking the right to access an operation or resource.
Sources and your next step
To prepare: M03 — MCP security and troubleshooting