Crate mcp_core

Source
Expand description

§Model Context Protocol (MCP) Core Library

mcp-core is a Rust implementation of the Model Context Protocol (MCP), an open protocol for interaction between AI models and tools/external systems.

This library provides a comprehensive framework for building both MCP servers (tool providers) and MCP clients (model interfaces), with support for:

  • Bidirectional communication between AI models and external tools
  • Tool registration, discovery, and invocation
  • Resource management
  • Transport-agnostic design (supporting both SSE and stdio)
  • Standardized request/response formats using JSON-RPC

§Architecture

The library is organized into several main components:

  • Client: Implementation of the MCP client for connecting to servers
  • Server: Implementation of the MCP server for exposing tools to clients
  • Protocol: Core protocol implementation using JSON-RPC
  • Types: Data structures representing MCP concepts
  • Transport: Network transport abstraction (SSE, stdio)
  • Tools: Framework for registering and invoking tools

§Usage

For examples of how to use this library, see the examples/ directory:

  • echo_server.rs: A simple MCP server implementation
  • echo_server_macro.rs: Using the #[tool] macro for simpler integration
  • echo_client.rs: A client connecting to an MCP server

§Macros

This library includes a set of utility macros to make working with the MCP protocol easier, including helpers for creating various types of tool responses.

Modules§

client
MCP Client
protocol
MCP Protocol Implementation
server
MCP Server
tools
MCP Tools Management
transport
MCP Transport Layer
types

Macros§

tool_audio_content
Creates an audio content object for tool responses.
tool_error_response
Creates a tool response with error information.
tool_image_content
Creates an image content object for tool responses.
tool_resource_content
Creates a resource content object for tool responses.
tool_text_content
Creates a text content object for tool responses.
tool_text_response
Creates a tool response with text content.