MCP Server with Tool, Resource, Prompt, and Sampling
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP Server with Tool, Resource, Prompt, and Sampling Create a random user"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP Server with Tool, Resource, Prompt, and Sampling
A full-featured Model Context Protocol (MCP) server built with Node.js and TypeScript. This project demonstrates how to implement and integrate the core capabilities of MCP into a single server, communicating over stdio.
π Features
This server showcases the four main pillars of the Model Context Protocol:
Resources (
users://all): Exposes local data to the LLM. It safely reads fromsrc/data/users.jsonusingnode:fsso the LLM can analyze existing user data.Tools (
create-user): Allows the LLM to take action by securely writing new user data to the local file system with strict validation viazod.Sampling (
create-random-user): Demonstrates server-to-client LLM requests. When triggered, the server uses thesampling/createMessageendpoint to ask the client LLM to generate fake user data, parses the response, and automatically saves it.Prompts: Configured to support structured prompt templates that guide the LLM's interactions with the provided tools and resources.
Related MCP server: LocalData MCP Server
π οΈ Prerequisites
Node.js: v20 or higher (Tested on v24)
Package Manager:
yarnornpm
π¦ Installation
Clone the repository and navigate to the directory:
cd mcp-server-samplingInstall dependencies:
yarn install(Ensure @modelcontextprotocol/sdk and zod are installed).
Initialize the data file: Ensure you have an empty or valid JSON array in src/data/users.json:
JSON:ποΈ Build & Run
Because this project uses modern ES Modules (ESM) and is strictly typed, you must build the project before connecting it to an MCP client like VS Code.
Compile the TypeScript code to JavaScript:
Bash yarn build (This outputs the compiled code to the /build directory).
(Optional) Test the server locally using the MCP Inspector:
npx @modelcontextprotocol/inspector node build/server.jsπ VS Code Configuration
To connect this server to VS Code (or Cursor/Claude Desktop), you need to register it in your client's MCP settings.
For VS Code, update your configuration (usually found in your MCP settings file) to point to the compiled server.js file:
{
"mcp.servers": {
"my-mcp-server-sampling": {
"type": "stdio",
"command": "node",
"args": ["${workspaceFolder}/build/server.js"],
"cwd": "${workspaceFolder}"
}
}
}β οΈ Important Troubleshooting Note:
Always remember to run yarn build after making any changes to src/server.ts. VS Code executes the compiled build/server.js file, so if you skip the build step, your changes will not be reflected in the IDE.
π Common Pitfalls Avoided
ESM Imports: All @modelcontextprotocol/sdk imports include the .js extension to comply with strict Node.js ESM resolution.
Stdio Corruption: Uses console.error exclusively for logging to prevent corrupting the JSON-RPC stdout stream used for client-server communication.
Dynamic JSON Loading: Uses node:fs with absolute paths rather than import statements to reliably read users.json both in development (tsx) and production (node).
Available Tools
2 toolscreate-random-userA
Create a random user with fake data
Inputs: no named parameters.
create-userB
Create a new user
Inputs: name (required), email (required), phone (required), address.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogβ¦
TDQS
Scored across 2 tools
Both tools create users, but one creates a specific user and the other creates a random one. Descriptions clearly distinguish them, though the core action is the same.
Both tools follow a consistent verb_noun snake_case pattern: create-user and create-random-user.
With only 2 tools focused solely on user creation, the count is too low for a server that also advertises resources, prompts, and sampling capabilities.
The tools only cover creation (specific and random) but lack essential user management operations like reading, updating, deleting, or listing users.
Related MCP Connectors
Per-user memory, connected accounts, permitted actions and the action record for your agents.
Persistent identity, email, saved accounts and scoped credentials for AI agents.
Universal persistent memory and knowledge retrieval layer for AI agents and LLMs.
Memory, reflection and safety for AI agents. Hosted or local, no vector database.
Related MCP Servers
- FlicenseNot gradedqualityNot gradedmaintenanceEnables AI assistants to access and manage user profile information including name, company, location, role, interests, and skills. Supports both static configuration files and dynamic session-based storage with automatic date context.-
- AlicenseNot gradedqualityCmaintenanceGives LLM agents access to local and remote data via databases, files, graphs, and structured documents, along with a full data science toolkit for analysis and modeling.15Apache 2.0
- AlicenseNot gradedqualityDmaintenanceEnables AI agents with long-term memory and retrieval-augmented generation (RAG) capabilities, allowing them to recall past conversations, search local files, and learn user preferences.MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI assistants to persist and retrieve user information across chats via a local knowledge graph with entities, relations, and observations, using a SQLite-backed MCP interface.3 npmApache 2.0