MCP Servers: What, Why and How?
Building our first MCP server in 5 easy steps | A practical introduction for network engineers
Introduction
With the rise of Agentic AI, one of the terms we are increasingly coming across is MCP (Model Context Protocol). However, before we delve into how to create an MCP server, I think it is important to understand why we actually need one in the first place.
Those of us who have developed AI agents using frameworks such as LangChain would know that we can already make our Python functions available to an LLM as tools. So why introduce another component into our architecture? What exactly does an MCP server achieve that we couldn’t achieve previously?
In this article, I want to address the what, the why and the how. We will then create a relatively simple MCP server using Visual Studio Code and establish how we can test it independently of an LLM.
The What – What is an MCP server?
MCP stands for Model Context Protocol. It is an open protocol, originally introduced by Anthropic, that provides a common mechanism for applications to discover and access external capabilities and information.
An MCP server is simply an application that exposes some of those capabilities through the MCP protocol. It does not have to contain any AI whatsoever. In fact, our server in this lab will have no LLM, GPU or AI framework.
| Capability | What it provides | Network example |
|---|---|---|
| Tools | Functions that can be invoked | Retrieve BGP neighbours |
| Resources | Contextual information | Network design documentation |
| Prompts | Reusable prompt templates | Troubleshooting template |
For this particular article we will focus on tools. The MCP server exposes the tool, executes the underlying automation when requested and returns the result. The MCP client is the component that communicates with the server; the host is the application containing the client, such as an AI assistant.
The Why – Why do we need one?
Imagine we have developed a network automation framework over the years that can retrieve interface information, routing tables, BGP neighbour status and firewall policies. Now we want to utilise these existing capabilities within an AI agent.
We could make the functions available directly to an LLM using LangChain. For example, assuming our model and functions are already defined:

VS Code — direct tool binding with LangChain. This standalone example assumes the model and functions already exist.
llm_with_tools = llm.bind_tools([
get_interfaces,
get_bgp_peers,
get_routing_table
])
There is absolutely nothing wrong with this approach. One important distinction, however, is that the LLM is not actually executing our Python code. We provide it with a description of each tool and the parameters it requires. The model can then request a tool call, but it is the application that executes the function and passes the result back to the model.
Imagine our requirements change. We now have several AI applications developed by different teams, potentially using different frameworks and programming languages. How do we make the same network automation capabilities available to all of them? We could share a Python package or develop REST APIs, but each application still needs an appropriate integration and a way of describing those tools to its model.
This is where MCP becomes particularly interesting. Rather than tightly coupling our automation functions to a particular AI application, we can expose them through a standardised protocol. A compatible MCP client can discover the available tools, their descriptions and required parameters, invoke them and retrieve the results.
From a network engineering perspective, the principle is not entirely new. Think of SNMP and the value of having a standard protocol for retrieving information from different vendors. MCP addresses a different problem, but the principle of standardisation is somewhat similar.

Figure 1 – Application-specific integration compared with a shared MCP interface. Multiple remote clients require a suitable transport, such as Streamable HTTP.
MCP is not a replacement for function calling, nor is it a replacement for REST APIs. Our MCP server might even call an existing REST API. If we are developing a small standalone agent, directly integrating the tools might be perfectly adequate. MCP becomes useful when we want a common interface and reusable capabilities across applications.
What happens when we ask an AI agent a question?
Imagine asking: “What is the BGP neighbour status on Leaf-01?” The host discovers the tool through its MCP client and presents the relevant tool definition to the LLM. The LLM requests get_bgp_peers with Leaf-01 as an argument. The host sends the request via MCP, the server invokes our automation, and the returned information is passed to the LLM to formulate the response.
Notice that the LLM has not established an SSH connection to the switch. Our network automation framework is still responsible for performing that operation.
The How – Building our first MCP server
As with any automation solution, I always like to start with the requirements. We want to accept an IPv4 address in CIDR notation and return its network address, subnet mask, broadcast address and total number of addresses. We then want a separate MCP client to discover and execute that capability.
I have deliberately selected a simple subnet calculation so we can focus on MCP rather than the complexities of connecting to network infrastructure.
Step 1 – Prepare our VS Code environment
Prerequisites: Ubuntu, Visual Studio Code with the Python extension, Python 3.11 or later with venv and pip, and a supported Node.js release with npm/npx. Inspector v2 requires Node 22.23.4+ within 22.x, 24.22.1+ within 24.x, or 26.12.1+. Internet connectivity is needed for the initial package installations. No model or API key is required.
From the Ubuntu terminal, create our project and open it in VS Code:
mkdir network-mcp
cd network-mcp
code .
In VS Code, select Terminal → New Terminal. Run the following commands in the integrated terminal:
python3 -m venv .venv
source .venv/bin/activate
python -m pip install “mcp[cli]>=2,<3”
python –version
mcp version
node –version
npx –version

VS Code integrated terminal — checking Python, the MCP SDK, Node.js and npx in the activated environment.
We are using the official MCP Python SDK v2 (MCPServer). If following an older v1 tutorial, you may see FastMCP instead. Do not mix the two versions. In VS Code, press Ctrl+Shift+P, select Python: Select Interpreter and choose .venv/bin/python.
In the Explorer panel, create the three Python files below using New File. Keep them in the project root, not inside .venv.
network-mcp/
.venv/
network_tools.py
test_function.py
server.py
Step 2 – Create and test the Python function
Open network_tools.py in the VS Code editor, paste the following code and save it using Ctrl+S.

VS Code — network_tools.py calculates the four subnet values using Python’s ipaddress module.
import ipaddress
def get_subnet(cidr: str) -> dict:
“””Calculate IPv4 subnet information.”””
network = ipaddress.IPv4Network(cidr, strict=False)
return {
“network”: str(network),
“subnet_mask”: str(network.netmask),
“broadcast”: str(network.broadcast_address),
“total_addresses”: network.num_addresses,
}
We are using Python’s built-in ipaddress library. The strict=False parameter allows us to supply a host address and have Python calculate the network it belongs to. At this point, there is no MCP functionality whatsoever.
Before introducing MCP, let us validate the underlying Python function. Open test_function.py, paste the following code and save it.

VS Code — test_function.py checks the returned dictionary against the expected /24 values.
import json
from network_tools import get_subnet
result = get_subnet(“192.168.10.50/24”)
print(json.dumps(result, indent=4))
assert result == {
“network”: “192.168.10.0/24”,
“subnet_mask”: “255.255.255.0”,
“broadcast”: “192.168.10.255”,
“total_addresses”: 256,
}
print(“PASS: Subnet calculation is correct.”)
From our VS Code integrated terminal, run:
python test_function.py

Figure 2 – VS Code integrated terminal showing the four returned values and the passing assertion.
The assert statement compares the returned dictionary against the expected result. A successful assertion prints PASS. This confirms the calculation for our /24 test case. The total of 256 includes the network and broadcast addresses; it is not a count of usable host addresses.
Step 3 – Expose the function through MCP
Open server.py in VS Code, paste the following code and save it.

VS Code — server.py registers calculate_subnet with the Network Automation server.
from mcp.server import MCPServer
from network_tools import get_subnet
mcp = MCPServer(“Network Automation”)
@mcp.tool()
def calculate_subnet(cidr: str) -> dict:
“””Calculate IPv4 subnet information.”””
return get_subnet(cidr)
if __name__ == “__main__”:
mcp.run(transport=”stdio”)
Let us look at precisely what we have introduced. MCPServer creates the server instance. The @mcp.tool() decorator registers calculate_subnet as an MCP tool. Its name, docstring and type hint describe what the tool does and its required argument. The wrapper invokes our original get_subnet function and returns its result. Finally, mcp.run starts the server using STDIO.
Notice that we have not modified the original Python function at all. We have simply established a standardised mechanism through which another application can discover and execute it.
Step 4 – Connect to the MCP server using Inspector
We could develop an AI agent at this point, but if something fails, how do we establish whether the problem resides within the Python function, the MCP server or the AI application? We have already tested the function. Now we want to test the MCP implementation independently.
The MCP Inspector is a testing utility for MCP servers. Those of us who have previously utilised Postman to test REST APIs will be familiar with the concept. We can use Inspector to discover and execute tools without developing an AI agent.
From the VS Code integrated terminal, with our virtual environment activated, run:
npx -y @modelcontextprotocol/inspector
“$PWD/.venv/bin/python” “$PWD/server.py”

VS Code integrated terminal — the Inspector launch command before pressing Enter.
Open the local URL displayed in the terminal. Keep the terminal running and keep the Inspector local to your machine. The Inspector should launch the server as a subprocess. If the connection is not already established, select the server entry and connect; check the settings below if prompted.
| Setting | Value |
|---|---|
| Transport | STDIO |
| Command | Absolute path to network-mcp/.venv/bin/python |
| Arguments | Absolute path to network-mcp/server.py |

MCP Inspector — the green Connected indicator confirms the STDIO connection to Network Automation.
STDIO means the client and server exchange protocol messages through standard input and output streams. There is no need to configure a listening TCP port on our MCP server. The Inspector itself uses a local web interface. Do not add print statements to the server’s standard output, as that is reserved for protocol messages.
Step 5 – Discover, execute and validate our MCP tool
We will validate four aspects of the server. The screenshots below show the live session in MCP Inspector 2.17.0.
Test 1 – Tool discovery
In Inspector v2, select the connected server, navigate to Tools and refresh the list if necessary. Select calculate_subnet. We expect to see the following tool definition (simplified):

MCP Inspector — selecting calculate_subnet reveals its description and required Cidr field.
{
“name”: “calculate_subnet”,
“description”: “Calculate IPv4 subnet information.”,
“inputSchema”: {
“type”: “object”,
“properties”: {“cidr”: {“type”: “string”}},
“required”: [“cidr”]
}
}
Pass criteria: the tool is discoverable, with cidr as a required string. The client has obtained this information without having to import our Python source code.
Test 2 – Execute the MCP tool
Select calculate_subnet, enter 192.168.10.50/24 into the cidr field and select Execute Tool (called Run Tool in some versions). Inspect the returned data. The expected payload is:

MCP Inspector — 192.168.10.50/24 returns network 192.168.10.0/24 and 256 total addresses.
{
“network”: “192.168.10.0/24”,
“subnet_mask”: “255.255.255.0”,
“broadcast”: “192.168.10.255”,
“total_addresses”: 256
}
Pass criteria: the values match the output of our Python test. The Inspector may wrap the data in a content or structuredContent response. This validates that the request reaches the MCP server, the function executes and its results reach the client.
Test 3 – Supply a different input
Change cidr to 10.10.20.35/27 and run the tool again. The expected result is:

MCP Inspector — 10.10.20.35/27 returns network 10.10.20.32/27 and broadcast 10.10.20.63.
{
“network”: “10.10.20.32/27”,
“subnet_mask”: “255.255.255.224”,
“broadcast”: “10.10.20.63”,
“total_addresses”: 32
}
Pass criteria: all four values match. This demonstrates that our function processes different parameters dynamically rather than returning a static result.
Test 4 – Supply invalid input
Enter 192.168.10.50/33 and execute the tool. IPv4 prefixes cannot exceed 32 bits. Inspector reports “Error executing tool calculate_subnet”. Calling the Python function directly shows the underlying exception:

MCP Inspector — submitting 192.168.10.50/33 produces a Tool Error.
NetmaskValueError: ’33’ is not a valid netmask
Pass criteria: invalid input is rejected. We cannot simply assume that an LLM will always provide valid parameters.
Optional – Testing directly from VS Code
We can also test our MCP server directly from a second VS Code terminal. The Inspector CLI is particularly useful if we later want to incorporate testing into our automation pipelines.
Discover the tools:
npx -y @modelcontextprotocol/inspector –cli
“$PWD/.venv/bin/python” “$PWD/server.py”
–method tools/list
Invoke the tool with the same /24 input:
npx -y @modelcontextprotocol/inspector –cli
“$PWD/.venv/bin/python” “$PWD/server.py”
–method tools/call –tool-name calculate_subnet
–tool-arg cidr=192.168.10.50/24

VS Code integrated terminal — the installed Inspector CLI returns the /24 result with isError set to false.
The first command should return the tool definition and the second should return the same subnet information as the graphical Inspector test.
Summary of our testing
| Test | Pass criteria | Evidence |
|---|---|---|
| Python /24 | Correct four values; assertion passes | Executed; PASS |
| Python /27 | Correct four values | Executed; correct |
| Python /33 | Invalid prefix rejected | Executed; error |
| MCP connectivity | Connection established | Connected over STDIO |
| MCP discovery | Tool and input schema returned | calculate_subnet listed with required string cidr |
| MCP execution | Correct /24 and /27 values | Both results verified in Inspector |
| MCP error handling | /33 rejected | Inspector returned Tool Error |
Lab verification — The editor and terminal screenshots were captured in Microsoft Visual Studio Code for the Web on Linux. MCP Inspector 2.17.0 connected over STDIO to the article’s server using Python 3.12.14 and MCP SDK 2.3.0. Both valid inputs returned the expected four values, and the invalid /33 produced a tool error.
What have we actually achieved?
Once the MCP tests pass, we will have demonstrated that an ordinary Python function can be exposed through a standardised protocol, discovered and executed by an independent MCP client. We can then apply exactly the same concept to more sophisticated automation capabilities, such as retrieving OMP routes, BGP neighbours, interface information or firewall policies.
Furthermore, there is no requirement for all our existing automation to be written in Python. The MCP tool could invoke PowerShell, Bash, Ansible or an external API. If we wanted multiple remote applications to utilise the same server, we could deploy it with Streamable HTTP and appropriate authentication, authorisation and access controls. MCP itself does not automatically secure our automation framework.
Conclusion
I think one of the most interesting aspects of MCP is not necessarily its association with AI, but rather the architectural principles behind it. The concept of decoupling applications, standardising communication mechanisms and developing reusable capabilities is certainly nothing new to us as network engineers.
We do not necessarily need to redevelop our existing automation capabilities simply because we want to introduce AI. We can extend the value of what we have already developed by exposing those capabilities through a standardised protocol.
Network automation is a creative innovation, and sometimes the process of introducing new technologies into our existing frameworks requires creativity in itself. Sometimes innovation isn’t about reinventing what we already have, but finding new ways of utilising it.
References
Model Context Protocol: https://modelcontextprotocol.io/
Official Python SDK v2: https://py.sdk.modelcontextprotocol.io/v2/
MCP Inspector: https://github.com/modelcontextprotocol/inspector
Inspector CLI: https://github.com/modelcontextprotocol/inspector/tree/main/clients/cli
Inspector v2 interface specification: https://github.com/modelcontextprotocol/inspector/blob/main/specification/v2_ux.md




Leave a Reply