Loading
Loading
MCP (Model Context Protocol) هو بروتوكول مفتوح طوّرته Anthropic يسمح لـ Claude بالتفاعل مع أدوات وأنظمة خارجية بطريقة آمنة وموحدة.
قبل MCP، كان كل تكامل يتطلب كوداً مخصصاً. مع MCP:
Claude ←→ MCP Protocol ←→ أي أداة/نظام
Claude يتحدث بـ MCP، والأداة تتحدث بـ MCP، والتكامل يحدث تلقائياً.
1. MCP Server تطبيق صغير يكشف وظائف الأداة عبر بروتوكول MCP.
2. MCP Client هو Claude Code أو Claude.ai — يتصل بالـ server ويستخدم وظائفه.
3. Tools الإجراءات التي يمكن لـ Claude استدعاؤها (read_file, run_query, create_issue...).
4. Resources بيانات يمكن لـ Claude قراءتها (قواعد بيانات، ملفات، APIs).
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed"]
}
}
}
يتيح لـ Claude قراءة/كتابة الملفات في المسار المحدد فقط.
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxx" }
}
}
}
يتيح لـ Claude إنشاء Issues، مراجعة PRs، البحث في الكود.
{
"mcpServers": {
"supabase": {
"command": "npx",
"args": ["-y", "@supabase/mcp-server-supabase"],
"env": {
"SUPABASE_URL": "https://xxx.supabase.co",
"SUPABASE_SERVICE_ROLE_KEY": "eyJxxx"
}
}
}
}
يتيح لـ Claude الاستعلام عن قاعدة البيانات وتنفيذ SQL.
{
"mcpServers": {
"brave-search": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-brave-search"],
"env": { "BRAVE_API_KEY": "BSAxxxx" }
}
}
}
يتيح لـ Claude البحث على الإنترنت في الوقت الفعلي.
# مشاهدة الـ servers المتصلة
claude mcp list
# إضافة server
claude mcp add filesystem -- npx -y @modelcontextprotocol/server-filesystem ~/projects
# إزالة server
claude mcp remove filesystem
أو يدوياً في ~/.config/claude/mcp.json:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/ahmed/projects"]
},
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_your_token"
}
}
}
}
إذا أردت ربط Claude بنظامك الداخلي، يمكنك بناء Server خاص بك في Python أو TypeScript.
مثال بسيط بـ Python:
from mcp.server import Server
from mcp.types import Tool, TextContent
import mcp.server.stdio
server = Server("my-company-tools")
@server.list_tools()
async def list_tools():
return [
Tool(
name="get_employee_info",
description="احصل على معلومات موظف بالـ ID",
inputSchema={
"type": "object",
"properties": {
"employee_id": {"type": "string"}
},
"required": ["employee_id"]
}
)
]
@server.call_tool()
async def call_tool(name: str, arguments: dict):
if name == "get_employee_info":
# هنا تقرأ من قاعدة بياناتك الداخلية
emp_id = arguments["employee_id"]
info = get_from_db(emp_id)
return [TextContent(type="text", text=str(info))]
if __name__ == "__main__":
mcp.server.stdio.run(server)
قاعدة ذهبية: امنح Claude الأذونات الأدنى الكافية.
# بناء MCP Server بسيط بـ Python
# يربط Claude بقاعدة بيانات SQLite محلية
# التثبيت: pip install mcp
import sqlite3
import asyncio
from mcp.server import Server
from mcp.types import Tool, TextContent, Resource, ReadResourceResult
import mcp.server.stdio
# إنشاء قاعدة بيانات تجريبية
def init_db():
conn = sqlite3.connect("academy.db")
conn.execute("""
CREATE TABLE IF NOT EXISTS students (
id TEXT PRIMARY KEY,
name TEXT,
email TEXT,
courses_enrolled INTEGER DEFAULT 0,
last_login TEXT
)
""")
conn.execute("""
INSERT OR IGNORE INTO students VALUES
('s001', 'أحمد محمد', 'ahmed@example.com', 3, '2026-06-01'),
('s002', 'سارة علي', 'sara@example.com', 5, '2026-06-05'),
('s003', 'محمد خالد', 'm.khalid@example.com', 1, '2026-05-28')
""")
conn.commit()
conn.close()
init_db()
# إنشاء الـ MCP Server
server = Server("academy-db-server")
@server.list_tools()
async def list_tools() -> list[Tool]:
"""قائمة الأدوات التي يمكن لـ Claude استخدامها"""
return [
Tool(
name="get_student",
description="احصل على معلومات طالب بالـ ID",
inputSchema={
"type": "object",
"properties": {
"student_id": {
"type": "string",
"description": "معرّف الطالب (مثل: s001)"
}
},
"required": ["student_id"]
}
),
Tool(
name="list_students",
description="احصل على قائمة كل الطلاب",
inputSchema={"type": "object", "properties": {}}
),
Tool(
name="run_query",
description="تشغيل استعلام SQL للقراءة فقط",
inputSchema={
"type": "object",
"properties": {
"sql": {
"type": "string",
"description": "استعلام SELECT فقط"
}
},
"required": ["sql"]
}
)
]
@server.call_tool()
async def call_tool(name: str, arguments: dict) -> list[TextContent]:
"""تنفيذ الأداة المطلوبة"""
conn = sqlite3.connect("academy.db")
conn.row_factory = sqlite3.Row
try:
if name == "get_student":
row = conn.execute(
"SELECT * FROM students WHERE id = ?",
(arguments["student_id"],)
).fetchone()
if not row:
return [TextContent(type="text", text="الطالب غير موجود")]
result = dict(row)
return [TextContent(type="text", text=str(result))]
elif name == "list_students":
rows = conn.execute("SELECT * FROM students").fetchall()
result = [dict(r) for r in rows]
return [TextContent(type="text", text=str(result))]
elif name == "run_query":
sql = arguments["sql"].strip().upper()
# أمان: SELECT فقط
if not sql.startswith("SELECT"):
return [TextContent(type="text", text="❌ مسموح فقط بـ SELECT")]
rows = conn.execute(arguments["sql"]).fetchall()
result = [dict(r) for r in rows]
return [TextContent(type="text", text=str(result))]
finally:
conn.close()
return [TextContent(type="text", text="أداة غير معروفة")]
async def main():
print("🚀 MCP Academy Server يعمل...")
async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
await server.run(read_stream, write_stream, server.create_initialization_options())
if __name__ == "__main__":
asyncio.run(main())
# ──────────────────────────────────────
# إضافة الـ Server لـ Claude Code:
# claude mcp add academy-db -- python path/to/this/server.py