Echo MCP Server

Echo MCP Server

A simple demonstration MCP server that provides an echo tool and resource for learning how to build MCP servers. Serves as a starting point and template for creating custom MCP server implementations.

Category
访问服务器

README

BlackArch Security Tools MCP Server

A comprehensive Model Context Protocol (MCP) server that integrates BlackArch Linux security tools for educational penetration testing. Built with security-first principles and strict input validation.

What is MCP?

The Model Context Protocol (MCP) is a standard for connecting AI assistants to external data sources and tools. This project serves as a starting point for building your own MCP servers.

Features

  • Echo Tool: A simple tool that echoes back any message you send
  • Echo Resource: A resource that can be read with custom messages
  • FastMCP Framework: Built using the modern FastMCP library
  • Comprehensive Testing: Includes PowerShell and Bash test scripts
  • Easy Setup: Minimal dependencies and clear structure

Quick Start

Prerequisites

  • Python 3.13 or higher
  • jq (for JSON formatting in tests)

Installation

  1. Clone or download this project
  2. Install dependencies:
    pip install -r requirements.txt
    
    or using uv (recommended):
    uv sync
    

Running the Server

python echo_server.py

The server runs in stdio mode, waiting for JSON-RPC requests.

Testing the Server

Quick Test with jq

# Test tool listing
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"test-client","version":"1.0.0"}}}' | python echo_server.py

echo '{"jsonrpc":"2.0","method":"notifications/initialized","params":{}}' | python echo_server.py

echo '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' | python echo_server.py | jq

Comprehensive Testing

PowerShell (Windows):

& "C:\Program Files\PowerShell\7-preview\pwsh.exe" -File test_echo_mcp.ps1

Bash (Linux/macOS):

chmod +x test_echo_mcp.sh
./test_echo_mcp.sh

Project Structure

project-011/
├── echo_server.py          # Main MCP server implementation
├── test_echo_mcp.ps1       # Comprehensive PowerShell test script
├── test_echo_mcp.sh        # Bash test script
├── requirements.txt        # Python dependencies
├── pyproject.toml         # Project configuration
└── README.md              # This file

Understanding the Code

Basic MCP Server Structure

from mcp.server.fastmcp import FastMCP

# Create the MCP server
mcp = FastMCP("YourServerName")

# Define a tool
@mcp.tool()
def your_tool(param: str) -> str:
    """Description of what your tool does"""
    return f"Result: {param}"

# Define a resource
@mcp.resource("your://{param}")
def your_resource(param: str) -> str:
    """Description of your resource"""
    return f"Resource content: {param}"

# Run the server
if __name__ == "__main__":
    mcp.run(transport='stdio')

Key Concepts

  • Tools: Functions that can be called by AI assistants to perform actions
  • Resources: Data sources that can be read by AI assistants
  • Transport: How the server communicates (stdio, HTTP, etc.)
  • JSON-RPC: The protocol used for communication

Creating Your Own MCP Server

1. Start with the Echo Server

Copy this project and modify echo_server.py:

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("MyCustomServer")

@mcp.tool()
def my_custom_tool(input_data: str) -> str:
    """My custom tool that does something useful"""
    # Your logic here
    return f"Processed: {input_data}"

if __name__ == "__main__":
    mcp.run(transport='stdio')

2. Add More Complex Tools

from typing import List, Dict, Any
import requests

@mcp.tool()
def fetch_weather(city: str) -> Dict[str, Any]:
    """Fetch weather data for a city"""
    # Your API call logic here
    return {"city": city, "temperature": "22°C", "condition": "sunny"}

@mcp.tool()
def process_data(data: List[str]) -> List[str]:
    """Process a list of data items"""
    return [item.upper() for item in data]

3. Add Resources

@mcp.resource("data://{dataset}")
def get_dataset(dataset: str) -> str:
    """Get data from a specific dataset"""
    # Your data retrieval logic here
    return f"Data from {dataset}: ..."

4. Update Dependencies

Add any new dependencies to requirements.txt:

mcp[cli]>=1.15.0
requests>=2.31.0
pandas>=2.0.0

Integration with AI Assistants

Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "echo-server": {
      "command": "python",
      "args": ["C:/path/to/your/echo_server.py"]
    }
  }
}

Other MCP Clients

The server follows the MCP specification and should work with any MCP-compatible client.

Testing Your Server

Manual Testing

  1. Initialize the server:

    {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"test-client","version":"1.0.0"}}}
    
  2. Send initialized notification:

    {"jsonrpc":"2.0","method":"notifications/initialized","params":{}}
    
  3. List available tools:

    {"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}
    
  4. Call a tool:

    {"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"echo_tool","arguments":{"message":"Hello!"}}}
    

Automated Testing

Use the provided test scripts as templates for your own testing:

  • test_echo_mcp.ps1 - Comprehensive PowerShell testing
  • test_echo_mcp.sh - Bash testing

Common Issues and Solutions

"Failed to validate request: Received request before initialization was complete"

Solution: Always send the initialization sequence first:

  1. initialize request
  2. notifications/initialized
  3. Then your actual requests

"Tool not found" errors

Solution: Check that your tool is properly decorated with @mcp.tool() and the name matches exactly.

Performance issues

Solution:

  • Use async functions for I/O operations
  • Implement proper error handling
  • Consider caching for expensive operations

Next Steps

  1. Explore the MCP Specification: Official MCP Documentation
  2. Check out FastMCP: FastMCP GitHub
  3. Build Real Tools: Create tools that interact with APIs, databases, or file systems
  4. Add Authentication: Implement security for production use
  5. Deploy: Consider containerization with Docker

Contributing

This is a template project. Feel free to:

  • Fork and modify for your needs
  • Add more examples
  • Improve the test scripts
  • Share your MCP server implementations

License

This project is provided as-is for educational and development purposes.


Happy MCP Development! 🚀

For questions or issues, refer to the MCP Community or create an issue in your fork of this project.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选