VOOZH about

URL: https://thenewstack.io/how-to-set-up-a-model-context-protocol-server/

⇱ How To Set Up a Model Context Protocol Server - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2025-05-03 06:00:45
How To Set Up a Model Context Protocol Server
tutorial,
AI / AI Agents / API Management

How To Set Up a Model Context Protocol Server

A tutorial for setting up a Model Context Protocol (MCP) server — the defacto way to communicate between LLM models and developer tools.
May 3rd, 2025 6:00am by David Eastman
👁 Featued image for: How To Set Up a Model Context Protocol Server
Image via Unsplash+. 
In this post we’ll walk through setting up a simple Model Context Protocol (MCP) server. MCP is, for now, the defacto way to communicate between LLM models and developer tools. You can read our deeper developer primer to MCP for more details, but this post doesn’t assume that knowledge. I am going to assume you have installed Claude Code, although I’m just using it as an LLM that sits in the terminal — making it easy to play with. You can still follow along regardless.

Why MCP?

The basic idea is to keep the connection between the AI and the developer tooling separate. In the tool script that I explain below, which is just a Python method sitting in its own local server, all I will do is return a secret word. Of course, what this is doing is using the server to control the context, because LLMs don’t know what exists in your local world, unless you tell them. And of course, we want to make sure we control that ability. Given that Anthropic created MCP, you might think that other LLM suppliers will try their own similar ideas. We know what Microsoft are like with its tendency to extend, embrace and extinguish, but it seems that other suppliers have started to support MCP. Like most connective tissue, MCP will likely get absorbed within other tools over time. So if it becomes truly successful, you will no longer be aware of it.

Know Your Transport

In our developer primer for MCP, we noted the difference between the two protocols — STDIO, which means standard input/output, and SSE (now stream transport), which is more for the web. Our tool is just a simple Command Line Interface (CLI) tool, so it uses this simpler STDIO protocol. By “simple,” we mean running everything locally with no extra dependencies.

Our MCP Server and Tool

First, set up a Python environment in a familiar way. I’m doing this on my MacBook: 👁 Image
We also need to install the MCP libraries: 👁 Image
I’ll call the script server.py. It combines a server and tool:
#!/usr/bin/env python3

from mcp.server.fastmcp import FastMCP
import time
import signal
import sys

# Handle SIGINT (Ctrl+C) gracefully
def signal_handler(sig, frame):
 print("Shutting down server gracefully...")
 sys.exit(0)

signal.signal(signal.SIGINT, signal_handler)

# Create an MCP server with increased timeout
mcp = FastMCP(
 name="secretword",
 host="127.0.0.1",
 port=5000,
 # Add this to make the server more resilient
 timeout=30 # Increase timeout to 30 seconds
)

# Define our tool
@mcp.tool()
def secretword() -> str:
 """Retuen the secret word"""
 try:
 return "ABRACADABRA"
 except Exception as e:
 # Return 0 on any error
 return ""

if __name__ == "__main__":
 try:
 print("Starting MCP server 'secretword' on 127.0.0.1:5000")
 # Use this approach to keep the server running
 mcp.run()
 except Exception as e:
 print(f"Error: {e}")
 # Sleep before exiting to give time for error logs
 time.sleep(5)
A good bit of this is exception handling, so our interest only lies in about 15 lines. We use FastMCP to define what will be a simple server, running on port 5000. We handle a Ctrl-C via the signal handler. Other than that, our tool secretword is just a method that returns the word “ABRACADABRA.” I adapted this from mberman84’s gist. I expect you could do something more substantial, but this proves that you can keep it simple, too. You can test it by running it directly: 👁 Image
Right, stop that and let’s go back to Claude Code and tell it about our fantastic new MCP server. Oh wait, one thing: let’s make sure the server file can be run directly by Claude: 👁 Image

Talking to Claude

Once you’ve installed Claude Code, it should be available in your shell. We will have to somehow inform Claude about my new server and the name of my secret-word tool. First of all, let’s check that Claude recognizes MCP at all: 👁 Image
OK, we can use that advice to add our Python script, since we know it can act as an MCP server: 👁 Image
That’s cool. OK, let’s run Claude (with debugging) and see how we go: 👁 Image
We only have one method, secretword, and it is connected to this. Great. But let’s actually ask Claude to wield our mighty tool: 👁 Image
There we go. This isn’t rock solid, so the debug code in red can help us with problems. Also, they may be reporting issues that don’t effect us.

Conclusion

Most senior developers will recognize that this is still pretty early in the protocol cycle, so there will probably be changes — I noted above that the other protocol, SSE, was deprecated last month. So grok the principles for now; this will likely be absorbed by libraries in the future.
TRENDING STORIES
David has been a London-based professional software developer with Oracle Corp. and British Telecom, and a consultant helping teams work in a more agile fashion. He wrote a book on UI design and has been writing technical articles ever since....
Read more from David Eastman
SHARE THIS STORY
TRENDING STORIES
TNS owner Insight Partners is an investor in: Anthropic.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.