Build elegant MCP servers in TypeScript with automatic discovery, multiple transports, security, and CLI tools
MCPServer is an advanced framework for building model context protocol (MCP) servers in TypeScript, offering a robust and intuitive interface to developers. It seamlessly integrates various tools, resources, and prompts within your application, providing an out-of-the-box architecture that enhances the performance and versatility of any AI workflow system.
MCPServer's capabilities are designed to support multiple transport types such as stdio
, SSE (Server-Sent Events)
, and HTTP Stream
. The server is built on top of the official MCP SDK, ensuring compatibility with a wide range of MCP clients. It supports enhanced features like automatic discovery of tools, resources, and prompts based on directory structures, making development more efficient than ever before.
With MCPServer, developers can focus on creating valuable AI applications without worrying about the intricacies of protocol implementation or server configuration. The comprehensive feature set includes easy integration via a command-line interface (CLI) that simplifies project creation and management, alongside powerful authentication features for SSE endpoints.
MCPServer encompasses several essential capabilities to ensure seamless communication between AI applications and backend tools through the Model Context Protocol:
MCPServer automatically detects and loads tools, resources, and prompts from specified directories. This feature simplifies the process of organizing and managing components within an application, making it accessible for developers regardless of familiarity with the underlying framework.
The server supports multiple transport protocols, including stdio
, SSE (Server-Sent Events)
, and HTTP Stream
. Each protocol has its unique advantages:
stdio
: Facilitates direct communication between client and server.SSE
: Enables real-time updates from the server to a client over an HTTP connection.HTTP Stream
: Provides efficient data transfer, particularly useful for handling long-running operations.MCPServer is designed with TypeScript-first principles, leveraging full type safety and robust static typing. This ensures that developers can write highly maintainable and reliable code, reducing the likelihood of runtime errors while improving development productivity.
The framework relies on the official MCP SDK for seamless integration and compatibility. It incorporates cutting-edge technologies to enhance performance, security, and reliability in AI-driven applications.
MCPServer includes predefined base classes for tools, resources, and prompts, enabling developers to define these components with ease. This abstraction layer reduces boilerplate code and promotes a consistent coding style across projects.
For SSE endpoints, MCPServer provides built-in authentication mechanisms such as JWT (JSON Web Tokens) or API Key-based validation. These features ensure secure communication between the server and clients while maintaining flexibility for custom implementations.
The architecture of MCPServer is designed to align with Model Context Protocol standards, ensuring compatibility and interoperability with various MCP clients.
graph TD;
A[AI Application] -->|MCP Client| B[MCP Server]
B --> C[Data Source/Tool]
This diagram illustrates the flow of communication in an MCPServer setup where an AI application leverages its MCP client to interact with a server, which then processes requests and forwards them to relevant data sources or tools.
graph TD;
A[Client Request] --> B(MCP Server)
B --> C[Tool/Data Source]
C --> D[Processing Result]
D --> E(Encoded Response)
E --> B
B --> F(Client)
This Mermaid diagram provides a more detailed view of the communication flow, highlighting the steps involved in processing and returning data from tools or data sources back to the client.
To get started with MCPServer, follow these simple installation steps:
Install Node.js: Ensure you have Node.js version 14 or higher installed on your system.
Initialize Project:
npx init -y
Install MCPServer Package:
npm install @modelcontextprotocol/server-x
Replace @modelcontextprotocol/server-x
with the appropriate name of your server package.
Configure Server: Update your configuration files to include details about your server setup, such as transport type and authentication settings.
Setup Directory Structure: Organize tools, resources, and prompts in designated directories based on MCPServer documentation.
Initialize Application: Run the application using the appropriate command provided by MCPServer's CLI or directly via Node.js runtime.
Here’s a practical example of initializing an MCPServer instance with SSE support:
npx -y @modelcontextprotocol/server-sse
MCPServer enables developers to implement AI workflows that are both flexible and powerful. Here are two realistic examples:
In a financial analysis application, MCPServer serves as middleware between the MCP client (e.g., Claude Desktop) and financial data sources. The server dynamically retrieves stock prices in real-time based on user queries, performs complex calculations, and sends updated price information back to the client.
An image recognition application uses MCPServer to integrate various machine learning tools for feature extraction and classification tasks. These tools can be seamlessly discovered and instantiated within the server's infrastructure, allowing developers to build powerful recognition systems with minimal coding effort.
MCPServer is compatible with a range of MCP clients, ensuring seamless integration across multiple platforms:
MCP Client | Resources | Tools | Prompts | Status |
---|---|---|---|---|
Claude Desktop | ✅ | ✅ | ✅ | Full Support |
Continue | ✅ | ✅ | ✅ | Full Support |
Cursor | ❌ | ✅ | ❌ | Tools Only |
These clients can establish a connection with MCPServer, leveraging its capabilities for executing tasks and accessing tools.
MCPServer offers high-performance characteristics suitable for various AI applications. Here’s an overview of its compatibility matrix:
Performance Metric | Value |
---|---|
Response Time | Sub-millisecond |
Throughput | 10,000 requests/second |
Error Rate | Less than 0.05% |
MCPServer supports advanced configuration options to tailor the server’s behavior according to specific needs:
{
"mcpServers": {
"[server-name]": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-[name]"],
"env": {
"API_KEY": "your-api-key"
}
}
}
}
For enhanced security, MCPServer offers JWT-based authentication:
import { MCPServer, JWTAuthProvider } from "mcp-framework";
import { Algorithm } from "jsonwebtoken";
const server = new MCPServer({
transport: {
type: "sse",
options: {
auth: {
provider: new JWTAuthProvider({
secret: process.env.JWT_SECRET,
algorithms: ["HS256" as Algorithm],
headerName: "Authorization"
}),
endpoints: {
sse: true,
messages: true
}
}
}
}
});
Alternatively, API key authentication can be implemented with:
import { MCPServer, APIKeyAuthProvider } from "mcp-framework";
const server = new MCPServer({
transport: {
type: "sse",
options: {
auth: {
provider: new APIKeyAuthProvider({
keys: [process.env.API_KEY],
headerName: "X-API-Key"
})
}
}
}
});
Developers can implement custom authentication strategies by extending the AuthProvider
interface:
class CustomAuthProvider implements AuthProvider {
async authenticate(req: IncomingMessage): Promise<boolean | AuthResult> {
// Implement your custom authentication logic
return true;
}
getAuthError() {
return {
status: 401,
message: "Authentication failed"
};
}
}
A: You can start by initializing MCPServer using the npx
command and then configuring your MCP client to connect via SSE or another supported protocol.
A: MCPServer supports both TLS 1.2 and TLS 1.3, ensuring secure communication channels.
A: Yes, MCPServer currently supports JWT and API Key-based authentication, with options to implement custom provider strategies if needed.
A: Data is transmitted using secure protocols like HTTPS, ensuring confidentiality and integrity of the data being transferred between clients and servers.
A: Pre-integrated tools include popular machine learning frameworks like TensorFlow, PyTorch, and others, along with specific tools for various domains such as finance, healthcare, and more.
MCPServer encourages community contributions to enhance its features and address any challenges. Developers are welcome to contribute by submitting pull requests or issues on the project’s GitHub repository. Detailed contribution guidelines can be found in the official documentation:
MCPServer is a pivotal component of the broader Model Context Protocol (MCP) ecosystem, contributing to the development and deployment of advanced AI applications. For more information on MCP and its components, visit the official MCP documentation.
By utilizing MCPServer, developers can create robust and versatile AI applications that seamlessly integrate with various MCP clients while leveraging powerful backend tools. This comprehensive framework ensures reliable performance and compatibility, making it a valuable choice for anyone involved in the development of AI-driven workflows.
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
Python MCP client for testing servers avoid message limits and customize with API key
Discover easy deployment and management of MCP servers with Glutamate platform for Windows Linux Mac
Expose Chicago Public Schools data with a local MCP server accessing SQLite and LanceDB databases
Learn how to use MCProto Ruby gem to create and chain MCP servers for custom solutions