MyAIServ MCP Server
MCP 服务器 - 模型上下文协议 API
MCP Server 是基于 FastAPI 的模型上下文协议 (MCP) 实现,为 LLM 模型和应用程序之间的交互提供了标准化接口。
特点
🚀 基于 FastAPI 和异步操作的高性能 API
🔄**提供全面的 MCP 支持,**包括资源、工具、提示和采样
📊 通过 Prometheus 和 Grafana 进行监控和指标
🧩 通过简单的界面添加新工具的可扩展性
📝 GraphQL API ,可灵活处理数据
💬 WebSocket 支持实时交互
🔍 通过与 Elasticsearch 集成进行语义搜索
🗃️ 通过 Redis缓存以提高性能
📦通过 Poetry管理依赖项以实现可靠的包管理
Related MCP server: microCMS MCP Server
入门
安装
克隆存储库:
git clone https://github.com/yourusername/myaiserv.git cd myaiserv安装 Poetry(如果尚未安装):
curl -sSL https://install.python-poetry.org | python3 -通过 Poetry 安装依赖项:
poetry install
启动服务器
poetry run uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload或者通过 just 实用程序:
just run启动后,API 可在以下网址访问: http://localhost:8000
API 文档
Swagger 用户界面: http://localhost:8000/docs
ReDoc: http://localhost:8000/redoc
GraphQL 游乐场: http://localhost:8000/graphql
项目结构
myaiserv/
├── app/
│ ├── core/ # Базовые компоненты MCP
│ │ ├── base_mcp.py # Абстрактные классы MCP
│ │ └── base_sampling.py # Базовые классы для сэмплирования
│ ├── models/ # Pydantic модели
│ │ ├── mcp.py # Модели данных MCP
│ │ └── graphql.py # GraphQL схема
│ ├── services/ # Бизнес-логика
│ │ └── mcp_service.py # Сервис MCP
│ ├── storage/ # Хранилище данных
│ ├── tools/ # Инструменты MCP
│ │ ├── example_tool.py # Примеры инструментов
│ │ └── text_processor.py # Инструмент обработки текста
│ ├── utils/ # Утилиты
│ └── main.py # Точка входа FastAPI
├── app/tests/ # Тесты
├── docs/ # Документация
│ └── MCP_API.md # Описание API
├── pyproject.toml # Конфигурация Poetry и инструментов
└── .justfile # Задачи для утилиты just可用工具
文件系统工具
支持读取、写入、删除和列出文件的文件系统工具。
curl -X POST "http://localhost:8000/tools/file_operations" \
-H "Content-Type: application/json" \
-d '{"operation": "list", "path": "."}'天气工具
通过坐标获取天气数据的工具。
curl -X POST "http://localhost:8000/tools/weather" \
-H "Content-Type: application/json" \
-d '{"latitude": 37.7749, "longitude": -122.4194}'文本分析工具
一种文本分析工具,包括情感检测和总结。
curl -X POST "http://localhost:8000/tools/text_analysis" \
-H "Content-Type: application/json" \
-d '{"text": "Example text for analysis", "analysis_type": "sentiment"}'文本处理工具
文本处理工具,包括格式化、统计计算、实体提取。
curl -X POST "http://localhost:8000/tools/text_processor" \
-H "Content-Type: application/json" \
-d '{"operation": "statistics", "text": "Example text", "stat_options": ["chars", "words"]}'图像处理工具
支持调整大小、裁剪和应用过滤器的图像处理工具。
curl -X POST "http://localhost:8000/tools/image_processing" \
-H "Content-Type: application/json" \
-d '{"operation": "resize", "image_data": "base64...", "params": {"width": 800, "height": 600}}'WebSocket API
要连接到 WebSocket API:
const socket = new WebSocket("ws://localhost:8000/ws");
socket.onopen = () => {
socket.send(JSON.stringify({
type: "initialize",
id: "my-request-id"
}));
};
socket.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log("Received:", data);
};GraphQL API
通过 GraphQL 进行查询的示例:
# Получение списка всех инструментов
query {
getTools {
name
description
}
}
# Выполнение инструмента
mutation {
executeTool(input: {
name: "text_processor",
parameters: {
operation: "statistics",
text: "Example text for analysis"
}
}) {
content {
type
text
}
is_error
}
}运行测试
要运行测试,请使用 Poetry:
poetry run pytest或者通过 just 实用程序:
just testDocker
通过 Docker Compose 构建和运行
docker compose up -d要启动单个服务:
docker compose up -d web redis elasticsearch与 LLM 集成
MCP Server 提供了标准化接口,可与来自不同供应商的 LLM 模型集成:
import httpx
async def query_mcp_with_llm(prompt: str):
async with httpx.AsyncClient() as client:
# Запрос к MCP для получения контекста и инструментов
tools_response = await client.get("http://localhost:8000/tools")
tools = tools_response.json()["tools"]
# Отправка запроса к LLM с включением MCP контекста
llm_response = await client.post(
"https://api.example-llm.com/v1/chat",
json={
"messages": [
{"role": "system", "content": "You have access to the following tools:"},
{"role": "user", "content": prompt}
],
"tools": tools,
"tool_choice": "auto"
}
)
return llm_response.json()指标和监控
MCP 服务器通过/metrics端点提供 Prometheus 格式的指标。指标包括:
每个工具的请求数量
查询执行时间
错误和异常
发展
格式化代码并使用 linters 检查:
just fmt
just lint执照
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/eagurin/myaiserv'
If you have feedback or need assistance with the MCP directory API, please join our Discord server