Utility MCP Server

Utility MCP Server

Provides basic greeting, math, and date utilities for AI assistants via the Model Context Protocol.

Category
访问服务器

README

Utility MCP Server

A beginner-friendly Model Context Protocol (MCP) server that provides essential utility tools for AI-powered applications. This project demonstrates how to build a functional MCP server that can be integrated with AI assistants like Claude Desktop.

What is MCP?

The Model Context Protocol (MCP) is an open protocol that enables AI assistants to securely interact with external tools, data sources, and APIs. Think of MCP as a universal language that allows AI models to request and receive information in a structured way. This project implements an MCP server that exposes utility tools which AI assistants can call to perform useful tasks.


Features

1. greet(name)

A friendly greeting tool that welcomes users by name.

Example:

Input:
{
  "name": "Alice"
}

Output:
"Hello, Alice! Welcome to MCP!"

2. farewell(name)

A polite goodbye tool that bids farewell to users.

Example:

Input:
{
  "name": "Bob"
}

Output:
"Goodbye, Bob! See you soon!"

3. add_numbers(a, b)

A mathematical tool that adds two integers and returns a formatted result.

Example:

Input:
{
  "a": 15,
  "b": 20
}

Output:
"The sum of 15 and 20 is 35."

4. get_current_date()

A utility tool that returns today's date in a human-readable format.

Example:

Input:
{}

Output:
"08 July 2026"

Project Structure

utility-mcp-server/
│
├── hello_server.py          # Main MCP server implementation
├── test_client.py            # Test client for server validation
├── mcp-config.json           # MCP server configuration file
├── requirements.txt          # Python dependencies
├── simple_test.py           # Message format demonstration
├── simple_mcp_test.py       # Direct server testing script
└── README.md                # Project documentation

Technologies Used

  • Python - Core programming language for server implementation
  • Model Context Protocol (MCP) - Open protocol for AI-tool communication
  • VS Code - Recommended IDE for development and debugging
  • JSON-RPC 2.0 - Remote procedure call protocol for client-server communication

Architecture

The project follows a client-server architecture using the MCP protocol:

┌─────────────┐
│    User     │
└──────┬──────┘
       │ Request
       ↓
┌─────────────────┐
│  MCP Client     │
│  (Claude Desktop│
│   or Inspector) │
└───────┬─────────┘
        │ JSON-RPC Message
        ↓
┌─────────────────┐
│   MCP Server    │
│  (hello_server) │
└───────┬─────────┘
        │ Tool Call
        ↓
┌─────────────────┐
│  Tool Handler   │
│  - greet()      │
│  - farewell()   │
│  - add_numbers()│
│  - get_current_ │
│    date()       │
└───────┬─────────┘
        │ Result
        ↓
┌─────────────────┐
│  Response       │
│  (Formatted     │
│   Text Content) │
└─────────────────┘

Message Flow:

  1. User makes a request via an AI assistant
  2. Client sends a JSON-RPC request to the MCP server
  3. Server processes the request and routes it to the appropriate tool
  4. Tool executes the logic and returns a result
  5. Response is sent back through the chain to the user

Installation

Prerequisites

  • Python 3.10 or higher
  • pip (Python package manager)
  • Git (for cloning the repository)

Step-by-Step Setup

  1. Clone the repository

    git clone <your-repo-url>
    cd utility-mcp-server
    
  2. Install dependencies

    pip install -r requirements.txt
    
  3. Verify installation

    python -c "import mcp; print('MCP installed successfully')"
    

How to Run

Start the MCP Server

Option 1: Direct Python execution

python hello_server.py

Option 2: Using MCP Inspector (Recommended for testing)

npx @modelcontextprotocol/inspector mcp-config.json

Option 3: Using Claude Desktop Add the following to your Claude Desktop config:

{
  "mcpServers": {
    "utility-server": {
      "command": "python",
      "args": ["path/to/hello_server.py"]
    }
  }
}

Verify Server is Running

The server will start in stdio mode and listen for JSON-RPC messages. If using MCP Inspector, a web interface will open at http://localhost:6277.


Testing

Method 1: Using test_client.py

The included test client automatically validates all server functionality:

python test_client.py

Expected Output:

>>> Starting MCP Server Test Client

[Test 1] Initializing connection...
   Initialized: 2024-11-05

[Test 2] Listing available tools...
   Found 4 tools:
   - greet: Say hello to someone
   - farewell: Say goodbye to someone
   - add_numbers: Add two numbers together
   - get_current_date: Get today's date in a formatted string

[Test 3] Calling 'greet' with name='Alice'...
   Response: Hello, Alice! Welcome to MCP!

[Test 4] Calling 'farewell' with name='Bob'...
   Response: Goodbye, Bob! See you soon!

[SUCCESS] All tests completed!

Method 2: Using MCP Inspector

  1. Start the Inspector

    npx @modelcontextprotocol/inspector mcp-config.json
    
  2. Open the web interface at the shown URL (usually http://localhost:6277)

  3. Test individual tools:

    • Click on any tool in the sidebar
    • Enter required parameters
    • Click "Call Tool"
    • View the response in the output panel

Method 3: Manual JSON-RPC Testing

Test specific tools directly via command line:

# Test add_numbers
(echo '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}},"id":1}' && echo '{"jsonrpc":"2.0","method":"notifications/initialized","params":{}}' && echo '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"add_numbers","arguments":{"a":15,"b":20}},"id":2}') | python hello_server.py

# Test get_current_date
(echo '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}},"id":1}' && echo '{"jsonrpc":"2.0","method":"notifications/initialized","params":{}}' && echo '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"get_current_date","arguments":{}},"id":2}') | python hello_server.py

Learning Outcomes

Building this project helped me master several important concepts:

Technical Skills

  • MCP Protocol Understanding: Learned how the Model Context Protocol enables AI assistants to interact with external tools through standardized JSON-RPC messages
  • Async Programming: Gained experience with Python's asyncio and asynchronous server architecture
  • API Design: Understood how to design clean, intuitive tool interfaces with proper input validation and response formatting
  • JSON-RPC Implementation: Learned to implement the JSON-RPC 2.0 protocol for client-server communication

Architecture Concepts

  • Client-Server Model: Understanding of how clients and servers communicate via message passing
  • Tool Abstraction: How to expose functionality as callable tools with standardized interfaces
  • Error Handling: Proper error handling and graceful degradation in distributed systems
  • Configuration Management: Using JSON configuration files for server setup and deployment

Development Practices

  • Testing Methodologies: Writing test clients and using inspector tools for validation
  • Documentation Skills: Creating comprehensive README files and inline code comments
  • Debugging Techniques: Using MCP Inspector and command-line testing for troubleshooting
  • Project Organization: Structuring code files logically for maintainability

Future Improvements

1. Enhanced Tool Set

Add more utility tools such as:

  • calculate_percentage(numerator, denominator) - Calculate percentages
  • format_currency(amount, currency_code) - Format monetary values
  • validate_email(email_address) - Email validation
  • generate_random_password(length, complexity) - Secure password generation

2. Error Handling & Validation

  • Implement robust input validation for all tools
  • Add comprehensive error messages with troubleshooting guidance
  • Include type checking and range validation for numeric inputs
  • Add logging for debugging and monitoring

3. Configuration Options

  • Make date format configurable in get_current_date()
  • Add language/locale support for internationalization
  • Allow customization of greeting and farewell messages
  • Support for custom number formatting in add_numbers()

4. Performance Optimization

  • Implement caching for frequently called operations
  • Add connection pooling for multiple client requests
  • Optimize message parsing and serialization
  • Add metrics collection for performance monitoring

5. Integration Features

  • Add support for environment variables for configuration
  • Implement authentication and authorization for production use
  • Create a REST API wrapper for web service deployment
  • Add webhook support for event-driven functionality

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For beginners, this is a great project to:

  • Learn MCP protocol implementation
  • Practice async Python programming
  • Understand client-server architectures
  • Improve documentation and testing skills

License

This project is open source and available under the MIT License.


Acknowledgments

  • Model Context Protocol (MCP) by Anthropic
  • MCP Python SDK for providing the server framework
  • Claude Desktop team for the reference implementation

Built with ❤️ for the MCP community

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选