Fire in da houseTop Tip:Paying $100+ per month for Perplexity, MidJourney, Runway, ChatGPT and other tools is crazy - get all your AI tools in one site starting at $15 per month with Galaxy AI Fire in da houseCheck it out free

mcp-js-server

MCP.Pizza Chef: davlgd

mcp-js-server is an unofficial JavaScript SDK designed to facilitate the creation and management of Model Context Protocol (MCP) servers. It enables developers to define server prompts, resources, and tools in JavaScript, allowing seamless integration of structured context and functionality into LLM workflows. With easy installation via npm and straightforward configuration, mcp-js-server supports building customizable MCP servers that expose APIs, data, and interactive tools to language models, enhancing their real-time environment awareness and interaction capabilities.

Use This MCP server To

Create custom MCP servers with JavaScript Define prompts for LLM interactions Expose API resources to language models Implement tools callable by MCP clients Integrate MCP servers into Node.js projects Manage structured context for LLM workflows

README

MCP Server - JavaScript SDK

This is an unofficial JavaScript SDK for Model Context Protocol.

Usage

Import the package to your project:

npm install mcp-js-server

Create files to define the server's prompts, resources, and tools.

Prompts

// 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

// resources.js
export const resources = {
    apiReference: {
        uri: 'https://api.example.com/openapi.json',
        mimeType: 'application/json'
    }
};

Tools

// 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

Then create a server instance with the following code:

// 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);

Debugging

You can find logs of the server in your user system logs directory:

Linux:   ~/.local/share/logs
macOS:   ~/Library/Logs
Windows: %USERPROFILE%\AppData\Local\Logs

mcp-js-server FAQ

How do I install mcp-js-server?
Install via npm using 'npm install mcp-js-server' to add it to your JavaScript project.
Can I define custom prompts with mcp-js-server?
Yes, you can create and export prompt objects that define messages and arguments for your MCP server.
How are resources defined in mcp-js-server?
Resources are defined as objects with properties like URI and mimeType, exposing external data or APIs to the MCP client.
What is the role of tools in mcp-js-server?
Tools are functions you define that the MCP client can call to perform actions or retrieve data during interactions.
Is mcp-js-server compatible with multiple LLM providers?
Yes, it is provider-agnostic and works with models from OpenAI, Anthropic Claude, and Google Gemini.
Can I use mcp-js-server in both frontend and backend JavaScript environments?
It is primarily designed for Node.js backend environments but can be adapted for frontend use with appropriate bundling.
Does mcp-js-server support real-time updates to prompts or resources?
You can programmatically update prompts and resources by modifying the exported objects and restarting the server.
Where can I find documentation for mcp-js-server?
Documentation is available on the GitHub repository, including usage examples and API references.