Discover how to build a JavaScript SDK with prompts, resources, tools, and MCP server setup
The MCP (Model Context Protocol) Server - JavaScript SDK is an essential component for integrating Model Context Protocol into AI applications. It enables developers to build robust, interoperable systems that can connect with various AI clients and tools through a standardized protocol. This server allows you to define the context in which your AI application operates—capturing prompts, resources, and tools that are crucial for enhancing its functionality.
The MCP Server - JavaScript SDK is built on core capabilities derived from Model Context Protocol (MCP). These features include:
Prompts define the context in which an AI application operates. With this SDK, you can create prompts that describe specific scenarios or tasks. For example, a simple prompt might be designed to say "Hello, world!" when executed.
// 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 are external data sources or APIs that can be accessed and utilized by your AI application. This SDK allows you to define these resources in a structured manner.
// resources.js
export const resources = {
apiReference: {
uri: 'https://api.example.com/openapi.json',
mimeType: 'application/json'
}
};
Tools are the actual functionality that your AI application can perform. They can range from simple functions to complex operations.
// 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']
}
}
};
The architecture of the MCP Server - JavaScript SDK is designed to be flexible and extensible. It uses a modular approach where you can define individual prompts, resources, and tools without affecting others. The server instance encapsulates these components into a cohesive system that adheres to the Model Context Protocol.
Below is an example of how data flows through the MCP protocol:
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
This diagram illustrates the interaction between an AI application, MCP clients, and the server. The server acts as a middleware layer that translates requests from various MCP clients into appropriate responses.
The compatibility matrix details which tools are supported by different MCP clients:
MCP Client | Resources | Tools | Prompts | Status |
---|---|---|---|---|
Claude Desktop | ✅ | ✅ | ✅ | Full Support |
Continue | ✅ | ✅ | ✅ | Full Support |
Cursor | ❌ | ✅ | ❌ | Tools Only |
This table helps developers understand which features are available when integrating the MCP server with different clients.
To get started, follow these steps to install and configure the MCP Server - JavaScript SDK:
Create Prompts File
Define prompts in a file named prompts.js
:
export const prompts = {
hello_world: {
description: 'A simple prompt that says hello.',
arguments: [],
messages: [{
role: 'assistant',
content: {
type: 'text',
text: 'Hello, world!'
}
}]
}
};
Create Resources File
Define resources in a file named resources.js
:
export const resources = {
apiReference: {
uri: 'https://api.example.com/openapi.json',
mimeType: 'application/json'
}
};
Create Tools File
Implement tools in a file named 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']
}
}
};
Create Server Instance
Create the server instance in a file named server.js
:
import { MCP } from 'mcp-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);
Run the Server
Finally, start the server to see it in action:
node server.js
Imagine an AI application that needs to create events based on user inputs and calendar data. By integrating the MCP Server - JavaScript SDK, you can define prompts for user input, tools for interacting with a calendar API, and resources for accessing event data.
// Define the context for creating an event
export const prompts = {
create_event: {
description: 'Input details to create a new event',
arguments: []
}
};
// Tools for handling calendar interactions
export const tools = {
addEvent: {
description: 'Add an event',
handler: async (data) => {
// Code to insert an event in the Calendar API
return "Event added successfully.";
},
schema: {
type: 'object',
properties: {
date: { type: 'string' },
summary: { type: 'string' }
}
}
}
};
// Server setup
const server = new MCP(infos, prompts, resources, tools);
Create an AI application that summarizes long texts. By defining a prompt for input and creating a tool to handle summarization tasks using NLP libraries, you can integrate these components into the MCP Server.
// Define the context for text summarization
export const prompts = {
summarize_text: {
description: 'Input a lengthy text for summary',
arguments: []
}
};
// Tool for handling summarization tasks
export const tools = {
summarize: {
description: 'Summarize text input',
handler: async (text) => {
// Code to perform NLP analysis and generate summary
return "Summary generated successfully.";
},
schema: {
type: 'object',
properties: {
content: { type: 'string' }
}
}
}
};
// Server setup
const server = new MCP(infos, prompts, resources, tools);
The MCP Server - JavaScript SDK is compatible with various MCP clients such as Claude Desktop and Continue. This ensures that your AI application can seamlessly connect to a wide range of platforms.
Here's an example configuration snippet for integrating the server into an MCP client:
{
"mcpServers": {
"[server-name]": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-[name]"],
"env": {
"API_KEY": "your-api-key"
}
}
}
}
The performance and compatibility of the MCP Server - JavaScript SDK have been tested with different MCP clients. The following table outlines its current status:
MCP Client | Resources | Tools | Prompts |
---|---|---|---|
Claude Desktop | ✅ | ✅ | ✅ |
Continue | ✅ | ✅ | ✅ |
Cursor | ❌ | ✅ | ❌ |
This matrix helps developers understand the specific features supported by each client.
The MCP server allows for extensive customization, enabling developers to tailor its behavior according to their requirements. For instance, you can define custom error handling and logging mechanisms.
Securing your MCP integration is crucial. Here are some best practices:
Can I use this server with multiple clients simultaneously?
What tools are currently available in the SDK?
Why is Cursor listed as 'Tools Only' in the compatibility matrix?
How do I handle errors in the server?
Is there a limit to the number of prompts, resources, and tools I can define?
To contribute to the MCP Server - JavaScript SDK:
Fork the Repository
Fork the official repository on GitHub and clone it locally.
Contribute Code Changes
Make your contributions by submitting pull requests with clear descriptions of changes made.
Run Unit Tests
Ensure that all unit tests pass before submitting a merge request.
The MCP ecosystem includes various tools, libraries, and resources to help developers build and integrate AI applications effectively. Join the community for more updates and support:
By leveraging the power of the MCP Server - JavaScript SDK, developers can build robust AI applications that are seamlessly interoperable with multiple clients, enhancing their functionality and reach.
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