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 implementationecho_server_macro.rs
: Using the#[tool]
macro for simpler integrationecho_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.