About MCP Server-Client Example
MCP Server-Client Example is a TypeScript SDK example for developers learning a basic MCP server and client. It demonstrates stdio communication and resource listing and reading.
Key features
- 01TypeScript MCP server and client
- 02Connect over stdio transport
- 03List available resources
- 04Read resource contents
- 05Handle unknown-resource errors
Use cases
- 01Learn basic MCP server-client communication
- 02Test resource listing and reading
- 03Use as a starting point for adding resources
MCP support
Includes an MCP server exposing a text resource and a client that connects over stdio to list and read it.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEMCP Server-Client Example
This project demonstrates a basic implementation of the Model Context Protocol (MCP) using the TypeScript SDK. It includes both a server and client implementation that communicate over stdio transport.
Overview
The example includes:
- An MCP server that provides access to resources
- An MCP client that connects to the server and requests resources
- Basic resource listing and reading functionality
Prerequisites
- Node.js (v16 or higher)
- npm
Installation
Clone the repository and install dependencies:
npm install
Project Structure
src/
├── index.ts # Server implementation
└── client.ts # Client implementation
Running the Example
You'll need to run the server and client in separate terminal windows.
- Start the server:
npm run start:server
- In a new terminal, start the client:
npm run start:client
The client will:
- Connect to the server
- Request a list of available resources
- Read the content of an example resource
Server Capabilities
The server currently supports:
- Resource listing
- Resource reading
- Basic error handling for unknown resources
Available Resources
The example server provides access to:
file:///example.txt: A simple text resource
Development
Scripts
npm run start:server: Starts the MCP servernpm run start:client: Starts the MCP client
Adding New Resources
To add new resources, modify the ListResourcesRequestSchema handler in src/index.ts:
server.setRequestHandler(ListResourcesRequestSchema, async () => {
return {
resources: [
{
uri: "file:///example.txt",
name: "Example Resource",
},
// Add new resources here
],
};
});
Dependencies
@modelcontextprotocol/sdk: MCP TypeScript SDKts-node: TypeScript execution environmenttypescript: TypeScript compiler
License
ISC
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.