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\LogsThis server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
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