MCP Server: Claude Desktop + локальные инструменты
Model Context Protocol (MCP) — открытый стандарт Anthropic для подключения AI-агентов к внешним данным и инструментам. MCP-серверы позволяют Claude работать с файловой системой, базами данных, API и браузером прямо из чата.
Архитектура MCP
MCP состоит из трёх компонентов: Host (Claude Desktop, Claude Code), Client (встроен в Host), Server (локальный процесс с инструментами). Сервер предоставляет: Tools (действия), Resources (данные) и Prompts (шаблоны).
Установка Claude Desktop
Скачайте с claude.ai/download. Конфигурация MCP-серверов находится в:
# macOS/Linux
~/.config/claude/claude_desktop_config.json
# Windows
%APPDATA%\Claude\claude_desktop_config.jsonПодключение готовых MCP-серверов
# claude_desktop_config.json
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/projects"]
},
"sqlite": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-sqlite", "--db-path", "/data/mydb.sqlite"]
},
"brave-search": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-brave-search"],
"env": {"BRAVE_API_KEY": "your-key"}
}
}
}Создание собственного MCP-сервера на Python
pip install mcpfrom mcp.server import Server
from mcp.server.stdio import stdio_server
from mcp import types
import asyncio
server = Server("my-hosting-tools")
@server.list_tools()
async def list_tools():
return [
types.Tool(
name="check_domain",
description="Проверить доступность домена",
inputSchema={
"type": "object",
"properties": {
"domain": {"type": "string", "description": "Доменное имя"}
},
"required": ["domain"]
}
)
]
@server.call_tool()
async def call_tool(name: str, arguments: dict):
if name == "check_domain":
domain = arguments["domain"]
import socket
try:
socket.gethostbyname(domain)
return [types.TextContent(type="text", text=f"Домен {domain} активен")]
except:
return [types.TextContent(type="text", text=f"Домен {domain} недоступен")]
async def main():
async with stdio_server() as streams:
await server.run(*streams, server.create_initialization_options())
asyncio.run(main())# Добавить в claude_desktop_config.json
{
"mcpServers": {
"hosting-tools": {
"command": "python3",
"args": ["/path/to/my-mcp-server.py"]
}
}
}Экосистема MCP: На mcp.so и github.com/modelcontextprotocol/servers доступны сотни готовых серверов: GitHub, PostgreSQL, Google Drive, Slack, Puppeteer и многие другие.