You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[MCP (Model Context Protocol)](https://modelcontextprotocol.io/) is an open protocol that allows AI applications to connect to external tools and data sources.
4
+
5
+
This example demonstrates how to connect to an MCP server via HTTP and use its tools with an agent.cpp agent.
6
+
7
+
## Building Blocks
8
+
9
+
### Tools
10
+
11
+
Tools are dynamically discovered from the MCP server at runtime. The client connects to the server, performs a handshake, and retrieves the available tool definitions.
12
+
13
+
### Callbacks
14
+
15
+
This example uses two shared callbacks from `examples/shared/`:
16
+
17
+
-**LoggingCallback**: Displays tool execution information with colored output showing which tools are called and their results.
18
+
19
+
-**ErrorRecoveryCallback**: Converts tool execution errors into JSON results, allowing the agent to see errors and potentially retry or adjust.
20
+
21
+
## Building
22
+
23
+
> [!IMPORTANT]
24
+
> Check the [llama.cpp build documentation](https://github.com/ggml-org/llama.cpp/blob/master/docs/build.md) to find
25
+
> Cmake flags you might want to pass depending on your available hardware.
-`-m <path>` - Path to the GGUF model file (required)
54
+
-`-u <url>` - MCP server URL (Streamable HTTP transport) (required)
55
+
56
+
## Example
57
+
58
+
This example includes a simple MCP server (`server.py`) with a `calculator` tool that performs basic math operations (similar to the calculator in `examples/shared`).
59
+
60
+
### 1. Start the MCP Server
61
+
62
+
The server uses [uv](https://docs.astral.sh/uv/) inline script metadata, so no installation is needed:
63
+
64
+
```bash
65
+
uv run server.py
66
+
```
67
+
68
+
This starts the MCP server on `http://localhost:8000/mcp`.
0 commit comments