Skip to main content
Glama

MCP JavaScript Server

by davlgd

MCP 服务器 - JavaScript SDK

这是模型上下文协议的非官方 JavaScript SDK。

用法

将包导入到您的项目中:

npm install mcp-js-server

创建文件来定义服务器的提示、资源和工具。

提示

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

调试

您可以在用户系统日志目录中找到服务器的日志:

Linux: ~/.local/share/logs macOS: ~/Library/Logs Windows: %USERPROFILE%\AppData\Local\Logs
-
security - not tested
A
license - permissive license
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

非官方的 JavaScript SDK 用于为模型上下文协议创建定制的服务器,允许定义提示、资源和工具以进行定制的交互。

  1. 用法
    1. 提示
    2. 资源
    3. 工具
    4. 服务器
    5. 调试

Related MCP Servers

  • A
    security
    A
    license
    A
    quality
    A production-ready template for creating Model Context Protocol servers with TypeScript, providing tools for efficient testing, development, and deployment.
    Last updated -
    1
    676
    34
    JavaScript
    MIT License
  • A
    security
    A
    license
    A
    quality
    A Model Context Protocol server that provides tools for code modification and generation via Large Language Models, allowing users to create, modify, rewrite, and delete files using structured XML instructions.
    Last updated -
    12
    1
    Python
    MIT License
    • Linux
    • Apple
  • A
    security
    A
    license
    A
    quality
    A comprehensive Model Context Protocol server that provides advanced Node.js development tooling for automating project creation, component generation, package management, and documentation with AI-powered assistance.
    Last updated -
    7
    4
    JavaScript
    MIT License
  • A
    security
    F
    license
    A
    quality
    A Model Context Protocol server that provides greeting tools, resources, and prompts, demonstrating client-server interaction using TypeScript.
    Last updated -
    1
    TypeScript

View all related MCP servers

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/davlgd/mcp-js-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server