الانتقال إلى المحتوى الرئيسي

ابحث في النماذج والأدوات والخدمات والشركات والمزودين وواجهات API والخطط والمقالات والأخبار.

بروتوكول MCPمتوسط 45 دقيقة

ابنِ أول خادم MCP: دليل عملي خطوة بخطوة

من الصفر إلى خادم يعمل: جهّز المشروع وعرّف الأدوات واربط العميل واختبر — كل ذلك في نحو ساعة.

ابنِ أول خادم MCP: دليل عملي خطوة بخطوة

What you will have at the end

A small but real MCP server with two tools (reading a file and counting words), registered in a real client and working. About an hour of work.

Step 1: scaffold the project

Create a folder, init a Python virtualenv or a Node project, and install the official MCP SDK. The whole server fits in one file; do not over-engineer it.

Step 2: define your first tool

Every tool has three parts: a name, a description (what the model reads to choose the tool) and an input schema. Deliberately start simple — say, "read the contents of a text file". Write the description seriously: "takes a file path and returns the full text" beats "read".

Step 3: connect it to a client

Register the server in your MCP client (editor or assistant) with one config entry: name, run command and arguments. If the connection fails, it is almost always one of: wrong executable path, an import error, or a stray print to stdout corrupting the protocol.

Step 4: test and debug

Call the tool in a chat and check three things: does the model pick the right tool? Does the output come back clean? And with bad input (a missing file), does it get a useful error message? Add the second tool right here, so the pattern "define → register → test" sticks.

Where to go next

After your first server, build something more useful: an internal database, a team API, a daily automation. The same four steps repeat — input schemas just get more professional and error handling more precise.