Get Your First MCP Server Running
This guide will walk you through setting up, building, and testing your first MCP server. We’ll use the TypeScript Game of Thrones quotes server as our example, but you can follow similar steps for Python or Go.By the end of this guide, you’ll have a working MCP server that can fetch quotes, perform calculations, and respond to prompts.
Prerequisites
Before you begin, make sure you have:Node.js
Version 18 or higher for TypeScript examples
Python
Version 3.10 or higher for Python examples
Git
To clone the course repository
Code Editor
VS Code, Cursor, or your preferred editor
Step-by-Step Tutorial
Clone the Repository
First, clone the MCP Course repository to get access to all the example code:The repository structure looks like this:
Navigate to the Server Directory
Let’s start with the TypeScript server that includes multiple features:Take a look at the The key dependency is
package.json to see the dependencies:@modelcontextprotocol/sdk, which provides all the MCP functionality.Install Dependencies
Install the required packages:This will install:
- The official MCP SDK for TypeScript
- Zod for schema validation
- Node-fetch for API calls
- TypeScript compiler
Build the Server
Compile the TypeScript code to JavaScript:This creates a If the build succeeds, you’re ready to run the server!
dist/ directory with the compiled JavaScript files. You should see output like:Understand the Server Code
Before running the server, let’s look at what it does. Open This server exposes:
src/server.ts:- 2 Tools:
get_random_quotesandlcm(least common multiple) - 2 Resources: Random quotes and person properties
- 2 Prompts: Game of Thrones analysis and code review
Run the Server
Start the MCP server:The server is now running and waiting for connections via stdio (standard input/output).To test the server, you’ll need to connect a client. Keep this terminal open and open a new one for the next step.
MCP servers typically communicate through stdio, which means they don’t print anything to the console. They’re waiting for a client to connect and send requests.
Connect a Client
In a new terminal, navigate to the TypeScript client:The client code shows how to connect to the server:
Client Connection
Try Other Examples
Now that you have the basic server running, try the other examples:Python Calculator Server
The Python example uses FastMCP for a simpler API:Python Server Example
What’s Next?
Now that you have a working MCP server, you can:Learn the Protocol
Understand how MCP works under the hood
Build Custom Tools
Create your own tools for specific use cases
Explore Examples
Deep dive into the server implementations
Integrate with LLMs
Connect your server to Ollama or Claude
Troubleshooting
Server doesn't start
Server doesn't start
Check Node.js version: Make sure you’re using Node.js 18 or higherCheck TypeScript compilation: Look for errors in the build stepVerify dependencies: Reinstall packages if needed
Client can't connect
Client can't connect
Update the server path: Make sure the client points to the correct server locationIn Check server is running: The server must be compiled and the path must exist
clients/basic-ts/src/index.ts, update:Import errors in TypeScript
Import errors in TypeScript
Check package.json type: Make sure This is required for ES modules in TypeScript.
"type": "module" is setUse .js extensions: Import statements need .js even for TypeScript files:Python import errors
Python import errors
Install MCP SDK: Make sure the package is installedCheck Python version: Use Python 3.10 or higherUse virtual environment: Recommended for isolation