J

mcp-js-server

...
Created 1/13/2025bydavlgd

Categories

aimcpstdio

Language:

JavaScript

Stars:

2

Forks:

3

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
Last updated: 2/4/2025

Publisher info

davlgd's avatar

David Legrand

Help turning great technologies into Clever products @CleverCloud. (Carb-free) Absolut Prompt & PoC Engineer 🤖 @v_language & @htmx_org promoter 🔥

@CleverCloud
Troyes, France
79
followers
3
following
97
repos

More MCP servers built with JavaScript

mcp-server-semgrep

MCP Server Semgrep is a [Model Context Protocol](https://modelcontextprotocol.io) compliant server that integrates the powerful Semgrep static analysis tool with AI assistants like Anthropic Claude. It enables advanced code analysis, security vulnerability detection, and code quality improvements directly through a conversational interface.

By Szowesgad9
protonmail-mcp

This MCP server provides email sending functionality using Protonmail's SMTP service. It allows both Claude Desktop and Cline VSCode extension to send emails on your behalf using your Protonmail credentials.

By amotivv6
agentql-mcp

Model Context Protocol server that integrates AgentQL's data extraction capabilities.

By tinyfish-io45