apache / apache/pulsar-client-python
[Example] Add MCP server example for AI agent integration
- 主要語言
- Python
- 星號
- 75
- 分支
- 53
- PR 合併指標
- 30 天內沒有已合併 PR
描述
### Motivation
The `examples/` directory shows basic producer/consumer, async, and RPC patterns, but there is no example demonstrating integration with AI agents.
The [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) is the emerging standard for connecting AI tools (Cursor, Claude Desktop, Windsurf, etc.) to external data sources. An MCP server example would allow developers to interact with Pulsar topics through natural language, bridging messaging infrastructure and the AI agent ecosystem.
### Proposed Change
Add `examples/mcp_server.py` that exposes three tools via the official MCP Python SDK (`pip install mcp`):
| Tool | Description |
|------|-------------|
| `pulsar_publish` | Publish a message to a topic (supports properties, partition key, delayed delivery) |
| `pulsar_consume` | Consume and auto-acknowledge messages from a subscription |
| `pulsar_peek` | Read messages using a Reader without affecting consumer state |
The example is a standalone script—`mcp` is only required at runtime for this example and is **not** added to the project's `setup.py` dependencies.
### Configuration
Once configured in an MCP-compatible client (e.g. Cursor `~/.cursor/mcp.json`), users can produce and consume Pulsar messages through natural language.
```json
{
"mcpServers": {
"pulsar": {
"command": "python3",
"args": ["examples/mcp_server.py"],
"env": {
"PULSAR_BROKER_URL": "pulsar://localhost:6650"
}
}
}
}
```
I'm happy to submit a PR for this.
貢獻指南
研究方向
先檢視現有的 examples/ 目錄,以及 producer、consumer 和 reader 的 Python 用戶端 API,接著檢查 setup.py,以確認執行階段相依性仍僅供範例使用。實作提議的進入點 examples/mcp_server.py,包含列出的三個工具和文件中說明的環境設定;當獨立腳本能夠提供這些操作,且不變更專案相依性時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend, distributed-systems
- Issue 類型
- 功能
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 58/100