Learn how to implement MCP server and client in TypeScript for resource access and communication
The Model Context Protocol (MCP) is a universal adapter designed to enable AI applications such as Claude Desktop, Continue, Cursor, and more to connect to specific data sources and tools through a standardized protocol. This MCP server implementation showcases how it is possible to build an MCP server from scratch using the TypeScript SDK, demonstrating both its core integration value and technical intricacies.
The Model Context Protocol (MCP) server included in this example project provides essential functionalities that are critical for seamless AI application integration. These features include:
file:///example.txt
, allowing AI clients to discover what they can access.graph TD
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[MCP Server]
C --> D[Data Source/Tool]
style A fill:#e1f5fe
style C fill:#f3e5f5
style D fill:#e8f5e8
The following table outlines the MCP client compatibility matrix, detailing which AI applications are supported by this server:
MCP Client | Resources | Tools | Prompts | Status |
---|---|---|---|---|
Claude Desktop | ✔️ | ✔️ | ✔️ | Full Support |
Continue | ✔️ | ✔️ | ✔️ | Full Support |
Cursor | ❌ | ✔️ | ❌ | Tools Only |
To set up and run the example MCP server, follow these installation steps:
Clone the repository:
git clone https://github.com/example/mcp-server-example.git
Install dependencies:
npm install
Run the server and client in separate terminal windows.
npm run start:server
In a new terminal window:
npm run start:client
The client will perform actions such as connecting to the server, requesting resources, and reading content based on the provided protocols.
In this workflow, an AI application like Continue could use the MCP server example to access a variety of data sources, such as CSV files or images stored in a local directory. This allows the training models used by Continue to gather diverse and relevant datasets without requiring custom integration code.
Claude Desktop might leverage this MCP server setup to enable its users to request specific types of content generation, such as summaries, translations, or analysis. The server could contain logic to handle these requests efficiently, ensuring that Claude Desktop can provide more contextual and relevant responses to user queries.
The provided example features a basic implementation that can be extended to support various AI clients through MCP. By configuring the "mcpServers"
section in the server’s settings, developers can integrate different clients according to their specific needs:
{
"mcpServers": {
"[server-name]": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-[name]"],
"env": {
"API_KEY": "your-api-key"
}
}
}
}
This configuration allows the server to recognize and handle incoming requests from various clients, ensuring that all interactions conform to standardized protocols.
The performance of this MCP server is optimized for real-time data exchanges, making it suitable for scenarios where quick response times are essential. The compatibility matrix provided earlier ensures that multiple AI applications can be seamlessly integrated into the system, expanding its utility across different domains and use cases.
Advanced configurations include options to customize error handling, security measures, and resource access permissions. For instance:
server.setErrorHandler((error) => {
console.error("Error occurred:", error);
});
This custom handler ensures that any unexpected issues can be promptly logged or handled by the server, enhancing overall reliability.
Q: Can this MCP server support multiple clients simultaneously?
Q: How can I secure the server configuration?
Q: Can I modify resource listing functionality easily?
ListResourcesRequestSchema
handler in src/index.ts
, you can add or remove resources as needed to fit your application's requirements.Q: Is there any sample code for advanced configuration?
Q: How do I test client compatibility with this MCP server?
To contribute to or extend this project, please follow these guidelines:
The wider MCP ecosystem includes various tools and resources that can be leveraged with this server example. Developers are encouraged to explore these additional options:
By understanding and utilizing the capabilities of the Model Context Protocol (MCP) server example, AI application developers can create more versatile and interoperable systems.
Learn to connect to MCP servers over HTTP with Python SDK using SSE for efficient protocol communication
Next-generation MCP server enhances documentation analysis with AI-powered neural processing and multi-language support
Analyze search intent with MCP API for SEO insights and keyword categorization
Python MCP client for testing servers avoid message limits and customize with API key
Learn how to use MCProto Ruby gem to create and chain MCP servers for custom solutions
AI Vision MCP Server offers AI-powered visual analysis, screenshots, and report generation for MCP-compatible AI assistants