first-mcp-server
first-mcp-server
プロジェクト概要
2つの数値を加算し、結果をテキストとして返す単一ツール
addを公開する最小限の MCP(Model Context Protocol)サーバー。入力検証のために @modelcontextprotocol パッケージと zod を使用しています。
主要ファイル
index.js —
addツールを登録し、サーバーを起動するメインのサーバⅰファイル。
要件
Node.js 16+(LTS 推奨)
npm または yarn
インストール
リポジトリをク蟜ーンして、プロジェクトディレクトリに移動します:
git clone && cd /Users/sagar/Documents/Learning/MCP-Server
依存関係をインストールします(npm の例):
npm install
このプロジェクトで使用している依存関係(コードからの例):
@modelcontextprotocol/server
@modelcontextprotocol/server/stdio(STDIOトランスポート)
@modelcontextprotocol/express(expressヘルパー)
@modelcontextprotocol/node(Node HTTP トランスポート)
zod(検証)
実行
デフォルの HTTP トランスポート(このプロジェクトの現在の起動方法):
node index.js
サーバーはポート3001で待ち受け、MCP エンドポイントを /mcp にマウントします(from index.js を参照)。
STDIO トランスポート(ローカ11 CLI との統合に便利):
index.js 内の
runServerOnSTDIOTransport()コールをコメントアウト解除して、次を実行します:node index.js
利用例
HTTP の例(curl)
リクエスト・ペイロード(JSON):
{ "tool": "add", "input": { "num1": 10, "num2": 20 } }
curl 呼び出しの例(必要応じて hostname/port を調整してください):
curl -X POST http://localhost:3001/mcp
-H "Content-Type: application/json"
-d '{"tool":"add","input":{"num1":10,"num2":20}}'期待されるレスポンス(サーバーのツールはテキストブロックの content 配列を返します):
{ "content": [ { "type": "text", "text": "30" } ] }
注記: index.jss は NodeStreamableHTTPServerTransport を使用して HTTP トランスポートを配線し、transport.handleRequest(req, res, req.body) を呼び出します([src] の "index.js)を参照)。トランスポートが期待するエンベロープは @modelcontextprotocol/node トランスポートの実装に依存します。上記の例は、このプロジェクトで使用されているシンプルな形式(toolとinput`)に従っています。
STDIO の例(ローカールCLI との統合)
このプロジェクトには、StdioServerTransport を介して STDIO 上でサーバーを実行するヘルパーが含まれています。STDIO モードで起動した場合、サーバーは stdin の JSON リクエストを受けけ、stdout にレスポンスを返します。トールは index.js に登録されており、zod で入力を検証し、合計をテキストとして返します。
ツールの詳細(コードに基づく)
ツール名: "add"
説明: "2つの数値を加算する"
入力スキーマ(zod):
num1: number
num2: number
実装スニペット(コード内の [index.js] から取得)
server.registerTool(
"add",
{
title: "add",
description: "Add two numbers",
inputSchema: z.object({ num1: z.number(), num2: z.number() }),
},
async (ctx) => ({
content: [{ type: "text", text: `${ctx.num1 + ctx.num2}` }],
}),
);注記:
バリデーション: zod が入力を既サにしています。呼び出し側は必ず数値を送り、検証エラーを適切に処理してください。
エラー処理:
transport.handleRequestとツールハンドラを try/catch で包み、一貫したエラー・ペイロードと HTTP ステータスコード(クライアント・エラーは 4xx、サーバー・エラーは 5xx)を返すようにしてください。ロギングとモニタリング: 構造化ロギング、リクエスト ID、基本メトリクスを追加して、使用状況とエラーを監視してください。
セキュリティ: 公開する場合は、
/ mcpエンドポイントを認証とレート制限で保護し、リバースプロキシ間で運してください。テス: ツールハンドラのユニットテスと、トランスポートの統合テス(HTTP と STDIO)を追加してください。
貢献
機能リクエストや修正には、Issue を開くか PR を作成してください。
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
No tool schema history has been recorded yet.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Add two numbers instantly and generate friendly greetings on demand. Speed up quick math and perso…
Create friendly greetings and add two numbers instantly. Speed up simple tasks and streamline ligh…
This MCP server enables users to perform scientific computations regarding linear algebra and vect…
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceA simple MCP server that provides integer addition functionality. Enables users to perform basic arithmetic operations by adding two integers together through natural language interactions.-
- AlicenseNot gradedqualityDmaintenanceA simple demonstration MCP server that provides a basic arithmetic tool for adding two numbers together, showcasing how to build custom MCP servers with input validation.15ISC
- AlicenseNot gradedqualityDmaintenanceEnables AI applications to perform basic mathematical operations like addition and subtraction through MCP tools. Also provides REST API endpoints for the same operations.MIT
- FlicenseNot gradedqualityDmaintenanceA simple MCP server that provides a tool for adding two numbers, designed for testing MCP integration with Claude.-
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/Sagar06/MCP-Server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server