Unofficial JavaScript SDK for Model Context Protocol to build customizable servers with prompts resources and tools
MCP (Model Context Protocol) is designed to serve as a universal adapter for AI applications, similar to USB-C for devices. The MCP Server - JavaScript SDK is an unofficial implementation that integrates seamlessly with the Model Context Protocol specification. By utilizing this server, developers can enable various AI applications like Claude Desktop, Continue, and Cursor to interact with specific data sources and tools through standardized communication channels.
The core value of the MCP Server lies in its ability to simplify complex interactions between AI platforms and diverse external resources, ensuring smooth and consistent integration across different environments. It acts as a bridge that leverages MCP's protocol to facilitate robust and scalable connectivity for AI workloads, making it an indispensable component for building robust AI solutions.
The MCP Server - JavaScript SDK offers several key features that enhance the capabilities of AI applications:
Prompts: Developers can define prompts that provide structured guidance to AI applications. Prompts are essential for defining tasks and expectations clearly, ensuring that the applications respond appropriately within the context provided.
Resources: This feature allows the server to connect with external resources, such as APIs or data sources. By exporting these resources via JavaScript, developers can ensure seamless access to critical tools and data by AI clients.
Tools: The server supports customizable tools that enable complex interactions between AI applications and various data contexts. Tools are defined through handlers and schemas, providing a robust framework for handling diverse functionalities.
Server Initialization: By integrating the MCP protocol into your project, developers can create instances of servers with specific configurations and capabilities.
Logging & Debugging: The server logs its activities, making it easier to diagnose issues and track performance. Logs are stored in user-defined directories, ensuring easy access for debugging purposes.
The architecture of the MCP Server - JavaScript SDK is built around the principles of simplicity and efficiency:
Prompts: Prompts are defined using a simple key-value structure with detailed descriptions and associated messages. This ensures that prompts can be easily understood by any MCP-compliant client.
Resources: Resources are managed through export functionalities, ensuring they can be retrieved and utilized by clients transparently.
Tools: Tools are developed as handler functions coupled with schema definitions. Handlers define the behavior of the tool, while schemas ensure valid input and output formats.
By adhering to the MCP protocol, this SDK guarantees interoperability across different AI ecosystems, making it a versatile choice for developers looking to build complex systems that require seamless interaction between various components.
To get started with using the MCP Server - JavaScript SDK in your project, follow these steps:
Installation: Add the mcp-js-server
package to your project via npm:
npm install mcp-js-server
Configuration Files: Create files for defining prompts, resources, and tools within your project directory. Here’s an example of how these files might look:
Prompts.js
export const prompts = {
hello_world: {
description: 'A simple prompt that says hello.',
arguments: [],
messages: [{
role: 'assistant',
content: {
type: 'text',
text: 'Hello, world!'
}
}]
}
};
Resources.js
export const resources = {
apiReference: {
uri: 'https://api.example.com/openapi.json',
mimeType: 'application/json'
}
};
Tools.js
export const tools = {
simple_tool: {
description: 'A simple tool',
handler: async () => new Date().toLocaleString(),
schema: {
type: 'object',
properties: {},
required: []
}
},
complex_tool: {
description: 'A complex tool',
handler: async ({ param1, param2 }) => {
return `param1: ${param1}, param2: ${param2}`;
},
schema: {
type: 'object',
properties: {
param1: { type: 'string' },
param2: { type: 'string' }
},
required: ['param1', 'param2']
}
}
};
Server Instance: Finally, create an instance of the MCP server with the necessary configurations and imported components:
import { MCP } from 'mcp-js-server';
import { tools } from './tools.js';
import { prompts } from './prompts.js';
import { resources } from './resources.js';
const infos = {
name: 'mcp-demo-server',
version: '0.1.0'
};
const server = new MCP(infos, prompts, resources, tools);
In this use case, an AI application like Claude Desktop could utilize the MCP Server to generate dynamic content. For example, by defining a prompt that describes a blog post topic, and using handlers for generating text based on user inputs.
Implementation: Define a prompt in prompts.js
:
export const prompts = {
blog_post_topic: {
description: 'A prompt for generating a blog post title and introduction.',
arguments: [],
messages: [{
role: 'assistant',
content: {
type: 'text',
text: 'Write an intro paragraph about [title].'
}
}]
}
};
The server can then handle requests from the AI application to generate relevant blog post content based on these predefined prompts.
Imagine using Continue for data processing tasks, where the server is configured with specific tools and resources. For example, integrating web scraping tools or custom APIs to process gathered information.
Implementation: Define a tool in tools.js
:
export const tools = {
scrapeWebsite: {
description: 'A tool for scraping websites',
handler: async ({ url }) => {
// Implementation details here
},
schema: {
type: 'object',
properties: {
url: { type: 'string' }
},
required: ['url']
}
}
};
This enables the server to interact with AI applications like Continue, providing them with the necessary tools to handle complex data processing tasks.
The MCP Server - JavaScript SDK is designed to enhance the capabilities of various MCP clients. The following table outlines its compatibility and features:
MCP Client | Resources | Tools | Prompts | Status |
---|---|---|---|---|
Claude Desktop | ✅ | ✅ | ✅ | Full Support |
Continue | ✅ | ✅ | ✅ | Full Support |
Cursor | ❌ | ✅ | ❌ | Tools Only |
This configuration ensures that all supported MCP clients can fully utilize the resources and tools provided by this server.
To ensure optimal performance, here’s a compatibility matrix for common AI workflows:
Feature | Claude Desktop | Continue | Cursor |
---|---|---|---|
Prompts | ✅ | ✅ | ❌ |
Resources | ✅ | ✅ | ✔️ |
Tools | ✅ | ✅ | ✔️ |
This matrix highlights which features are supported by each client, helping developers plan their integrations effectively.
For more advanced configurations and security measures, you can customize the server settings as needed:
Logging: Adjust logging levels and options to monitor server performance.
Security Settings: Ensure that API keys and other sensitive information are securely stored and managed.
Environment Variables: You can define environment variables in server.js
for additional security measures.
Here’s an example of advanced configuration code:
{
"mcpServers": {
"[server-name]": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-[name]"],
"env": {
"API_KEY": "your-api-key"
}
}
}
}
You can find detailed logs in your system's defined log directories. Check these logs for error messages and warnings.
Yes, you can define custom prompts as needed to tailor instructions or tasks for AI applications.
Tools are integrated via handler functions with input schemas. This allows you to handle complex interactions between your server and external systems.
Security measures include secure storage of API keys, logging mechanisms, and environment variable handling.
Ensure that all necessary resources, tools, and prompts are defined correctly. Additionally, refer to the provided compatibility matrix to make informed decisions about client integration.
Contributors can aid in improving the MCP Server - JavaScript SDK by following these guidelines:
The MCP ecosystem supports a wide range of applications and tools that can be integrated via the MCP protocol. For more information on building and integrating MCP servers with clients like Claude Desktop and Continue, visit the official Model Context Protocol documentation: Model Context Protocol Documentation.
By leveraging the MCP Server - JavaScript SDK, developers can create powerful AI solutions that are both flexible and secure, aligning seamlessly with the broader MCP ecosystem.
RuinedFooocus is a local AI image generator and chatbot image server for seamless creative control
Simplify MySQL queries with Java-based MysqlMcpServer for easy standard input-output communication
Learn to set up MCP Airflow Database server for efficient database interactions and querying airflow data
Access NASA APIs for space data, images, asteroids, weather, and exoplanets via MCP integration
Build stunning one-page websites track engagement create QR codes monetize content easily with Acalytica
Explore CoRT MCP server for advanced self-arguing AI with multi-LLM inference and enhanced evaluation methods