In a previous post I talked about MCP and how to use it to integrate with LLMs. In this post I want to talk about how to use MCP to integrate with Peering DB. I am being honest here, this all really opens up a lot of power possibilities and I am barely scratching the surface of what is possible.
What is Peering DB?
Peering DB is a free and open-source database of network operators and their associated networks. It is a community-driven project that aims to provide accurate and up-to-date information about the internet’s infrastructure.
What is MCP?
MCP is a protocol that allows you to integrate your data with LLMs. It is a way to standardize how you provide data to LLMs, making it easier to integrate with different LLMs and tools.
How to use MCP to integrate with Peering DB
I remember when I was working at a Service Provider, I was always wondering information about a particular network and like most good Network Engineers, I would just go to Peering DB and search for the network. This is a great tool, but who want to go around and search for networks? I know I don’t.
Fast forward to today, MCP may have just made this a lot easier.
Our Use Case
I simply want to see what ASN has peering capablities within my network. Pretty trivial right?
In this example I want to peer with AS46489
and I am coming from ASN19108
. Lets build a simple MCP server that will give me this information. I want to make it pretty clear that this is a simple example and there is a lot more that can be done.
This code implements a service that queries the PeeringDB API to find Internet Exchange (IX) locations for any given Autonomous System Number (ASN). Let’s dive into how it works and what makes it interesting.
Understanding the Core Structures In Our MCP Server
The code begins by defining several important data structures that mirror PeeringDB’s API responses:
type NetResponse struct {
Data []Network `json:"data"`
}
type Network struct {
ID int `json:"id"`
Name string `json:"name"`
ASN int `json:"asn"`
}
These structures are crucial as they map directly to the JSON responses from PeeringDB’s API. The use of struct tags (json:"field"
) tells Go’s JSON decoder how to map the incoming data to our structures.
The Main Server Setup
The heart of the application lies in the main()
function, which sets up an MCP (Model Control Protocol) server. Nothing too fancy here.
s := server.NewMCPServer(
"PeeringDB Location Server",
"1.0.0",
server.WithPromptCapabilities(true),
)
What’s particularly clever here is the implementation of a tool system. The code registers a single tool called “get_peering_locations” that accepts an ASN parameter:
locationsTool := mcp.NewTool("get_peering_locations",
mcp.WithDescription("Get IX locations for an ASN"),
mcp.WithNumber("asn",
mcp.Required(),
mcp.Description("Autonomous System Number"),
),
)
As more tools are added, this will become more and more powerful. These get registered with the MCP server and then can be used in the same way as the get_peering_locations
tool and should feel very idiomatic to use thanks to github.com/mark3labs/mcp-go/mcp.
The Core Logic: Finding Peering Locations
The most interesting part in our code is that it handles the actual querying of peering locations. It’s implemented as a two-step process:
- First, it converts an ASN to a network ID using
getNetworkID()
:
func getNetworkID(asn int) (int, error) {
url := fmt.Sprintf("https://api.peeringdb.com/api/net?asn=%d", asn)
// ... API call and response processing ...
}
- Then, it uses that network ID to fetch all peering locations using
getPeeringLocations()
:
func getPeeringLocations(netID int) ([]Netixlan, error) {
url := fmt.Sprintf("https://api.peeringdb.com/api/netixlan?net_id=%d", netID)
// ... API call and response processing ...
}
The “Handler”: Where It All Comes Together
The getPeeringLocationsHandler
function is where everything comes together. It includes several smart features:
- Type assertion and validation of the ASN parameter
- Error handling at each step
response.WriteString(fmt.Sprintf("%d. %s\n 📍 %s\n Status: %s\n\n",
i+1,
loc.IXName,
loc.City,
status))
Building the MCP Server
Just as we did before you will need to build the MCP server.
go build -o /tmp/peering-db-mcp main.go
And then you will need to add the MCP server to your Claude Desktop config file.
{
"mcpServers": {
"peering-db-mcp": {
"command": "/tmp/peering-db-mcp"
}
}
}
In Action
Source Code: https://github.com/metajar/peeringdb-mcp