Skip to main content
Glama
v4lheru

generic-mcp-server

by v4lheru

汎用 MCP サーバー テンプレート

簡単にカスタマイズおよび拡張できるように設計された、モジュール式の拡張可能なモデル コンテキスト プロトコル (MCP) サーバー テンプレート。

特徴

  • モジュラーアーキテクチャ:明確に定義された構造による関心事の明確な分離

  • 小さく、焦点を絞ったファイル:メンテナンス性が向上し、AIが取り込みやすくなります

  • 簡単な拡張ポイント: 新しいツールやサービスを追加するためのシンプルなパターン

  • 包括的なエラー処理: コードベース全体にわたる堅牢なエラー管理

  • 型安全性: 適切な型付けによる完全なTypeScriptサポート

Related MCP server: Swagger MCP

プロジェクト構造

generic-mcp-template/
├── src/
│   ├── services/       # Service classes for API interactions
│   │   ├── base-service.ts        # Abstract base service with common functionality
│   │   └── example-service.ts     # Example service implementation
│   ├── tools/          # MCP tool definitions and handlers
│   │   ├── example-tools.ts       # Tool definitions (name, description, schema)
│   │   └── example-tool-handlers.ts # Tool handler implementations
│   ├── types/          # TypeScript type definitions
│   │   └── example-types.ts       # Example type definitions
│   ├── config.ts       # Configuration management
│   └── index.ts        # Main entry point
├── .env.example        # Example environment variables
├── package.json        # Project dependencies and scripts
├── tsconfig.json       # TypeScript configuration
└── README.md           # Project documentation

はじめる

前提条件

  • Node.js 18以上

  • npmまたはyarn

インストール

  1. このリポジトリをクローンします:

    git clone https://github.com/v4lheru/generic-mcp-template.git
    cd generic-mcp-template
  2. 依存関係をインストールします:

    npm install
  3. .env.exampleに基づいて.envファイルを作成します。

    cp .env.example .env
  4. API キーと設定を使用して.envファイルを編集します。

構築と実行

  1. プロジェクトをビルドします。

    npm run build
  2. サーバーを実行します。

    npm start

テンプレートの拡張

新しいサービスの追加

  1. src/services/に新しいサービス ファイルを作成します。

    // src/services/my-service.ts
    import { BaseService } from './base-service.js';
    import config from '../config.js';
    
    export class MyService extends BaseService {
        // Implement your service...
    }
  2. 必要なタイプをsrc/types/に追加します。

新しいツールの追加

  1. 新しいファイルでツールを定義するか、 src/tools/内の既存のツールを拡張します。

    // src/tools/my-tools.ts
    export const myTools = [
        {
            name: "my_tool",
            description: "Description of my tool",
            inputSchema: {
                // JSON Schema for the tool's input
            }
        }
    ];
  2. ツールのハンドラーを実装します。

    // src/tools/my-tool-handlers.ts
    import { MyService } from '../services/my-service.js';
    
    export function createMyToolHandlers(myService: MyService) {
        return {
            my_tool: async (args: any) => {
                // Implement your tool handler
            }
        };
    }
  3. ツールとハンドラーをsrc/index.tsに登録します。

構成

このテンプレートはsrc/config.ts内の集中設定システムを使用します。設定は以下の方法で行うことができます。

  • 環境変数

  • コマンドライン引数( --env KEY=VALUEを使用)

  • コード内のデフォルト値

エラー処理

テンプレートには包括的なエラー処理が含まれています。

  • レート制限をサポートするサービスレベルのエラー処理

  • 適切なエラーメッセージによるツールレベルのエラー処理

  • MCPプロトコルエラー処理

ライセンス

マサチューセッツ工科大学

Available Tools

2 tools
calculate-sumB

Calculates the sum of two numbers

NameRequiredDescriptionDefault
aYesThe first number
bYesThe second number

TDQS

B3.1/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. While 'calculates' implies a read-only operation, the description doesn't address important behavioral aspects like error handling (e.g., overflow, invalid inputs), performance characteristics, or whether the operation has side effects. For a tool with zero annotation coverage, this represents a significant gap in behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly concise at just one sentence that directly states the tool's function. There's zero wasted language, no unnecessary elaboration, and the information is front-loaded effectively. Every word earns its place in this minimal but complete statement of purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (simple arithmetic operation), 100% schema coverage, and no output schema, the description is minimally adequate. However, it lacks information about return values (though no output schema exists), error conditions, or limitations (e.g., numeric range constraints). For a basic calculation tool, this represents the minimum viable description but with clear gaps in completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with both parameters 'a' and 'b' clearly documented as 'the first number' and 'the second number' respectively. The description adds no additional parameter semantics beyond what the schema already provides. According to the scoring rules, when schema_description_coverage is high (>80%), the baseline is 3 even with no parameter information in the description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('calculates') and resource ('sum of two numbers'). It distinguishes from the sibling tool 'get-weather' by focusing on mathematical calculation rather than weather data retrieval. However, it doesn't explicitly differentiate from potential mathematical sibling tools, which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. There's no mention of when-not-to-use scenarios or comparison with other calculation tools. The only implied usage is for summing two numbers, but this is basic and doesn't help an agent make informed decisions about tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get-weatherC

Get weather forecast for a city

NameRequiredDescriptionDefault
cityYesThe city name

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions 'Get weather forecast' but doesn't specify details like data freshness, rate limits, error handling, or authentication needs. This leaves significant gaps in understanding how the tool behaves beyond its basic function.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without any wasted words. It is appropriately sized and front-loaded, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain what the weather forecast includes (e.g., temperature, conditions), potential limitations, or return format. For a tool with no structured behavioral data, more context is needed to fully understand its operation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the 'city' parameter fully documented. The description implies the parameter's use ('for a city') but adds no additional meaning beyond what the schema provides, such as format examples or constraints. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('Get') and resource ('weather forecast for a city'), making it immediately understandable. However, it doesn't differentiate from sibling tools, as 'calculate-sum' is unrelated, so no sibling distinction is needed or provided.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, such as other weather-related tools or data sources. It only states what the tool does, without context for its application or prerequisites.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 2 tool updates
    • First observedcalculate-sum
    • First observedget-weather

TDQS

C2.9/5.0

Scored across 2 tools

Disambiguation5/5

The two tools have completely distinct purposes: calculate-sum performs a mathematical operation on numbers, while get-weather retrieves weather data for a city. There is no overlap or ambiguity between these functions, making it impossible for an agent to confuse them.

Naming Consistency3/5

The tool names use a verb-noun pattern (calculate-sum, get-weather), which is consistent in structure. However, they use different verb styles (calculate vs. get) and a hyphen delimiter, which is readable but shows minor deviation in convention.

Tool Count2/5

With only 2 tools, the server feels thin and under-scoped for a generic purpose. This minimal set lacks coverage for typical operations in any specific domain, making it inappropriate for most agent workflows.

Completeness1/5

The tool surface is severely incomplete for a generic server. There are major gaps in functionality, such as missing basic CRUD operations, data processing tools, or domain-specific coverage, which will likely cause agent failures in practical use.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers