MCP Playground Server

MCP Playground Server

A simple educational MCP server providing basic math operations, string manipulation, and greeting functionality. Demonstrates how to implement MCP tools for learning purposes.

Category
访问服务器

README

MCP Server Example (Python)

A simple Model Context Protocol (MCP) server implementation in Python.

What is MCP?

The Model Context Protocol (MCP) is an open protocol that enables AI assistants like Claude to securely interact with external tools and data sources. MCP servers expose tools that clients can discover and call.

Project Structure

mcp_playground/
├── server.py           # Main MCP server implementation
├── pyproject.toml      # Project metadata and dependencies
├── .python-version     # Python version specification (3.13)
├── .gitignore         # Git ignore rules
└── README.md          # This file

Setup

Prerequisites

  • Python 3.13
  • uv - Fast Python package installer and manager

Installing uv

If you don't have uv installed yet:

# On macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# On Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

Installation

  1. Clone this repository (if you haven't already)

  2. Install dependencies using uv:

uv sync

This will:

  • Automatically install Python 3.13 if needed
  • Create a virtual environment
  • Install all dependencies from pyproject.toml

Running the Server

To run the MCP server:

uv run server.py

Or activate the virtual environment first:

source .venv/bin/activate  # On Windows: .venv\Scripts\activate
python server.py

The server uses stdio (standard input/output) for communication, which is the standard way MCP servers communicate with clients.

Available Tools

This example server provides three simple tools:

1. add_numbers

Adds two numbers together.

Parameters:

  • a (number): First number
  • b (number): Second number

Example:

{
  "a": 5,
  "b": 3
}

2. greet

Generates a personalized greeting.

Parameters:

  • name (string): Name of the person to greet

Example:

{
  "name": "Alice"
}

3. reverse_string

Reverses a string.

Parameters:

  • text (string): Text to reverse

Example:

{
  "text": "Hello World"
}

Using with Claude Code

To use this MCP server with Claude Code, you need to configure it in your MCP settings:

  1. Open your Claude Code MCP configuration file (typically at ~/.config/claude/claude_desktop_config.json)

  2. Add this server to the mcpServers section:

{
  "mcpServers": {
    "example-server": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/mcp_playground",
        "run",
        "server.py"
      ]
    }
  }
}
  1. Restart Claude Code

  2. The tools will now be available for Claude to use!

Customizing the Server

Adding New Tools

To add a new tool to the server:

  1. Add the tool definition to the list_tools() function
  2. Add the tool implementation to the call_tool() function

Example:

# In list_tools():
Tool(
    name="my_new_tool",
    description="Description of what the tool does",
    inputSchema={
        "type": "object",
        "properties": {
            "param1": {
                "type": "string",
                "description": "Parameter description"
            }
        },
        "required": ["param1"]
    }
)

# In call_tool():
elif name == "my_new_tool":
    param1 = arguments["param1"]
    result = do_something(param1)
    return [TextContent(
        type="text",
        text=f"Result: {result}"
    )]

Advanced Features

The MCP protocol supports additional features beyond basic tools:

  • Resources: Expose data that can be read (files, API data, etc.)
  • Prompts: Provide templated prompts
  • Sampling: Allow the server to request LLM completions

Check the MCP documentation for more information.

Development

Running in Development Mode

For development, you might want to add logging:

import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

Testing

You can test your MCP server using the MCP Inspector tool or by integrating it directly with Claude Code.

Troubleshooting

"Module not found" errors

Make sure you've installed the dependencies:

uv sync

Server not appearing in Claude Code

  • Check that the path in your MCP configuration is correct
  • Make sure the virtual environment is activated (if using one)
  • Try restarting Claude Code

Tool calls failing

  • Check the server logs for error messages
  • Verify that the input schema matches what you're passing
  • Make sure all required parameters are provided

Why uv?

uv is a modern Python package manager that's:

  • 10-100x faster than pip
  • Automatically manages Python versions
  • Has built-in virtual environment support
  • Compatible with pip and pyproject.toml standards

Resources

License

This is an example project for educational purposes.

推荐服务器

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

官方
精选