---
title: "When AI talks to AI: MCP Extension for simple agent queries"
date: 2026-04-24
description: "I have developed a small extension called nanoclaw-mcp-ext. With it, my coding assistant Pi can communicate directly with my AI agent. An exciting use case for the Model Context Protocol."
translationKey: "pi-carson-mcp-post"
---

A few weeks ago, I talked about [my AI job application agent](/blog/ki-bewerbungsagent/). Since then, the system has become much more than that: It has grown into a full-fledged digital assistant. It coordinates my private and family calendars, autonomously checks my emails, manages my Bring! shopping list, tracks open to-dos, stores my knowledge in a long-term memory, and tracks my location to be able to execute location-dependent tasks precisely when needed (e.g., for local recommendations or mobility planning). In short: The system massively relieves me of everyday administrative tasks—and usually does so better (and more patiently) than I ever could.

At the same time, I use the [Pi Coding Agent](https://github.com/mariozechner/pi-coding-agent) for my programming projects, a fantastic AI-supported assistant right in the terminal. Often, I am working deeply focused on some code snippet, and suddenly a private to-do comes to mind, or I want to give my AI agent an instruction (e.g., "Add coffee beans to the shopping list") without breaking out of my terminal flow.

That raised the question: **Can't the two simply talk to each other?**

The answer is a clear yes—and the magic word is the **Model Context Protocol (MCP)**.

## The Bridge: nanoclaw-mcp-ext

Over the last few hours, I wrote a small extension for Pi: `nanoclaw-mcp-ext`. 
The idea behind it is quite simple: Carson runs as an agent in a [NanoClaw instance](https://nanoclaw.dev/) on my server and can provide MCP tools through it. The new Pi extension connects to this NanoClaw MCP server via an HTTP transport.

As soon as Pi is started, the extension authenticates with a token, queries which tools Carson offers, and registers them dynamically directly in Pi.

### What the whole thing looks like in everyday life (Two Use Cases)

Imagine I'm sitting in the terminal, programming an application together with Pi, and I want to start a longer "deep work" phase. I briefly need to check if an appointment in the family calendar is about to interfere.

Previously, I would have had to leave the terminal and open my calendar separately. Today it looks like this:

**Me (to Pi):** *"Ask my agent if I have any appointments in the next two hours. If not, let's start with the big database refactoring."*

**Pi:** Autonomously executes the newly loaded tool, connects to the NanoClaw instance, passes the message to the agent, waits for its calendar check, and gives me the answer right in the terminal.

Example output from Pi in the terminal:
> *The agent reports that you have no appointments until 5:30 PM. So we have a free time window for the refactoring—let's go!*

Another everyday scenario: I drink the last cup of coffee while coding. I simply tell Pi: *"Tell the agent to add coffee beans to my Bring! shopping list."* Pi forwards this to my system, which uses its Bring! integration, and the problem is delegated without me having to interrupt my workflow for even a single second.

So it is no longer just a human chatting with an AI, but Pi independently decides *when* to consult my AI agent to answer my questions or delegate tasks. This feels almost a bit like AI magic.

## A Look Under the Hood

### The Extension (Pi Side)
Out of the box, Pi does not have native MCP support for tools. That's why I developed the `nanoclaw-mcp-ext` extension. It is written in TypeScript and establishes a `StreamableHTTPClientTransport` connection to the NanoClaw instance when a Pi session starts (via the `session_start` event) to dynamically register the tools.

```typescript
// A small excerpt of how Pi loads my AI agent's tools:
const client = new Client({ name: "pi-mcp-client", version: "1.0.0" }, { capabilities: { tools: {} } });
await client.connect(transport);
const { tools } = await client.listTools();

// All tools are made available to Pi
for (const tool of tools) {
  pi.registerTool({
    name: tool.name,
    description: tool.description,
    // ...
  });
}
```

### Integration in Claude Code
Unlike Pi, `claude` already supports the Model Context Protocol natively. No dedicated extension is needed here, just a configuration in `mcp.json`. I simply deposited the endpoint of my AI agent there, and `claude` accesses it directly:

```json
{
  "mcpServers": {
    "nanoclaw": {
      "command": "bash",
      "args": ["-c", "curl -s -H \"Authorization: Bearer $NANOCLAW_MCP_TOKEN\" http://localhost:3002/mcp"]
    }
  }
}
```

### The Server Side (NanoClaw Side)
The heart of the communication lies in `mcp-server.ts` within the NanoClaw instance. An `McpServer` is started there, which acts as a bridge between the MCP protocol and the internal messaging system of my AI agent.

The most technically exciting part about this is the `McpChannel` class:
- **Injection:** When Pi makes a request, the MCP server injects this message as a temporary message into a chat channel of the agent.
- **Waiting:** A `Promise` waits with a timeout for the agent to write a reply in this specific channel.
- **Debounce:** Since the agent often responds in multiple messages, the MCP channel uses a "debounce" procedure that pieces together the collected text chunks into a single response only after a brief silence (when the agent has finished typing).

This way, the agent is quasi "remote-controlled" and can react like a native tool for Pi without even noticing that the request is coming from a completely different environment.

For security reasons, the connection is usually secured via an **SSH tunnel**, as I do not want to expose the MCP protocol directly to the internet.

## Conclusion: Agent Collaboration is the Future

It has something almost magical when one AI (Pi) suddenly decides to call a tool to ask another AI (Carson) for advice, data, or the execution of a task. We are slowly moving in a direction where we no longer just have "one" monolithic AI helper, but an entire network of specialized agents interacting seamlessly with each other via standards like MCP.

By the way, the code for the extension (`nanoclaw-mcp-ext`) can be found on my [Codeberg profile](ssh://git@codeberg.org/gurix/nanoclaw-mcp-ext.git). So, for anyone who wants to pair their own Pi agent with a NanoClaw server: Have fun experimenting!
