MCP服务器和客户端最简单的实现。用两行代码搭建服务器或客户端。
概览
MCP-123 运行MCP服务器和客户端的最简单方式(各2线) - : 在两行内启动服务器或客户端。 - : 在你的 tools.py 文件中写入正常函数——它们会作为工具被包含在你的MCP服务器上,自动使用。 - : 客户端使用您的 OpenAI API 密钥回答问题,必要时调用工具。 在 tools.py 中定义你的函数。不需要装饰工具,它们会自动作为工具添加到你的MCP服务器。例如: - : 在两行内启动服务器或客户端。 - : 在你的 tools.py 文件中写入正常函数——它们会作为工具被包含在你的MCP服务器上,自动使用。 - : 客户端使用您的 OpenAI API 密钥回答问题,必要时调用工具。
概述(AI 翻译)
MCP-123
运行MCP服务器和客户端(各2行)的最简单方法
🚀 特色
-
超最小配置:在两行内启动服务器或客户端。
-
简单的工具创建:在你的
tools.py文件中写入普通函数——不需要装饰工具或特殊封装器——它们会作为工具被包含在你的MCP服务器上,自动使用。 -
OpenAI 集成:客户端使用您的 OpenAI API 密钥回答问题,并根据需要调用工具。
🖥️ 快速开始
1.安装要求
2.创建你的工具
在tools.py中定义你的函数。不需要装饰器,它们会自动作为工具添加到你的MCP服务器。例如:
3.启动MCP服务器(2行)
4.设置MCP客户端(2行)
5.使用 MCP 客户端
6.完成后关闭MCP客户端
🚀 特色
-
超最小配置:在两行内启动服务器或客户端。
-
简单工具创建:在你的
tools.py文件中写入普通函数——无需装饰器或特殊封装器——这些函数会作为工具被纳入MCP服务器自动使用。
本页由 AI 翻译,技术细节请以原文为准。
README
MCP-123
The easiest way to run an MCP server & client (2 lines each)
🚀 Features
-
Ultra-minimal setup: Start a server or client in 2 lines.
-
Easy tool creation: Write normal functions in your
tools.pyfile—no decorators or special wrappers needed—and they get included as tools that your MCP server can use automatically. -
OpenAI integration: The client uses your OpenAI API key to answer questions, calling tools as needed.
🖥️ Quickstart
1. Install Requirements
pip install -r requirements.txt
2. Create Your Tools
Define your functions in tools.py. No decorators needed, they are automatically added to your MCP server as tools. For example:
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
3. Start the MCP Server (2 lines)
from mcp123 import server
server.run_server("tools.py", port=9999)
4. Set up the MCP Client (2 lines)
from mcp123.client import McpClient
client = McpClient("http://localhost:9999", "sk-...your OpenAI key...")
5. Use the MCP Client
answer = client.ask("Add 15 and 14.")
print("Answer:", answer)
6. Close the MCP Client when you are done
client.close()
🚀 Features
-
Ultra-minimal setup: Start a server or client in 2 lines.
-
Easy tool creation: Write normal functions in your
tools.pyfile—no decorators or special wrappers needed—and they get included as tools that your MCP server can use automatically. -
OpenAI integration: The client uses your OpenAI API key to answer questions, calling tools as needed.
📝 How It Works
-
Server: Loads all top-level functions from
tools.pyand exposes them as MCP tools via HTTP. -
Client: Discovers available tools, sends prompts to OpenAI, and automatically calls tools if needed.
🛠️ Example Output
When you run the client, you’ll see:
Tools discovered:
[ ...list of tools... ]
Answer: 29
🔑 Requirements
-
Python 3.11+
-
OpenAI API key (for the client)
📢 Why MCP123?
-
Zero boilerplate: No need to write schemas or wrappers—just write functions.
-
LLM-native: Designed for seamless LLM tool use.
-
Extensible: Add more tools by simply adding functions.
🤝 Credits
-
Built with FastMCP
-
Inspired by the Model Context Protocol (MCP)
📬 Feedback & Contributions
Pull requests and issues are welcome, but only if they are in ALL-CAPS.
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →