This repository is a small learning project showing how to build a Model Context Protocol (MCP) server and client in TypeScript.
It includes:
- An MCP server that exposes:
- User data as resources
- Tools to create users (including via an LLM)
- A prompt to generate fake user profiles
- An MCP client (CLI) that connects to the server and lets you explore:
ResourcesToolsPrompts
- TypeScript
- Node.js
- @modelcontextprotocol/sdk
- zod
- tsx
- Node
fs/promisesfor simple JSON-based persistence
src/
server.ts # MCP server (resources, tools, prompts)
client.ts # MCP client (interactive CLI)
data/
users.json # Sample "database" of usersusers.json starts with some sample users and is updated whenever new users are created.
Implemented in src/server.ts:
-
Resources
user–users://all
Returns the full list of users fromsrc/data/users.json.user-details–users://{userId}/profile
AResourceTemplatethat returns details for a user byid, or an error JSON if the user is not found.
-
Tools
create-user
Creates a new user with the fields:nameemailaddressphone
The user is appended tosrc/data/users.json.
create-random-user
Uses MCP’ssampling/createMessageendpoint to ask an LLM for fake user data in JSON, parses it, and saves it tousers.json.
-
Prompt
generate-fake-user
Builds a prompt to generate a fake user profile (email, address, phone) for a given name.
Implemented in src/client.ts:
- Connects to the server using
StdioClientTransport, spawningnpm run server:dev. - On startup, loads:
- Tools
- Prompts
- Resources
- Resource templates
- Shows an interactive menu:
Query(placeholder for custom logic)Tools(list and run tools, prompting for arguments)Resources(read resources and resource templates)Prompts(run server-defined prompts)
git clone <your-repo-url>
cd <your-repo-folder>
npm install(Optional) TypeScript build:
npm run server:buildOr watch mode:
npm run server:build:watchDefined in package.json:
| Script | Command | Description |
|---|---|---|
server:build |
tsc |
Build the server with TypeScript |
server:build:watch |
tsc --watch |
Build and watch for changes |
server:dev |
tsx src/server.ts |
Run the MCP server in dev mode |
server:inspect |
set DANGEROUSLY_OMIT_AUTH=true && npx @modelcontextprotocol/inspector npm run server:dev |
Run MCP Inspector against the dev server |
client:dev |
tsx src/client.ts |
Run the interactive MCP client |
npm run client:devThe client will:
- Start
npm run server:devas a child process. - Connect to the MCP server over stdio.
- Show the menu:
Query,Tools,Resources,Prompts.
npm run server:inspectOnce the client is running:
-
List all users
- Choose
Resources - Select the
Usersresource (users://all) - The client prints the full
users.jsoncontent.
- Choose
-
Get a single user’s details
- Choose
Resources - Select the
User Detailsresource (users://{userId}/profile) - Enter a
userIdsuch as1 - The client prints that user’s data or an error JSON.
- Choose
-
Create a user
- Choose
Tools - Select
Create user - Fill in
name,email,address,phone - A new user is saved to
src/data/users.jsonand the new ID is returned.
- Choose
-
Create a random user via LLM
- Choose
Tools - Select
Create Random User - The server asks the model for fake user data, parses it, and saves it.
- Choose
-
Generate a fake user profile with a prompt
- Choose
Prompts - Select
generate-fake-user - Enter a name (e.g.
Jane Doe) - The prompt text is generated and shown in the CLI.
- Choose
This project is meant as a learning playground for:
- Understanding MCP servers (resources, tools, prompts)
- Building a simple MCP client
- Experimenting with JSON storage and LLM-powered tools
Feel free to extend it with more tools, resources, or real databases as you learn more.