MCP ExplorerExplorer

Davlgd Mcp Js Server

@MCP-Mirroron 10 months ago
1 Apache-2.0
FreeCommunity
AI Systems
Mirror of https://github.com/davlgd/mcp-js-server

Overview

What is Davlgd Mcp Js Server

davlgd_mcp-js-server is an unofficial JavaScript SDK for the Model Context Protocol, designed to facilitate the creation of servers that can handle prompts, resources, and tools in a structured manner.

Use cases

Use cases include creating interactive chat interfaces, developing API-driven applications, and building tools that require dynamic responses based on user input or external data.

How to use

To use davlgd_mcp-js-server, define your server’s prompts, resources, and tools in separate JavaScript files, then create a server instance by importing these definitions and initializing the MCP class with the necessary information.

Key features

Key features include the ability to define custom prompts, manage resources via API references, and implement various tools with specific handlers and schemas, allowing for flexible server functionality.

Where to use

davlgd_mcp-js-server can be used in web applications, chatbots, and any other context where structured interaction with a server is required, particularly in environments that utilize the Model Context Protocol.

Content

MCP Server - JavaScript SDK

This is an unofficial JavaScript SDK for Model Context Protocol.

Usage

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

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers