This lesson is locked. Login or Subscribe for more access!

Creating an MCP server with Go

Duration: 6 mins

In this video we'll create a custom Model Context Protocol server with Go and connect it to Cursor.

Instructor

Matt Boyle

Share with a friend!

Transcript

In this video I'm gonna talk to you about the Model Context Protocol. So if you've spent any time on Twitter recently you'll have seen a lot of discussion about building MCP or Model Context Protocol servers.

If you wonder what they are or why they should be interesting and more importantly for us how to build them in Go this is the right video for you.

The key bit to call out is this bit here. I think this does a really good job of describing what it is.

The Model Context Protocol is an open standard that enables developers to build secure two-way connections between their data sources and AI-powered tools.

So imagine while you're vibe coding or you're trying to use something like Cursor and you want to include data from one of your data sources maybe a Postgres database or maybe an API that you own in the reasoning MCP allows us to add those private data collections into consideration.

Now if you go to the documentation for MCP you'll see a lot of examples on how to do it in Python in Node and in Java but there's very little written about how to do this in Go which is what I wanted to overcome.

So what we're gonna do in this video is we're gonna figure out how to build an MCP server in Golang uh how to connect it up to Cursor and how you can use it while you're uh vibe coding.

So firstly I spent a bunch of time looking around the internet and I found this one that I really like which is MCP Golang. I did try some other libraries and I also tried building my own and I think this is a nice balance.

So I'd really recommend using this and it's what we are gonna use in this video. They give a really simple example project to help you get started as well which is actually what we're gonna build on top of.

So on my screen now you can see Cursor what I've done here is I've built a really simple uh tool which is one of the sort of domain language features you need to learn about MCP.

You'll see what tools are in a minute because Cursor actually makes them very easy to understand. But what we do is we use the MCP Golang project to start a new server.

We register a tool. The first one is a really simple one which just says say hello to someone with a personalized message and it just gives you a sprintf response.

The second one is a little bit more interesting. We make a tool where we get the latest Bitcoin price in various currencies and return it to do that we actually make an API call to CoinGecko.

This is a little bit more typical of what I expect to see usage of MCP servers for. It's calling an API it's reading from a database. Both of those things would be possible here.

But as you can see the code is pretty reasonable to understand. You receive a request which is almost like a request to a server which you handle like anything else.

You build up your response and then you respond very similar to dealing with HTTP requests.

Now the more interesting bit is how do we get this set up to work with Cursor. The easiest way I found is to build your binary.

So do go build and then do PWD which will print your working directory. The path to our tool is going to be this working directory slash the name of the binary.

So I'm gonna click this settings cog. Let me just make it a little bit clearer.

This settings cog in the top right corner of Cursor and I'm gonna go down to MCP and you'll see I've already got one configured but if I edit it give it a name there's the path and the name of the binary I just used.

And once you've done that if you click refresh you'll see this green dot appear which means that Cursor has determined your MCP server to be valid.

It also has detected these tools a tool one is called Bitcoin Price and one is called hello and other things that are gonna become available to us now in Cursor.

So what I'm gonna do now is I'm gonna open the chat window and you can see I've been testing it just before this.

Uh but we can say we can copy our previous prompt and we can ask it again say hello to a person with a personalized greeting.

As you can see it goes away and generates but it does consider our MCP server and it actually chooses to use our MCP server in the response.

And this response is actually what comes back from us so this is great. It's actually using our custom thing in its prompt consideration and reply consideration and then the other one we have is the Bitcoin one.

So let's ask this question too and as you can see it called our MCP tool it shows the parameters gets the results and then it gives us more details beyond what we returned as well.

So this is really powerful. Say you had coding guidelines at your company or perhaps you have various compliance requirements you need to meet.

You could see kind of building them into an MCP tool and using them as part of your vibe coding to be able to produce enterprise standard code out of these things because it can consider some business constraints and rules that might be applicable to you.

I can also see people using this to add questions of data as well. Super interesting.

I hope you found this useful. Let me know what you end up building with this.

I'll push my example code but I really hope this helps you figure out how to get it connected up to Cursor and start experimenting with it. You can find the example code in the repository here.