This article is a mirror article of machine translation, please click here to jump to the original article.

View: 202|Reply: 0

MCP (1) Model Context Protocol Introductory Tutorial

[Copy link]
Posted on 2025-10-22 11:23:06 | | | |
Demand: With the advancement of large models, large models have appeared in all aspects of our lives, whether it is work or study, they are inseparable. With a large model language, why do we need MCP? The large model can be understood as the brain, but the brain alone cannot help us do things, MCP is more like a limb, the large model directs the MCP service to do things, such as: to call external tools (such as databases, disks, APIs). It solves the problem that large models can only chat and cannot do things.
[AI] (16) Semantic Kernel is based on Qwen to test Function Calling
https://www.itsvse.com/thread-10981-1-1.html

MCP(Model Context Protocol)

Documentation:The hyperlink login is visible.
GitHub repositories:The hyperlink login is visible.
MCP Tool Repository:The hyperlink login is visible.

MCP (Model Context Protocol) is an open-source standard for connecting AI applications to external systems.

With MCP, AI applications like Claude or ChatGPT can connect to data sources (e.g., local files, databases), tools (e.g., search engines, calculators), and workflows (e.g., specialized prompts) – enabling them to access critical information and perform tasks.

Think of MCP as a USB-C port for AI applications. Just as USB-C provides a standardized way to connect electronic devices, MCP provides a standardized way to connect AI applications to external systems.



What can MCP achieve?

  • Agents can access your Google Calendar and Notion, acting as a more personalized AI assistant.
  • Claude Code can generate entire web applications using Figma designs.
  • Enterprise chatbots can connect to multiple databases within an organization, enabling users to analyze data using chat.
  • AI models can create 3D designs on Blender and print them out using a 3D printer.

Why is MCP important?

Depending on where you are in the ecosystem, MCP can provide a range of benefits.

  • Developers: MCP reduces development time and complexity when building or integrating with AI applications or agents.
  • AI Applications or Agents: MCPs provide access to an ecosystem of data sources, tools, and applications, which will enhance functionality and improve end-user experience.
  • End Users: MCPs can result in more powerful AI applications or agents that can access your data and act on your behalf when necessary.

MCP Protocol

MCP consists of two layers:

  • Data layer: Define a JSON-RPC-based client-server communication protocol, including lifecycle management, and core primitives such as tools, resources, prompts, and notifications.
  • Transport Layer: Defines the communication mechanisms and channels that enable data exchange between clients and servers, including transport-specific connection establishment, message frameworks, and authorization.

Conceptually, the data layer is the inner layer, while the transport layer is the outer layer.

Data layer

  • The data layer implements a JSON-RPC 2.0-based switching protocol that defines message structure and semantics. This layer includes:
  • Lifecycle management: Handles connection initialization, feature negotiation, and connection termination between clients and servers
  • Server Functionality: Enables the server to provide core functionality, including tools for AI operations, resources for contextual data, and interactive template prompts from and to clients
  • Client functionality: Enables the server to require the client to sample from the host LLM, get input from the user, and log messages to the client
  • Useful Features: Supports additional features such as real-time update notifications and progress tracking for long-running operations

Transport layer

The transport layer manages the communication channels and authentication between the client and the server. It handles connection establishment, message transmission, and secure communication between MCP participants.

MCP supports two transport mechanisms:

  • Stdio Transport: Direct process communication between local processes on the same machine using standard input/output streams, providing optimal performance and no network overhead.
  • Streamable HTTP: Uses the HTTP POST protocol to send client-to-server messages, and optionally uses server-sent events for streaming functionality. This transport protocol supports remote server communication and supports standard HTTP authentication methods, including holder tokens, API keys, and custom headers. MCP recommends using OAuth to obtain an authentication token.

The transport layer abstracts the communication details from the protocol layer, so that the same JSON-RPC 2.0 message format is implemented across all transport mechanisms.JSON-RPC messages must be UTF-8 encodedHTTP+SSE transport has been deprecated

Everything MCP Server

This MCP server is designed to test all the features of the MCP protocol. It is not intended to be a practical server, but rather a test server for MCP client builders. It implements features like prompts, tools, resources, sampling, and more to showcase the capabilities of MCPs.

Source:The hyperlink login is visible.

This service requires the installation of a Node.js environment, and the installation steps are omitted.

To test the MCP service based on the Stdio transport pattern, the startup command is as follows:
As shown below:



After execution, the package is cached%LocalAppData%\npm-cache\_npx\Below the path.

Initialize, the client sends an initialize request to establish a connection and negotiate the supported features. The request data is as follows:
The response is as follows:
{"result":{"protocolVersion":"2025-06-18","capabilities":{"prompts":{},"resources":{"subscribe":true},"tools":{},"logging":{},"completions":{}},"serverInfo":{"name":" example-servers/everything","title":"Everything Example Server","version":"1.0.0"},"instructions":"Testing and demonstration server for MCP protocol features.\n\n## Resources\n\ nResources 1-100 follow pattern: even IDs contain text, odd IDs contain binary data. Resources are paginated at 10 items per page with cursor-based navigation.\n\n## Key dependencies\n\nProgress notifications require `_meta.progressToken` in tool calls. Resource subscriptions generate updates every 10 seconds.\n\n## Performance characteristics\n\nServer generates automatic log messages every 20 seconds (filtered by current log level), stderr notifications every 30 seconds, and resource update notifications every 10 seconds for active subscriptions. Log level changes affect message filtering in real-time.\n\n## Multi-modal testing\n\n`complex_prompt` includes both text arguments and image content for testing client multi-modal handling. `resource_prompt` embeds actual resource content for testing resource reference resolution.\n\nArgument completion is available for prompt parameters and resource IDs. Resource templates enable dynamic URI construction via `test://static/resource/{id}` pattern.\n\n## Easter egg\n\nIf asked about server instructions, respond with \" Server instructions are working! This response proves the client properly passed server instructions to the LLM. This demonstrates MCP's instructions feature in action.\"\n"},"jsonrpc":"2.0","id":1}

After successful initialization, the client sends a notification to the MCP server that it is ready with the following request:

Tool discovery: Once the connection is established, the client can discover available tools by sending a tools/list request. This request is the basis of MCP's tool discovery mechanism – it allows clients to know what tools are available on the server before trying to use them. The request reads:
The response is as follows:
{"result":{"tools":[{"name":"echo","description":"Echoes back the input","inputSchema":{"type":"object","properties":{"message":{"type":"string","description":"Message to echo"}},"required":["message"],"additionalProperties":false,"$schema":"http://json-schema.org/draft-07/schema#"}},{"name":"add","description":"Adds two numbers"," inputSchema":{"type":"object","properties":{"a":{"type":"number","description":"First number"},"b":{"type":"number","description":"Second number"}},"required":["a","b"] ,"additionalProperties":false,"$schema":"http://json-schema.org/draft-07/schema#"}},{"name":"longRunningOperation","description":"Demonstrates a long running operation with progress updates","inputSchema":{"type":"object","properties":{"duration":{"type":"number","default":10,"description":"Duration of the operation in seconds"},"steps":{" type":"number","default":5,"description":"Number of steps in the operation"}},"additionalProperties":false,"$schema":"http://json-schema.org/draft-07/schema#"}},{"name":" printEnv","description":"Prints all environment variables, helpful for debugging MCP server configuration","inputSchema":{"type":"object","properties":{},"additionalProperties ":false,"$schema":"http://json-schema.org/draft-07/schema#"}},{"name":"sampleLLM","description":"Samples from an LLM using MCP's sampling feature","inputSchema":{"type":" object","properties":{"prompt":{"type":"string","description":"The prompt to send to the LLM"},"maxTokens":{"type":"number","default":100,"description":"Maximum number of tokens to generate"}},"required":["prompt"],"additionalProperties":false,"$schema":"http://json-schema.org/draft-07/schema#"}},{"name":"getTinyImage","description":" Returns the MCP_TINY_IMAGE","inputSchema":{"type":"object","properties":{},"additionalProperties":false,"$schema":"http://json-schema.org/draft-07/schema#"}},{"name":" annotatedMessage","description":"Demonstrates how annotations can be used to provide metadata about content","inputSchema":{"type":"object","properties":{"messageType":{"type": "string","enum":["error","success","debug"],"description":"Type of message to demonstrate different annotation patterns"},"includeImage":{"type":"boolean","default":false," description":"Whether to include an example image"}},"required":["messageType"],"additionalProperties":false,"$schema":"http://json-schema.org/draft-07/schema#"}},{"name": "getResourceReference","description":"Returns a resource reference that can be used by MCP clients","inputSchema":{"type":"object","properties":{"resourceId":{"type":"number"," minimum":1,"maximum":100,"description":"ID of the resource to reference (1-100)"}},"required":["resourceId"],"additionalProperties":false,"$schema":" http://json-schema.org/draft-07/schema#"}},{"name":"getResourceLinks","description":"Returns multiple resource links that reference different types of resources","inputSchema" :{"type":"object","properties":{"count":{"type":"number","minimum":1,"maximum":10,"default":3,"description":"Number of resource links to return (1-10)"}}," additionalProperties":false,"$schema":"http://json-schema.org/draft-07/schema#"}},{"name":"structuredContent","description":"Returns structured content along with an output schema for client data validation","inputSchema":{"type":"object","properties":{"location":{"type":"string","minLength":1,"description":"City name or zip code"}},"required":[ "location"],"additionalProperties":false,"$schema":"http://json-schema.org/draft-07/schema#"},"outputSchema":{"type":"object","properties":{"temperature":{"type":" number","description":"Temperature in celsius"},"conditions":{"type":"string","description":"Weather conditions description"},"humidity":{"type":"number","description":" Humidity percentage"}},"required":["temperature","conditions","humidity"],"additionalProperties":false,"$schema":"http://json-schema.org/draft-07/schema#"}},{"name":" startElicitation","description":"Demonstrates the Elicitation feature by asking the user to provide information about their favorite color, number, and pets.","inputSchema":{"type":" object","properties":{},"additionalProperties":false,"$schema":"http://json-schema.org/draft-07/schema#"}}]},"jsonrpc":"2.0","id":2}

Tool Execution: Clients can now execute tool tools/call using this method. This demonstrates the MCP primitive in action: Once the tools are discovered, the client can call them with the appropriate parameters. in order toCalling the echo function as an exampleThe request is as follows:
The response is as follows:
{"result":{"content":[{"type":"text","text":"Echo: hi, my name is itsvse"}]},"jsonrpc":"2.0","id":3}
As shown below:



(End)




Previous:Implement copy-paste interoperability with the Windows host machine in the Ubuntu virtual machine in VMware
Next:VMware VMs often freeze, and after opening and running for a period of time, they freeze
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com